Skip to content

Commit

Permalink
fixed Web3Utils toHex for Buffer input web3#3021
Browse files Browse the repository at this point in the history
  • Loading branch information
akhil2015 committed Sep 25, 2019
1 parent 35b2e22 commit e2299b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/web3-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ var toHex = function (value, returnType) {
if (_.isBoolean(value)) {
return returnType ? 'bool' : value ? '0x01' : '0x00';
}


// if it is a buffer then, pass it through bytesToHex
if (Buffer.isBuffer(value)) {
return bytesToHex(value);
}

if (_.isObject(value) && !isBigNumber(value) && !isBN(value)) {
return returnType ? 'string' : utf8ToHex(JSON.stringify(value));
Expand Down
1 change: 1 addition & 0 deletions test/utils.toHex.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var tests = [
{ value: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ',
expected: '0x0300000035c3a8c386c3954c5d127cc29dc38ec2bec29e1a37c2abc29b05321128c390c297590a3c100000000000006521c39f642fc3b1c3b5c3ac0c3a7ac2a6c38ec2a6c2b1c3a7c2b7c3b7c38dc2a2c38bc39f07362ac28508c28ec297c3b1c29ec3b94331c38955c380c3a9321ac393c28642c28c'},
{ value: '내가 제일 잘 나가', expected:'0xeb82b4eab08020eca09cec9dbc20ec9e9820eb8298eab080'},
{ value: Buffer.from('100'), expected:'0x313030'}
];

describe('lib/utils/utils', function () {
Expand Down

0 comments on commit e2299b5

Please sign in to comment.