Skip to content

Commit

Permalink
Allow modifiers on Human-Readable ABI for tuples and arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 1, 2020
1 parent 54dfb75 commit 83fba3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/abi/src.ts/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ type ParseNode = {
};

let ModifiersBytes: { [ name: string ]: boolean } = { calldata: true, memory: true, storage: true };
let ModifiersNest: { [ name: string ]: boolean } = { calldata: true, memory: true };
function checkModifier(type: string, name: string): boolean {
if (type === "bytes" || type === "string") {
if (ModifiersBytes[name]) { return true; }
} else if (type === "address") {
if (name === "payable") { return true; }
} else if (type.indexOf("[") >= 0 || type === "tuple") {
if (ModifiersNest[name]) { return true; }
}
if (ModifiersBytes[name] || name === "payable") {
logger.throwArgumentError("invalid modifier", "name", name);
Expand Down
37 changes: 37 additions & 0 deletions packages/tests/src.ts/test-contract-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,40 @@ describe('Test Filters', function() {
doTest(test);
});
});

describe("Test ParamType Parser", function() {
const Tests: Array<{ type: string, format: string }> = [
{ type: "address", format: "address" },
{ type: "address foo", format: "address foo" },
{ type: "address payable", format: "address" },
{ type: "address payable foo", format: "address foo" },

{ type: "uint", format: "uint256" },
{ type: "uint16", format: "uint16" },
{ type: "uint256", format: "uint256" },
{ type: "int", format: "int256" },
{ type: "int16", format: "int16" },
{ type: "int256", format: "int256" },

{ type: "string", format: "string" },
{ type: "string memory", format: "string" },
{ type: "string calldata", format: "string" },
{ type: "string storage", format: "string" },
{ type: "string memory foo", format: "string foo" },
{ type: "string foo", format: "string foo" },

{ type: "string[]", format: "string[]" },
{ type: "string[5]", format: "string[5]" },

{ type: "uint[] memory", format: "uint256[]" },
{ type: "tuple(address a, string[] b) memory foo", format: "tuple(address a, string[] b) foo" },
];

Tests.forEach((test) => {
it(`allows correct modifiers ${ JSON.stringify(test.type) }`, function() {
const paramType = ethers.utils.ParamType.from(test.type);
//console.log(test, paramType.format("full"));
assert.equal(paramType.format("full"), test.format);
});
});
});

0 comments on commit 83fba3d

Please sign in to comment.