Additional BN & BigInt negative tests (#1443)

This commit is contained in:
Jaco
2022-03-23 14:18:14 +02:00
committed by GitHub
parent 3bcd1d17f6
commit 30d5f5c118
2 changed files with 9 additions and 3 deletions
+7 -1
View File
@@ -50,12 +50,18 @@ describe('bnToU8a', (): void => {
).toEqual(new Uint8Array([251, 46]));
});
it('converts negative numbers (bitLength)', (): void => {
it('converts negative numbers (LE)', (): void => {
expect(
bnToU8a(new BN(-1234), { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([46, 251, 255, 255]));
});
it('converts negative numbers (LE, bitLength)', (): void => {
expect(
bnToU8a(new BN(-123456), { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([192, 29, 254, 255]));
});
it('handles backwards compatibility', (): void => {
expect(
bnToU8a(new BN(1234), 32, false)
+2 -2
View File
@@ -42,10 +42,10 @@ describe('u8aToBigInt', (): void => {
it('handles negative numbers (little-endian)', (): void => {
expect(
u8aToBigInt(
new Uint8Array([46, 251]),
new Uint8Array([192, 29, 254]),
{ isLe: true, isNegative: true }
)
).toEqual(-1234n);
).toEqual(-123456n);
});
it('handles negative numbers (big-endian)', (): void => {