Removed stray localName in array sub-coders.

This commit is contained in:
Richard Moore 2018-06-15 17:50:22 -04:00
parent 059b03e090
commit aa48dfcdf4
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
3 changed files with 32 additions and 3 deletions

@ -1,6 +1,6 @@
{
"name": "ethers",
"version": "3.0.22",
"version": "3.0.23",
"description": "Ethereum wallet library.",
"main": "index.js",
"scripts": {

@ -173,6 +173,26 @@ describe('ABI Coder ABIv2 Decoding', function() {
it(('decodes ABIv2 parameters - ' + test.name + ' - ' + test.types), function() {
var decoded = coder.decode(types, result);
assert.ok(equals(decoded, values), 'decoded positional parameters - ' + title);
// Test for mutation
// https://github.com/ethers-io/ethers.js/issues/200
// https://github.com/ethers-io/ethers.js/issues/201
// @TODO: Expose parseParameter
// Check that it works with objects as well as strings
var expandedTypes = [];
types.forEach(function(type) {
var sig = 'function foo(' + type + ' foo)';
var abi = ethers.utils.AbiCoder.parseSignature(sig);
expandedTypes.push(abi.inputs[0]);
});
var typesBefore = JSON.stringify(expandedTypes);
decoded = coder.decode(expandedTypes, result);
assert.ok(equals(decoded, values), 'decoded positional parameters - ' + title);
assert.equal(typesBefore, JSON.stringify(expandedTypes), 'decoding does not modify the types');
});
});
});

@ -382,7 +382,7 @@ var coderBoolean = function(coerceFunc, localName) {
encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0);
},
decode: function(data, offset) {
decode: function(data, offset) {
try {
var result = uint256Coder.decode(data, offset);
} catch (error) {
@ -758,8 +758,17 @@ function coderArray(coerceFunc, coder, length, localName) {
offset += decodedLength.consumed;
}
// We don't want the children to have a localName
var subCoder = {
name: coder.name,
type: coder.type,
encode: coder.encode,
decode: coder.decode,
dynamic: coder.dynamic
};
var coders = [];
for (var i = 0; i < count; i++) { coders.push(coder); }
for (var i = 0; i < count; i++) { coders.push(subCoder); }
var result = unpack(coders, data, offset);
result.consumed += consumed;