From a0c8545040721b3ea2ff3f827935e62a9d2c7840 Mon Sep 17 00:00:00 2001 From: Michael Maurer Date: Mon, 13 Feb 2017 09:24:15 -0800 Subject: [PATCH 1/2] Fix solidityPack() early return on bytes32 input. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 1af16d5..0e96c2b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -450,7 +450,7 @@ ABI.solidityPack = function (types, values) { throw new Error('Invalid bytes 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)) { From bff8a2b2dbb3a63aaf661678513612e6ca69e2e5 Mon Sep 17 00:00:00 2001 From: Michael Maurer Date: Mon, 13 Feb 2017 09:54:25 -0800 Subject: [PATCH 2/2] New test cases for packing multiple arguments --- test/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/index.js b/test/index.js index c9af43f..1c62908 100644 --- a/test/index.js +++ b/test/index.js @@ -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( @@ -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(