Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fixed Web3Utils toHex for Buffer input #3021
  • Loading branch information
akhil2015 committed Sep 25, 2019
commit e2299b52b8c20b0550e8db528352ca30f1470953
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