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.
- package/.github/workflows/publish-npmjs.yaml +22 -22
- package/.gitignore +15 -15
- package/LICENSE +21 -21
- package/README-SDK.md +756 -754
- package/README.md +165 -150
- package/SPEC.md +3845 -3843
- package/config.d.ts +50 -50
- package/config.js +115 -115
- package/examples/AllSolidityTypes.sol +184 -184
- package/examples/SimpleIERC20.sol +74 -74
- package/examples/events.js +41 -35
- package/examples/events.ts +35 -0
- package/examples/example-generator-sdk-js.js +100 -95
- package/examples/example-generator-sdk-js.ts +77 -0
- package/examples/example-generator-sdk-ts.js +100 -95
- package/examples/example-generator-sdk-ts.ts +77 -0
- package/examples/example.js +72 -61
- package/examples/example.ts +61 -0
- package/examples/offline-signing.js +79 -73
- package/examples/offline-signing.ts +66 -0
- package/examples/package-lock.json +48 -57
- package/examples/package.json +32 -16
- package/examples/read-operations.js +32 -27
- package/examples/read-operations.ts +31 -0
- package/examples/sdk-generator-erc20.inline.json +251 -251
- package/examples/solidity-types.ts +43 -43
- package/examples/wallet-offline.js +35 -29
- package/examples/wallet-offline.ts +34 -0
- package/generate-sdk.js +1824 -1490
- package/index.js +12 -12
- package/package.json +95 -75
- package/scripts/copy-declarations.js +31 -0
- package/scripts/run-all-one-by-one.js +151 -0
- package/src/abi/fragments.d.ts +42 -42
- package/src/abi/fragments.js +63 -63
- package/src/abi/index.d.ts +13 -13
- package/src/abi/index.js +9 -9
- package/src/abi/interface.d.ts +128 -132
- package/src/abi/interface.js +590 -590
- package/src/abi/js-abi-coder.d.ts +8 -0
- package/src/abi/js-abi-coder.js +474 -474
- package/src/constants.d.ts +66 -61
- package/src/constants.js +101 -94
- package/src/contract/contract-factory.d.ts +28 -28
- package/src/contract/contract-factory.js +105 -105
- package/src/contract/contract.d.ts +113 -114
- package/src/contract/contract.js +354 -354
- package/src/contract/index.d.ts +9 -9
- package/src/contract/index.js +9 -9
- package/src/errors/index.d.ts +92 -92
- package/src/errors/index.js +188 -188
- package/src/generator/index.d.ts +74 -0
- package/src/generator/index.js +1404 -1404
- package/src/index.d.ts +125 -127
- package/src/index.js +41 -41
- package/src/internal/hex.d.ts +61 -61
- package/src/internal/hex.js +144 -144
- package/src/providers/extra-providers.d.ts +139 -128
- package/src/providers/extra-providers.js +600 -575
- package/src/providers/index.d.ts +17 -16
- package/src/providers/index.js +10 -10
- package/src/providers/json-rpc-provider.d.ts +12 -12
- package/src/providers/json-rpc-provider.js +79 -79
- package/src/providers/provider.d.ts +207 -203
- package/src/providers/provider.js +392 -371
- package/src/types/index.d.ts +214 -462
- package/src/types/index.js +9 -9
- package/src/utils/address.d.ts +72 -72
- package/src/utils/address.js +181 -182
- package/src/utils/encoding.d.ts +120 -120
- package/src/utils/encoding.js +306 -306
- package/src/utils/hashing.d.ts +82 -76
- package/src/utils/hashing.js +313 -298
- package/src/utils/index.d.ts +65 -55
- package/src/utils/index.js +13 -13
- package/src/utils/result.d.ts +57 -57
- package/src/utils/result.js +128 -128
- package/src/utils/rlp.d.ts +12 -12
- package/src/utils/rlp.js +200 -200
- package/src/utils/units.d.ts +29 -29
- package/src/utils/units.js +107 -107
- package/src/wallet/index.d.ts +10 -10
- package/src/wallet/index.js +8 -8
- package/src/wallet/wallet.d.ts +160 -160
- package/src/wallet/wallet.js +483 -489
- package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
- package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -231
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -368
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
- package/test/e2e/helpers.js +59 -47
- package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
- package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -151
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
- package/test/e2e/transactional.test.js +245 -191
- package/test/e2e/transactional.test.ts +208 -0
- package/test/e2e/typed-generator.e2e.test.js +407 -404
- package/test/e2e/typed-generator.e2e.test.ts +337 -0
- package/test/fixtures/ConstructorParam.sol +23 -23
- package/test/fixtures/MultiContracts.sol +37 -37
- package/test/fixtures/SimpleStorage.sol +18 -18
- package/test/fixtures/StakingContract.abi.json +1 -1
- package/test/integration/ipc-provider.test.js +49 -44
- package/test/integration/ipc-provider.test.ts +44 -0
- package/test/integration/provider.test.js +88 -72
- package/test/integration/provider.test.ts +85 -0
- package/test/integration/ws-provider.test.js +41 -33
- package/test/integration/ws-provider.test.ts +38 -0
- package/test/security/malformed-input.test.js +37 -31
- package/test/security/malformed-input.test.ts +35 -0
- package/test/unit/_encrypted-output.txt +6 -0
- package/test/unit/_log-encrypted-jsons.js +45 -0
- package/test/unit/_write-keystore-fixture.js +16 -0
- package/test/unit/abi-interface.test.js +103 -98
- package/test/unit/abi-interface.test.ts +102 -0
- package/test/unit/address-wallet.test.js +355 -257
- package/test/unit/address-wallet.test.ts +342 -0
- package/test/unit/browser-provider.test.js +85 -82
- package/test/unit/browser-provider.test.ts +79 -0
- package/test/unit/contract.test.js +85 -82
- package/test/unit/contract.test.ts +83 -0
- package/test/unit/encoding-units-rlp.test.js +92 -89
- package/test/unit/encoding-units-rlp.test.ts +91 -0
- package/test/unit/errors.test.js +77 -74
- package/test/unit/errors.test.ts +76 -0
- package/test/unit/filter-by-blockhash.test.js +55 -52
- package/test/unit/filter-by-blockhash.test.ts +54 -0
- package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
- package/test/unit/generate-contract-cli.test.js +42 -39
- package/test/unit/generate-contract-cli.test.ts +41 -0
- package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
- package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
- package/test/unit/generator.test.js +102 -99
- package/test/unit/generator.test.ts +101 -0
- package/test/unit/hashing.test.js +68 -54
- package/test/unit/hashing.test.ts +67 -0
- package/test/unit/init.test.js +39 -36
- package/test/unit/init.test.ts +38 -0
- package/test/unit/interface.test.js +56 -53
- package/test/unit/interface.test.ts +54 -0
- package/test/unit/internal-hex.test.js +50 -47
- package/test/unit/internal-hex.test.ts +49 -0
- package/test/unit/populate-transaction.test.js +65 -62
- package/test/unit/populate-transaction.test.ts +64 -0
- package/test/unit/providers.test.js +200 -144
- package/test/unit/providers.test.ts +196 -0
- package/test/unit/result.test.js +80 -77
- package/test/unit/result.test.ts +79 -0
- package/test/unit/solidity-types.test.js +49 -46
- package/test/unit/solidity-types.test.ts +39 -0
- package/test/unit/utils.test.js +57 -54
- package/test/unit/utils.test.ts +56 -0
- package/test/verbose-logger.js +74 -0
- 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
|
+
});
|
package/test/unit/result.test.js
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
assert.deepEqual(r1.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
assert.deepEqual(outer.
|
|
41
|
-
assert.deepEqual(outer.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
assert.equal(errs
|
|
63
|
-
assert.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"export type
|
|
25
|
-
"export type
|
|
26
|
-
"export type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
assert.
|
|
41
|
-
assert.ok(pkg.
|
|
42
|
-
|
|
43
|
-
assert.
|
|
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
|
+
});
|