@kontor/kontor-sdk 1.0.0-alpha.39 → 1.0.0-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/cjs/sdk/chains/definitions/signet.js +2 -2
- package/dist/cjs/sdk/test/e2e.test-deprecated.js +2 -0
- package/dist/cjs/sdk/test/e2e.test-deprecated.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/bool.js +9 -21
- package/dist/cjs/sdk/utils/wit/codecs/bool.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/contract-address.js +92 -0
- package/dist/cjs/sdk/utils/wit/codecs/contract-address.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/index.js +29 -0
- package/dist/cjs/sdk/utils/wit/codecs/index.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/list.js +21 -95
- package/dist/cjs/sdk/utils/wit/codecs/list.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/numerics.js +228 -0
- package/dist/cjs/sdk/utils/wit/codecs/numerics.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/option.js +21 -72
- package/dist/cjs/sdk/utils/wit/codecs/option.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/result.js +32 -0
- package/dist/cjs/sdk/utils/wit/codecs/result.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/string.js +16 -21
- package/dist/cjs/sdk/utils/wit/codecs/string.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/unit.js +11 -19
- package/dist/cjs/sdk/utils/wit/codecs/unit.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/util.js +185 -0
- package/dist/cjs/sdk/utils/wit/codecs/util.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +297 -163
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js +214 -221
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/cjs/wit/built-ins.js +19 -0
- package/dist/cjs/wit/built-ins.js.map +1 -0
- package/dist/cjs/wit/regex.js +1 -1
- package/dist/cjs/wit/regex.js.map +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/signature.js +17 -2
- package/dist/cjs/wit/wit-parser/core/errors/signature.js.map +1 -1
- package/dist/cjs/wit/wit-parser/core/signatures.js +18 -0
- package/dist/cjs/wit/wit-parser/core/signatures.js.map +1 -1
- package/dist/cjs/wit/wit-parser/core/types/{records.js → user-defined.js} +1 -1
- package/dist/cjs/wit/wit-parser/core/types/user-defined.js.map +1 -0
- package/dist/cjs/wit/wit-parser/core/user-defined.js +271 -0
- package/dist/cjs/wit/wit-parser/core/user-defined.js.map +1 -0
- package/dist/cjs/wit/wit-parser/core/utils.js +29 -7
- package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/cjs/wit/wit-parser/parse-wit-parameter.js +9 -3
- package/dist/cjs/wit/wit-parser/parse-wit-parameter.js.map +1 -1
- package/dist/cjs/wit/wit-parser/parse-wit.js +7 -3
- package/dist/cjs/wit/wit-parser/parse-wit.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/esm/sdk/chains/definitions/signet.js +2 -2
- package/dist/esm/sdk/test/e2e.test-deprecated.js +197 -0
- package/dist/esm/sdk/test/e2e.test-deprecated.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/bool.js +9 -21
- package/dist/esm/sdk/utils/wit/codecs/bool.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/contract-address.js +92 -0
- package/dist/esm/sdk/utils/wit/codecs/contract-address.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/index.js +9 -0
- package/dist/esm/sdk/utils/wit/codecs/index.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/list.js +20 -114
- package/dist/esm/sdk/utils/wit/codecs/list.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/numerics.js +234 -0
- package/dist/esm/sdk/utils/wit/codecs/numerics.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/option.js +21 -88
- package/dist/esm/sdk/utils/wit/codecs/option.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/result.js +29 -0
- package/dist/esm/sdk/utils/wit/codecs/result.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/string.js +22 -22
- package/dist/esm/sdk/utils/wit/codecs/string.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/unit.js +12 -21
- package/dist/esm/sdk/utils/wit/codecs/unit.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/util.js +181 -0
- package/dist/esm/sdk/utils/wit/codecs/util.js.map +1 -0
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +322 -188
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js +230 -233
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/wit/built-ins.js +16 -0
- package/dist/esm/wit/built-ins.js.map +1 -0
- package/dist/esm/wit/regex.js +1 -1
- package/dist/esm/wit/regex.js.map +1 -1
- package/dist/esm/wit/wit-parser/core/errors/signature.js +15 -1
- package/dist/esm/wit/wit-parser/core/errors/signature.js.map +1 -1
- package/dist/esm/wit/wit-parser/core/signatures.js +14 -0
- package/dist/esm/wit/wit-parser/core/signatures.js.map +1 -1
- package/dist/esm/wit/wit-parser/core/types/signatures.js.map +1 -1
- package/dist/esm/wit/wit-parser/core/types/user-defined.js +2 -0
- package/dist/esm/wit/wit-parser/core/types/user-defined.js.map +1 -0
- package/dist/esm/wit/wit-parser/core/types/utils.js +25 -0
- package/dist/esm/wit/wit-parser/core/types/utils.js.map +1 -1
- package/dist/esm/wit/wit-parser/core/user-defined.js +280 -0
- package/dist/esm/wit/wit-parser/core/user-defined.js.map +1 -0
- package/dist/esm/wit/wit-parser/core/utils.js +33 -36
- package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/esm/wit/wit-parser/parse-wit-parameter.js +10 -4
- package/dist/esm/wit/wit-parser/parse-wit-parameter.js.map +1 -1
- package/dist/esm/wit/wit-parser/parse-wit.js +8 -4
- package/dist/esm/wit/wit-parser/parse-wit.js.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts +2 -1
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts.map +1 -1
- package/dist/types/sdk/chains/definitions/signet.d.ts +2 -2
- package/dist/types/sdk/test/e2e.test-deprecated.d.ts +2 -0
- package/dist/types/sdk/test/e2e.test-deprecated.d.ts.map +1 -0
- package/dist/types/sdk/types/contract.d.ts +5 -5
- package/dist/types/sdk/types/contract.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts +2 -2
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts +5 -0
- package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/index.d.ts +9 -0
- package/dist/types/sdk/utils/wit/codecs/index.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/list.d.ts +2 -16
- package/dist/types/sdk/utils/wit/codecs/list.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/numerics.d.ts +14 -0
- package/dist/types/sdk/utils/wit/codecs/numerics.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/option.d.ts +3 -23
- package/dist/types/sdk/utils/wit/codecs/option.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/result.d.ts +4 -0
- package/dist/types/sdk/utils/wit/codecs/result.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/string.d.ts +6 -2
- package/dist/types/sdk/utils/wit/codecs/string.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/types.d.ts +4 -0
- package/dist/types/sdk/utils/wit/codecs/types.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/unit.d.ts +2 -11
- package/dist/types/sdk/utils/wit/codecs/unit.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/util.d.ts +12 -0
- package/dist/types/sdk/utils/wit/codecs/util.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts +9 -31
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts +9 -1
- package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts.map +1 -1
- package/dist/types/wit/built-ins.d.ts +6 -0
- package/dist/types/wit/built-ins.d.ts.map +1 -0
- package/dist/types/wit/regex.d.ts.map +1 -1
- package/dist/types/wit/utils.d.ts +53 -33
- package/dist/types/wit/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/errors/signature.d.ts +7 -1
- package/dist/types/wit/wit-parser/core/errors/signature.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/signatures.d.ts +10 -0
- package/dist/types/wit/wit-parser/core/signatures.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/types/signatures.d.ts +6 -2
- package/dist/types/wit/wit-parser/core/types/signatures.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/types/user-defined.d.ts +134 -0
- package/dist/types/wit/wit-parser/core/types/user-defined.d.ts.map +1 -0
- package/dist/types/wit/wit-parser/core/types/utils.d.ts +86 -11
- package/dist/types/wit/wit-parser/core/types/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/user-defined.d.ts +19 -0
- package/dist/types/wit/wit-parser/core/user-defined.d.ts.map +1 -0
- package/dist/types/wit/wit-parser/core/utils.d.ts +8 -4
- package/dist/types/wit/wit-parser/core/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts +11 -5
- package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/parse-wit.d.ts +7 -3
- package/dist/types/wit/wit-parser/parse-wit.d.ts.map +1 -1
- package/dist/types/wit/wit.d.ts +20 -12
- package/dist/types/wit/wit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/actions/get-contract.test-d.ts +430 -50
- package/src/sdk/actions/get-contract.test.ts +324 -24
- package/src/sdk/actions/kontor/public/call-view.ts +2 -1
- package/src/sdk/actions/kontor/public/proc-contract.test-d.ts +107 -0
- package/src/sdk/actions/kontor/public/proc-contract.test.ts +234 -21
- package/src/sdk/actions/kontor/public/view-contract.test-d.ts +240 -0
- package/src/sdk/actions/kontor/public/view-contract.test.ts +613 -18
- package/src/sdk/chains/definitions/signet.ts +2 -2
- package/src/sdk/clients/base/create-rpc-client.test.ts +2 -2
- package/src/sdk/clients/create-public-client.test.ts +2 -2
- package/src/sdk/clients/kontor/create-public-client.test.ts +2 -2
- package/src/sdk/clients/transports/http-rpc.test.ts +0 -24
- package/src/sdk/test/e2e.test-deprecated.ts +195 -0
- package/src/sdk/types/contract.test-d.ts +489 -55
- package/src/sdk/types/contract.ts +6 -7
- package/src/sdk/utils/wit/codecs/bool.test.ts +29 -0
- package/src/sdk/utils/wit/codecs/bool.ts +10 -25
- package/src/sdk/utils/wit/codecs/contract-address.test.ts +37 -0
- package/src/sdk/utils/wit/codecs/contract-address.ts +114 -0
- package/src/sdk/utils/wit/codecs/index.ts +20 -0
- package/src/sdk/utils/wit/codecs/list.test-d.ts +13 -0
- package/src/sdk/utils/wit/codecs/list.test.ts +55 -0
- package/src/sdk/utils/wit/codecs/list.ts +21 -150
- package/src/sdk/utils/wit/codecs/numerics.test.ts +399 -0
- package/src/sdk/utils/wit/codecs/numerics.ts +304 -0
- package/src/sdk/utils/wit/codecs/option.test.ts +71 -0
- package/src/sdk/utils/wit/codecs/option.ts +21 -120
- package/src/sdk/utils/wit/codecs/result.test.ts +82 -0
- package/src/sdk/utils/wit/codecs/result.ts +37 -0
- package/src/sdk/utils/wit/codecs/string.test.ts +62 -0
- package/src/sdk/utils/wit/codecs/string.ts +23 -25
- package/src/sdk/utils/wit/codecs/types.ts +5 -0
- package/src/sdk/utils/wit/codecs/unit.test.ts +27 -0
- package/src/sdk/utils/wit/codecs/unit.ts +14 -38
- package/src/sdk/utils/wit/codecs/util.test.ts +221 -0
- package/src/sdk/utils/wit/codecs/util.ts +193 -0
- package/src/sdk/utils/wit/decode-wit-parameter.test.ts +1264 -32
- package/src/sdk/utils/wit/decode-wit-parameter.ts +508 -211
- package/src/sdk/utils/wit/encode-wit-parameters.test.ts +955 -91
- package/src/sdk/utils/wit/encode-wit-parameters.ts +277 -274
- package/src/sdk/utils/wit/get-wit-item.test.ts +1 -1
- package/src/wit/built-ins.ts +23 -0
- package/src/wit/regex.ts +1 -1
- package/src/wit/utils.ts +120 -74
- package/src/wit/wit-parser/core/errors/signature.ts +13 -2
- package/src/wit/wit-parser/core/signatures.ts +28 -0
- package/src/wit/wit-parser/core/types/signatures.test-d.ts +21 -0
- package/src/wit/wit-parser/core/types/signatures.ts +19 -2
- package/src/wit/wit-parser/core/types/user-defined.test-d.ts +1308 -0
- package/src/wit/wit-parser/core/types/user-defined.ts +412 -0
- package/src/wit/wit-parser/core/types/utils.test-d.ts +43 -2
- package/src/wit/wit-parser/core/types/utils.ts +143 -14
- package/src/wit/wit-parser/core/user-defined.test.ts +609 -0
- package/src/wit/wit-parser/core/user-defined.ts +392 -0
- package/src/wit/wit-parser/core/utils.test.ts +334 -115
- package/src/wit/wit-parser/core/utils.ts +54 -38
- package/src/wit/wit-parser/parse-wit-parameter.test.ts +282 -4
- package/src/wit/wit-parser/parse-wit-parameter.ts +37 -11
- package/src/wit/wit-parser/parse-wit.test.ts +738 -12
- package/src/wit/wit-parser/parse-wit.ts +25 -10
- package/src/wit/wit.ts +37 -16
- package/vitest.config.ts +5 -0
- package/dist/cjs/sdk/utils/wit/codecs/decimal.js +0 -148
- package/dist/cjs/sdk/utils/wit/codecs/decimal.js.map +0 -1
- package/dist/cjs/sdk/utils/wit/codecs/enum.js +0 -94
- package/dist/cjs/sdk/utils/wit/codecs/enum.js.map +0 -1
- package/dist/cjs/sdk/utils/wit/codecs/integer.js +0 -125
- package/dist/cjs/sdk/utils/wit/codecs/integer.js.map +0 -1
- package/dist/cjs/sdk/utils/wit/codecs/s64.js +0 -57
- package/dist/cjs/sdk/utils/wit/codecs/s64.js.map +0 -1
- package/dist/cjs/sdk/utils/wit/codecs/u64.js +0 -56
- package/dist/cjs/sdk/utils/wit/codecs/u64.js.map +0 -1
- package/dist/cjs/wit/wit-parser/core/records.js +0 -70
- package/dist/cjs/wit/wit-parser/core/records.js.map +0 -1
- package/dist/cjs/wit/wit-parser/core/types/records.js.map +0 -1
- package/dist/esm/sdk/utils/wit/codecs/decimal.js +0 -165
- package/dist/esm/sdk/utils/wit/codecs/decimal.js.map +0 -1
- package/dist/esm/sdk/utils/wit/codecs/enum.js +0 -104
- package/dist/esm/sdk/utils/wit/codecs/enum.js.map +0 -1
- package/dist/esm/sdk/utils/wit/codecs/integer.js +0 -167
- package/dist/esm/sdk/utils/wit/codecs/integer.js.map +0 -1
- package/dist/esm/sdk/utils/wit/codecs/s64.js +0 -65
- package/dist/esm/sdk/utils/wit/codecs/s64.js.map +0 -1
- package/dist/esm/sdk/utils/wit/codecs/u64.js +0 -63
- package/dist/esm/sdk/utils/wit/codecs/u64.js.map +0 -1
- package/dist/esm/wit/wit-parser/core/records.js +0 -73
- package/dist/esm/wit/wit-parser/core/records.js.map +0 -1
- package/dist/esm/wit/wit-parser/core/types/records.js +0 -2
- package/dist/esm/wit/wit-parser/core/types/records.js.map +0 -1
- package/dist/types/sdk/utils/wit/codecs/decimal.d.ts +0 -42
- package/dist/types/sdk/utils/wit/codecs/decimal.d.ts.map +0 -1
- package/dist/types/sdk/utils/wit/codecs/enum.d.ts +0 -49
- package/dist/types/sdk/utils/wit/codecs/enum.d.ts.map +0 -1
- package/dist/types/sdk/utils/wit/codecs/integer.d.ts +0 -36
- package/dist/types/sdk/utils/wit/codecs/integer.d.ts.map +0 -1
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts +0 -23
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts.map +0 -1
- package/dist/types/sdk/utils/wit/codecs/u64.d.ts +0 -23
- package/dist/types/sdk/utils/wit/codecs/u64.d.ts.map +0 -1
- package/dist/types/wit/wit-parser/core/records.d.ts +0 -4
- package/dist/types/wit/wit-parser/core/records.d.ts.map +0 -1
- package/dist/types/wit/wit-parser/core/types/records.d.ts +0 -51
- package/dist/types/wit/wit-parser/core/types/records.d.ts.map +0 -1
- package/src/sdk/test/e2e.test.ts +0 -194
- package/src/sdk/utils/wit/codecs/decimal.ts +0 -215
- package/src/sdk/utils/wit/codecs/enum.ts +0 -114
- package/src/sdk/utils/wit/codecs/integer.ts +0 -193
- package/src/sdk/utils/wit/codecs/s64.ts +0 -76
- package/src/sdk/utils/wit/codecs/u64.ts +0 -73
- package/src/wit/wit-parser/core/records.test.ts +0 -69
- package/src/wit/wit-parser/core/records.ts +0 -101
- package/src/wit/wit-parser/core/types/records.test-d.ts +0 -331
- package/src/wit/wit-parser/core/types/records.ts +0 -91
|
@@ -1,124 +1,988 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
1
|
+
import { expect, test, describe } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { encodeWitParameters } from "./encode-wit-parameters.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
describe("basic encoding", () => {
|
|
6
|
+
test("blank", () => {
|
|
7
|
+
expect(encodeWitParameters([], [])).toBe("");
|
|
8
|
+
});
|
|
7
9
|
});
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// STRING TYPES
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
describe("string types", () => {
|
|
16
|
+
test("string", () => {
|
|
17
|
+
expect(encodeWitParameters([{ type: "string" }], ["bc1deadbeef"])).toBe(
|
|
18
|
+
`"bc1deadbeef"`,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("option<string> - some", () => {
|
|
23
|
+
expect(
|
|
24
|
+
encodeWitParameters([{ type: "option<string>" }], [["some", "hello"]]),
|
|
25
|
+
).toBe(`some("hello")`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("option<string> - none", () => {
|
|
29
|
+
expect(encodeWitParameters([{ type: "option<string>" }], [["none"]])).toBe(
|
|
30
|
+
`none`,
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("list<string>", () => {
|
|
35
|
+
expect(
|
|
36
|
+
encodeWitParameters([{ type: "list<string>" }], [["foo", "bar"]]),
|
|
37
|
+
).toBe(`["foo", "bar"]`);
|
|
38
|
+
});
|
|
13
39
|
});
|
|
14
40
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// DECIMAL TYPES
|
|
43
|
+
// ============================================================================
|
|
44
|
+
|
|
45
|
+
describe("decimal types", () => {
|
|
46
|
+
test("decimal", () => {
|
|
47
|
+
expect(encodeWitParameters([{ type: "decimal" }], [[7n, 18]])).toBe(
|
|
48
|
+
`{r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}`,
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("decimal negative", () => {
|
|
53
|
+
expect(encodeWitParameters([{ type: "decimal" }], [[-7n, 18]])).toBe(
|
|
54
|
+
`{r0: 7, r1: 0, r2: 0, r3: 0, sign: minus}`,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("option<decimal> - some", () => {
|
|
59
|
+
expect(
|
|
60
|
+
encodeWitParameters([{ type: "option<decimal>" }], [["some", [7n, 18]]]),
|
|
61
|
+
).toBe(`some({r0: 7, r1: 0, r2: 0, r3: 0, sign: plus})`);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("option<decimal> - none", () => {
|
|
65
|
+
expect(encodeWitParameters([{ type: "option<decimal>" }], [["none"]])).toBe(
|
|
66
|
+
`none`,
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("list<decimal>", () => {
|
|
71
|
+
expect(
|
|
72
|
+
encodeWitParameters(
|
|
73
|
+
[{ type: "list<decimal>" }],
|
|
74
|
+
[
|
|
75
|
+
[
|
|
76
|
+
[7n, 18],
|
|
77
|
+
[8n, 18],
|
|
78
|
+
],
|
|
79
|
+
],
|
|
80
|
+
),
|
|
81
|
+
).toBe(
|
|
82
|
+
`[{r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, {r0: 8, r1: 0, r2: 0, r3: 0, sign: plus}]`,
|
|
83
|
+
);
|
|
84
|
+
});
|
|
19
85
|
});
|
|
20
86
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// BOOL TYPES
|
|
89
|
+
// ============================================================================
|
|
90
|
+
|
|
91
|
+
describe("bool types", () => {
|
|
92
|
+
test("bool - true", () => {
|
|
93
|
+
expect(encodeWitParameters([{ type: "bool" }], [true])).toBe("true");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("bool - false", () => {
|
|
97
|
+
expect(encodeWitParameters([{ type: "bool" }], [false])).toBe("false");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("option<bool> - some", () => {
|
|
101
|
+
expect(
|
|
102
|
+
encodeWitParameters([{ type: "option<bool>" }], [["some", true]]),
|
|
103
|
+
).toBe("some(true)");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("option<bool> - none", () => {
|
|
107
|
+
expect(encodeWitParameters([{ type: "option<bool>" }], [["none"]])).toBe(
|
|
108
|
+
"none",
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("list<bool>", () => {
|
|
113
|
+
expect(
|
|
114
|
+
encodeWitParameters([{ type: "list<bool>" }], [[true, false, true]]),
|
|
115
|
+
).toBe("[true, false, true]");
|
|
116
|
+
});
|
|
25
117
|
});
|
|
26
118
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
119
|
+
// ============================================================================
|
|
120
|
+
// INTEGER TYPES
|
|
121
|
+
// ============================================================================
|
|
122
|
+
|
|
123
|
+
describe("integer types", () => {
|
|
124
|
+
test("integer", () => {
|
|
125
|
+
expect(encodeWitParameters([{ type: "integer" }], [7n])).toBe(
|
|
126
|
+
`{r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}`,
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("integer negative", () => {
|
|
131
|
+
expect(encodeWitParameters([{ type: "integer" }], [-7n])).toBe(
|
|
132
|
+
`{r0: 7, r1: 0, r2: 0, r3: 0, sign: minus}`,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("option<integer> - some", () => {
|
|
137
|
+
expect(
|
|
138
|
+
encodeWitParameters([{ type: "option<integer>" }], [["some", 42n]]),
|
|
139
|
+
).toBe(`some({r0: 42, r1: 0, r2: 0, r3: 0, sign: plus})`);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("option<integer> - none", () => {
|
|
143
|
+
expect(encodeWitParameters([{ type: "option<integer>" }], [["none"]])).toBe(
|
|
144
|
+
`none`,
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("list<integer>", () => {
|
|
149
|
+
expect(encodeWitParameters([{ type: "list<integer>" }], [[7n, 8n]])).toBe(
|
|
150
|
+
`[{r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, {r0: 8, r1: 0, r2: 0, r3: 0, sign: plus}]`,
|
|
151
|
+
);
|
|
152
|
+
});
|
|
32
153
|
});
|
|
33
154
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
155
|
+
// ============================================================================
|
|
156
|
+
// UNSIGNED INTEGER TYPES (u8, u16, u32, u64)
|
|
157
|
+
// ============================================================================
|
|
158
|
+
|
|
159
|
+
describe("unsigned integer types", () => {
|
|
160
|
+
test("u8", () => {
|
|
161
|
+
expect(encodeWitParameters([{ type: "u8" }], [255])).toBe("255");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("option<u8>", () => {
|
|
165
|
+
expect(encodeWitParameters([{ type: "option<u8>" }], [["some", 128]])).toBe(
|
|
166
|
+
"some(128)",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("list<u8>", () => {
|
|
171
|
+
expect(encodeWitParameters([{ type: "list<u8>" }], [[1, 2, 3]])).toBe(
|
|
172
|
+
"[1, 2, 3]",
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("u16", () => {
|
|
177
|
+
expect(encodeWitParameters([{ type: "u16" }], [65535])).toBe("65535");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("option<u16>", () => {
|
|
181
|
+
expect(
|
|
182
|
+
encodeWitParameters([{ type: "option<u16>" }], [["some", 1000]]),
|
|
183
|
+
).toBe("some(1000)");
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("list<u16>", () => {
|
|
187
|
+
expect(encodeWitParameters([{ type: "list<u16>" }], [[100, 200]])).toBe(
|
|
188
|
+
"[100, 200]",
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("u32", () => {
|
|
193
|
+
expect(encodeWitParameters([{ type: "u32" }], [4294967295])).toBe(
|
|
194
|
+
"4294967295",
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("option<u32>", () => {
|
|
199
|
+
expect(
|
|
200
|
+
encodeWitParameters([{ type: "option<u32>" }], [["some", 1000000]]),
|
|
201
|
+
).toBe("some(1000000)");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("list<u32>", () => {
|
|
205
|
+
expect(encodeWitParameters([{ type: "list<u32>" }], [[1000, 2000]])).toBe(
|
|
206
|
+
"[1000, 2000]",
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("u64", () => {
|
|
211
|
+
expect(encodeWitParameters([{ type: "u64" }], [30n])).toBe("30");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("option<u64>", () => {
|
|
215
|
+
expect(
|
|
216
|
+
encodeWitParameters([{ type: "option<u64>" }], [["some", 999n]]),
|
|
217
|
+
).toBe("some(999)");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("list<u64>", () => {
|
|
221
|
+
expect(
|
|
222
|
+
encodeWitParameters([{ type: "list<u64>" }], [[100n, 200n, 300n]]),
|
|
223
|
+
).toBe("[100, 200, 300]");
|
|
224
|
+
});
|
|
38
225
|
});
|
|
39
226
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
227
|
+
// ============================================================================
|
|
228
|
+
// SIGNED INTEGER TYPES (s8, s16, s32, s64)
|
|
229
|
+
// ============================================================================
|
|
230
|
+
|
|
231
|
+
describe("signed integer types", () => {
|
|
232
|
+
test("s8", () => {
|
|
233
|
+
expect(encodeWitParameters([{ type: "s8" }], [-128])).toBe("-128");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("option<s8>", () => {
|
|
237
|
+
expect(encodeWitParameters([{ type: "option<s8>" }], [["some", -42]])).toBe(
|
|
238
|
+
"some(-42)",
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("list<s8>", () => {
|
|
243
|
+
expect(encodeWitParameters([{ type: "list<s8>" }], [[-1, 0, 1]])).toBe(
|
|
244
|
+
"[-1, 0, 1]",
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("s16", () => {
|
|
249
|
+
expect(encodeWitParameters([{ type: "s16" }], [-32768])).toBe("-32768");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("option<s16>", () => {
|
|
253
|
+
expect(
|
|
254
|
+
encodeWitParameters([{ type: "option<s16>" }], [["some", -1000]]),
|
|
255
|
+
).toBe("some(-1000)");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("list<s16>", () => {
|
|
259
|
+
expect(encodeWitParameters([{ type: "list<s16>" }], [[-100, 100]])).toBe(
|
|
260
|
+
"[-100, 100]",
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("s32", () => {
|
|
265
|
+
expect(encodeWitParameters([{ type: "s32" }], [-2147483648])).toBe(
|
|
266
|
+
"-2147483648",
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("option<s32>", () => {
|
|
271
|
+
expect(
|
|
272
|
+
encodeWitParameters([{ type: "option<s32>" }], [["some", -100000]]),
|
|
273
|
+
).toBe("some(-100000)");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("list<s32>", () => {
|
|
277
|
+
expect(encodeWitParameters([{ type: "list<s32>" }], [[-1000, 1000]])).toBe(
|
|
278
|
+
"[-1000, 1000]",
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("s64", () => {
|
|
283
|
+
expect(encodeWitParameters([{ type: "s64" }], [-100n])).toBe("-100");
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("option<s64>", () => {
|
|
287
|
+
expect(
|
|
288
|
+
encodeWitParameters([{ type: "option<s64>" }], [["some", -999n]]),
|
|
289
|
+
).toBe("some(-999)");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("list<s64>", () => {
|
|
293
|
+
expect(
|
|
294
|
+
encodeWitParameters([{ type: "list<s64>" }], [[-100n, 0n, 100n]]),
|
|
295
|
+
).toBe("[-100, 0, 100]");
|
|
296
|
+
});
|
|
44
297
|
});
|
|
45
298
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
299
|
+
// ============================================================================
|
|
300
|
+
// RECORD TYPES
|
|
301
|
+
// ============================================================================
|
|
302
|
+
|
|
303
|
+
describe("record types", () => {
|
|
304
|
+
test("record", () => {
|
|
305
|
+
expect(
|
|
306
|
+
encodeWitParameters(
|
|
307
|
+
[
|
|
308
|
+
{
|
|
309
|
+
type: "record",
|
|
310
|
+
components: [
|
|
311
|
+
{ name: "a", type: "integer" },
|
|
312
|
+
{ name: "b", type: "decimal" },
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
[{ a: 7n, b: [7n, 18] }],
|
|
317
|
+
),
|
|
318
|
+
).toBe(
|
|
319
|
+
`{a: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, b: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}}`,
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("option<record> - some", () => {
|
|
324
|
+
expect(
|
|
325
|
+
encodeWitParameters(
|
|
326
|
+
[
|
|
327
|
+
{
|
|
328
|
+
type: "option<record>",
|
|
329
|
+
components: [
|
|
330
|
+
{ name: "a", type: "integer" },
|
|
331
|
+
{ name: "b", type: "decimal" },
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
[["some", { a: 7n, b: [7n, 18] }]],
|
|
336
|
+
),
|
|
337
|
+
).toBe(
|
|
338
|
+
`some({a: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, b: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}})`,
|
|
339
|
+
);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("option<record> - none", () => {
|
|
343
|
+
expect(
|
|
344
|
+
encodeWitParameters(
|
|
345
|
+
[
|
|
346
|
+
{
|
|
347
|
+
type: "option<record>",
|
|
348
|
+
components: [
|
|
349
|
+
{ name: "x", type: "u32" },
|
|
350
|
+
{ name: "y", type: "u32" },
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
[["none"]],
|
|
355
|
+
),
|
|
356
|
+
).toBe("none");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("list<record>", () => {
|
|
360
|
+
expect(
|
|
361
|
+
encodeWitParameters(
|
|
362
|
+
[
|
|
363
|
+
{
|
|
364
|
+
type: "list<record>",
|
|
365
|
+
components: [
|
|
366
|
+
{ name: "x", type: "u32" },
|
|
367
|
+
{ name: "y", type: "u32" },
|
|
368
|
+
],
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
[[{ x: 1, y: 2 }]],
|
|
372
|
+
),
|
|
373
|
+
).toBe("[{x: 1, y: 2}]");
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test("record with variant field", () => {
|
|
377
|
+
expect(
|
|
378
|
+
encodeWitParameters(
|
|
379
|
+
[
|
|
380
|
+
{
|
|
381
|
+
type: "record",
|
|
382
|
+
components: [
|
|
383
|
+
{ name: "id", type: "u64" },
|
|
384
|
+
{
|
|
385
|
+
name: "status",
|
|
386
|
+
type: "variant",
|
|
387
|
+
components: [
|
|
388
|
+
{ name: "pending", type: "_" },
|
|
389
|
+
{ name: "completed", type: "string" },
|
|
390
|
+
],
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
{
|
|
397
|
+
id: 123n,
|
|
398
|
+
status: ["completed", "done"],
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
),
|
|
402
|
+
).toBe(`{id: 123, status: completed("done")}`);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("record with option<record> - some", () => {
|
|
406
|
+
expect(
|
|
407
|
+
encodeWitParameters(
|
|
51
408
|
[
|
|
52
|
-
|
|
53
|
-
|
|
409
|
+
{
|
|
410
|
+
type: "record",
|
|
411
|
+
components: [
|
|
412
|
+
{ name: "a", type: "integer" },
|
|
413
|
+
{
|
|
414
|
+
name: "b",
|
|
415
|
+
type: "option<record>",
|
|
416
|
+
components: [{ name: "c", type: "integer" }],
|
|
417
|
+
},
|
|
418
|
+
],
|
|
419
|
+
},
|
|
54
420
|
],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
421
|
+
[
|
|
422
|
+
{
|
|
423
|
+
a: 7n,
|
|
424
|
+
b: ["some", { c: 3n }],
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
),
|
|
428
|
+
).toBe(
|
|
429
|
+
`{a: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, ` +
|
|
430
|
+
`b: some({c: {r0: 3, r1: 0, r2: 0, r3: 0, sign: plus}})}`,
|
|
431
|
+
);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("record with option<record> - none", () => {
|
|
435
|
+
expect(
|
|
436
|
+
encodeWitParameters(
|
|
437
|
+
[
|
|
438
|
+
{
|
|
439
|
+
type: "record",
|
|
440
|
+
components: [
|
|
441
|
+
{ name: "a", type: "integer" },
|
|
442
|
+
{
|
|
443
|
+
name: "b",
|
|
444
|
+
type: "option<record>",
|
|
445
|
+
components: [{ name: "c", type: "integer" }],
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
{
|
|
452
|
+
a: 7n,
|
|
453
|
+
b: ["none"],
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
),
|
|
457
|
+
).toBe(`{a: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, b: none}`);
|
|
458
|
+
});
|
|
60
459
|
});
|
|
61
460
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
).toThrowError(
|
|
66
|
-
`Type "list<list<<integer>>" is not a valid encoding type.
|
|
67
|
-
Please provide a valid WIT type.
|
|
461
|
+
// ============================================================================
|
|
462
|
+
// ENUM TYPES
|
|
463
|
+
// ============================================================================
|
|
68
464
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
465
|
+
describe("enum types", () => {
|
|
466
|
+
test("enum", () => {
|
|
467
|
+
expect(
|
|
468
|
+
encodeWitParameters(
|
|
469
|
+
[
|
|
470
|
+
{
|
|
471
|
+
type: "enum",
|
|
472
|
+
components: [
|
|
473
|
+
{ name: "red", type: "_" },
|
|
474
|
+
{ name: "green", type: "_" },
|
|
475
|
+
{ name: "blue", type: "_" },
|
|
476
|
+
],
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
["red"],
|
|
480
|
+
),
|
|
481
|
+
).toBe("red");
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
test("option<enum> - some", () => {
|
|
485
|
+
expect(
|
|
486
|
+
encodeWitParameters(
|
|
487
|
+
[
|
|
488
|
+
{
|
|
489
|
+
type: "option<enum>",
|
|
490
|
+
components: [
|
|
491
|
+
{ name: "red", type: "_" },
|
|
492
|
+
{ name: "green", type: "_" },
|
|
493
|
+
{ name: "blue", type: "_" },
|
|
494
|
+
],
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
[["some", "green"]],
|
|
498
|
+
),
|
|
499
|
+
).toBe("some(green)");
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
test("option<enum> - none", () => {
|
|
503
|
+
expect(
|
|
504
|
+
encodeWitParameters(
|
|
505
|
+
[
|
|
506
|
+
{
|
|
507
|
+
type: "option<enum>",
|
|
508
|
+
components: [
|
|
509
|
+
{ name: "red", type: "_" },
|
|
510
|
+
{ name: "green", type: "_" },
|
|
511
|
+
{ name: "blue", type: "_" },
|
|
512
|
+
],
|
|
513
|
+
},
|
|
514
|
+
],
|
|
515
|
+
[["none"]],
|
|
516
|
+
),
|
|
517
|
+
).toBe("none");
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test("list<enum>", () => {
|
|
521
|
+
expect(
|
|
522
|
+
encodeWitParameters(
|
|
523
|
+
[
|
|
524
|
+
{
|
|
525
|
+
type: "list<enum>",
|
|
526
|
+
components: [
|
|
527
|
+
{ name: "red", type: "_" },
|
|
528
|
+
{ name: "green", type: "_" },
|
|
529
|
+
{ name: "blue", type: "_" },
|
|
530
|
+
],
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
[["red", "blue", "green"]],
|
|
534
|
+
),
|
|
535
|
+
).toBe("[red, blue, green]");
|
|
536
|
+
});
|
|
72
537
|
});
|
|
73
538
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
539
|
+
// ============================================================================
|
|
540
|
+
// VARIANT TYPES
|
|
541
|
+
// ============================================================================
|
|
542
|
+
|
|
543
|
+
describe("variant types", () => {
|
|
544
|
+
test("variant with unit case (no payload)", () => {
|
|
545
|
+
expect(
|
|
546
|
+
encodeWitParameters(
|
|
547
|
+
[
|
|
548
|
+
{
|
|
549
|
+
type: "variant",
|
|
550
|
+
components: [
|
|
551
|
+
{ name: "none", type: "_" },
|
|
552
|
+
{ name: "some", type: "integer" },
|
|
553
|
+
],
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
[["none"]],
|
|
557
|
+
),
|
|
558
|
+
).toBe("none");
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test("variant with integer payload", () => {
|
|
562
|
+
expect(
|
|
563
|
+
encodeWitParameters(
|
|
564
|
+
[
|
|
565
|
+
{
|
|
566
|
+
type: "variant",
|
|
567
|
+
components: [
|
|
568
|
+
{ name: "none", type: "_" },
|
|
569
|
+
{ name: "some", type: "integer" },
|
|
570
|
+
],
|
|
571
|
+
},
|
|
572
|
+
],
|
|
573
|
+
[["some", 42n]],
|
|
574
|
+
),
|
|
575
|
+
).toBe("some({r0: 42, r1: 0, r2: 0, r3: 0, sign: plus})");
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
test("variant with string payload", () => {
|
|
579
|
+
expect(
|
|
580
|
+
encodeWitParameters(
|
|
581
|
+
[
|
|
582
|
+
{
|
|
583
|
+
type: "variant",
|
|
584
|
+
components: [
|
|
585
|
+
{ name: "error", type: "string" },
|
|
586
|
+
{ name: "success", type: "string" },
|
|
587
|
+
],
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
[["error", "something went wrong"]],
|
|
591
|
+
),
|
|
592
|
+
).toBe(`error("something went wrong")`);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
test("variant with record payload", () => {
|
|
596
|
+
expect(
|
|
597
|
+
encodeWitParameters(
|
|
598
|
+
[
|
|
599
|
+
{
|
|
600
|
+
type: "variant",
|
|
601
|
+
components: [
|
|
602
|
+
{ name: "none", type: "_" },
|
|
603
|
+
{
|
|
604
|
+
name: "person",
|
|
605
|
+
type: "record",
|
|
606
|
+
components: [
|
|
607
|
+
{ name: "name", type: "string" },
|
|
608
|
+
{ name: "age", type: "u64" },
|
|
609
|
+
],
|
|
610
|
+
},
|
|
611
|
+
],
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
[["person", { name: "Alice", age: 30n }]],
|
|
615
|
+
),
|
|
616
|
+
).toBe(`person({name: "Alice", age: 30})`);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
test("variant with list payload", () => {
|
|
620
|
+
expect(
|
|
621
|
+
encodeWitParameters(
|
|
622
|
+
[
|
|
623
|
+
{
|
|
624
|
+
type: "variant",
|
|
625
|
+
components: [
|
|
626
|
+
{ name: "empty", type: "_" },
|
|
627
|
+
{ name: "items", type: "list<string>" },
|
|
628
|
+
],
|
|
629
|
+
},
|
|
630
|
+
],
|
|
631
|
+
[["items", ["apple", "banana", "cherry"]]],
|
|
632
|
+
),
|
|
633
|
+
).toBe(`items(["apple", "banana", "cherry"])`);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
test("option<variant> - some", () => {
|
|
637
|
+
expect(
|
|
638
|
+
encodeWitParameters(
|
|
639
|
+
[
|
|
640
|
+
{
|
|
641
|
+
type: "option<variant>",
|
|
642
|
+
components: [
|
|
643
|
+
{ name: "red", type: "_" },
|
|
644
|
+
{ name: "blue", type: "_" },
|
|
645
|
+
],
|
|
646
|
+
},
|
|
647
|
+
],
|
|
648
|
+
[["some", ["red" as const]]],
|
|
649
|
+
),
|
|
650
|
+
).toBe("some(red)");
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
test("option<variant> - none", () => {
|
|
654
|
+
expect(
|
|
655
|
+
encodeWitParameters(
|
|
656
|
+
[
|
|
657
|
+
{
|
|
658
|
+
type: "option<variant>",
|
|
659
|
+
components: [
|
|
660
|
+
{ name: "red", type: "_" },
|
|
661
|
+
{ name: "blue", type: "_" },
|
|
662
|
+
],
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
[["none"]],
|
|
666
|
+
),
|
|
667
|
+
).toBe("none");
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
test("list<variant>", () => {
|
|
671
|
+
expect(
|
|
672
|
+
encodeWitParameters(
|
|
673
|
+
[
|
|
674
|
+
{
|
|
675
|
+
type: "list<variant>",
|
|
676
|
+
components: [
|
|
677
|
+
{ name: "none", type: "_" },
|
|
678
|
+
{ name: "value", type: "u64" },
|
|
679
|
+
],
|
|
680
|
+
},
|
|
681
|
+
],
|
|
682
|
+
[[["none"], ["value", 42n], ["none"]]],
|
|
683
|
+
),
|
|
684
|
+
).toBe("[none, value(42), none]");
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
test("variant with nested variant payload", () => {
|
|
688
|
+
expect(
|
|
689
|
+
encodeWitParameters(
|
|
690
|
+
[
|
|
691
|
+
{
|
|
692
|
+
type: "variant",
|
|
693
|
+
components: [
|
|
694
|
+
{ name: "none", type: "_" },
|
|
695
|
+
{
|
|
696
|
+
name: "color",
|
|
697
|
+
type: "variant",
|
|
698
|
+
components: [
|
|
699
|
+
{ name: "red", type: "_" },
|
|
700
|
+
{
|
|
701
|
+
name: "rgb",
|
|
702
|
+
type: "record",
|
|
703
|
+
components: [
|
|
704
|
+
{ name: "r", type: "u8" },
|
|
705
|
+
{ name: "g", type: "u8" },
|
|
706
|
+
{ name: "b", type: "u8" },
|
|
707
|
+
],
|
|
708
|
+
},
|
|
709
|
+
],
|
|
710
|
+
},
|
|
711
|
+
],
|
|
712
|
+
},
|
|
713
|
+
],
|
|
714
|
+
[["color", ["rgb", { r: 255, g: 0, b: 0 }]]],
|
|
715
|
+
),
|
|
716
|
+
).toBe("color(rgb({r: 255, g: 0, b: 0}))");
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test("variant with list<record> payload", () => {
|
|
720
|
+
expect(
|
|
721
|
+
encodeWitParameters(
|
|
722
|
+
[
|
|
723
|
+
{
|
|
724
|
+
type: "variant",
|
|
725
|
+
components: [
|
|
726
|
+
{ name: "none", type: "_" },
|
|
727
|
+
{
|
|
728
|
+
name: "addresses",
|
|
729
|
+
type: "list<record>",
|
|
730
|
+
components: [
|
|
731
|
+
{ name: "street", type: "string" },
|
|
732
|
+
{ name: "city", type: "string" },
|
|
733
|
+
],
|
|
734
|
+
},
|
|
735
|
+
],
|
|
736
|
+
},
|
|
737
|
+
],
|
|
738
|
+
[
|
|
739
|
+
[
|
|
740
|
+
"addresses",
|
|
741
|
+
[
|
|
742
|
+
{ street: "123 Main St", city: "Boston" },
|
|
743
|
+
{ street: "456 Oak Ave", city: "Cambridge" },
|
|
744
|
+
],
|
|
745
|
+
],
|
|
746
|
+
],
|
|
747
|
+
),
|
|
748
|
+
).toBe(
|
|
749
|
+
`addresses([{street: "123 Main St", city: "Boston"}, {street: "456 Oak Ave", city: "Cambridge"}])`,
|
|
750
|
+
);
|
|
751
|
+
});
|
|
81
752
|
});
|
|
82
753
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
754
|
+
// ============================================================================
|
|
755
|
+
// UNIT TYPE (special cases)
|
|
756
|
+
// ============================================================================
|
|
757
|
+
|
|
758
|
+
describe("unit type special cases", () => {
|
|
759
|
+
test("option<_> - some", () => {
|
|
760
|
+
expect(
|
|
761
|
+
encodeWitParameters(
|
|
762
|
+
[{ type: "option<_>" }],
|
|
763
|
+
[["some", { _tag: "Unit" }]],
|
|
764
|
+
),
|
|
765
|
+
).toBe("some(_)");
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
test("option<_> - none", () => {
|
|
769
|
+
expect(encodeWitParameters([{ type: "option<_>" }], [["none"]])).toBe(
|
|
770
|
+
"none",
|
|
771
|
+
);
|
|
772
|
+
});
|
|
87
773
|
});
|
|
88
774
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
775
|
+
// ============================================================================
|
|
776
|
+
// NESTED OPTION<LIST<T>>
|
|
777
|
+
// ============================================================================
|
|
778
|
+
|
|
779
|
+
describe("option<list<T>> types", () => {
|
|
780
|
+
test("option<list<string>> - some", () => {
|
|
781
|
+
expect(
|
|
782
|
+
encodeWitParameters(
|
|
783
|
+
[{ type: "option<list<string>>" }],
|
|
784
|
+
[["some", ["a", "b", "c"]]],
|
|
785
|
+
),
|
|
786
|
+
).toBe(`some(["a", "b", "c"])`);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
test("option<list<string>> - none", () => {
|
|
790
|
+
expect(
|
|
791
|
+
encodeWitParameters([{ type: "option<list<string>>" }], [["none"]]),
|
|
792
|
+
).toBe("none");
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
test("option<list<decimal>>", () => {
|
|
796
|
+
expect(
|
|
797
|
+
encodeWitParameters(
|
|
798
|
+
[{ type: "option<list<decimal>>" }],
|
|
799
|
+
[["some", [[1n, 18]]]],
|
|
800
|
+
),
|
|
801
|
+
).toBe("some([{r0: 1, r1: 0, r2: 0, r3: 0, sign: plus}])");
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
test("option<list<bool>>", () => {
|
|
805
|
+
expect(
|
|
806
|
+
encodeWitParameters(
|
|
807
|
+
[{ type: "option<list<bool>>" }],
|
|
808
|
+
[["some", [true, false]]],
|
|
809
|
+
),
|
|
810
|
+
).toBe("some([true, false])");
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
test("option<list<integer>>", () => {
|
|
814
|
+
expect(
|
|
815
|
+
encodeWitParameters(
|
|
816
|
+
[{ type: "option<list<integer>>" }],
|
|
817
|
+
[["some", [1n, 2n]]],
|
|
818
|
+
),
|
|
819
|
+
).toBe(
|
|
820
|
+
"some([{r0: 1, r1: 0, r2: 0, r3: 0, sign: plus}, {r0: 2, r1: 0, r2: 0, r3: 0, sign: plus}])",
|
|
821
|
+
);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
test("option<list<u8>>", () => {
|
|
825
|
+
expect(
|
|
826
|
+
encodeWitParameters(
|
|
827
|
+
[{ type: "option<list<u8>>" }],
|
|
828
|
+
[["some", [1, 2, 3]]],
|
|
829
|
+
),
|
|
830
|
+
).toBe("some([1, 2, 3])");
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
test("option<list<u16>>", () => {
|
|
834
|
+
expect(
|
|
835
|
+
encodeWitParameters(
|
|
836
|
+
[{ type: "option<list<u16>>" }],
|
|
837
|
+
[["some", [100, 200]]],
|
|
838
|
+
),
|
|
839
|
+
).toBe("some([100, 200])");
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test("option<list<u32>>", () => {
|
|
843
|
+
expect(
|
|
844
|
+
encodeWitParameters(
|
|
845
|
+
[{ type: "option<list<u32>>" }],
|
|
846
|
+
[["some", [1000, 2000]]],
|
|
847
|
+
),
|
|
848
|
+
).toBe("some([1000, 2000])");
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
test("option<list<u64>>", () => {
|
|
852
|
+
expect(
|
|
853
|
+
encodeWitParameters(
|
|
854
|
+
[{ type: "option<list<u64>>" }],
|
|
855
|
+
[["some", [100n, 200n]]],
|
|
856
|
+
),
|
|
857
|
+
).toBe("some([100, 200])");
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
test("option<list<s8>>", () => {
|
|
861
|
+
expect(
|
|
862
|
+
encodeWitParameters(
|
|
863
|
+
[{ type: "option<list<s8>>" }],
|
|
864
|
+
[["some", [-1, 0, 1]]],
|
|
865
|
+
),
|
|
866
|
+
).toBe("some([-1, 0, 1])");
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
test("option<list<s16>>", () => {
|
|
870
|
+
expect(
|
|
871
|
+
encodeWitParameters(
|
|
872
|
+
[{ type: "option<list<s16>>" }],
|
|
873
|
+
[["some", [-100, 100]]],
|
|
874
|
+
),
|
|
875
|
+
).toBe("some([-100, 100])");
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
test("option<list<s32>>", () => {
|
|
879
|
+
expect(
|
|
880
|
+
encodeWitParameters(
|
|
881
|
+
[{ type: "option<list<s32>>" }],
|
|
882
|
+
[["some", [-1000, 1000]]],
|
|
883
|
+
),
|
|
884
|
+
).toBe("some([-1000, 1000])");
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
test("option<list<s64>>", () => {
|
|
888
|
+
expect(
|
|
889
|
+
encodeWitParameters(
|
|
890
|
+
[{ type: "option<list<s64>>" }],
|
|
891
|
+
[["some", [-100n, 100n]]],
|
|
892
|
+
),
|
|
893
|
+
).toBe("some([-100, 100])");
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
test("option<list<record>>", () => {
|
|
897
|
+
expect(
|
|
898
|
+
encodeWitParameters(
|
|
899
|
+
[
|
|
900
|
+
{
|
|
901
|
+
type: "option<list<record>>",
|
|
902
|
+
components: [
|
|
903
|
+
{ name: "a", type: "integer" },
|
|
904
|
+
{ name: "b", type: "decimal" },
|
|
905
|
+
],
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
[
|
|
909
|
+
[
|
|
910
|
+
"some",
|
|
911
|
+
[
|
|
912
|
+
{ a: 7n, b: [7n, 18] },
|
|
913
|
+
{ a: 1n, b: [2n, 18] },
|
|
914
|
+
],
|
|
915
|
+
],
|
|
916
|
+
],
|
|
917
|
+
),
|
|
918
|
+
).toBe(
|
|
919
|
+
`some([{a: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}, b: {r0: 7, r1: 0, r2: 0, r3: 0, sign: plus}}, ` +
|
|
920
|
+
`{a: {r0: 1, r1: 0, r2: 0, r3: 0, sign: plus}, b: {r0: 2, r1: 0, r2: 0, r3: 0, sign: plus}}])`,
|
|
921
|
+
);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test("option<list<variant>>", () => {
|
|
925
|
+
expect(
|
|
926
|
+
encodeWitParameters(
|
|
927
|
+
[
|
|
928
|
+
{
|
|
929
|
+
type: "option<list<variant>>",
|
|
930
|
+
components: [
|
|
931
|
+
{ name: "none", type: "_" },
|
|
932
|
+
{ name: "value", type: "u32" },
|
|
933
|
+
],
|
|
934
|
+
},
|
|
935
|
+
],
|
|
936
|
+
[["some", [["none"], ["value", 10]]]],
|
|
937
|
+
),
|
|
938
|
+
).toBe("some([none, value(10)])");
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
test("option<list<enum>>", () => {
|
|
942
|
+
expect(
|
|
943
|
+
encodeWitParameters(
|
|
944
|
+
[
|
|
945
|
+
{
|
|
946
|
+
type: "option<list<enum>>",
|
|
947
|
+
components: [
|
|
948
|
+
{ name: "red", type: "_" },
|
|
949
|
+
{ name: "green", type: "_" },
|
|
950
|
+
{ name: "blue", type: "_" },
|
|
951
|
+
],
|
|
952
|
+
},
|
|
953
|
+
],
|
|
954
|
+
[["some", ["red", "blue"]]],
|
|
955
|
+
),
|
|
956
|
+
).toBe("some([red, blue])");
|
|
957
|
+
});
|
|
96
958
|
});
|
|
97
959
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
960
|
+
// ============================================================================
|
|
961
|
+
// CONTRACT ADDRESS TYPE
|
|
962
|
+
// ============================================================================
|
|
963
|
+
|
|
964
|
+
describe("contract-address type", () => {
|
|
965
|
+
test("contract-address", () => {
|
|
966
|
+
expect(
|
|
967
|
+
encodeWitParameters([{ type: "contract-address" }], ["token_0_0"]),
|
|
968
|
+
).toBe(`{name: "token", height: 0, tx_index: 0}`);
|
|
969
|
+
});
|
|
105
970
|
});
|
|
106
971
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
972
|
+
// ============================================================================
|
|
973
|
+
// ERROR CASES
|
|
974
|
+
// ============================================================================
|
|
975
|
+
|
|
976
|
+
describe("error cases", () => {
|
|
977
|
+
test("invalid list<list<integer>>", () => {
|
|
978
|
+
expect(() =>
|
|
979
|
+
encodeWitParameters([{ type: "list<list<integer>>" }], [[[7n, 8n]]]),
|
|
980
|
+
).toThrowError(
|
|
981
|
+
`Type "list<list<integer>>" is not a valid encoding type.
|
|
982
|
+
Please provide a valid WIT type.
|
|
983
|
+
|
|
984
|
+
Docs: https://docs.kontor.networktk
|
|
985
|
+
Version: kontor-sdk@1.0.0`,
|
|
986
|
+
);
|
|
987
|
+
});
|
|
124
988
|
});
|