Fixed bool and number types not throwing an exception in the ABI decoding for empty bytes.
This commit is contained in:
parent
46fd2deb8b
commit
1ec8f9cf85
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "3.0.6",
|
||||
"version": "3.0.7",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -228,3 +228,16 @@ describe('Test Interface Signatures', function() {
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test Invalid Input', function() {
|
||||
var coder = ethers.utils.AbiCoder.defaultCoder;
|
||||
it('null input failed', function() {
|
||||
assert.throws(function() {
|
||||
var result = coder.decode([ 'bool' ], '0x');
|
||||
console.log(result);
|
||||
}, function(error) {
|
||||
assert.equal(error.message, 'invalid bool', 'got invalid bool');
|
||||
return true;
|
||||
}, 'null bytes throws an error');
|
||||
});
|
||||
});
|
||||
|
@ -70,6 +70,7 @@ var coderNumber = function(coerceFunc, size, signed, localName) {
|
||||
return utils.padZeros(utils.arrayify(value), 32);
|
||||
},
|
||||
decode: function(data, offset) {
|
||||
if (data.length < offset + 32) { throwError('invalid ' + name); }
|
||||
var junkLength = 32 - size;
|
||||
var value = utils.bigNumberify(data.slice(offset + junkLength, offset + 32));
|
||||
if (signed) {
|
||||
@ -98,7 +99,14 @@ var coderBoolean = function(coerceFunc, localName) {
|
||||
return uint256Coder.encode(value ? 1: 0);
|
||||
},
|
||||
decode: function(data, offset) {
|
||||
try {
|
||||
var result = uint256Coder.decode(data, offset);
|
||||
} catch (error) {
|
||||
if (error.message === 'invalid uint256') {
|
||||
throwError('invalid bool');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return {
|
||||
consumed: result.consumed,
|
||||
value: coerceFunc('boolean', !result.value.isZero())
|
||||
|
Loading…
x
Reference in New Issue
Block a user