Added proper support for v0.6 Solidity JSON type (#688).

This commit is contained in:
Richard Moore 2019-12-21 01:03:05 -05:00
parent 4ac08432b8
commit 20f34f1ba9
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 51 additions and 1 deletions

@ -311,6 +311,13 @@ function addMethod(method: any): void {
let signature = formatSignature(method).replace(/tuple/g, '');
let sighash = id(signature).substring(0, 10);
let isConst = false;
if (method.constant != null) {
isConst = method.constant;
} else if (method.stateMutability != null) {
isConst = (method.stateMutability == "view" || method.stateMutability == "pure");
}
let description = new _FunctionDescription({
inputs: method.inputs,
outputs: method.outputs,
@ -318,7 +325,7 @@ function addMethod(method: any): void {
gas: method.gas,
payable: (method.payable == null || !!method.payable),
type: ((method.constant) ? 'call': 'transaction'),
type: (isConst ? 'call': 'transaction'),
name: method.name,
signature: signature,

@ -540,3 +540,46 @@ describe('Test Filters', function() {
doTest(test);
});
});
describe('Test Solidity v0.6 ABI', function() {
var tests = [
{
inputs: [ ],
outputs: [ ],
stateMutability: "view",
type: "function",
name: "testView_call"
},
{
inputs: [ ],
outputs: [ ],
stateMutability: "pure",
type: "function",
name: "testPure_call"
},
{
inputs: [ ],
outputs: [ ],
stateMutability: "payable",
type: "function",
name: "testPayable_transaction"
},
{
inputs: [ ],
outputs: [ ],
stateMutability: "nonpayable",
type: "function",
name: "testNonpayable_transaction"
},
];
tests.forEach(function(test, index) {
var type = test.name.split("_")[1];
it(('generates fragment from ABI - ' + test.name.split("_")[0]), function() {
var iface = new ethers.utils.Interface(JSON.stringify([ test ]));
var func = iface.functions[test.name];
assert.equal(func.type, type, "matches type");
});
});
});