Allow modifiers on Human-Readable ABI for tuples and arrays.
This commit is contained in:
parent
54dfb757c4
commit
83fba3de25
@ -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);
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user