Avoid u8a -> string conversion costs (#106)

* Avoid u8a -> string conversion for pair keys

* Update hexToBn tests
This commit is contained in:
Jaco Greeff
2018-03-12 15:18:32 +01:00
committed by GitHub
parent ebdd3cb76f
commit 827012783f
5 changed files with 13 additions and 11 deletions
+2 -2
View File
@@ -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);
};
+8 -2
View File
@@ -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');