quantumcoin 7.0.2 → 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 -756
  5. package/README.md +165 -152
  6. package/SPEC.md +3845 -3845
  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 -0
  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 -1383
  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 -105
  47. package/src/contract/contract.js +354 -312
  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 -1201
  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 -196
  65. package/src/providers/provider.js +392 -359
  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 -361
  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 -144
  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 -402
  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 -98
  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 -0
  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,65 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description populateTransaction namespace and sendRawTransaction API
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+
11
+ const { Initialize } = require("../../config");
12
+ const qc = require("../../index");
13
+ const { logSuite, logTest } = require("../verbose-logger");
14
+
15
+ describe("populateTransaction + sendRawTransaction", () => {
16
+ logSuite("populateTransaction + sendRawTransaction");
17
+ it("contract.populateTransaction.<fn> builds tx request without provider/signer", async () => {
18
+ logTest("contract.populateTransaction.<fn> builds tx request without provider/signer", {});
19
+ await Initialize(null);
20
+
21
+ const abi = [
22
+ {
23
+ type: "function",
24
+ name: "setValue",
25
+ stateMutability: "nonpayable",
26
+ inputs: [{ name: "value", type: "uint256" }],
27
+ outputs: [],
28
+ },
29
+ ];
30
+
31
+ const addr = "0x" + "11".repeat(32);
32
+ const contract = new qc.Contract(addr, abi);
33
+
34
+ const tx = await contract.populateTransaction.setValue(123, { gasLimit: 50000 });
35
+ assert.equal(tx.to, addr);
36
+ assert.equal(typeof tx.data, "string");
37
+ assert.ok(tx.data.startsWith("0x") && tx.data.length > 10);
38
+ assert.equal(tx.gasLimit, 50000);
39
+ });
40
+
41
+ it("provider.sendRawTransaction exists and forwards to eth_sendRawTransaction", async () => {
42
+ await Initialize(null);
43
+
44
+ class TestProvider extends qc.AbstractProvider {
45
+ constructor() {
46
+ super();
47
+ this.calls = [];
48
+ }
49
+ async _perform(method, params) {
50
+ this.calls.push({ method, params });
51
+ if (method === "eth_sendRawTransaction") return "0x" + "aa".repeat(32);
52
+ if (method === "eth_getTransactionByHash") return null;
53
+ return null;
54
+ }
55
+ }
56
+
57
+ const p = new TestProvider();
58
+ const raw = "0xdeadbeef";
59
+ const resp = await p.sendRawTransaction(raw);
60
+ assert.ok(resp && typeof resp.hash === "string");
61
+ assert.equal(p.calls[0].method, "eth_sendRawTransaction");
62
+ assert.deepEqual(p.calls[0].params, [raw]);
63
+ });
64
+ });
65
+
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description populateTransaction namespace and sendRawTransaction API
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+
11
+ import { Initialize } from "../../config";
12
+ import qc from "../../index";
13
+ import { logSuite, logTest } from "../verbose-logger";
14
+
15
+ describe("populateTransaction + sendRawTransaction", () => {
16
+ logSuite("populateTransaction + sendRawTransaction");
17
+ it("contract.populateTransaction.<fn> builds tx request without provider/signer", async () => {
18
+ logTest("contract.populateTransaction.<fn> builds tx request without provider/signer", {});
19
+ await Initialize(null);
20
+
21
+ const abi = [
22
+ {
23
+ type: "function",
24
+ name: "setValue",
25
+ stateMutability: "nonpayable",
26
+ inputs: [{ name: "value", type: "uint256" }],
27
+ outputs: [],
28
+ },
29
+ ];
30
+
31
+ const addr = "0x" + "11".repeat(32);
32
+ const contract = new qc.Contract(addr, abi);
33
+
34
+ const tx = await contract.populateTransaction.setValue(123, { gasLimit: 50000 });
35
+ assert.equal(tx.to, addr);
36
+ assert.equal(typeof tx.data, "string");
37
+ assert.ok(tx.data.startsWith("0x") && tx.data.length > 10);
38
+ assert.equal(tx.gasLimit, 50000);
39
+ });
40
+
41
+ it("provider.sendRawTransaction exists and forwards to eth_sendRawTransaction", async () => {
42
+ await Initialize(null);
43
+
44
+ class TestProvider extends qc.AbstractProvider {
45
+ calls: { method: string; params: unknown[] }[] = [];
46
+ constructor() {
47
+ super();
48
+ }
49
+ async _perform(method: string, params: unknown[]) {
50
+ this.calls.push({ method, params });
51
+ if (method === "eth_sendRawTransaction") return "0x" + "aa".repeat(32);
52
+ if (method === "eth_getTransactionByHash") return null;
53
+ return null;
54
+ }
55
+ }
56
+
57
+ const p = new TestProvider();
58
+ const raw = "0xdeadbeef";
59
+ const resp = await p.sendRawTransaction(raw);
60
+ assert.ok(resp && typeof resp.hash === "string");
61
+ assert.equal(p.calls[0].method, "eth_sendRawTransaction");
62
+ assert.deepEqual(p.calls[0].params, [raw]);
63
+ });
64
+ });
@@ -1,144 +1,200 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Provider helpers, wrappers, defaults, and extra providers
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("JsonRpcProvider", () => {
14
- it("defaults url/chainId when omitted vs null (no Initialize required)", () => {
15
- const p1 = new qc.JsonRpcProvider();
16
- const p2 = new qc.JsonRpcProvider(null, null);
17
-
18
- assert.equal(typeof p1.url, "string");
19
- assert.ok(p1.url.length > 0);
20
- assert.equal(p1.chainId, 123123);
21
-
22
- assert.equal(p2.url, p1.url);
23
- assert.equal(p2.chainId, 123123);
24
- });
25
-
26
- it("_perform defaults params when omitted vs null", async (t) => {
27
- if (typeof fetch !== "function") {
28
- t.skip("global fetch not available");
29
- return;
30
- }
31
-
32
- const originalFetch = fetch;
33
- /** @type {any[]} */
34
- const seen = [];
35
-
36
- global.fetch = async (_url, init) => {
37
- const body = JSON.parse(init.body);
38
- seen.push(body.params);
39
- return {
40
- ok: true,
41
- json: async () => ({ jsonrpc: "2.0", id: body.id, result: "0x1" }),
42
- };
43
- };
44
-
45
- try {
46
- const p = new qc.JsonRpcProvider("http://example.invalid", 123123);
47
- const a = await p._perform("eth_blockNumber");
48
- const b = await p._perform("eth_blockNumber", null);
49
- assert.equal(a, "0x1");
50
- assert.equal(b, "0x1");
51
- assert.deepEqual(seen, [[], []]);
52
- } finally {
53
- global.fetch = originalFetch;
54
- }
55
- });
56
- });
57
-
58
- describe("AbstractProvider defaults", () => {
59
- it("getTransactionCount/call/getCode default blockTag when omitted vs null", async () => {
60
- class P extends qc.AbstractProvider {
61
- constructor() {
62
- super();
63
- this.calls = [];
64
- }
65
- async _perform(method, params) {
66
- this.calls.push({ method, params });
67
- if (method === "eth_getTransactionCount") return "0x2";
68
- if (method === "eth_call") return "0x";
69
- if (method === "eth_getCode") return "0x";
70
- throw new Error("unexpected");
71
- }
72
- }
73
-
74
- const p = new P();
75
- await p.getTransactionCount("0x" + "11".repeat(32));
76
- await p.getTransactionCount("0x" + "11".repeat(32), null);
77
- await p.call({ to: "0x" + "11".repeat(32), data: "0x" });
78
- await p.call({ to: "0x" + "11".repeat(32), data: "0x" }, null);
79
- await p.getCode("0x" + "11".repeat(32));
80
- await p.getCode("0x" + "11".repeat(32), null);
81
-
82
- const tags = p.calls.map((c) => c.params[c.params.length - 1]);
83
- // All these methods use `blockTag || "latest"`, so omitted/null => "latest"
84
- assert.deepEqual(tags, ["latest", "latest", "latest", "latest", "latest", "latest"]);
85
- });
86
- });
87
-
88
- describe("TransactionResponse.wait", () => {
89
- it("uses default confirmations when omitted vs null", async () => {
90
- const fakeProvider = {
91
- getTransactionReceipt: async () => ({ blockNumber: 1 }),
92
- getBlockNumber: async () => 1,
93
- };
94
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, fakeProvider);
95
- const r1 = await tx.wait();
96
- const r2 = await tx.wait(null, null);
97
- assert.deepEqual(r1, { blockNumber: 1 });
98
- assert.deepEqual(r2, { blockNumber: 1 });
99
- });
100
-
101
- it("throws if provider missing", async () => {
102
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, null);
103
- await assert.rejects(() => tx.wait(), (e) => e && e.code === "UNKNOWN_ERROR" && /missing provider/i.test(e.message));
104
- });
105
- });
106
-
107
- describe("Extra providers", () => {
108
- it("BrowserProvider requires an EIP-1193 provider with request()", () => {
109
- assert.throws(() => new qc.BrowserProvider(null), (e) => e && e.code === "INVALID_ARGUMENT");
110
- assert.throws(() => new qc.BrowserProvider({}), (e) => e && e.code === "INVALID_ARGUMENT");
111
- const p = new qc.BrowserProvider({ request: async () => null });
112
- assert.ok(p);
113
- });
114
-
115
- it("WebSocketProvider requires a url and stores it", () => {
116
- assert.throws(() => new qc.WebSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
117
- const p = new qc.WebSocketProvider("ws://127.0.0.1:8546 ");
118
- assert.equal(p.url, "ws://127.0.0.1:8546");
119
- });
120
-
121
- it("IpcSocketProvider requires a path and stores it", () => {
122
- assert.throws(() => new qc.IpcSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
123
- const p = new qc.IpcSocketProvider("\\\\.\\pipe\\geth.ipc");
124
- assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
125
- });
126
-
127
- it("FallbackProvider accepts single vs array and tries providers in order", async () => {
128
- const p1 = { _perform: async () => "0x10" };
129
- const fp1 = new qc.FallbackProvider(p1);
130
- const bn1 = await fp1.getBlockNumber();
131
- assert.equal(bn1, 16);
132
-
133
- const pFail = { _perform: async () => { throw new Error("fail"); } };
134
- const pOk = { _perform: async () => "0x02" };
135
- const fp2 = new qc.FallbackProvider([pFail, pOk]);
136
- const bn2 = await fp2.getBlockNumber();
137
- assert.equal(bn2, 2);
138
- });
139
-
140
- it("FallbackProvider throws when no providers provided", () => {
141
- assert.throws(() => new qc.FallbackProvider([]));
142
- });
143
- });
144
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Provider helpers, wrappers, defaults, and extra providers
6
+ * Run with VERBOSE=1 for test names.
7
+ */
8
+
9
+ const { describe, it } = require("node:test");
10
+ const assert = require("node:assert/strict");
11
+
12
+ const qc = require("../../index");
13
+ const { logSuite, logTest } = require("../verbose-logger");
14
+
15
+ describe("JsonRpcProvider", () => {
16
+ logSuite("JsonRpcProvider");
17
+ it("defaults url/chainId when omitted vs null (no Initialize required)", () => {
18
+ logTest("defaults url/chainId when omitted vs null (no Initialize required)", {});
19
+ const p1 = new qc.JsonRpcProvider();
20
+ const p2 = new qc.JsonRpcProvider(null, null);
21
+
22
+ assert.equal(typeof p1.url, "string");
23
+ assert.ok(p1.url.length > 0);
24
+ assert.equal(p1.chainId, 123123);
25
+
26
+ assert.equal(p2.url, p1.url);
27
+ assert.equal(p2.chainId, 123123);
28
+ });
29
+
30
+ it("_perform defaults params when omitted vs null", async (t) => {
31
+ logTest("_perform defaults params when omitted vs null", {});
32
+ if (typeof fetch !== "function") {
33
+ t.skip("global fetch not available");
34
+ return;
35
+ }
36
+
37
+ const originalFetch = fetch;
38
+ /** @type {any[]} */
39
+ const seen = [];
40
+
41
+ global.fetch = async (_url, init) => {
42
+ const body = JSON.parse(init.body);
43
+ seen.push(body.params);
44
+ return {
45
+ ok: true,
46
+ json: async () => ({ jsonrpc: "2.0", id: body.id, result: "0x1" }),
47
+ };
48
+ };
49
+
50
+ try {
51
+ const p = new qc.JsonRpcProvider("http://example.invalid", 123123);
52
+ const a = await p._perform("eth_blockNumber");
53
+ const b = await p._perform("eth_blockNumber", null);
54
+ assert.equal(a, "0x1");
55
+ assert.equal(b, "0x1");
56
+ assert.deepEqual(seen, [[], []]);
57
+ } finally {
58
+ global.fetch = originalFetch;
59
+ }
60
+ });
61
+ });
62
+
63
+ describe("AbstractProvider defaults", () => {
64
+ logSuite("AbstractProvider defaults");
65
+ it("getTransactionCount/call/getCode default blockTag when omitted vs null", async () => {
66
+ logTest("getTransactionCount/call/getCode default blockTag when omitted vs null", {});
67
+ class P extends qc.AbstractProvider {
68
+ constructor() {
69
+ super();
70
+ this.calls = [];
71
+ }
72
+ async _perform(method, params) {
73
+ this.calls.push({ method, params });
74
+ if (method === "eth_getTransactionCount") return "0x2";
75
+ if (method === "eth_call") return "0x";
76
+ if (method === "eth_getCode") return "0x";
77
+ throw new Error("unexpected");
78
+ }
79
+ }
80
+
81
+ const p = new P();
82
+ await p.getTransactionCount("0x" + "11".repeat(32));
83
+ await p.getTransactionCount("0x" + "11".repeat(32), null);
84
+ await p.call({ to: "0x" + "11".repeat(32), data: "0x" });
85
+ await p.call({ to: "0x" + "11".repeat(32), data: "0x" }, null);
86
+ await p.getCode("0x" + "11".repeat(32));
87
+ await p.getCode("0x" + "11".repeat(32), null);
88
+
89
+ const tags = p.calls.map((c) => c.params[c.params.length - 1]);
90
+ // All these methods use `blockTag || "latest"`, so omitted/null => "latest"
91
+ assert.deepEqual(tags, ["latest", "latest", "latest", "latest", "latest", "latest"]);
92
+ });
93
+ });
94
+
95
+ describe("TransactionResponse.wait", () => {
96
+ logSuite("TransactionResponse.wait");
97
+ it("uses default confirmations when omitted vs null", async () => {
98
+ logTest("uses default confirmations when omitted vs null", {});
99
+ const fakeProvider = {
100
+ getTransactionReceipt: async () => ({ blockNumber: 1 }),
101
+ getBlockNumber: async () => 1,
102
+ };
103
+ const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, fakeProvider);
104
+ const r1 = await tx.wait();
105
+ const r2 = await tx.wait(null, null);
106
+ assert.deepEqual(r1, { blockNumber: 1 });
107
+ assert.deepEqual(r2, { blockNumber: 1 });
108
+ });
109
+
110
+ it("throws if provider missing", async () => {
111
+ logTest("throws if provider missing", {});
112
+ const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, null);
113
+ await assert.rejects(() => tx.wait(), (e) => e && e.code === "UNKNOWN_ERROR" && /missing provider/i.test(e.message));
114
+ });
115
+ });
116
+
117
+ describe("getProvider", () => {
118
+ logSuite("getProvider");
119
+ it("returns JsonRpcProvider for http/https URLs", () => {
120
+ logTest("returns JsonRpcProvider for http/https URLs", {});
121
+ const p1 = qc.getProvider("https://public.rpc.quantumcoinapi.com", 123123);
122
+ const p2 = qc.getProvider("http://localhost:8545");
123
+ assert.ok(p1 instanceof qc.JsonRpcProvider);
124
+ assert.ok(p2 instanceof qc.JsonRpcProvider);
125
+ assert.equal(p1.url, "https://public.rpc.quantumcoinapi.com");
126
+ assert.equal(p1.chainId, 123123);
127
+ });
128
+
129
+ it("returns WebSocketProvider for ws/wss URLs", () => {
130
+ logTest("returns WebSocketProvider for ws/wss URLs", {});
131
+ const p1 = qc.getProvider("ws://127.0.0.1:8546");
132
+ const p2 = qc.getProvider("wss://example.com/ws", 1);
133
+ assert.ok(p1 instanceof qc.WebSocketProvider);
134
+ assert.ok(p2 instanceof qc.WebSocketProvider);
135
+ assert.equal(p1.url, "ws://127.0.0.1:8546");
136
+ assert.equal(p2.chainId, 1);
137
+ });
138
+
139
+ it("returns IpcSocketProvider for IPC paths", () => {
140
+ logTest("returns IpcSocketProvider for IPC paths", {});
141
+ const p = qc.getProvider("\\\\.\\pipe\\geth.ipc");
142
+ assert.ok(p instanceof qc.IpcSocketProvider);
143
+ assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
144
+ });
145
+
146
+ it("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", () => {
147
+ logTest("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", {});
148
+ const p1 = qc.getProvider();
149
+ const p2 = qc.getProvider("");
150
+ assert.ok(p1 instanceof qc.JsonRpcProvider);
151
+ assert.ok(p2 instanceof qc.JsonRpcProvider);
152
+ assert.ok(p1.url.length > 0);
153
+ assert.equal(p1.chainId, 123123);
154
+ });
155
+ });
156
+
157
+ describe("Extra providers", () => {
158
+ logSuite("Extra providers");
159
+ it("BrowserProvider requires an EIP-1193 provider with request()", () => {
160
+ logTest("BrowserProvider requires an EIP-1193 provider with request()", {});
161
+ assert.throws(() => new qc.BrowserProvider(null), (e) => e && e.code === "INVALID_ARGUMENT");
162
+ assert.throws(() => new qc.BrowserProvider({}), (e) => e && e.code === "INVALID_ARGUMENT");
163
+ const p = new qc.BrowserProvider({ request: async () => null });
164
+ assert.ok(p);
165
+ });
166
+
167
+ it("WebSocketProvider requires a url and stores it", () => {
168
+ logTest("WebSocketProvider requires a url and stores it", {});
169
+ assert.throws(() => new qc.WebSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
170
+ const p = new qc.WebSocketProvider("ws://127.0.0.1:8546 ");
171
+ assert.equal(p.url, "ws://127.0.0.1:8546");
172
+ });
173
+
174
+ it("IpcSocketProvider requires a path and stores it", () => {
175
+ logTest("IpcSocketProvider requires a path and stores it", {});
176
+ assert.throws(() => new qc.IpcSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
177
+ const p = new qc.IpcSocketProvider("\\\\.\\pipe\\geth.ipc");
178
+ assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
179
+ });
180
+
181
+ it("FallbackProvider accepts single vs array and tries providers in order", async () => {
182
+ logTest("FallbackProvider accepts single vs array and tries providers in order", {});
183
+ const p1 = { _perform: async () => "0x10" };
184
+ const fp1 = new qc.FallbackProvider(p1);
185
+ const bn1 = await fp1.getBlockNumber();
186
+ assert.equal(bn1, 16);
187
+
188
+ const pFail = { _perform: async () => { throw new Error("fail"); } };
189
+ const pOk = { _perform: async () => "0x02" };
190
+ const fp2 = new qc.FallbackProvider([pFail, pOk]);
191
+ const bn2 = await fp2.getBlockNumber();
192
+ assert.equal(bn2, 2);
193
+ });
194
+
195
+ it("FallbackProvider throws when no providers provided", () => {
196
+ logTest("FallbackProvider throws when no providers provided", {});
197
+ assert.throws(() => new qc.FallbackProvider([]));
198
+ });
199
+ });
200
+