From 985f12f69c52a139a72aecc9b050e71545a90df8 Mon Sep 17 00:00:00 2001 From: AzaharaC Date: Mon, 19 Apr 2021 10:25:51 -0700 Subject: [PATCH] feat(connector-besu,connector-quorum): updated Signed-off-by: AzaharaC --- .../main/typescript/plugin-ledger-connector-besu.ts | 6 +++++- .../deploy-contract-from-json.test.ts | 13 +++++++++++++ .../typescript/plugin-ledger-connector-quorum.ts | 8 ++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts index 0f2fbe8d64..4185553eb5 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts @@ -282,7 +282,11 @@ export class PluginLedgerConnectorBesu contractJSON.networks[networkId].address, ); this.contracts[contractName] = contract; - } else { + } else if ( + req.keychainId == undefined && + req.contractAbi == undefined && + req.contractAddress == undefined + ) { throw new Error( `${fnTag} Cannot invoke a contract without contract instance, the keychainId param is needed`, ); diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts index 22b16e2845..2fbe2485eb 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts @@ -164,6 +164,7 @@ test(testCase, async (t: Test) => { ); const { callOutput: helloMsg } = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.CALL, @@ -218,6 +219,7 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => { const newName = `DrCactus${uuidv4()}`; const setNameOut = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -234,6 +236,7 @@ test(testCase, async (t: Test) => { try { const setNameOutInvalid = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -256,6 +259,7 @@ test(testCase, async (t: Test) => { ); } const { callOutput: getNameOut } = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.CALL, @@ -271,6 +275,7 @@ test(testCase, async (t: Test) => { t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -286,6 +291,7 @@ test(testCase, async (t: Test) => { t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); const response = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -302,6 +308,7 @@ test(testCase, async (t: Test) => { t2.ok(response, "deposit() payable invocation output is truthy OK"); const { callOutput } = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.CALL, @@ -334,6 +341,7 @@ test(testCase, async (t: Test) => { }; const setNameOut = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -347,6 +355,7 @@ test(testCase, async (t: Test) => { try { const setNameOutInvalid = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -366,6 +375,7 @@ test(testCase, async (t: Test) => { } const { callOutput: getNameOut } = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.CALL, @@ -377,6 +387,7 @@ test(testCase, async (t: Test) => { t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -388,6 +399,7 @@ test(testCase, async (t: Test) => { t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); const response = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.SEND, @@ -400,6 +412,7 @@ test(testCase, async (t: Test) => { t2.ok(response, "deposit() payable invocation output is truthy OK"); const { callOutput } = await connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, contractAddress, invocationType: EthContractInvocationType.CALL, diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts index 157edc58f0..4ed179391f 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts @@ -211,7 +211,7 @@ export class PluginLedgerConnectorQuorum ): Promise { const fnTag = `${this.className}#invokeContract()`; const contractName = req.contractName; - let contractInstance: Contract; + let contractInstance: InstanceType; if (req.keychainId != undefined) { const networkId = await this.web3.eth.net.getId(); @@ -262,7 +262,11 @@ export class PluginLedgerConnectorQuorum contractJSON.networks[networkId].address, ); this.contracts[contractName] = contract; - } else { + } else if ( + req.keychainId == undefined && + req.contractAbi == undefined && + req.contractAddress == undefined + ) { throw new Error( `${fnTag} Cannot invoke a contract without contract instance, the keychainId param is needed`, );