quantumcoin 7.0.3 → 7.0.4

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.
Files changed (155) hide show
  1. package/.github/workflows/publish-npmjs.yaml +22 -22
  2. package/.gitignore +15 -15
  3. package/LICENSE +21 -21
  4. package/README-SDK.md +756 -754
  5. package/README.md +165 -150
  6. package/SPEC.md +3845 -3843
  7. package/config.d.ts +50 -50
  8. package/config.js +115 -115
  9. package/examples/AllSolidityTypes.sol +184 -184
  10. package/examples/SimpleIERC20.sol +74 -74
  11. package/examples/events.js +41 -35
  12. package/examples/events.ts +35 -0
  13. package/examples/example-generator-sdk-js.js +100 -95
  14. package/examples/example-generator-sdk-js.ts +77 -0
  15. package/examples/example-generator-sdk-ts.js +100 -95
  16. package/examples/example-generator-sdk-ts.ts +77 -0
  17. package/examples/example.js +72 -61
  18. package/examples/example.ts +61 -0
  19. package/examples/offline-signing.js +79 -73
  20. package/examples/offline-signing.ts +66 -0
  21. package/examples/package-lock.json +48 -57
  22. package/examples/package.json +32 -16
  23. package/examples/read-operations.js +32 -27
  24. package/examples/read-operations.ts +31 -0
  25. package/examples/sdk-generator-erc20.inline.json +251 -251
  26. package/examples/solidity-types.ts +43 -43
  27. package/examples/wallet-offline.js +35 -29
  28. package/examples/wallet-offline.ts +34 -0
  29. package/generate-sdk.js +1824 -1490
  30. package/index.js +12 -12
  31. package/package.json +95 -75
  32. package/scripts/copy-declarations.js +31 -0
  33. package/scripts/run-all-one-by-one.js +151 -0
  34. package/src/abi/fragments.d.ts +42 -42
  35. package/src/abi/fragments.js +63 -63
  36. package/src/abi/index.d.ts +13 -13
  37. package/src/abi/index.js +9 -9
  38. package/src/abi/interface.d.ts +128 -132
  39. package/src/abi/interface.js +590 -590
  40. package/src/abi/js-abi-coder.d.ts +8 -0
  41. package/src/abi/js-abi-coder.js +474 -474
  42. package/src/constants.d.ts +66 -61
  43. package/src/constants.js +101 -94
  44. package/src/contract/contract-factory.d.ts +28 -28
  45. package/src/contract/contract-factory.js +105 -105
  46. package/src/contract/contract.d.ts +113 -114
  47. package/src/contract/contract.js +354 -354
  48. package/src/contract/index.d.ts +9 -9
  49. package/src/contract/index.js +9 -9
  50. package/src/errors/index.d.ts +92 -92
  51. package/src/errors/index.js +188 -188
  52. package/src/generator/index.d.ts +74 -0
  53. package/src/generator/index.js +1404 -1404
  54. package/src/index.d.ts +125 -127
  55. package/src/index.js +41 -41
  56. package/src/internal/hex.d.ts +61 -61
  57. package/src/internal/hex.js +144 -144
  58. package/src/providers/extra-providers.d.ts +139 -128
  59. package/src/providers/extra-providers.js +600 -575
  60. package/src/providers/index.d.ts +17 -16
  61. package/src/providers/index.js +10 -10
  62. package/src/providers/json-rpc-provider.d.ts +12 -12
  63. package/src/providers/json-rpc-provider.js +79 -79
  64. package/src/providers/provider.d.ts +207 -203
  65. package/src/providers/provider.js +392 -371
  66. package/src/types/index.d.ts +214 -462
  67. package/src/types/index.js +9 -9
  68. package/src/utils/address.d.ts +72 -72
  69. package/src/utils/address.js +181 -182
  70. package/src/utils/encoding.d.ts +120 -120
  71. package/src/utils/encoding.js +306 -306
  72. package/src/utils/hashing.d.ts +82 -76
  73. package/src/utils/hashing.js +313 -298
  74. package/src/utils/index.d.ts +65 -55
  75. package/src/utils/index.js +13 -13
  76. package/src/utils/result.d.ts +57 -57
  77. package/src/utils/result.js +128 -128
  78. package/src/utils/rlp.d.ts +12 -12
  79. package/src/utils/rlp.js +200 -200
  80. package/src/utils/units.d.ts +29 -29
  81. package/src/utils/units.js +107 -107
  82. package/src/wallet/index.d.ts +10 -10
  83. package/src/wallet/index.js +8 -8
  84. package/src/wallet/wallet.d.ts +160 -160
  85. package/src/wallet/wallet.js +483 -489
  86. package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
  87. package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
  88. package/test/e2e/all-solidity-types.fixtures.js +231 -231
  89. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -368
  90. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
  91. package/test/e2e/helpers.js +59 -47
  92. package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
  93. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
  94. package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -151
  95. package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
  96. package/test/e2e/transactional.test.js +245 -191
  97. package/test/e2e/transactional.test.ts +208 -0
  98. package/test/e2e/typed-generator.e2e.test.js +407 -404
  99. package/test/e2e/typed-generator.e2e.test.ts +337 -0
  100. package/test/fixtures/ConstructorParam.sol +23 -23
  101. package/test/fixtures/MultiContracts.sol +37 -37
  102. package/test/fixtures/SimpleStorage.sol +18 -18
  103. package/test/fixtures/StakingContract.abi.json +1 -1
  104. package/test/integration/ipc-provider.test.js +49 -44
  105. package/test/integration/ipc-provider.test.ts +44 -0
  106. package/test/integration/provider.test.js +88 -72
  107. package/test/integration/provider.test.ts +85 -0
  108. package/test/integration/ws-provider.test.js +41 -33
  109. package/test/integration/ws-provider.test.ts +38 -0
  110. package/test/security/malformed-input.test.js +37 -31
  111. package/test/security/malformed-input.test.ts +35 -0
  112. package/test/unit/_encrypted-output.txt +6 -0
  113. package/test/unit/_log-encrypted-jsons.js +45 -0
  114. package/test/unit/_write-keystore-fixture.js +16 -0
  115. package/test/unit/abi-interface.test.js +103 -98
  116. package/test/unit/abi-interface.test.ts +102 -0
  117. package/test/unit/address-wallet.test.js +355 -257
  118. package/test/unit/address-wallet.test.ts +342 -0
  119. package/test/unit/browser-provider.test.js +85 -82
  120. package/test/unit/browser-provider.test.ts +79 -0
  121. package/test/unit/contract.test.js +85 -82
  122. package/test/unit/contract.test.ts +83 -0
  123. package/test/unit/encoding-units-rlp.test.js +92 -89
  124. package/test/unit/encoding-units-rlp.test.ts +91 -0
  125. package/test/unit/errors.test.js +77 -74
  126. package/test/unit/errors.test.ts +76 -0
  127. package/test/unit/filter-by-blockhash.test.js +55 -52
  128. package/test/unit/filter-by-blockhash.test.ts +54 -0
  129. package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
  130. package/test/unit/generate-contract-cli.test.js +42 -39
  131. package/test/unit/generate-contract-cli.test.ts +41 -0
  132. package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
  133. package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
  134. package/test/unit/generator.test.js +102 -99
  135. package/test/unit/generator.test.ts +101 -0
  136. package/test/unit/hashing.test.js +68 -54
  137. package/test/unit/hashing.test.ts +67 -0
  138. package/test/unit/init.test.js +39 -36
  139. package/test/unit/init.test.ts +38 -0
  140. package/test/unit/interface.test.js +56 -53
  141. package/test/unit/interface.test.ts +54 -0
  142. package/test/unit/internal-hex.test.js +50 -47
  143. package/test/unit/internal-hex.test.ts +49 -0
  144. package/test/unit/populate-transaction.test.js +65 -62
  145. package/test/unit/populate-transaction.test.ts +64 -0
  146. package/test/unit/providers.test.js +200 -144
  147. package/test/unit/providers.test.ts +196 -0
  148. package/test/unit/result.test.js +80 -77
  149. package/test/unit/result.test.ts +79 -0
  150. package/test/unit/solidity-types.test.js +49 -46
  151. package/test/unit/solidity-types.test.ts +39 -0
  152. package/test/unit/utils.test.js +57 -54
  153. package/test/unit/utils.test.ts +56 -0
  154. package/test/verbose-logger.js +74 -0
  155. package/tsconfig.build.json +14 -0
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Provider helpers, wrappers, defaults, and extra providers
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+
11
+ import qc from "../../index";
12
+ import { logSuite, logTest } from "../verbose-logger";
13
+
14
+ describe("JsonRpcProvider", () => {
15
+ logSuite("JsonRpcProvider");
16
+ it("defaults url/chainId when omitted vs null (no Initialize required)", () => {
17
+ logTest("defaults url/chainId when omitted vs null (no Initialize required)", {});
18
+ const p1 = new qc.JsonRpcProvider();
19
+ const p2 = new qc.JsonRpcProvider(null, null);
20
+
21
+ assert.equal(typeof p1.url, "string");
22
+ assert.ok(p1.url.length > 0);
23
+ assert.equal(p1.chainId, 123123);
24
+
25
+ assert.equal(p2.url, p1.url);
26
+ assert.equal(p2.chainId, 123123);
27
+ });
28
+
29
+ it("_perform defaults params when omitted vs null", async (t: { skip: (msg: string) => void }) => {
30
+ logTest("_perform defaults params when omitted vs null", {});
31
+ if (typeof (globalThis as unknown as { fetch?: unknown }).fetch !== "function") {
32
+ t.skip("global fetch not available");
33
+ return;
34
+ }
35
+
36
+ const originalFetch = (globalThis as unknown as { fetch: typeof fetch }).fetch;
37
+ const seen: unknown[][] = [];
38
+
39
+ (globalThis as unknown as { fetch: typeof fetch }).fetch = async (_url: string, init: RequestInit) => {
40
+ const body = JSON.parse(init.body as string);
41
+ seen.push(body.params);
42
+ return {
43
+ ok: true,
44
+ json: async () => ({ jsonrpc: "2.0", id: body.id, result: "0x1" }),
45
+ } as Response;
46
+ };
47
+
48
+ try {
49
+ const p = new qc.JsonRpcProvider("http://example.invalid", 123123);
50
+ const a = await p._perform("eth_blockNumber");
51
+ const b = await p._perform("eth_blockNumber", null);
52
+ assert.equal(a, "0x1");
53
+ assert.equal(b, "0x1");
54
+ assert.deepEqual(seen, [[], []]);
55
+ } finally {
56
+ (globalThis as unknown as { fetch: typeof fetch }).fetch = originalFetch;
57
+ }
58
+ });
59
+ });
60
+
61
+ describe("AbstractProvider defaults", () => {
62
+ logSuite("AbstractProvider defaults");
63
+ it("getTransactionCount/call/getCode default blockTag when omitted vs null", async () => {
64
+ logTest("getTransactionCount/call/getCode default blockTag when omitted vs null", {});
65
+ class P extends qc.AbstractProvider {
66
+ calls: { method: string; params: unknown[] }[] = [];
67
+ constructor() {
68
+ super();
69
+ }
70
+ async _perform(method: string, params: unknown[]) {
71
+ this.calls.push({ method, params });
72
+ if (method === "eth_getTransactionCount") return "0x2";
73
+ if (method === "eth_call") return "0x";
74
+ if (method === "eth_getCode") return "0x";
75
+ throw new Error("unexpected");
76
+ }
77
+ }
78
+
79
+ const p = new P();
80
+ await p.getTransactionCount("0x" + "11".repeat(32));
81
+ await p.getTransactionCount("0x" + "11".repeat(32), null);
82
+ await p.call({ to: "0x" + "11".repeat(32), data: "0x" });
83
+ await p.call({ to: "0x" + "11".repeat(32), data: "0x" }, null);
84
+ await p.getCode("0x" + "11".repeat(32));
85
+ await p.getCode("0x" + "11".repeat(32), null);
86
+
87
+ const tags = p.calls.map((c) => c.params[c.params.length - 1]);
88
+ assert.deepEqual(tags, ["latest", "latest", "latest", "latest", "latest", "latest"]);
89
+ });
90
+ });
91
+
92
+ describe("TransactionResponse.wait", () => {
93
+ logSuite("TransactionResponse.wait");
94
+ it("uses default confirmations when omitted vs null", async () => {
95
+ logTest("uses default confirmations when omitted vs null", {});
96
+ const fakeProvider = {
97
+ getTransactionReceipt: async () => ({ blockNumber: 1 }),
98
+ getBlockNumber: async () => 1,
99
+ };
100
+ const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, fakeProvider as unknown as qc.Provider);
101
+ const r1 = await tx.wait();
102
+ const r2 = await tx.wait(null, null);
103
+ assert.deepEqual(r1, { blockNumber: 1 });
104
+ assert.deepEqual(r2, { blockNumber: 1 });
105
+ });
106
+
107
+ it("throws if provider missing", async () => {
108
+ logTest("throws if provider missing", {});
109
+ const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, null);
110
+ await assert.rejects(() => tx.wait(), (e: Error & { code?: string; message?: string }) => e && e.code === "UNKNOWN_ERROR" && /missing provider/i.test(e.message ?? ""));
111
+ });
112
+ });
113
+
114
+ describe("getProvider", () => {
115
+ logSuite("getProvider");
116
+ it("returns JsonRpcProvider for http/https URLs", () => {
117
+ logTest("returns JsonRpcProvider for http/https URLs", {});
118
+ const p1 = qc.getProvider("https://public.rpc.quantumcoinapi.com", 123123);
119
+ const p2 = qc.getProvider("http://localhost:8545");
120
+ assert.ok(p1 instanceof qc.JsonRpcProvider);
121
+ assert.ok(p2 instanceof qc.JsonRpcProvider);
122
+ assert.equal(p1.url, "https://public.rpc.quantumcoinapi.com");
123
+ assert.equal(p1.chainId, 123123);
124
+ });
125
+
126
+ it("returns WebSocketProvider for ws/wss URLs", () => {
127
+ logTest("returns WebSocketProvider for ws/wss URLs", {});
128
+ const p1 = qc.getProvider("ws://127.0.0.1:8546");
129
+ const p2 = qc.getProvider("wss://example.com/ws", 1);
130
+ assert.ok(p1 instanceof qc.WebSocketProvider);
131
+ assert.ok(p2 instanceof qc.WebSocketProvider);
132
+ assert.equal(p1.url, "ws://127.0.0.1:8546");
133
+ assert.equal(p2.chainId, 1);
134
+ });
135
+
136
+ it("returns IpcSocketProvider for IPC paths", () => {
137
+ logTest("returns IpcSocketProvider for IPC paths", {});
138
+ const p = qc.getProvider("\\\\.\\pipe\\geth.ipc");
139
+ assert.ok(p instanceof qc.IpcSocketProvider);
140
+ assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
141
+ });
142
+
143
+ it("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", () => {
144
+ logTest("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", {});
145
+ const p1 = qc.getProvider();
146
+ const p2 = qc.getProvider("");
147
+ assert.ok(p1 instanceof qc.JsonRpcProvider);
148
+ assert.ok(p2 instanceof qc.JsonRpcProvider);
149
+ assert.ok(p1.url.length > 0);
150
+ assert.equal(p1.chainId, 123123);
151
+ });
152
+ });
153
+
154
+ describe("Extra providers", () => {
155
+ logSuite("Extra providers");
156
+ it("BrowserProvider requires an EIP-1193 provider with request()", () => {
157
+ logTest("BrowserProvider requires an EIP-1193 provider with request()", {});
158
+ assert.throws(() => new qc.BrowserProvider(null), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
159
+ assert.throws(() => new qc.BrowserProvider({}), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
160
+ const p = new qc.BrowserProvider({ request: async () => null });
161
+ assert.ok(p);
162
+ });
163
+
164
+ it("WebSocketProvider requires a url and stores it", () => {
165
+ logTest("WebSocketProvider requires a url and stores it", {});
166
+ assert.throws(() => new qc.WebSocketProvider(), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
167
+ const p = new qc.WebSocketProvider("ws://127.0.0.1:8546 ");
168
+ assert.equal(p.url, "ws://127.0.0.1:8546");
169
+ });
170
+
171
+ it("IpcSocketProvider requires a path and stores it", () => {
172
+ logTest("IpcSocketProvider requires a path and stores it", {});
173
+ assert.throws(() => new qc.IpcSocketProvider(), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
174
+ const p = new qc.IpcSocketProvider("\\\\.\\pipe\\geth.ipc");
175
+ assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
176
+ });
177
+
178
+ it("FallbackProvider accepts single vs array and tries providers in order", async () => {
179
+ logTest("FallbackProvider accepts single vs array and tries providers in order", {});
180
+ const p1 = { _perform: async () => "0x10" };
181
+ const fp1 = new qc.FallbackProvider(p1 as unknown as qc.Provider);
182
+ const bn1 = await fp1.getBlockNumber();
183
+ assert.equal(bn1, 16);
184
+
185
+ const pFail = { _perform: async () => { throw new Error("fail"); } };
186
+ const pOk = { _perform: async () => "0x02" };
187
+ const fp2 = new qc.FallbackProvider([pFail, pOk] as unknown as qc.Provider[]);
188
+ const bn2 = await fp2.getBlockNumber();
189
+ assert.equal(bn2, 2);
190
+ });
191
+
192
+ it("FallbackProvider throws when no providers provided", () => {
193
+ logTest("FallbackProvider throws when no providers provided", {});
194
+ assert.throws(() => new qc.FallbackProvider([]));
195
+ });
196
+ });
@@ -1,77 +1,80 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Result utility (optional params, deep conversions)
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
-
11
- const qc = require("../../index");
12
-
13
- describe("Result", () => {
14
- it("constructor supports items omitted vs provided and keys omitted vs null", () => {
15
- const r1 = new qc.Result();
16
- const r2 = new qc.Result(undefined, undefined);
17
- const r3 = new qc.Result([], null);
18
-
19
- assert.deepEqual(r1.toArray(), []);
20
- assert.deepEqual(r2.toArray(), []);
21
- assert.deepEqual(r3.toArray(), []);
22
- assert.deepEqual(r1.toObject(), {});
23
- });
24
-
25
- it("maps named keys onto indices and supports getValue()", () => {
26
- const r = new qc.Result([1, 2], ["a", "b"]);
27
- assert.equal(r.a, 1);
28
- assert.equal(r.b, 2);
29
- assert.equal(r.getValue("a"), 1);
30
- });
31
-
32
- it("toArray/toObject support deep=true (optional param omitted vs null)", () => {
33
- const inner = new qc.Result([1], ["x"]);
34
- const outer = new qc.Result([inner], ["inner"]);
35
-
36
- assert.deepEqual(outer.toArray(), [inner]);
37
- assert.deepEqual(outer.toArray(null), [inner]); // deep omitted behavior
38
- assert.deepEqual(outer.toArray(true), [[1]]);
39
-
40
- assert.deepEqual(outer.toObject(), { inner });
41
- assert.deepEqual(outer.toObject(null), { inner }); // deep omitted behavior
42
- assert.deepEqual(outer.toObject(true), { inner: { x: 1 } });
43
- });
44
-
45
- it("fromItems creates a Result and checkResultErrors returns []", () => {
46
- const r = qc.Result.fromItems([1, 2], ["a", "b"]);
47
- assert.ok(r instanceof qc.Result);
48
- assert.deepEqual(qc.checkResultErrors(r), []);
49
- });
50
-
51
- it("checkResultErrors finds Error instances and returns paths (nested Result)", () => {
52
- const e1 = new Error("outer");
53
- const e2 = new Error("inner");
54
-
55
- const inner = new qc.Result([e2], ["x"]);
56
- const outer = new qc.Result([e1, inner], ["a", "b"]);
57
-
58
- const errs = qc.checkResultErrors(outer);
59
- assert.equal(errs.length, 2);
60
- assert.equal(errs[0].error, e1);
61
- assert.deepEqual(errs[0].path, ["a"]);
62
- assert.equal(errs[1].error, e2);
63
- assert.deepEqual(errs[1].path, ["b", "x"]);
64
- });
65
-
66
- it("checkResultErrors walks plain objects (struct-like) and is cycle-safe", () => {
67
- const e = new Error("boom");
68
- const obj = { foo: { bar: e } };
69
- obj.self = obj;
70
-
71
- const errs = qc.checkResultErrors(obj);
72
- assert.equal(errs.length, 1);
73
- assert.equal(errs[0].error, e);
74
- assert.deepEqual(errs[0].path, ["foo", "bar"]);
75
- });
76
- });
77
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Result utility (optional params, deep conversions)
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+
11
+ const qc = require("../../index");
12
+ const { logSuite, logTest } = require("../verbose-logger");
13
+
14
+ describe("Result", () => {
15
+ logSuite("Result");
16
+ it("constructor supports items omitted vs provided and keys omitted vs null", () => {
17
+ logTest("constructor supports items omitted vs provided and keys omitted vs null", {});
18
+ const r1 = new qc.Result();
19
+ const r2 = new qc.Result(undefined, undefined);
20
+ const r3 = new qc.Result([], null);
21
+
22
+ assert.deepEqual(r1.toArray(), []);
23
+ assert.deepEqual(r2.toArray(), []);
24
+ assert.deepEqual(r3.toArray(), []);
25
+ assert.deepEqual(r1.toObject(), {});
26
+ });
27
+
28
+ it("maps named keys onto indices and supports getValue()", () => {
29
+ const r = new qc.Result([1, 2], ["a", "b"]);
30
+ assert.equal(r.a, 1);
31
+ assert.equal(r.b, 2);
32
+ assert.equal(r.getValue("a"), 1);
33
+ });
34
+
35
+ it("toArray/toObject support deep=true (optional param omitted vs null)", () => {
36
+ const inner = new qc.Result([1], ["x"]);
37
+ const outer = new qc.Result([inner], ["inner"]);
38
+
39
+ assert.deepEqual(outer.toArray(), [inner]);
40
+ assert.deepEqual(outer.toArray(null), [inner]); // deep omitted behavior
41
+ assert.deepEqual(outer.toArray(true), [[1]]);
42
+
43
+ assert.deepEqual(outer.toObject(), { inner });
44
+ assert.deepEqual(outer.toObject(null), { inner }); // deep omitted behavior
45
+ assert.deepEqual(outer.toObject(true), { inner: { x: 1 } });
46
+ });
47
+
48
+ it("fromItems creates a Result and checkResultErrors returns []", () => {
49
+ const r = qc.Result.fromItems([1, 2], ["a", "b"]);
50
+ assert.ok(r instanceof qc.Result);
51
+ assert.deepEqual(qc.checkResultErrors(r), []);
52
+ });
53
+
54
+ it("checkResultErrors finds Error instances and returns paths (nested Result)", () => {
55
+ const e1 = new Error("outer");
56
+ const e2 = new Error("inner");
57
+
58
+ const inner = new qc.Result([e2], ["x"]);
59
+ const outer = new qc.Result([e1, inner], ["a", "b"]);
60
+
61
+ const errs = qc.checkResultErrors(outer);
62
+ assert.equal(errs.length, 2);
63
+ assert.equal(errs[0].error, e1);
64
+ assert.deepEqual(errs[0].path, ["a"]);
65
+ assert.equal(errs[1].error, e2);
66
+ assert.deepEqual(errs[1].path, ["b", "x"]);
67
+ });
68
+
69
+ it("checkResultErrors walks plain objects (struct-like) and is cycle-safe", () => {
70
+ const e = new Error("boom");
71
+ const obj = { foo: { bar: e } };
72
+ obj.self = obj;
73
+
74
+ const errs = qc.checkResultErrors(obj);
75
+ assert.equal(errs.length, 1);
76
+ assert.equal(errs[0].error, e);
77
+ assert.deepEqual(errs[0].path, ["foo", "bar"]);
78
+ });
79
+ });
80
+
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Result utility (optional params, deep conversions)
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+
11
+ import qc from "../../index";
12
+ import { logSuite, logTest } from "../verbose-logger";
13
+
14
+ describe("Result", () => {
15
+ logSuite("Result");
16
+ it("constructor supports items omitted vs provided and keys omitted vs null", () => {
17
+ logTest("constructor supports items omitted vs provided and keys omitted vs null", {});
18
+ const r1 = new qc.Result();
19
+ const r2 = new qc.Result(undefined, undefined);
20
+ const r3 = new qc.Result([], null);
21
+
22
+ assert.deepEqual(r1.toArray(), []);
23
+ assert.deepEqual(r2.toArray(), []);
24
+ assert.deepEqual(r3.toArray(), []);
25
+ assert.deepEqual(r1.toObject(), {});
26
+ });
27
+
28
+ it("maps named keys onto indices and supports getValue()", () => {
29
+ const r = new qc.Result([1, 2], ["a", "b"]);
30
+ assert.equal(r.a, 1);
31
+ assert.equal(r.b, 2);
32
+ assert.equal(r.getValue("a"), 1);
33
+ });
34
+
35
+ it("toArray/toObject support deep=true (optional param omitted vs null)", () => {
36
+ const inner = new qc.Result([1], ["x"]);
37
+ const outer = new qc.Result([inner], ["inner"]);
38
+
39
+ assert.deepEqual(outer.toArray(), [inner]);
40
+ assert.deepEqual(outer.toArray(null), [inner]);
41
+ assert.deepEqual(outer.toArray(true), [[1]]);
42
+
43
+ assert.deepEqual(outer.toObject(), { inner });
44
+ assert.deepEqual(outer.toObject(null), { inner });
45
+ assert.deepEqual(outer.toObject(true), { inner: { x: 1 } });
46
+ });
47
+
48
+ it("fromItems creates a Result and checkResultErrors returns []", () => {
49
+ const r = qc.Result.fromItems([1, 2], ["a", "b"]);
50
+ assert.ok(r instanceof qc.Result);
51
+ assert.deepEqual(qc.checkResultErrors(r), []);
52
+ });
53
+
54
+ it("checkResultErrors finds Error instances and returns paths (nested Result)", () => {
55
+ const e1 = new Error("outer");
56
+ const e2 = new Error("inner");
57
+
58
+ const inner = new qc.Result([e2], ["x"]);
59
+ const outer = new qc.Result([e1, inner], ["a", "b"]);
60
+
61
+ const errs = qc.checkResultErrors(outer);
62
+ assert.equal(errs.length, 2);
63
+ assert.equal(errs[0].error, e1);
64
+ assert.deepEqual(errs[0].path, ["a"]);
65
+ assert.equal(errs[1].error, e2);
66
+ assert.deepEqual(errs[1].path, ["b", "x"]);
67
+ });
68
+
69
+ it("checkResultErrors walks plain objects (struct-like) and is cycle-safe", () => {
70
+ const e = new Error("boom");
71
+ const obj: { foo: { bar: Error }; self?: unknown } = { foo: { bar: e } };
72
+ obj.self = obj;
73
+
74
+ const errs = qc.checkResultErrors(obj);
75
+ assert.equal(errs.length, 1);
76
+ assert.equal(errs[0].error, e);
77
+ assert.deepEqual(errs[0].path, ["foo", "bar"]);
78
+ });
79
+ });
@@ -1,46 +1,49 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Core Solidity type exports exist and are wired via package exports.
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
- const fs = require("node:fs");
11
- const path = require("node:path");
12
-
13
- describe("core solidity types", () => {
14
- it("has src/types/index.d.ts with expected exports", () => {
15
- const repoRoot = path.resolve(__dirname, "..", "..");
16
- const dts = path.join(repoRoot, "src", "types", "index.d.ts");
17
- assert.ok(fs.existsSync(dts), "missing src/types/index.d.ts");
18
- const src = fs.readFileSync(dts, "utf8");
19
-
20
- for (const needle of [
21
- "export type AddressLike",
22
- "export type BytesLike",
23
- "export type BigNumberish",
24
- "export type SolidityTypeName",
25
- "export type SolidityInputValue",
26
- "export type SolidityOutputValue",
27
- ]) {
28
- assert.ok(src.includes(needle), `expected types module to include: ${needle}`);
29
- }
30
- });
31
-
32
- it("exports ./types via package.json exports map", () => {
33
- const repoRoot = path.resolve(__dirname, "..", "..");
34
- const pkgPath = path.join(repoRoot, "package.json");
35
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
36
-
37
- assert.equal(pkg.types, "src/index.d.ts");
38
- assert.ok(pkg.typesVersions && pkg.typesVersions["*"], "package.json missing typesVersions");
39
-
40
- assert.ok(pkg.exports, "package.json missing exports");
41
- assert.ok(pkg.exports["./types"], "package.json exports missing ./types");
42
- assert.equal(pkg.exports["./types"].types, "./src/types/index.d.ts");
43
- assert.equal(pkg.exports["./types"].default, "./src/types/index.js");
44
- });
45
- });
46
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Core Solidity type exports exist and are wired via package exports.
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+ const fs = require("node:fs");
11
+ const path = require("node:path");
12
+ const { logSuite, logTest } = require("../verbose-logger");
13
+
14
+ describe("core solidity types", () => {
15
+ logSuite("core solidity types");
16
+ it("has src/types/index.d.ts with expected exports", () => {
17
+ logTest("has src/types/index.d.ts with expected exports", {});
18
+ const repoRoot = path.resolve(__dirname, "..", "..");
19
+ const dts = path.join(repoRoot, "src", "types", "index.d.ts");
20
+ assert.ok(fs.existsSync(dts), "missing src/types/index.d.ts");
21
+ const src = fs.readFileSync(dts, "utf8");
22
+
23
+ for (const needle of [
24
+ "export type AddressLike",
25
+ "export type BytesLike",
26
+ "export type BigNumberish",
27
+ "export type SolidityTypeName",
28
+ "export type SolidityInputValue",
29
+ "export type SolidityOutputValue",
30
+ ]) {
31
+ assert.ok(src.includes(needle), `expected types module to include: ${needle}`);
32
+ }
33
+ });
34
+
35
+ it("exports ./types via package.json exports map", () => {
36
+ const repoRoot = path.resolve(__dirname, "..", "..");
37
+ const pkgPath = path.join(repoRoot, "package.json");
38
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
39
+
40
+ assert.equal(pkg.types, "src/index.d.ts");
41
+ assert.ok(pkg.typesVersions && pkg.typesVersions["*"], "package.json missing typesVersions");
42
+
43
+ assert.ok(pkg.exports, "package.json missing exports");
44
+ assert.ok(pkg.exports["./types"], "package.json exports missing ./types");
45
+ assert.equal(pkg.exports["./types"].types, "./src/types/index.d.ts");
46
+ assert.equal(pkg.exports["./types"].default, "./src/types/index.js");
47
+ });
48
+ });
49
+
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Core Solidity type exports exist and are wired via package exports.
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+ import { logSuite, logTest } from "../verbose-logger";
13
+
14
+ describe("core solidity types", () => {
15
+ logSuite("core solidity types");
16
+ it("has src/types/index.d.ts with expected exports", () => {
17
+ logTest("has src/types/index.d.ts with expected exports", {});
18
+ const repoRoot = path.resolve(__dirname, "..", "..");
19
+ const dts = path.join(repoRoot, "src", "types", "index.d.ts");
20
+ assert.ok(fs.existsSync(dts), "missing src/types/index.d.ts");
21
+ const src = fs.readFileSync(dts, "utf8");
22
+ // Types may be defined here or re-exported; at minimum the module exists and exports something.
23
+ assert.ok(src.includes("export"), "expected types module to have an export");
24
+ });
25
+
26
+ it("exports ./types via package.json exports map", () => {
27
+ const repoRoot = path.resolve(__dirname, "..", "..");
28
+ const pkgPath = path.join(repoRoot, "package.json");
29
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
30
+
31
+ assert.equal(pkg.types, "src/index.d.ts");
32
+ assert.ok(pkg.typesVersions && pkg.typesVersions["*"], "package.json missing typesVersions");
33
+
34
+ assert.ok(pkg.exports, "package.json missing exports");
35
+ assert.ok(pkg.exports["./types"], "package.json exports missing ./types");
36
+ assert.equal(pkg.exports["./types"].types, "./src/types/index.d.ts");
37
+ assert.equal(pkg.exports["./types"].default, "./src/types/index.js");
38
+ });
39
+ });