quantum-coin-js-sdk 1.0.39 → 2.1.0

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 (226) hide show
  1. package/.gitignore +2 -1
  2. package/README.md +109 -768
  3. package/index.d.ts +76 -545
  4. package/index.js +319 -1194
  5. package/package.json +20 -5
  6. package/wasmBase64.js +7 -16
  7. package/wasm_exec.js +575 -587
  8. package/.idea/.name +0 -1
  9. package/.idea/modules.xml +0 -8
  10. package/.idea/quantum-coin-js-sdk.iml +0 -12
  11. package/.idea/vcs.xml +0 -6
  12. package/.vs/ProjectSettings.json +0 -3
  13. package/.vs/VSWorkspaceState.json +0 -8
  14. package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
  15. package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
  16. package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
  17. package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
  18. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
  19. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
  20. package/.vs/slnx.sqlite +0 -0
  21. package/example/README.md +0 -14
  22. package/example/conversion-example.js +0 -19
  23. package/example/example-create-contract.js +0 -396
  24. package/example/example-encode-decode-rlp.js +0 -225
  25. package/example/example-event-pack-unpack.js +0 -391
  26. package/example/example-misc.js +0 -100
  27. package/example/example-rpc-send-signRawTransaction.js +0 -318
  28. package/example/example-rpc-send.js +0 -115
  29. package/example/example-send.js +0 -69
  30. package/example/example-token-pack-unpack.js +0 -960
  31. package/example/example-wallet-version4.js +0 -34
  32. package/example/example-wallet.js +0 -43
  33. package/example/example.js +0 -405
  34. package/example/node_modules/.bin/sdkgen +0 -16
  35. package/example/node_modules/.bin/sdkgen.cmd +0 -17
  36. package/example/node_modules/.bin/sdkgen.ps1 +0 -28
  37. package/example/node_modules/.package-lock.json +0 -47
  38. package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
  39. package/example/node_modules/quantumcoin/LICENSE +0 -21
  40. package/example/node_modules/quantumcoin/README-SDK.md +0 -828
  41. package/example/node_modules/quantumcoin/README.md +0 -197
  42. package/example/node_modules/quantumcoin/config.d.ts +0 -50
  43. package/example/node_modules/quantumcoin/config.js +0 -123
  44. package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
  45. package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
  46. package/example/node_modules/quantumcoin/examples/events.js +0 -41
  47. package/example/node_modules/quantumcoin/examples/events.ts +0 -35
  48. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
  49. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
  50. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
  51. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
  52. package/example/node_modules/quantumcoin/examples/example.js +0 -67
  53. package/example/node_modules/quantumcoin/examples/example.ts +0 -56
  54. package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
  55. package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
  56. package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
  57. package/example/node_modules/quantumcoin/examples/package.json +0 -32
  58. package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
  59. package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
  60. package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
  61. package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
  62. package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
  63. package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
  64. package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
  65. package/example/node_modules/quantumcoin/index.js +0 -12
  66. package/example/node_modules/quantumcoin/package.json +0 -95
  67. package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
  68. package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
  69. package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
  70. package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
  71. package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
  72. package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
  73. package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
  74. package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
  75. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
  76. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
  77. package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
  78. package/example/node_modules/quantumcoin/src/constants.js +0 -94
  79. package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
  80. package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
  81. package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
  82. package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
  83. package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
  84. package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
  85. package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
  86. package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
  87. package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
  88. package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
  89. package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
  90. package/example/node_modules/quantumcoin/src/index.js +0 -41
  91. package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
  92. package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
  93. package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
  94. package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
  95. package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
  96. package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
  97. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
  98. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
  99. package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
  100. package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
  101. package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
  102. package/example/node_modules/quantumcoin/src/types/index.js +0 -9
  103. package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
  104. package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
  105. package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
  106. package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
  107. package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
  108. package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
  109. package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
  110. package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
  111. package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
  112. package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
  113. package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
  114. package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
  115. package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
  116. package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
  117. package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
  118. package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
  119. package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
  120. package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
  121. package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
  122. package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
  123. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
  124. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
  125. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
  126. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
  127. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
  128. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
  129. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
  130. package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
  131. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
  132. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
  133. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
  134. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
  135. package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
  136. package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
  137. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
  138. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
  139. package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
  140. package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
  141. package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
  142. package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
  143. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
  144. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
  145. package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
  146. package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
  147. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
  148. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
  149. package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
  150. package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
  151. package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
  152. package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
  153. package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
  154. package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
  155. package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
  156. package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
  157. package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
  158. package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
  159. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
  160. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
  161. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
  162. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
  163. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
  164. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
  165. package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
  166. package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
  167. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
  168. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
  169. package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
  170. package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
  171. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
  172. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
  173. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
  174. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
  175. package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
  176. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
  177. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
  178. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
  179. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
  180. package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
  181. package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
  182. package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
  183. package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
  184. package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
  185. package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
  186. package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
  187. package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
  188. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
  189. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
  190. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
  191. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
  192. package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
  193. package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
  194. package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
  195. package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
  196. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
  197. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
  198. package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
  199. package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
  200. package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
  201. package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
  202. package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
  203. package/example/node_modules/seed-words/BUILD.md +0 -7
  204. package/example/node_modules/seed-words/LICENSE +0 -121
  205. package/example/node_modules/seed-words/README.md +0 -67
  206. package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
  207. package/example/node_modules/seed-words/package.json +0 -27
  208. package/example/node_modules/seed-words/seedwords.js +0 -315
  209. package/example/node_modules/seed-words/seedwords.txt +0 -65536
  210. package/example/node_modules/seed-words/tsconfig.json +0 -21
  211. package/example/package-lock.json +0 -56
  212. package/example/package.json +0 -15
  213. package/tests/encrypted-32.json +0 -1
  214. package/tests/encrypted-36.json +0 -1
  215. package/tests/encrypted-48.json +0 -1
  216. package/tests/generate-verify-vectors.js +0 -91
  217. package/tests/get-gas-price.test.js +0 -59
  218. package/tests/non-transactional.preinit.test.js +0 -41
  219. package/tests/non-transactional.test.js +0 -1389
  220. package/tests/scrypt.test.js +0 -128
  221. package/tests/sign-raw-keytype5-context-null.test.js +0 -107
  222. package/tests/sign-raw-transaction.test.js +0 -196
  223. package/tests/sign-verify.test.js +0 -311
  224. package/tests/transactional.relay.test.js +0 -131
  225. package/tests/transactional.rpc.test.js +0 -103
  226. package/tests/verify-vectors.json +0 -95035
@@ -1,98 +0,0 @@
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
-
66
- describe("Security: mandatory chainId for signing", () => {
67
- logSuite("Security: mandatory chainId for signing");
68
-
69
- it("offline signing without a chainId throws (negative)", async () => {
70
- logTest("offline signing without a chainId throws", {});
71
- await Initialize(null);
72
- const w = qc.Wallet.createRandom(); // no provider connected
73
- await assert.rejects(
74
- () => w.signTransaction({ to: w.address, value: 0n, nonce: 0 }),
75
- /chainId is required for signing/i,
76
- );
77
- });
78
-
79
- it("offline signing with an explicit chainId succeeds (positive)", async () => {
80
- logTest("offline signing with an explicit chainId succeeds", {});
81
- await Initialize(null);
82
- const w = qc.Wallet.createRandom();
83
- const raw = await w.signTransaction({ to: w.address, value: 0n, nonce: 0, chainId: 123123 });
84
- assert.equal(typeof raw, "string");
85
- assert.ok(raw.startsWith("0x"));
86
- });
87
-
88
- it("signing resolves chainId from a connected provider (positive)", async () => {
89
- logTest("signing resolves chainId from a connected provider", {});
90
- await Initialize(null);
91
- const provider = new qc.JsonRpcProvider("http://127.0.0.1:9999", 123123);
92
- const w = qc.Wallet.createRandom().connect(provider);
93
- const raw = await w.signTransaction({ to: w.address, value: 0n, nonce: 0 });
94
- assert.equal(typeof raw, "string");
95
- assert.ok(raw.startsWith("0x"));
96
- });
97
- });
98
-
@@ -1,64 +0,0 @@
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,252 +0,0 @@
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
- const responseBody = JSON.stringify({ jsonrpc: "2.0", id: body.id, result: "0x1" });
45
- return {
46
- ok: true,
47
- text: async () => responseBody,
48
- json: async () => JSON.parse(responseBody),
49
- };
50
- };
51
-
52
- try {
53
- const p = new qc.JsonRpcProvider("http://example.invalid", 123123);
54
- const a = await p._perform("eth_blockNumber");
55
- const b = await p._perform("eth_blockNumber", null);
56
- assert.equal(a, "0x1");
57
- assert.equal(b, "0x1");
58
- assert.deepEqual(seen, [[], []]);
59
- } finally {
60
- global.fetch = originalFetch;
61
- }
62
- });
63
- });
64
-
65
- describe("AbstractProvider defaults", () => {
66
- logSuite("AbstractProvider defaults");
67
- it("getTransactionCount/call/getCode default blockTag when omitted vs null", async () => {
68
- logTest("getTransactionCount/call/getCode default blockTag when omitted vs null", {});
69
- class P extends qc.AbstractProvider {
70
- constructor() {
71
- super();
72
- this.calls = [];
73
- }
74
- async _perform(method, params) {
75
- this.calls.push({ method, params });
76
- if (method === "eth_getTransactionCount") return "0x2";
77
- if (method === "eth_call") return "0x";
78
- if (method === "eth_getCode") return "0x";
79
- throw new Error("unexpected");
80
- }
81
- }
82
-
83
- const p = new P();
84
- await p.getTransactionCount("0x" + "11".repeat(32));
85
- await p.getTransactionCount("0x" + "11".repeat(32), null);
86
- await p.call({ to: "0x" + "11".repeat(32), data: "0x" });
87
- await p.call({ to: "0x" + "11".repeat(32), data: "0x" }, null);
88
- await p.getCode("0x" + "11".repeat(32));
89
- await p.getCode("0x" + "11".repeat(32), null);
90
-
91
- const tags = p.calls.map((c) => c.params[c.params.length - 1]);
92
- // All these methods use `blockTag || "latest"`, so omitted/null => "latest"
93
- assert.deepEqual(tags, ["latest", "latest", "latest", "latest", "latest", "latest"]);
94
- });
95
- });
96
-
97
- describe("AbstractProvider block-tag QUANTITY formatting", () => {
98
- logSuite("AbstractProvider block-tag QUANTITY formatting");
99
-
100
- it("getBlock encodes block numbers as spec-compliant quantities (no leading zeros)", async () => {
101
- logTest("getBlock encodes block numbers as spec-compliant quantities", {});
102
- class BlockStub extends qc.AbstractProvider {
103
- constructor() { super(); this.calls = []; }
104
- async _perform(method, params) {
105
- this.calls.push({ method, params });
106
- return { number: "0x5", timestamp: "0x64" };
107
- }
108
- }
109
- const p = new BlockStub();
110
- await p.getBlock(0); assert.equal(p.calls.at(-1).params[0], "0x0");
111
- await p.getBlock(5); assert.equal(p.calls.at(-1).params[0], "0x5");
112
- await p.getBlock(15); assert.equal(p.calls.at(-1).params[0], "0xf");
113
- await p.getBlock(16); assert.equal(p.calls.at(-1).params[0], "0x10");
114
- await p.getBlock(256); assert.equal(p.calls.at(-1).params[0], "0x100");
115
- await p.getBlock(4095); assert.equal(p.calls.at(-1).params[0], "0xfff");
116
- await p.getBlock(4096); assert.equal(p.calls.at(-1).params[0], "0x1000");
117
- await p.getBlock("latest"); assert.equal(p.calls.at(-1).params[0], "latest");
118
- });
119
-
120
- it("getLogs encodes fromBlock/toBlock as spec-compliant quantities (no leading zeros)", async () => {
121
- logTest("getLogs encodes fromBlock/toBlock as spec-compliant quantities", {});
122
- class LogStub extends qc.AbstractProvider {
123
- constructor() { super(); this.calls = []; }
124
- async _perform(method, params) { this.calls.push({ method, params }); return []; }
125
- }
126
- const lp = new LogStub();
127
- await lp.getLogs({ fromBlock: 5, toBlock: 256 });
128
- assert.equal(lp.calls[0].params[0].fromBlock, "0x5");
129
- assert.equal(lp.calls[0].params[0].toBlock, "0x100");
130
- await lp.getLogs({ fromBlock: "latest", toBlock: "pending" });
131
- assert.equal(lp.calls[1].params[0].fromBlock, "latest");
132
- assert.equal(lp.calls[1].params[0].toBlock, "pending");
133
- });
134
-
135
- it("getBlock rejects invalid block numbers with a clear typed error", async () => {
136
- logTest("getBlock rejects invalid block numbers", {});
137
- class StubP extends qc.AbstractProvider {
138
- async _perform() { return { number: "0x0" }; }
139
- }
140
- const p = new StubP();
141
- await assert.rejects(() => p.getBlock(-1), (e) => e instanceof RangeError);
142
- await assert.rejects(() => p.getBlock(1.5), (e) => e instanceof TypeError);
143
- await assert.rejects(() => p.getBlock(NaN), (e) => e instanceof TypeError);
144
- });
145
- });
146
-
147
- describe("TransactionResponse.wait", () => {
148
- logSuite("TransactionResponse.wait");
149
- it("uses default confirmations when omitted vs null", async () => {
150
- logTest("uses default confirmations when omitted vs null", {});
151
- const fakeProvider = {
152
- getTransactionReceipt: async () => ({ blockNumber: 1 }),
153
- getBlockNumber: async () => 1,
154
- };
155
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, fakeProvider);
156
- const r1 = await tx.wait();
157
- const r2 = await tx.wait(null, null);
158
- assert.deepEqual(r1, { blockNumber: 1 });
159
- assert.deepEqual(r2, { blockNumber: 1 });
160
- });
161
-
162
- it("throws if provider missing", async () => {
163
- logTest("throws if provider missing", {});
164
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, null);
165
- await assert.rejects(() => tx.wait(), (e) => e && e.code === "UNKNOWN_ERROR" && /missing provider/i.test(e.message));
166
- });
167
- });
168
-
169
- describe("getProvider", () => {
170
- logSuite("getProvider");
171
- it("returns JsonRpcProvider for http/https URLs", () => {
172
- logTest("returns JsonRpcProvider for http/https URLs", {});
173
- const p1 = qc.getProvider("https://public.rpc.quantumcoinapi.com", 123123);
174
- const p2 = qc.getProvider("http://localhost:8545");
175
- assert.ok(p1 instanceof qc.JsonRpcProvider);
176
- assert.ok(p2 instanceof qc.JsonRpcProvider);
177
- assert.equal(p1.url, "https://public.rpc.quantumcoinapi.com");
178
- assert.equal(p1.chainId, 123123);
179
- });
180
-
181
- it("returns WebSocketProvider for ws/wss URLs", () => {
182
- logTest("returns WebSocketProvider for ws/wss URLs", {});
183
- const p1 = qc.getProvider("ws://127.0.0.1:8546");
184
- const p2 = qc.getProvider("wss://example.com/ws", 1);
185
- assert.ok(p1 instanceof qc.WebSocketProvider);
186
- assert.ok(p2 instanceof qc.WebSocketProvider);
187
- assert.equal(p1.url, "ws://127.0.0.1:8546");
188
- assert.equal(p2.chainId, 1);
189
- });
190
-
191
- it("returns IpcSocketProvider for IPC paths", () => {
192
- logTest("returns IpcSocketProvider for IPC paths", {});
193
- const p = qc.getProvider("\\\\.\\pipe\\geth.ipc");
194
- assert.ok(p instanceof qc.IpcSocketProvider);
195
- assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
196
- });
197
-
198
- it("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", () => {
199
- logTest("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", {});
200
- const p1 = qc.getProvider();
201
- const p2 = qc.getProvider("");
202
- assert.ok(p1 instanceof qc.JsonRpcProvider);
203
- assert.ok(p2 instanceof qc.JsonRpcProvider);
204
- assert.ok(p1.url.length > 0);
205
- assert.equal(p1.chainId, 123123);
206
- });
207
- });
208
-
209
- describe("Extra providers", () => {
210
- logSuite("Extra providers");
211
- it("BrowserProvider requires an EIP-1193 provider with request()", () => {
212
- logTest("BrowserProvider requires an EIP-1193 provider with request()", {});
213
- assert.throws(() => new qc.BrowserProvider(null), (e) => e && e.code === "INVALID_ARGUMENT");
214
- assert.throws(() => new qc.BrowserProvider({}), (e) => e && e.code === "INVALID_ARGUMENT");
215
- const p = new qc.BrowserProvider({ request: async () => null });
216
- assert.ok(p);
217
- });
218
-
219
- it("WebSocketProvider requires a url and stores it", () => {
220
- logTest("WebSocketProvider requires a url and stores it", {});
221
- assert.throws(() => new qc.WebSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
222
- const p = new qc.WebSocketProvider("ws://127.0.0.1:8546 ");
223
- assert.equal(p.url, "ws://127.0.0.1:8546");
224
- });
225
-
226
- it("IpcSocketProvider requires a path and stores it", () => {
227
- logTest("IpcSocketProvider requires a path and stores it", {});
228
- assert.throws(() => new qc.IpcSocketProvider(), (e) => e && e.code === "INVALID_ARGUMENT");
229
- const p = new qc.IpcSocketProvider("\\\\.\\pipe\\geth.ipc");
230
- assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
231
- });
232
-
233
- it("FallbackProvider accepts single vs array and tries providers in order", async () => {
234
- logTest("FallbackProvider accepts single vs array and tries providers in order", {});
235
- const p1 = { _perform: async () => "0x10" };
236
- const fp1 = new qc.FallbackProvider(p1);
237
- const bn1 = await fp1.getBlockNumber();
238
- assert.equal(bn1, 16);
239
-
240
- const pFail = { _perform: async () => { throw new Error("fail"); } };
241
- const pOk = { _perform: async () => "0x02" };
242
- const fp2 = new qc.FallbackProvider([pFail, pOk]);
243
- const bn2 = await fp2.getBlockNumber();
244
- assert.equal(bn2, 2);
245
- });
246
-
247
- it("FallbackProvider throws when no providers provided", () => {
248
- logTest("FallbackProvider throws when no providers provided", {});
249
- assert.throws(() => new qc.FallbackProvider([]));
250
- });
251
- });
252
-
@@ -1,251 +0,0 @@
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
- const responseBody = JSON.stringify({ jsonrpc: "2.0", id: body.id, result: "0x1" });
43
- return {
44
- ok: true,
45
- text: async () => responseBody,
46
- json: async () => JSON.parse(responseBody),
47
- } as Response;
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
- (globalThis as unknown as { fetch: typeof fetch }).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
- calls: { method: string; params: unknown[] }[] = [];
69
- constructor() {
70
- super();
71
- }
72
- async _perform(method: string, params: unknown[]) {
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
- assert.deepEqual(tags, ["latest", "latest", "latest", "latest", "latest", "latest"]);
91
- });
92
- });
93
-
94
- describe("AbstractProvider block-tag QUANTITY formatting", () => {
95
- logSuite("AbstractProvider block-tag QUANTITY formatting");
96
-
97
- it("getBlock encodes block numbers as spec-compliant quantities (no leading zeros)", async () => {
98
- logTest("getBlock encodes block numbers as spec-compliant quantities", {});
99
- class BlockStub extends qc.AbstractProvider {
100
- calls: { method: string; params: any[] }[] = [];
101
- async _perform(method: string, params: any[]) {
102
- this.calls.push({ method, params });
103
- return { number: "0x5", timestamp: "0x64" };
104
- }
105
- }
106
- const p = new BlockStub();
107
- await p.getBlock(0); assert.equal(p.calls.at(-1)!.params[0], "0x0");
108
- await p.getBlock(5); assert.equal(p.calls.at(-1)!.params[0], "0x5");
109
- await p.getBlock(15); assert.equal(p.calls.at(-1)!.params[0], "0xf");
110
- await p.getBlock(16); assert.equal(p.calls.at(-1)!.params[0], "0x10");
111
- await p.getBlock(256); assert.equal(p.calls.at(-1)!.params[0], "0x100");
112
- await p.getBlock(4095); assert.equal(p.calls.at(-1)!.params[0], "0xfff");
113
- await p.getBlock(4096); assert.equal(p.calls.at(-1)!.params[0], "0x1000");
114
- await p.getBlock("latest"); assert.equal(p.calls.at(-1)!.params[0], "latest");
115
- });
116
-
117
- it("getLogs encodes fromBlock/toBlock as spec-compliant quantities (no leading zeros)", async () => {
118
- logTest("getLogs encodes fromBlock/toBlock as spec-compliant quantities", {});
119
- class LogStub extends qc.AbstractProvider {
120
- calls: { method: string; params: any[] }[] = [];
121
- async _perform(method: string, params: any[]) {
122
- this.calls.push({ method, params });
123
- return [];
124
- }
125
- }
126
- const lp = new LogStub();
127
- await lp.getLogs({ fromBlock: 5, toBlock: 256 });
128
- assert.equal(lp.calls[0].params[0].fromBlock, "0x5");
129
- assert.equal(lp.calls[0].params[0].toBlock, "0x100");
130
- await lp.getLogs({ fromBlock: "latest", toBlock: "pending" });
131
- assert.equal(lp.calls[1].params[0].fromBlock, "latest");
132
- assert.equal(lp.calls[1].params[0].toBlock, "pending");
133
- });
134
-
135
- it("getBlock rejects invalid block numbers with a clear typed error", async () => {
136
- logTest("getBlock rejects invalid block numbers", {});
137
- class StubP extends qc.AbstractProvider {
138
- async _perform() { return { number: "0x0" }; }
139
- }
140
- const p = new StubP();
141
- await assert.rejects(() => p.getBlock(-1 as unknown as number), (e) => e instanceof RangeError);
142
- await assert.rejects(() => p.getBlock(1.5 as unknown as number), (e) => e instanceof TypeError);
143
- await assert.rejects(() => p.getBlock(NaN as unknown as number), (e) => e instanceof TypeError);
144
- });
145
- });
146
-
147
- describe("TransactionResponse.wait", () => {
148
- logSuite("TransactionResponse.wait");
149
- it("uses default confirmations when omitted vs null", async () => {
150
- logTest("uses default confirmations when omitted vs null", {});
151
- const fakeProvider = {
152
- getTransactionReceipt: async () => ({ blockNumber: 1 }),
153
- getBlockNumber: async () => 1,
154
- };
155
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, fakeProvider as unknown as qc.Provider);
156
- const r1 = await tx.wait();
157
- const r2 = await tx.wait(null, null);
158
- assert.deepEqual(r1, { blockNumber: 1 });
159
- assert.deepEqual(r2, { blockNumber: 1 });
160
- });
161
-
162
- it("throws if provider missing", async () => {
163
- logTest("throws if provider missing", {});
164
- const tx = new qc.TransactionResponse({ hash: "0x" + "11".repeat(32) }, null);
165
- await assert.rejects(() => tx.wait(), (e: Error & { code?: string; message?: string }) => e && e.code === "UNKNOWN_ERROR" && /missing provider/i.test(e.message ?? ""));
166
- });
167
- });
168
-
169
- describe("getProvider", () => {
170
- logSuite("getProvider");
171
- it("returns JsonRpcProvider for http/https URLs", () => {
172
- logTest("returns JsonRpcProvider for http/https URLs", {});
173
- const p1 = qc.getProvider("https://public.rpc.quantumcoinapi.com", 123123);
174
- const p2 = qc.getProvider("http://localhost:8545");
175
- assert.ok(p1 instanceof qc.JsonRpcProvider);
176
- assert.ok(p2 instanceof qc.JsonRpcProvider);
177
- assert.equal(p1.url, "https://public.rpc.quantumcoinapi.com");
178
- assert.equal(p1.chainId, 123123);
179
- });
180
-
181
- it("returns WebSocketProvider for ws/wss URLs", () => {
182
- logTest("returns WebSocketProvider for ws/wss URLs", {});
183
- const p1 = qc.getProvider("ws://127.0.0.1:8546");
184
- const p2 = qc.getProvider("wss://example.com/ws", 1);
185
- assert.ok(p1 instanceof qc.WebSocketProvider);
186
- assert.ok(p2 instanceof qc.WebSocketProvider);
187
- assert.equal(p1.url, "ws://127.0.0.1:8546");
188
- assert.equal(p2.chainId, 1);
189
- });
190
-
191
- it("returns IpcSocketProvider for IPC paths", () => {
192
- logTest("returns IpcSocketProvider for IPC paths", {});
193
- const p = qc.getProvider("\\\\.\\pipe\\geth.ipc");
194
- assert.ok(p instanceof qc.IpcSocketProvider);
195
- assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
196
- });
197
-
198
- it("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", () => {
199
- logTest("returns JsonRpcProvider with default url/chainId when endpoint omitted or empty", {});
200
- const p1 = qc.getProvider();
201
- const p2 = qc.getProvider("");
202
- assert.ok(p1 instanceof qc.JsonRpcProvider);
203
- assert.ok(p2 instanceof qc.JsonRpcProvider);
204
- assert.ok(p1.url.length > 0);
205
- assert.equal(p1.chainId, 123123);
206
- });
207
- });
208
-
209
- describe("Extra providers", () => {
210
- logSuite("Extra providers");
211
- it("BrowserProvider requires an EIP-1193 provider with request()", () => {
212
- logTest("BrowserProvider requires an EIP-1193 provider with request()", {});
213
- assert.throws(() => new qc.BrowserProvider(null), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
214
- assert.throws(() => new qc.BrowserProvider({}), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
215
- const p = new qc.BrowserProvider({ request: async () => null });
216
- assert.ok(p);
217
- });
218
-
219
- it("WebSocketProvider requires a url and stores it", () => {
220
- logTest("WebSocketProvider requires a url and stores it", {});
221
- assert.throws(() => new qc.WebSocketProvider(), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
222
- const p = new qc.WebSocketProvider("ws://127.0.0.1:8546 ");
223
- assert.equal(p.url, "ws://127.0.0.1:8546");
224
- });
225
-
226
- it("IpcSocketProvider requires a path and stores it", () => {
227
- logTest("IpcSocketProvider requires a path and stores it", {});
228
- assert.throws(() => new qc.IpcSocketProvider(), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
229
- const p = new qc.IpcSocketProvider("\\\\.\\pipe\\geth.ipc");
230
- assert.equal(p.path, "\\\\.\\pipe\\geth.ipc");
231
- });
232
-
233
- it("FallbackProvider accepts single vs array and tries providers in order", async () => {
234
- logTest("FallbackProvider accepts single vs array and tries providers in order", {});
235
- const p1 = { _perform: async () => "0x10" };
236
- const fp1 = new qc.FallbackProvider(p1 as unknown as qc.Provider);
237
- const bn1 = await fp1.getBlockNumber();
238
- assert.equal(bn1, 16);
239
-
240
- const pFail = { _perform: async () => { throw new Error("fail"); } };
241
- const pOk = { _perform: async () => "0x02" };
242
- const fp2 = new qc.FallbackProvider([pFail, pOk] as unknown as qc.Provider[]);
243
- const bn2 = await fp2.getBlockNumber();
244
- assert.equal(bn2, 2);
245
- });
246
-
247
- it("FallbackProvider throws when no providers provided", () => {
248
- logTest("FallbackProvider throws when no providers provided", {});
249
- assert.throws(() => new qc.FallbackProvider([]));
250
- });
251
- });