|
@@ -1,5 +1,6 @@
|
|
|
import * as assert from "assert";
|
|
|
import { BorshCoder } from "../src";
|
|
|
+import BN from "bn.js";
|
|
|
|
|
|
describe("coder.types", () => {
|
|
|
test("Can encode and decode user-defined types", () => {
|
|
@@ -42,4 +43,48 @@ describe("coder.types", () => {
|
|
|
|
|
|
assert.deepEqual(coder.types.decode("MintInfo", encoded), mintInfo);
|
|
|
});
|
|
|
+
|
|
|
+ test("Can encode and decode 256-bit integers", () => {
|
|
|
+ const idl = {
|
|
|
+ version: "0.0.0",
|
|
|
+ name: "basic_0",
|
|
|
+ instructions: [
|
|
|
+ {
|
|
|
+ name: "initialize",
|
|
|
+ accounts: [],
|
|
|
+ args: [],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ types: [
|
|
|
+ {
|
|
|
+ name: "IntegerTest",
|
|
|
+ type: {
|
|
|
+ kind: "struct" as const,
|
|
|
+ fields: [
|
|
|
+ {
|
|
|
+ name: "unsigned",
|
|
|
+ type: "u256" as const,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "signed",
|
|
|
+ type: "i256" as const,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+
|
|
|
+ const testing = {
|
|
|
+ unsigned: new BN(2588012355),
|
|
|
+ signed: new BN(-93842345),
|
|
|
+ };
|
|
|
+
|
|
|
+ const coder = new BorshCoder(idl);
|
|
|
+ const encoded = coder.types.encode("IntegerTest", testing);
|
|
|
+ assert.strictEqual(
|
|
|
+ coder.types.decode("IntegerTest", encoded).toString(),
|
|
|
+ testing.toString()
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|