From 0f84af8bda7cac24ff1f674942b174cdf9bcd7cb Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 20 Sep 2023 10:53:09 +0000 Subject: [PATCH 1/3] WIP --- yarn-project/cli/src/encoding.ts | 4 +++- yarn-project/cli/src/index.ts | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/yarn-project/cli/src/encoding.ts b/yarn-project/cli/src/encoding.ts index 50a088cc4c5..0128e10a64d 100644 --- a/yarn-project/cli/src/encoding.ts +++ b/yarn-project/cli/src/encoding.ts @@ -91,7 +91,9 @@ function encodeArg(arg: string, abiType: ABIType, name: string): any { export function encodeArgs(args: any[], params: ABIParameter[]) { if (args.length !== params.length) { throw new Error( - `Invalid number of args provided. Expected: ${params.length}, received: ${args.length}\nReceived args: ${args}`, + `Invalid args provided.\nExpected args: [${params + .map(param => param.name + ': ' + param.type.kind) + .join(', ')}]\nReceived args: ${args}`, ); } return args.map((arg: any, index) => { diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 71e61409f65..fe38efd4508 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -172,11 +172,6 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { const constructor = getAbiFunction(contractAbi, 'constructor'); if (!constructor) throw new Error(`Constructor not found in contract ABI`); - if (constructor.parameters.length !== options.args.length) { - throw new Error( - `Invalid number of args passed (expected ${constructor.parameters.length} but got ${options.args.length})`, - ); - } debugLogger(`Input arguments: ${options.args.map((x: any) => `"${x}"`).join(', ')}`); const args = encodeArgs(options.args, constructorAbi!.parameters); @@ -376,13 +371,6 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { log, ); - const fnAbi = getAbiFunction(contractAbi, functionName); - if (fnAbi.parameters.length !== options.args.length) { - throw Error( - `Invalid number of args passed. Expected ${fnAbi.parameters.length}; Received: ${options.args.length}`, - ); - } - const privateKey = GrumpkinScalar.fromString(stripLeadingHex(options.privateKey)); const client = await createCompatibleClient(options.rpcUrl, debugLogger); From 55b63c8cebdb05203b080110f8037132fb70198b Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 20 Sep 2023 11:01:28 +0000 Subject: [PATCH 2/3] test fix --- yarn-project/cli/src/test/utils.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/yarn-project/cli/src/test/utils.test.ts b/yarn-project/cli/src/test/utils.test.ts index b37ec4fd7dd..3d34a48a217 100644 --- a/yarn-project/cli/src/test/utils.test.ts +++ b/yarn-project/cli/src/test/utils.test.ts @@ -74,9 +74,7 @@ describe('CLI Utils', () => { it('Errors on invalid inputs', () => { // invalid number of args const args1 = [field.toString(), 'false']; - expect(() => encodeArgs(args1, mockContractAbi.functions[1].parameters)).toThrow( - 'Invalid number of args provided. Expected: 5, received: 2', - ); + expect(() => encodeArgs(args1, mockContractAbi.functions[1].parameters)).toThrow('Invalid args provided'); // invalid array length const invalidArray = fieldArray.concat([Fr.random().toString()]); From c9f9e4e3c3f749cbaab45542ae14c80eb514d94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Thu, 21 Sep 2023 08:48:04 +0200 Subject: [PATCH 3/3] Update yarn-project/cli/src/encoding.ts Co-authored-by: Santiago Palladino --- yarn-project/cli/src/encoding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/cli/src/encoding.ts b/yarn-project/cli/src/encoding.ts index 0128e10a64d..a118c3b12b1 100644 --- a/yarn-project/cli/src/encoding.ts +++ b/yarn-project/cli/src/encoding.ts @@ -93,7 +93,7 @@ export function encodeArgs(args: any[], params: ABIParameter[]) { throw new Error( `Invalid args provided.\nExpected args: [${params .map(param => param.name + ': ' + param.type.kind) - .join(', ')}]\nReceived args: ${args}`, + .join(', ')}]\nReceived args: ${args.join(', ')}`, ); } return args.map((arg: any, index) => {