Skip to content

Commit

Permalink
update result and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoulai committed May 22, 2023
1 parent f50dc17 commit e454a29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/web3-utils/src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export const toHex = (
return returnType ? 'bytes' : value;
}
if (isHex(value) && !isInt(value)) {
return returnType ? 'bytes' : value;
return returnType ? 'bytes' : `0x${value}`;
}

if (!Number.isFinite(value)) {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-utils/test/fixtures/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export const toHexValidData: [Numbers | Bytes | Address | boolean, [HexString, V
['0x72fdb1c1ddd4c67804f42b93de95cf6a8c51d2d1', 'address'],
],

This comment has been minimized.

['-0x01', ['-0x1', 'int256']],
['123c', ['0x123c', 'bytes']],
];

export const toHexInvalidData: [any, string][] = [
Expand Down

1 comment on commit e454a29

@djrann13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.