Avoid u8a -> string conversion costs (#106)
* Avoid u8a -> string conversion for pair keys * Update hexToBn tests
This commit is contained in:
@@ -30,7 +30,7 @@ module.exports = function hexToBn (_value?: string, isLe: boolean = false): BN {
|
||||
return new BN(0);
|
||||
}
|
||||
|
||||
const value = hexStripPrefix(_value) || '00';
|
||||
const value = hexStripPrefix(_value);
|
||||
|
||||
return new BN(isLe ? reverse(value) : value, 16);
|
||||
return new BN((isLe ? reverse(value) : value) || '00', 16);
|
||||
};
|
||||
|
||||
@@ -23,19 +23,25 @@ describe('hexToBn', () => {
|
||||
).toEqual('0');
|
||||
});
|
||||
|
||||
it('converts 0x values to BN(0) (LE)', () => {
|
||||
expect(
|
||||
hexToBn('0x', true).toString()
|
||||
).toEqual('0');
|
||||
});
|
||||
|
||||
it('converts little-endian', () => {
|
||||
expect(
|
||||
hexToBn('0x4500000000000000', true).toString()
|
||||
).toEqual('69');
|
||||
});
|
||||
|
||||
it('handles starting zeros correctly (be)', () => {
|
||||
it('handles starting zeros correctly (BE)', () => {
|
||||
expect(
|
||||
hexToBn('0x0000000000000100', false).toString()
|
||||
).toEqual('256');
|
||||
});
|
||||
|
||||
it('handles starting zeros correctly (le)', () => {
|
||||
it('handles starting zeros correctly (LE)', () => {
|
||||
expect(
|
||||
hexToBn('0x0001000000000000', true).toString()
|
||||
).toEqual('256');
|
||||
|
||||
Reference in New Issue
Block a user