From 41ba6c78688a6a35b23cf60b0fe496691158b536 Mon Sep 17 00:00:00 2001 From: astarinmymind <58123480+astarinmymind@users.noreply.github.com> Date: Sun, 10 Jan 2021 09:24:41 -0800 Subject: [PATCH] Updating parse to handle array arguments (#22) * update parse to handle array arguments * added additional tests for parse signature that includes an array parameter Co-authored-by: Kyle Ribordy --- src/index.ts | 2 +- test/index.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4d9dcc0..4c67a28 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,7 +60,7 @@ export class MethodRegistry { } if (rawName) { - const match = signature.match(new RegExp(`${rawName[1]}\\(+([a-z1-9,()]+)\\)`, 'u')); + const match = signature.match(new RegExp(`${rawName[1]}\\(+([a-z1-9,()\\[\\]]+)\\)`, 'u')); let matches; let args: { type: string }[] = []; if (match) { diff --git a/test/index.js b/test/index.js index ab2751b..e878857 100644 --- a/test/index.js +++ b/test/index.js @@ -129,3 +129,14 @@ test('parse signature that includes a tuple as the last param', function (t) { t.equal(parsed.args[4].type, 'bytes'); t.end(); }); + +test('parse signature that includes an array param', function (t) { + const sig = 'method(uint256[],string)'; + const parsed = registry.parse(sig); + + t.equal(parsed.name, 'Method'); + t.equal(parsed.args.length, 2); + t.equal(parsed.args[0].type, 'uint256[]'); + t.equal(parsed.args[1].type, 'string'); + t.end(); +});