Skip to content

Commit

Permalink
feat(connector-quorum): contractAbi optional parameter
Browse files Browse the repository at this point in the history
Signed-off-by: AzaharaC <a.castano.benito@accenture.com>
  • Loading branch information
AzaharaC authored and petermetz committed Apr 23, 2021
1 parent 26cf7c2 commit c79d763
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { K_CACTUS_BESU_TOTAL_TX_COUNT } from "../../../../../main/typescript/pro

const testCase = "deploys contract via .json file";
const logLevel: LogLevelDesc = "TRACE";
const contractName = "HelloWorld";

test("BEFORE " + testCase, async (t: Test) => {
const pruning = pruneDockerAllIfGithubAction({ logLevel });
Expand Down Expand Up @@ -165,7 +164,6 @@ test(testCase, async (t: Test) => {
);

const { callOutput: helloMsg } = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
Expand Down Expand Up @@ -220,7 +218,6 @@ test(testCase, async (t: Test) => {
test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => {
const newName = `DrCactus${uuidv4()}`;
const setNameOut = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -237,7 +234,6 @@ test(testCase, async (t: Test) => {

try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -260,7 +256,6 @@ test(testCase, async (t: Test) => {
);
}
const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
Expand All @@ -276,7 +271,6 @@ test(testCase, async (t: Test) => {
t2.equal(getNameOut, newName, `getName() output reflects the update OK`);

const getNameOut2 = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -292,7 +286,6 @@ test(testCase, async (t: Test) => {
t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK");

const response = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -309,7 +302,6 @@ test(testCase, async (t: Test) => {
t2.ok(response, "deposit() payable invocation output is truthy OK");

const { callOutput } = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
Expand Down Expand Up @@ -342,7 +334,6 @@ test(testCase, async (t: Test) => {
};

const setNameOut = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -356,7 +347,6 @@ test(testCase, async (t: Test) => {

try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -376,7 +366,6 @@ test(testCase, async (t: Test) => {
}

const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
Expand All @@ -388,7 +377,6 @@ test(testCase, async (t: Test) => {
t2.equal(getNameOut, newName, `getName() output reflects the update OK`);

const getNameOut2 = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -400,7 +388,6 @@ test(testCase, async (t: Test) => {
t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK");

const response = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
Expand All @@ -413,7 +400,6 @@ test(testCase, async (t: Test) => {
t2.ok(response, "deposit() payable invocation output is truthy OK");

const { callOutput } = await connector.invokeContract({
contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,17 @@
"default": [],
"items": {}
},
"contractAbi": {
"description": "The application binary interface of the solidity contract, optional parameter",
"type": "array",
"items": {},
"nullable": false
},
"contractAddress": {
"description": "Address of the solidity contract, optional parameter",
"type": "string",
"nullable": false
},
"value": {
"oneOf": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ export interface InvokeContractV1Request {
* @memberof InvokeContractV1Request
*/
params: Array<any>;
/**
* The application binary interface of the solidity contract, optional parameter
* @type {Array<any>}
* @memberof InvokeContractV1Request
*/
contractAbi?: Array<any>;
/**
* Address of the solidity contract, optional parameter
* @type {string}
* @memberof InvokeContractV1Request
*/
contractAddress?: string;
/**
*
* @type {string | number}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class PluginLedgerConnectorQuorum
): Promise<InvokeContractV1Response> {
const fnTag = `${this.className}#invokeContract()`;
const contractName = req.contractName;
let contractInstance: Contract;

if (req.keychainId != undefined) {
const networkId = await this.web3.eth.net.getId();
Expand Down Expand Up @@ -267,7 +268,19 @@ export class PluginLedgerConnectorQuorum
);
}

const contractInstance = this.contracts[contractName];
contractInstance = this.contracts[contractName];
if (req.contractAbi != undefined) {
let abi;
if (typeof req.contractAbi === "string") {
abi = JSON.parse(req.contractAbi);
} else {
abi = req.contractAbi;
}

const { contractAddress } = req;
contractInstance = new this.web3.eth.Contract(abi, contractAddress);
}

const methodRef = contractInstance.methods[req.methodName];
Checks.truthy(methodRef, `${fnTag} YourContract.${req.methodName}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ test(testCase, async (t: Test) => {

const { callOutput: helloMsg } = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
methodName: "sayHello",
params: [],
Expand All @@ -187,7 +188,8 @@ test(testCase, async (t: Test) => {
const newName = `DrCactus${uuidV4()}`;
const setNameOut = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -203,7 +205,8 @@ test(testCase, async (t: Test) => {
try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -226,7 +229,8 @@ test(testCase, async (t: Test) => {

const getNameOut = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "getName",
params: [],
Expand All @@ -240,7 +244,8 @@ test(testCase, async (t: Test) => {

const { callOutput: getNameOut2 } = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
methodName: "getName",
params: [],
Expand Down Expand Up @@ -291,7 +296,8 @@ test(testCase, async (t: Test) => {
const newName = `DrCactus${uuidV4()}`;
const setNameOut = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -307,7 +313,8 @@ test(testCase, async (t: Test) => {
try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -329,7 +336,8 @@ test(testCase, async (t: Test) => {
}
const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
methodName: "getName",
params: [],
Expand All @@ -344,7 +352,8 @@ test(testCase, async (t: Test) => {

const getNameOut2 = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "getName",
params: [],
Expand Down Expand Up @@ -372,7 +381,8 @@ test(testCase, async (t: Test) => {

const setNameOut = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -385,7 +395,8 @@ test(testCase, async (t: Test) => {
try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "setName",
params: [newName],
Expand All @@ -407,7 +418,8 @@ test(testCase, async (t: Test) => {
}
const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.CALL,
methodName: "getName",
params: [],
Expand All @@ -418,7 +430,8 @@ test(testCase, async (t: Test) => {

const getNameOut2 = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.SEND,
methodName: "getName",
params: [],
Expand Down

0 comments on commit c79d763

Please sign in to comment.