Skip to content

Commit ab10658

Browse files
committed
test: strict type check for BigInt decoder
1 parent 8e86465 commit ab10658

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/codec-bigint.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "assert";
2-
import { encode, decode, ExtensionCodec } from "../src";
2+
import { encode, decode, ExtensionCodec, DecodeError } from "../src";
33

44
const extensionCodec = new ExtensionCodec();
55
extensionCodec.register({
@@ -16,7 +16,11 @@ extensionCodec.register({
1616
}
1717
},
1818
decode: (data: Uint8Array) => {
19-
return BigInt(decode(data));
19+
const val = decode(data);
20+
if (!(typeof val === "string" || typeof val === "number")) {
21+
throw new DecodeError(`unexpected BigInt source: ${val} (${typeof val})`);
22+
}
23+
return BigInt(val);
2024
},
2125
});
2226

0 commit comments

Comments
 (0)