Skip to content

Commit

Permalink
Merge pull request #40 from MichaelMaurer/mjm-solidity-pack-bytes32
Browse files Browse the repository at this point in the history
Fix #39 incorrect handling of bytesX arguments in solidityPack()
  • Loading branch information
axic committed Mar 9, 2017
2 parents 4a33f23 + bff8a2b commit cf8c093
Show file tree
Hide file tree
Showing 2 changed files with 23 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 @@ -450,7 +450,7 @@ ABI.solidityPack = function (types, values) {
throw new Error('Invalid bytes<N> width: ' + size)
}

return utils.setLengthRight(value, size)
ret.push(utils.setLengthRight(value, size))
} else if (type.startsWith('uint')) {
size = parseTypeN(type)
if ((size % 8) || (size < 8) || (size > 256)) {
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,17 @@ describe('solidity tight packing int16', function () {
})
})

describe('solidity tight packing multiple arguments', function () {
it('should equal', function () {
var a = abi.solidityPack(
[ 'bytes32', 'uint32', 'uint32', 'uint32', 'uint32' ],
[ new Buffer('123456', 'hex'), 6, 7, 8, 9 ]
)
var b = '123456000000000000000000000000000000000000000000000000000000000000000006000000070000000800000009'
assert.equal(a.toString('hex'), b.toString('hex'))
})
})

describe('solidity tight packing sha3', function () {
it('should equal', function () {
var a = abi.soliditySHA3(
Expand All @@ -501,6 +512,17 @@ describe('solidity tight packing sha3', function () {
})
})

describe('solidity tight packing sha3 #2', function () {
it('should equal', function () {
var a = abi.soliditySHA3(
[ 'bytes32', 'uint32', 'uint32', 'uint32', 'uint32' ],
[ new Buffer('123456', 'hex'), 6, 7, 8, 9 ]
)
var b = '1f2eedb6c2ac3e4b4e4c9f7598e626baf1e15a4e848d295479f46ec85d967cba'
assert.equal(a.toString('hex'), b.toString('hex'))
})
})

describe('solidity tight packing sha256', function () {
it('should equal', function () {
var a = abi.soliditySHA256(
Expand Down

0 comments on commit cf8c093

Please sign in to comment.