From 429bf5456e4fb24d33c602e5761a837913e85649 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 13 Jan 2021 13:00:10 +0100 Subject: [PATCH] Add tests for toBigInt usage (#3049) * Add tests for toBigInt usage * Update packages/types/src/codec/UInt.spec.ts --- packages/types/src/codec/Compact.spec.ts | 4 +++- packages/types/src/codec/Date.spec.ts | 6 ++++++ packages/types/src/codec/UInt.spec.ts | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/types/src/codec/Compact.spec.ts b/packages/types/src/codec/Compact.spec.ts index 7aab56689e..a788c59177 100644 --- a/packages/types/src/codec/Compact.spec.ts +++ b/packages/types/src/codec/Compact.spec.ts @@ -73,7 +73,9 @@ describe('Compact', (): void => { }); it('has a valid toBigInt interface', (): void => { - expect(new (Compact.with('u128'))(registry, 12345678987654321n).toBigInt() === 12345678987654321n).toBe(true); + expect( + (new (Compact.with('u128'))(registry, 12345678987654321n).toBigInt() + 1n) === 12345678987654322n + ).toBe(true); }); }); }); diff --git a/packages/types/src/codec/Date.spec.ts b/packages/types/src/codec/Date.spec.ts index 02b5ac6aa1..31c51e70f1 100644 --- a/packages/types/src/codec/Date.spec.ts +++ b/packages/types/src/codec/Date.spec.ts @@ -59,6 +59,12 @@ describe('Date', (): void => { new CodecDate(registry, 3).toHex(true) ).toEqual('0x0300000000000000'); }); + + it('encodes correctly to BigInt', (): void => { + expect( + new CodecDate(registry, 41).toBigInt() + 1n + ).toEqual(42n); + }); }); describe('utils', (): void => { diff --git a/packages/types/src/codec/UInt.spec.ts b/packages/types/src/codec/UInt.spec.ts index 1cd31bf23a..cde91caf40 100644 --- a/packages/types/src/codec/UInt.spec.ts +++ b/packages/types/src/codec/UInt.spec.ts @@ -45,6 +45,12 @@ describe('UInt', (): void => { ).toEqual(4567); }); + it('has a working toBigInt', (): void => { + expect( + new UInt(registry, 4567).toBigInt() + BigInt(1) + ).toEqual(BigInt(4568)); + }); + it('converts to Little Endian from the provided value', (): void => { expect( new UInt(registry, 1234567).toU8a()