Skip to content

Commit

Permalink
Merge pull request #57 from yann300/patch-1
Browse files Browse the repository at this point in the history
Fix Address decoding (containing 0s at the front)
  • Loading branch information
axic committed Dec 6, 2017
2 parents ee6ded6 + 732c9b4 commit eef8ea9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function decodeSingle (parsedType, data, offset) {
var size, num, ret, i

if (parsedType.name === 'address') {
return decodeSingle(parsedType.rawType, data, offset)
return decodeSingle(parsedType.rawType, data, offset).toArrayLike(Buffer, 'be', 20).toString('hex')
} else if (parsedType.name === 'bool') {
return decodeSingle(parsedType.rawType, data, offset).toString() === new BN(1).toString()
} else if (parsedType.name === 'string') {
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ describe('encoding uint8 with 9bit data', function () {
})
})

it('decoding address with leading 0', function () {
var decoded = abi.rawDecode([ 'address' ], new Buffer('0000000000000000000000000005b7d915458ef540ade6068dfe2f44e8fa733c', 'hex'))
assert.deepEqual(abi.stringify([ 'address' ], decoded), [ '0x0005b7d915458ef540ade6068dfe2f44e8fa733c' ])
})

// Homebrew decoding tests

describe('decoding uint32', function () {
Expand Down

0 comments on commit eef8ea9

Please sign in to comment.