diff --git a/packages/rpc-provider/src/mock/subscribe.spec.ts b/packages/rpc-provider/src/mock/subscribe.spec.ts index 85a9426648..64fd1cb49b 100644 --- a/packages/rpc-provider/src/mock/subscribe.spec.ts +++ b/packages/rpc-provider/src/mock/subscribe.spec.ts @@ -39,7 +39,7 @@ describe('subscribe', () => { it('calls back with new headers', (done) => { return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: any) => { - if (header.number === '0x0000000000000004') { + if (header.number === 4) { done(); } }); @@ -55,7 +55,7 @@ describe('subscribe', () => { throw new Error('testing'); } - if (header.number === '0x0000000000000003') { + if (header.number === 3) { done(); } }); diff --git a/packages/types/src/Digest.spec.ts b/packages/types/src/Digest.spec.ts index 772eeab701..4ca58911c0 100644 --- a/packages/types/src/Digest.spec.ts +++ b/packages/types/src/Digest.spec.ts @@ -15,7 +15,7 @@ describe('Digest', () => { expect(log.type).toBe('Seal'); expect(log.value.toJSON()).toEqual([ - '0x000000000f4e8607', + 256804359, '0x2c0e0ee8a5d1a073da3f8db002b8eaebcd7b1a7eb25662e09f9ef0ac58d96bf17896256cd5f0bc672f96aab49fe5163ca5cb4c1a0f047dc39e89cd4a9eb2ea05' ]); }); diff --git a/packages/types/src/I128.ts b/packages/types/src/I128.ts index 7e1308045d..4c95eccbbb 100644 --- a/packages/types/src/I128.ts +++ b/packages/types/src/I128.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I128 extends Int { constructor (value?: AnyNumber) { - super(value, 128, true); + super(value, 128); } } diff --git a/packages/types/src/I16.ts b/packages/types/src/I16.ts index be220865c8..bad7c36c95 100644 --- a/packages/types/src/I16.ts +++ b/packages/types/src/I16.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I16 extends Int { constructor (value?: AnyNumber) { - super(value, 16, false); + super(value, 16); } } diff --git a/packages/types/src/I256.ts b/packages/types/src/I256.ts index 3ae4d99861..bd873605ab 100644 --- a/packages/types/src/I256.ts +++ b/packages/types/src/I256.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I256 extends Int { constructor (value?: AnyNumber) { - super(value, 256, true); + super(value, 256); } } diff --git a/packages/types/src/I32.ts b/packages/types/src/I32.ts index 364ed56634..6b6691ac8c 100644 --- a/packages/types/src/I32.ts +++ b/packages/types/src/I32.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I32 extends Int { constructor (value?: AnyNumber) { - super(value, 32, false); + super(value, 32); } } diff --git a/packages/types/src/I64.ts b/packages/types/src/I64.ts index 71a56069d5..daf68e045e 100644 --- a/packages/types/src/I64.ts +++ b/packages/types/src/I64.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I64 extends Int { constructor (value?: AnyNumber) { - super(value, 64, true); + super(value, 64); } } diff --git a/packages/types/src/I8.ts b/packages/types/src/I8.ts index 65e27daa9a..b10aece88a 100644 --- a/packages/types/src/I8.ts +++ b/packages/types/src/I8.ts @@ -13,6 +13,6 @@ import Int from './codec/Int'; */ export default class I8 extends Int { constructor (value?: AnyNumber) { - super(value, 8, false); + super(value, 8); } } diff --git a/packages/types/src/U128.ts b/packages/types/src/U128.ts index 385f67b969..461636e785 100644 --- a/packages/types/src/U128.ts +++ b/packages/types/src/U128.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U128 extends UInt { constructor (value?: AnyNumber) { - super(value, 128, true); + super(value, 128); } } diff --git a/packages/types/src/U16.ts b/packages/types/src/U16.ts index bdda09535d..e38b1753cf 100644 --- a/packages/types/src/U16.ts +++ b/packages/types/src/U16.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U16 extends UInt { constructor (value?: AnyNumber) { - super(value, 16, false); + super(value, 16); } } diff --git a/packages/types/src/U256.ts b/packages/types/src/U256.ts index 35f276fd18..6731fe6195 100644 --- a/packages/types/src/U256.ts +++ b/packages/types/src/U256.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U256 extends UInt { constructor (value?: AnyNumber) { - super(value, 256, true); + super(value, 256); } } diff --git a/packages/types/src/U32.ts b/packages/types/src/U32.ts index 9045119301..3abe5f5046 100644 --- a/packages/types/src/U32.ts +++ b/packages/types/src/U32.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U32 extends UInt { constructor (value?: AnyNumber) { - super(value, 32, false); + super(value, 32); } } diff --git a/packages/types/src/U64.ts b/packages/types/src/U64.ts index 9379a31c97..8f14a57482 100644 --- a/packages/types/src/U64.ts +++ b/packages/types/src/U64.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U64 extends UInt { constructor (value?: AnyNumber) { - super(value, 64, true); + super(value, 64); } } diff --git a/packages/types/src/U8.ts b/packages/types/src/U8.ts index cbf0414af3..1172886ffb 100644 --- a/packages/types/src/U8.ts +++ b/packages/types/src/U8.ts @@ -13,6 +13,6 @@ import UInt from './codec/UInt'; */ export default class U8 extends UInt { constructor (value?: AnyNumber) { - super(value, 8, false); + super(value, 8); } } diff --git a/packages/types/src/codec/AbstractInt.ts b/packages/types/src/codec/AbstractInt.ts index d71866d2e7..a947c92f5e 100644 --- a/packages/types/src/codec/AbstractInt.ts +++ b/packages/types/src/codec/AbstractInt.ts @@ -101,7 +101,8 @@ export default abstract class AbstractInt extends BN implements Codec { * @description Converts the Object to JSON, typically used for RPC transfers */ toJSON (): any { - return this._isHexJson + // Maximum allowed integer for JS is 2^53 - 1, set limit at 52 + return this._isHexJson || (super.bitLength() > 52) ? this.toHex() : this.toNumber(); } diff --git a/packages/types/src/codec/UInt.spec.ts b/packages/types/src/codec/UInt.spec.ts index 869eb3138a..cc167d693b 100644 --- a/packages/types/src/codec/UInt.spec.ts +++ b/packages/types/src/codec/UInt.spec.ts @@ -46,9 +46,10 @@ describe('UInt', () => { ).toEqual(123); }); - it('converts to JSON depending on flags', () => { - expect(new UInt(0x12, 16).toJSON()).toEqual('0x0012'); - expect(new UInt(0x12, 16, false).toJSON()).toEqual(0x12); + it('converts to JSON representation based on flags/size', () => { + expect(new UInt('0x12345678', 64, true).toJSON()).toEqual('0x0000000012345678'); + expect(new UInt('0x1234567890', 64, false).toJSON()).toEqual(0x1234567890); + expect(new UInt('0x1234567890abcdef', 64, false).toJSON()).toEqual('0x1234567890abcdef'); }); describe('eq', () => { diff --git a/packages/types/src/codec/UInt.ts b/packages/types/src/codec/UInt.ts index d4dd3c9f71..abf2da7ac1 100644 --- a/packages/types/src/codec/UInt.ts +++ b/packages/types/src/codec/UInt.ts @@ -21,7 +21,7 @@ import AbstractInt, { DEFAULT_UINT_BITS, UIntBitLength } from './AbstractInt'; export default class UInt extends AbstractInt { constructor ( value: AnyNumber = 0, - bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson: boolean = true) { + bitLength: UIntBitLength = DEFAULT_UINT_BITS, isHexJson: boolean = false) { super( false, value, diff --git a/packages/types/src/codec/createType.spec.ts b/packages/types/src/codec/createType.spec.ts index 79f5e24509..967b854756 100644 --- a/packages/types/src/codec/createType.spec.ts +++ b/packages/types/src/codec/createType.spec.ts @@ -208,7 +208,7 @@ describe('createType', () => { index: '0x10' }).toJSON() ).toEqual({ - balance: '0x000000000000000000000000000004d2', + balance: 1234, index: 16 }); });