Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #39 incorrect handling of bytesX arguments in solidityPack() #40

Merged
merged 2 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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