diff --git a/package.json b/package.json index 9e56fef2e..8b78097b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ethers", - "version": "3.0.22", + "version": "3.0.23", "description": "Ethereum wallet library.", "main": "index.js", "scripts": { diff --git a/tests/test-contract-interface.js b/tests/test-contract-interface.js index 17fcc40c8..3e51cdb7c 100644 --- a/tests/test-contract-interface.js +++ b/tests/test-contract-interface.js @@ -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'); }); }); }); diff --git a/utils/abi-coder.js b/utils/abi-coder.js index 6b1134713..8c9a6571f 100644 --- a/utils/abi-coder.js +++ b/utils/abi-coder.js @@ -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;