Skip to content

Commit

Permalink
Updating parse to handle array arguments (#22)
Browse files Browse the repository at this point in the history
* update parse to handle array arguments
* added additional tests for parse signature that includes an array parameter
Co-authored-by: Kyle Ribordy <hello@ribordy.tech>
  • Loading branch information
astarinmymind authored Jan 10, 2021
1 parent d48259b commit 41ba6c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 41ba6c7

Please sign in to comment.