Skip to content

Commit 2732911

Browse files
authored
Update codec-bigint.test.ts
Changed the test to encode as number if its in SAFE_INTEGER Area.
1 parent 2ee2065 commit 2732911

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/codec-bigint.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ const extensionCodec = new ExtensionCodec();
55
extensionCodec.register({
66
type: 0,
77
encode: (input: unknown) => {
8-
if (typeof input === "bigint") {
9-
return encode(input.toString());
10-
} else {
11-
return null;
12-
}
8+
if (typeof input === "bigint") {
9+
if (input <= Number.MAX_SAFE_INTEGER && input >= Number.MIN_SAFE_INTEGER) {
10+
return encode(parseInt(input.toString(), 10));
11+
} else {
12+
return encode(input.toString());
13+
}
14+
} else {
15+
return null;
16+
}
1317
},
1418
decode: (data: Uint8Array) => {
1519
return BigInt(decode(data));

0 commit comments

Comments
 (0)