Skip to content

Commit

Permalink
test(quorum): 💍 ensure keychain refs work
Browse files Browse the repository at this point in the history
This test verifies that the Quorum connector plugin is indeed capable of
accepting transaction requests that do not contain explicitly the
signing credentials but instead provide a reference to a keychain entry
accessible through the keychain plugin.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Dec 1, 2020
1 parent 0d4769f commit 00b7e62
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
},
"devDependencies": {
"@hyperledger/cactus-common": "0.2.0",
"@hyperledger/cactus-plugin-keychain-memory": "^0.2.0",
"@hyperledger/cactus-test-tooling": "0.2.0",
"@types/express": "4.17.8",
"@types/joi": "14.3.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
LogLevelDesc,
} from "@hyperledger/cactus-common";

import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";

import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";

import {
EthContractInvocationType,
PluginLedgerConnectorQuorum,
Web3SigningCredentialCactusKeychainRef,
Web3SigningCredentialType,
} from "../../../../../main/typescript/public-api";

Expand Down Expand Up @@ -53,16 +56,30 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => {
const [firstHighNetWorthAccount] = highNetWorthAccounts;

const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidV4());

const keychainEntryKey = uuidV4();
const keychainEntryValue = testEthAccount.privateKey;
const keychainPlugin = new PluginKeychainMemory({
instanceId: uuidV4(),
keychainId: uuidV4(),
// pre-provision keychain with mock backend holding the private key of the
// test account that we'll reference while sending requests with the
// signing credential pointing to this keychain entry.
backend: new Map([[keychainEntryKey, keychainEntryValue]]),
logLevel,
});

// Instantiate connector with the keychain plugin that already has the
// private key we want to use for one of our tests
const connector: PluginLedgerConnectorQuorum = new PluginLedgerConnectorQuorum(
{
instanceId: uuidV4(),
rpcApiHttpHost,
logLevel,
pluginRegistry: new PluginRegistry(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
}
);
const testEthAccount = web3.eth.accounts.create(uuidV4());

await connector.transact({
web3SigningCredential: {
Expand Down Expand Up @@ -260,5 +277,51 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => {
t2.end();
});

test("invoke Web3SigningCredentialType.CACTUSKEYCHAINREF", async (t2: Test) => {
const newName = `DrCactus${uuidV4()}`;

const web3SigningCredential: Web3SigningCredentialCactusKeychainRef = {
ethAccount: testEthAccount.address,
keychainEntryKey,
keychainId: keychainPlugin.getKeychainId(),
type: Web3SigningCredentialType.CACTUSKEYCHAINREF,
};

const setNameOut = await connector.invokeContract({
contractAddress,
contractAbi: HelloWorldContractJson.abi,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
gas: 1000000,
web3SigningCredential,
});
t2.ok(setNameOut, "setName() invocation #1 output is truthy OK");

const { callOutput: getNameOut } = await connector.invokeContract({
contractAddress,
contractAbi: HelloWorldContractJson.abi,
invocationType: EthContractInvocationType.CALL,
methodName: "getName",
params: [],
gas: 1000000,
web3SigningCredential,
});
t2.equal(getNameOut, newName, `getName() output reflects the update OK`);

const getNameOut2 = await connector.invokeContract({
contractAddress,
contractAbi: HelloWorldContractJson.abi,
invocationType: EthContractInvocationType.SEND,
methodName: "getName",
params: [],
gas: 1000000,
web3SigningCredential,
});
t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK");

t2.end();
});

t.end();
});

0 comments on commit 00b7e62

Please sign in to comment.