Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion yarn-project/cli/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Comment thread
benesjan marked this conversation as resolved.
Outdated
);
}
return args.map((arg: any, index) => {
Expand Down
12 changes: 0 additions & 12 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/cli/src/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down