Added proper support for v0.6 Solidity JSON type (#688).
This commit is contained in:
parent
4ac08432b8
commit
20f34f1ba9
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user