quantumcoin 7.0.3 → 7.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.github/workflows/publish-npmjs.yaml +22 -22
  2. package/.gitignore +15 -15
  3. package/LICENSE +21 -21
  4. package/README-SDK.md +756 -754
  5. package/README.md +165 -150
  6. package/SPEC.md +3845 -3843
  7. package/config.d.ts +50 -50
  8. package/config.js +115 -115
  9. package/examples/AllSolidityTypes.sol +184 -184
  10. package/examples/SimpleIERC20.sol +74 -74
  11. package/examples/events.js +41 -35
  12. package/examples/events.ts +35 -0
  13. package/examples/example-generator-sdk-js.js +100 -95
  14. package/examples/example-generator-sdk-js.ts +77 -0
  15. package/examples/example-generator-sdk-ts.js +100 -95
  16. package/examples/example-generator-sdk-ts.ts +77 -0
  17. package/examples/example.js +72 -61
  18. package/examples/example.ts +61 -0
  19. package/examples/offline-signing.js +79 -73
  20. package/examples/offline-signing.ts +66 -0
  21. package/examples/package-lock.json +48 -57
  22. package/examples/package.json +32 -16
  23. package/examples/read-operations.js +32 -27
  24. package/examples/read-operations.ts +31 -0
  25. package/examples/sdk-generator-erc20.inline.json +251 -251
  26. package/examples/solidity-types.ts +43 -43
  27. package/examples/wallet-offline.js +35 -29
  28. package/examples/wallet-offline.ts +34 -0
  29. package/generate-sdk.js +1824 -1490
  30. package/index.js +12 -12
  31. package/package.json +95 -75
  32. package/scripts/copy-declarations.js +31 -0
  33. package/scripts/run-all-one-by-one.js +151 -0
  34. package/src/abi/fragments.d.ts +42 -42
  35. package/src/abi/fragments.js +63 -63
  36. package/src/abi/index.d.ts +13 -13
  37. package/src/abi/index.js +9 -9
  38. package/src/abi/interface.d.ts +128 -132
  39. package/src/abi/interface.js +590 -590
  40. package/src/abi/js-abi-coder.d.ts +8 -0
  41. package/src/abi/js-abi-coder.js +474 -474
  42. package/src/constants.d.ts +66 -61
  43. package/src/constants.js +101 -94
  44. package/src/contract/contract-factory.d.ts +28 -28
  45. package/src/contract/contract-factory.js +105 -105
  46. package/src/contract/contract.d.ts +113 -114
  47. package/src/contract/contract.js +354 -354
  48. package/src/contract/index.d.ts +9 -9
  49. package/src/contract/index.js +9 -9
  50. package/src/errors/index.d.ts +92 -92
  51. package/src/errors/index.js +188 -188
  52. package/src/generator/index.d.ts +74 -0
  53. package/src/generator/index.js +1404 -1404
  54. package/src/index.d.ts +125 -127
  55. package/src/index.js +41 -41
  56. package/src/internal/hex.d.ts +61 -61
  57. package/src/internal/hex.js +144 -144
  58. package/src/providers/extra-providers.d.ts +139 -128
  59. package/src/providers/extra-providers.js +600 -575
  60. package/src/providers/index.d.ts +17 -16
  61. package/src/providers/index.js +10 -10
  62. package/src/providers/json-rpc-provider.d.ts +12 -12
  63. package/src/providers/json-rpc-provider.js +79 -79
  64. package/src/providers/provider.d.ts +207 -203
  65. package/src/providers/provider.js +392 -371
  66. package/src/types/index.d.ts +214 -462
  67. package/src/types/index.js +9 -9
  68. package/src/utils/address.d.ts +72 -72
  69. package/src/utils/address.js +181 -182
  70. package/src/utils/encoding.d.ts +120 -120
  71. package/src/utils/encoding.js +306 -306
  72. package/src/utils/hashing.d.ts +82 -76
  73. package/src/utils/hashing.js +313 -298
  74. package/src/utils/index.d.ts +65 -55
  75. package/src/utils/index.js +13 -13
  76. package/src/utils/result.d.ts +57 -57
  77. package/src/utils/result.js +128 -128
  78. package/src/utils/rlp.d.ts +12 -12
  79. package/src/utils/rlp.js +200 -200
  80. package/src/utils/units.d.ts +29 -29
  81. package/src/utils/units.js +107 -107
  82. package/src/wallet/index.d.ts +10 -10
  83. package/src/wallet/index.js +8 -8
  84. package/src/wallet/wallet.d.ts +160 -160
  85. package/src/wallet/wallet.js +483 -489
  86. package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
  87. package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
  88. package/test/e2e/all-solidity-types.fixtures.js +231 -231
  89. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -368
  90. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
  91. package/test/e2e/helpers.js +59 -47
  92. package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
  93. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
  94. package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -151
  95. package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
  96. package/test/e2e/transactional.test.js +245 -191
  97. package/test/e2e/transactional.test.ts +208 -0
  98. package/test/e2e/typed-generator.e2e.test.js +407 -404
  99. package/test/e2e/typed-generator.e2e.test.ts +337 -0
  100. package/test/fixtures/ConstructorParam.sol +23 -23
  101. package/test/fixtures/MultiContracts.sol +37 -37
  102. package/test/fixtures/SimpleStorage.sol +18 -18
  103. package/test/fixtures/StakingContract.abi.json +1 -1
  104. package/test/integration/ipc-provider.test.js +49 -44
  105. package/test/integration/ipc-provider.test.ts +44 -0
  106. package/test/integration/provider.test.js +88 -72
  107. package/test/integration/provider.test.ts +85 -0
  108. package/test/integration/ws-provider.test.js +41 -33
  109. package/test/integration/ws-provider.test.ts +38 -0
  110. package/test/security/malformed-input.test.js +37 -31
  111. package/test/security/malformed-input.test.ts +35 -0
  112. package/test/unit/_encrypted-output.txt +6 -0
  113. package/test/unit/_log-encrypted-jsons.js +45 -0
  114. package/test/unit/_write-keystore-fixture.js +16 -0
  115. package/test/unit/abi-interface.test.js +103 -98
  116. package/test/unit/abi-interface.test.ts +102 -0
  117. package/test/unit/address-wallet.test.js +355 -257
  118. package/test/unit/address-wallet.test.ts +342 -0
  119. package/test/unit/browser-provider.test.js +85 -82
  120. package/test/unit/browser-provider.test.ts +79 -0
  121. package/test/unit/contract.test.js +85 -82
  122. package/test/unit/contract.test.ts +83 -0
  123. package/test/unit/encoding-units-rlp.test.js +92 -89
  124. package/test/unit/encoding-units-rlp.test.ts +91 -0
  125. package/test/unit/errors.test.js +77 -74
  126. package/test/unit/errors.test.ts +76 -0
  127. package/test/unit/filter-by-blockhash.test.js +55 -52
  128. package/test/unit/filter-by-blockhash.test.ts +54 -0
  129. package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
  130. package/test/unit/generate-contract-cli.test.js +42 -39
  131. package/test/unit/generate-contract-cli.test.ts +41 -0
  132. package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
  133. package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
  134. package/test/unit/generator.test.js +102 -99
  135. package/test/unit/generator.test.ts +101 -0
  136. package/test/unit/hashing.test.js +68 -54
  137. package/test/unit/hashing.test.ts +67 -0
  138. package/test/unit/init.test.js +39 -36
  139. package/test/unit/init.test.ts +38 -0
  140. package/test/unit/interface.test.js +56 -53
  141. package/test/unit/interface.test.ts +54 -0
  142. package/test/unit/internal-hex.test.js +50 -47
  143. package/test/unit/internal-hex.test.ts +49 -0
  144. package/test/unit/populate-transaction.test.js +65 -62
  145. package/test/unit/populate-transaction.test.ts +64 -0
  146. package/test/unit/providers.test.js +200 -144
  147. package/test/unit/providers.test.ts +196 -0
  148. package/test/unit/result.test.js +80 -77
  149. package/test/unit/result.test.ts +79 -0
  150. package/test/unit/solidity-types.test.js +49 -46
  151. package/test/unit/solidity-types.test.ts +39 -0
  152. package/test/unit/utils.test.js +57 -54
  153. package/test/unit/utils.test.ts +56 -0
  154. package/test/verbose-logger.js +74 -0
  155. package/tsconfig.build.json +14 -0
@@ -1,44 +1,49 @@
1
- /**
2
- * @testCategory integration
3
- * @blockchainRequired readonly
4
- * @transactional false
5
- * @description Read-only IPC JSON-RPC integration tests against a local geth IPC endpoint
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
-
11
- const qc = require("../../index");
12
-
13
- // Windows named pipe endpoint for geth IPC
14
- const IPC = "\\\\.\\pipe\\geth.ipc";
15
-
16
- describe("IpcSocketProvider (readonly)", () => {
17
- it("getBlockNumber and getBlock('latest') work over IPC", async (t) => {
18
- const provider = new qc.IpcSocketProvider(IPC);
19
- try {
20
- const bn = await provider.getBlockNumber();
21
- assert.ok(Number.isInteger(bn) && bn >= 0);
22
-
23
- const latest = await provider.getBlock("latest");
24
- assert.ok(latest && typeof latest === "object");
25
- assert.ok(typeof latest.number === "number" && latest.number >= bn);
26
- // best-effort sanity: hash often exists on latest blocks
27
- assert.ok(latest.hash == null || typeof latest.hash === "string");
28
-
29
- // Print a JSON-safe summary (avoid circular refs like latest.provider)
30
- const latestSummary = {
31
- number: latest.number,
32
- hash: latest.hash,
33
- parentHash: latest.parentHash,
34
- timestamp: latest.timestamp,
35
- transactionsCount: Array.isArray(latest.transactions) ? latest.transactions.length : null,
36
- };
37
- // This shows up in TAP output as "# ..."
38
- console.log("IPC latest block:", JSON.stringify(latestSummary));
39
- } catch (e) {
40
- t.skip(`IPC endpoint unavailable (${IPC}): ${e && e.message ? e.message : String(e)}`);
41
- }
42
- });
43
- });
44
-
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only IPC JSON-RPC integration tests against a local geth IPC endpoint
6
+ * Run with VERBOSE=1 for test names, block number/hash.
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
+ const IPC = process.env.QC_ENDPOINT || process.env.QC_IPC_PATH || "\\\\.\\pipe\\geth.ipc";
16
+
17
+ describe("IpcSocketProvider (readonly)", () => {
18
+ it("getBlockNumber and getBlock('latest') work over IPC", async (t) => {
19
+ logSuite("IpcSocketProvider (readonly)");
20
+ logTest("getBlockNumber and getBlock('latest') work over IPC", { endpoint: IPC });
21
+ const provider = qc.getProvider(IPC);
22
+ try {
23
+ const bn = await provider.getBlockNumber();
24
+ logTest("getBlockNumber (ipc)", { blockNumber: bn });
25
+ assert.ok(Number.isInteger(bn) && bn >= 0);
26
+
27
+ const latest = await provider.getBlock("latest");
28
+ logTest("getBlock('latest') (ipc)", { blockNumber: latest.number, blockHash: latest.hash });
29
+ assert.ok(latest && typeof latest === "object");
30
+ assert.ok(typeof latest.number === "number" && latest.number >= bn);
31
+ // best-effort sanity: hash often exists on latest blocks
32
+ assert.ok(latest.hash == null || typeof latest.hash === "string");
33
+
34
+ // Print a JSON-safe summary (avoid circular refs like latest.provider)
35
+ const latestSummary = {
36
+ number: latest.number,
37
+ hash: latest.hash,
38
+ parentHash: latest.parentHash,
39
+ timestamp: latest.timestamp,
40
+ transactionsCount: Array.isArray(latest.transactions) ? latest.transactions.length : null,
41
+ };
42
+ // This shows up in TAP output as "# ..."
43
+ console.log("IPC latest block:", JSON.stringify(latestSummary));
44
+ } catch (e) {
45
+ t.skip(`IPC endpoint unavailable (${IPC}): ${e && e.message ? e.message : String(e)}`);
46
+ }
47
+ });
48
+ });
49
+
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only IPC JSON-RPC integration tests against a local geth IPC endpoint
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
+ const IPC = process.env.QC_ENDPOINT || process.env.QC_IPC_PATH || "\\\\.\\pipe\\geth.ipc";
15
+
16
+ describe("IpcSocketProvider (readonly)", () => {
17
+ it("getBlockNumber and getBlock('latest') work over IPC", async (t: { skip: (msg: string) => void }) => {
18
+ logSuite("IpcSocketProvider (readonly)");
19
+ logTest("getBlockNumber and getBlock('latest') work over IPC", { endpoint: IPC });
20
+ const provider = qc.getProvider(IPC);
21
+ try {
22
+ const bn = await provider.getBlockNumber();
23
+ logTest("getBlockNumber (ipc)", { blockNumber: bn });
24
+ assert.ok(Number.isInteger(bn) && bn >= 0);
25
+
26
+ const latest = await provider.getBlock("latest");
27
+ logTest("getBlock('latest') (ipc)", { blockNumber: latest.number, blockHash: latest.hash });
28
+ assert.ok(latest && typeof latest === "object");
29
+ assert.ok(typeof latest.number === "number" && latest.number >= bn);
30
+ assert.ok(latest.hash == null || typeof latest.hash === "string");
31
+
32
+ const latestSummary = {
33
+ number: latest.number,
34
+ hash: latest.hash,
35
+ parentHash: latest.parentHash,
36
+ timestamp: latest.timestamp,
37
+ transactionsCount: Array.isArray(latest.transactions) ? latest.transactions.length : null,
38
+ };
39
+ console.log("IPC latest block:", JSON.stringify(latestSummary));
40
+ } catch (e) {
41
+ t.skip(`IPC endpoint unavailable (${IPC}): ${e && (e as Error).message ? (e as Error).message : String(e)}`);
42
+ }
43
+ });
44
+ });
@@ -1,72 +1,88 @@
1
- /**
2
- * @testCategory integration
3
- * @blockchainRequired readonly
4
- * @transactional false
5
- * @description Read-only JSON-RPC integration tests against public QuantumCoin RPC
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
-
14
- const RPC = "https://public.rpc.quantumcoinapi.com";
15
- const CHAIN_ID = 123123;
16
- const STAKING_CONTRACT = "0x" + "00".repeat(30) + "10" + "00"; // ...1000 (32-byte address)
17
-
18
- describe("JsonRpcProvider (readonly)", () => {
19
- it("getBlockNumber returns a recent block", async (t) => {
20
- const provider = new qc.JsonRpcProvider(RPC, CHAIN_ID);
21
- try {
22
- const bn = await provider.getBlockNumber();
23
- assert.ok(bn > 3000000);
24
- } catch (e) {
25
- t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
26
- }
27
- });
28
-
29
- it("getBlock works for a block > 3000000 and for latest", async (t) => {
30
- const provider = new qc.JsonRpcProvider(RPC, CHAIN_ID);
31
- try {
32
- const latest = await provider.getBlockNumber();
33
- const target = 3386000;
34
- if (latest < target) t.skip("chain not at expected height yet");
35
-
36
- const b = await provider.getBlock(target);
37
- assert.equal(b.number, target);
38
-
39
- const l = await provider.getBlock("latest");
40
- assert.ok(l.number >= target);
41
- } catch (e) {
42
- t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
43
- }
44
- });
45
-
46
- it("getBalance works for a known system contract address", async (t) => {
47
- const provider = new qc.JsonRpcProvider(RPC, CHAIN_ID);
48
- try {
49
- const bal = await provider.getBalance(STAKING_CONTRACT);
50
- assert.equal(typeof bal, "bigint");
51
- assert.ok(bal >= 0n);
52
- } catch (e) {
53
- t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
54
- }
55
- });
56
-
57
- it("contract read operations work (staking contract)", async (t) => {
58
- await Initialize(null);
59
- const provider = new qc.JsonRpcProvider(RPC, CHAIN_ID);
60
- try {
61
- const abi = require("../fixtures/StakingContract.abi.json");
62
- const contract = new qc.Contract(STAKING_CONTRACT, abi, provider);
63
- const count = await contract.getDepositorCount();
64
- // qcsdk returns JSON; for single return values it is usually an array with one element
65
- const value = Array.isArray(count) ? count[0] : count;
66
- assert.ok(value != null);
67
- } catch (e) {
68
- t.skip(`network/ABI unavailable: ${e && e.message ? e.message : String(e)}`);
69
- }
70
- });
71
- });
72
-
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only integration tests. Endpoint from QC_ENDPOINT or QC_RPC_URL (default: public RPC).
6
+ * Works with HTTP, WebSocket, or IPC; use QC_ENDPOINT=\\.\pipe\geth.ipc to run over IPC.
7
+ * Run with VERBOSE=1 or QC_VERBOSE=1 for test names, addresses, block numbers.
8
+ */
9
+
10
+ const { describe, it } = require("node:test");
11
+ const assert = require("node:assert/strict");
12
+
13
+ const { Initialize } = require("../../config");
14
+ const qc = require("../../index");
15
+ const { logSuite, logTest, logAddress } = require("../verbose-logger");
16
+
17
+ const DEFAULT_RPC = "https://public.rpc.quantumcoinapi.com";
18
+ const CHAIN_ID = 123123;
19
+ const STAKING_CONTRACT = "0x" + "00".repeat(30) + "10" + "00"; // ...1000 (32-byte address)
20
+
21
+ const ENDPOINT = process.env.QC_ENDPOINT || process.env.QC_RPC_URL || DEFAULT_RPC;
22
+ const isPublicRpc = ENDPOINT === DEFAULT_RPC;
23
+
24
+ describe("Provider (readonly)", () => {
25
+ it("getBlockNumber returns a block number", async (t) => {
26
+ logSuite("Provider (readonly)");
27
+ logTest("getBlockNumber returns a block number", { endpoint: ENDPOINT, chainId: CHAIN_ID });
28
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
29
+ try {
30
+ const bn = await provider.getBlockNumber();
31
+ logTest("getBlockNumber returns a block number", { blockNumber: bn });
32
+ assert.ok(Number.isInteger(bn) && bn >= 0);
33
+ if (isPublicRpc) assert.ok(bn > 3000000, "public chain height");
34
+ } catch (e) {
35
+ t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
36
+ }
37
+ });
38
+
39
+ it("getBlock('latest') works", async (t) => {
40
+ logTest("getBlock('latest') works", {});
41
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
42
+ try {
43
+ const latest = await provider.getBlockNumber();
44
+ const block = await provider.getBlock("latest");
45
+ logTest("getBlock('latest') works", { blockNumber: block.number, blockHash: block.hash });
46
+ assert.ok(block && typeof block === "object");
47
+ assert.ok(typeof block.number === "number" && block.number >= latest);
48
+ if (isPublicRpc && latest >= 3386000) {
49
+ const b = await provider.getBlock(3386000);
50
+ assert.equal(b.number, 3386000);
51
+ }
52
+ } catch (e) {
53
+ t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
54
+ }
55
+ });
56
+
57
+ it("getBalance works for an address", async (t) => {
58
+ logTest("getBalance works for an address", {});
59
+ logAddress("staking_contract", STAKING_CONTRACT);
60
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
61
+ try {
62
+ const bal = await provider.getBalance(STAKING_CONTRACT);
63
+ logTest("getBalance works for an address", { balance: bal.toString() });
64
+ assert.equal(typeof bal, "bigint");
65
+ assert.ok(bal >= 0n);
66
+ } catch (e) {
67
+ t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
68
+ }
69
+ });
70
+
71
+ it("contract read operations work (staking contract when available)", async (t) => {
72
+ logTest("contract read operations work (staking contract when available)", {});
73
+ logAddress("staking_contract", STAKING_CONTRACT);
74
+ await Initialize(null);
75
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
76
+ try {
77
+ const abi = require("../fixtures/StakingContract.abi.json");
78
+ const contract = new qc.Contract(STAKING_CONTRACT, abi, provider);
79
+ const count = await contract.getDepositorCount();
80
+ const value = Array.isArray(count) ? count[0] : count;
81
+ logTest("contract read operations work", { depositorCount: value != null ? String(value) : null });
82
+ assert.ok(value != null);
83
+ } catch (e) {
84
+ t.skip(`network/ABI unavailable: ${e && e.message ? e.message : String(e)}`);
85
+ }
86
+ });
87
+ });
88
+
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only integration tests. Endpoint from QC_ENDPOINT or QC_RPC_URL (default: public RPC).
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, logAddress } from "../verbose-logger";
14
+
15
+ const DEFAULT_RPC = "https://public.rpc.quantumcoinapi.com";
16
+ const CHAIN_ID = 123123;
17
+ const STAKING_CONTRACT = "0x" + "00".repeat(30) + "10" + "00";
18
+
19
+ const ENDPOINT = process.env.QC_ENDPOINT || process.env.QC_RPC_URL || DEFAULT_RPC;
20
+ const isPublicRpc = ENDPOINT === DEFAULT_RPC;
21
+
22
+ describe("Provider (readonly)", () => {
23
+ it("getBlockNumber returns a block number", async (t: { skip: (msg: string) => void }) => {
24
+ logSuite("Provider (readonly)");
25
+ logTest("getBlockNumber returns a block number", { endpoint: ENDPOINT, chainId: CHAIN_ID });
26
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
27
+ try {
28
+ const bn = await provider.getBlockNumber();
29
+ logTest("getBlockNumber returns a block number", { blockNumber: bn });
30
+ assert.ok(Number.isInteger(bn) && bn >= 0);
31
+ if (isPublicRpc) assert.ok(bn > 3000000, "public chain height");
32
+ } catch (e) {
33
+ t.skip(`network unavailable: ${e && (e as Error).message ? (e as Error).message : String(e)}`);
34
+ }
35
+ });
36
+
37
+ it("getBlock('latest') works", async (t: { skip: (msg: string) => void }) => {
38
+ logTest("getBlock('latest') works", {});
39
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
40
+ try {
41
+ const latest = await provider.getBlockNumber();
42
+ const block = await provider.getBlock("latest");
43
+ logTest("getBlock('latest') works", { blockNumber: block.number, blockHash: block.hash });
44
+ assert.ok(block && typeof block === "object");
45
+ assert.ok(typeof block.number === "number" && block.number >= latest);
46
+ if (isPublicRpc && latest >= 3386000) {
47
+ const b = await provider.getBlock(3386000);
48
+ assert.equal(b.number, 3386000);
49
+ }
50
+ } catch (e) {
51
+ t.skip(`network unavailable: ${e && (e as Error).message ? (e as Error).message : String(e)}`);
52
+ }
53
+ });
54
+
55
+ it("getBalance works for an address", async (t: { skip: (msg: string) => void }) => {
56
+ logTest("getBalance works for an address", {});
57
+ logAddress("staking_contract", STAKING_CONTRACT);
58
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
59
+ try {
60
+ const bal = await provider.getBalance(STAKING_CONTRACT);
61
+ logTest("getBalance works for an address", { balance: bal.toString() });
62
+ assert.equal(typeof bal, "bigint");
63
+ assert.ok(bal >= 0n);
64
+ } catch (e) {
65
+ t.skip(`network unavailable: ${e && (e as Error).message ? (e as Error).message : String(e)}`);
66
+ }
67
+ });
68
+
69
+ it("contract read operations work (staking contract when available)", async (t: { skip: (msg: string) => void }) => {
70
+ logTest("contract read operations work (staking contract when available)", {});
71
+ logAddress("staking_contract", STAKING_CONTRACT);
72
+ await Initialize(null);
73
+ const provider = qc.getProvider(ENDPOINT, CHAIN_ID);
74
+ try {
75
+ const abi = require("../fixtures/StakingContract.abi.json");
76
+ const contract = new qc.Contract(STAKING_CONTRACT, abi, provider);
77
+ const count = await contract.getDepositorCount();
78
+ const value = Array.isArray(count) ? count[0] : count;
79
+ logTest("contract read operations work", { depositorCount: value != null ? String(value) : null });
80
+ assert.ok(value != null);
81
+ } catch (e) {
82
+ t.skip(`network/ABI unavailable: ${e && (e as Error).message ? (e as Error).message : String(e)}`);
83
+ }
84
+ });
85
+ });
@@ -1,33 +1,41 @@
1
- /**
2
- * @testCategory integration
3
- * @blockchainRequired readonly
4
- * @transactional false
5
- * @description Read-only WebSocket JSON-RPC integration tests against a local geth websocket endpoint
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
-
11
- const qc = require("../../index");
12
-
13
- const WS = process.env.QC_WS_URL || "ws://127.0.0.1:8546";
14
-
15
- describe("WebSocketProvider (readonly)", () => {
16
- it("getBlockNumber and getBlock('latest') work over WebSocket", async (t) => {
17
- const provider = new qc.WebSocketProvider(WS);
18
- try {
19
- const bn = await provider.getBlockNumber();
20
- assert.ok(Number.isInteger(bn) && bn >= 0);
21
-
22
- const latest = await provider.getBlock("latest");
23
- assert.ok(latest && typeof latest === "object");
24
- assert.ok(typeof latest.number === "number" && latest.number >= bn);
25
- assert.ok(latest.hash == null || typeof latest.hash === "string");
26
- } catch (e) {
27
- t.skip(`WebSocket endpoint unavailable (${WS}): ${e && e.message ? e.message : String(e)}`);
28
- } finally {
29
- if (provider && typeof provider.destroy === "function") provider.destroy();
30
- }
31
- });
32
- });
33
-
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only WebSocket JSON-RPC integration tests (validates WebSocketProvider only).
6
+ * Skipped when QC_ENDPOINT is set (e.g. running integration tests over IPC).
7
+ * Run with VERBOSE=1 for test names, block number/hash.
8
+ */
9
+
10
+ const { describe, it } = require("node:test");
11
+ const assert = require("node:assert/strict");
12
+
13
+ const qc = require("../../index");
14
+ const { logSuite, logTest } = require("../verbose-logger");
15
+
16
+ const WS = process.env.QC_WS_URL || "ws://127.0.0.1:8546";
17
+ const skipBecauseOtherEndpoint = process.env.QC_ENDPOINT != null && process.env.QC_ENDPOINT !== "";
18
+
19
+ describe("WebSocketProvider (readonly)", { skip: skipBecauseOtherEndpoint }, () => {
20
+ it("getBlockNumber and getBlock('latest') work over WebSocket", async (t) => {
21
+ logSuite("WebSocketProvider (readonly)");
22
+ logTest("getBlockNumber and getBlock('latest') work over WebSocket", { endpoint: WS });
23
+ const provider = qc.getProvider(WS);
24
+ try {
25
+ const bn = await provider.getBlockNumber();
26
+ logTest("getBlockNumber (ws)", { blockNumber: bn });
27
+ assert.ok(Number.isInteger(bn) && bn >= 0);
28
+
29
+ const latest = await provider.getBlock("latest");
30
+ logTest("getBlock('latest') (ws)", { blockNumber: latest.number, blockHash: latest.hash });
31
+ assert.ok(latest && typeof latest === "object");
32
+ assert.ok(typeof latest.number === "number" && latest.number >= bn);
33
+ assert.ok(latest.hash == null || typeof latest.hash === "string");
34
+ } catch (e) {
35
+ t.skip(`WebSocket endpoint unavailable (${WS}): ${e && e.message ? e.message : String(e)}`);
36
+ } finally {
37
+ if (provider && typeof provider.destroy === "function") provider.destroy();
38
+ }
39
+ });
40
+ });
41
+
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @testCategory integration
3
+ * @blockchainRequired readonly
4
+ * @transactional false
5
+ * @description Read-only WebSocket JSON-RPC integration tests (validates WebSocketProvider only).
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
+ const WS = process.env.QC_WS_URL || "ws://127.0.0.1:8546";
15
+ const skipBecauseOtherEndpoint = process.env.QC_ENDPOINT != null && process.env.QC_ENDPOINT !== "";
16
+
17
+ describe("WebSocketProvider (readonly)", { skip: skipBecauseOtherEndpoint }, () => {
18
+ it("getBlockNumber and getBlock('latest') work over WebSocket", async (t: { skip: (msg: string) => void }) => {
19
+ logSuite("WebSocketProvider (readonly)");
20
+ logTest("getBlockNumber and getBlock('latest') work over WebSocket", { endpoint: WS });
21
+ const provider = qc.getProvider(WS);
22
+ try {
23
+ const bn = await provider.getBlockNumber();
24
+ logTest("getBlockNumber (ws)", { blockNumber: bn });
25
+ assert.ok(Number.isInteger(bn) && bn >= 0);
26
+
27
+ const latest = await provider.getBlock("latest");
28
+ logTest("getBlock('latest') (ws)", { blockNumber: latest.number, blockHash: latest.hash });
29
+ assert.ok(latest && typeof latest === "object");
30
+ assert.ok(typeof latest.number === "number" && latest.number >= bn);
31
+ assert.ok(latest.hash == null || typeof latest.hash === "string");
32
+ } catch (e) {
33
+ t.skip(`WebSocket endpoint unavailable (${WS}): ${e && (e as Error).message ? (e as Error).message : String(e)}`);
34
+ } finally {
35
+ if (provider && typeof provider.destroy === "function") provider.destroy();
36
+ }
37
+ });
38
+ });
@@ -1,31 +1,37 @@
1
- /**
2
- * @testCategory security
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Security tests for malformed input, edge cases, and invalid values
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
-
14
- describe("Security: Malformed Input", () => {
15
- it("rejects invalid address length and characters", async () => {
16
- await Initialize(null);
17
- assert.equal(qc.isAddress("0x1234"), false);
18
- assert.equal(qc.isAddress("not-an-address"), false);
19
- assert.throws(() => qc.getAddress("0x1234"), /invalid address/i);
20
- });
21
-
22
- it("rejects too-long bytes32 strings", () => {
23
- assert.throws(() => qc.encodeBytes32String("x".repeat(33)), /max 32/i);
24
- });
25
-
26
- it("rejects invalid parseUnits inputs", () => {
27
- assert.throws(() => qc.parseUnits("", 18), /invalid/i);
28
- assert.throws(() => qc.parseUnits("1.234", 2), /exceeds decimals/i);
29
- });
30
- });
31
-
1
+ /**
2
+ * @testCategory security
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Security tests for malformed input, edge cases, and invalid values
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 { Initialize } = require("../../config");
13
+ const qc = require("../../index");
14
+ const { logSuite, logTest } = require("../verbose-logger");
15
+
16
+ describe("Security: Malformed Input", () => {
17
+ logSuite("Security: Malformed Input");
18
+ it("rejects invalid address length and characters", async () => {
19
+ logTest("rejects invalid address length and characters", {});
20
+ await Initialize(null);
21
+ assert.equal(qc.isAddress("0x1234"), false);
22
+ assert.equal(qc.isAddress("not-an-address"), false);
23
+ assert.throws(() => qc.getAddress("0x1234"), /invalid address/i);
24
+ });
25
+
26
+ it("rejects too-long bytes32 strings", () => {
27
+ logTest("rejects too-long bytes32 strings", {});
28
+ assert.throws(() => qc.encodeBytes32String("x".repeat(33)), /max 32/i);
29
+ });
30
+
31
+ it("rejects invalid parseUnits inputs", () => {
32
+ logTest("rejects invalid parseUnits inputs", {});
33
+ assert.throws(() => qc.parseUnits("", 18), /invalid/i);
34
+ assert.throws(() => qc.parseUnits("1.234", 2), /exceeds decimals/i);
35
+ });
36
+ });
37
+
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @testCategory security
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Security tests for malformed input, edge cases, and invalid values
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("Security: Malformed Input", () => {
16
+ logSuite("Security: Malformed Input");
17
+ it("rejects invalid address length and characters", async () => {
18
+ logTest("rejects invalid address length and characters", {});
19
+ await Initialize(null);
20
+ assert.equal(qc.isAddress("0x1234"), false);
21
+ assert.equal(qc.isAddress("not-an-address"), false);
22
+ assert.throws(() => qc.getAddress("0x1234"), /invalid address/i);
23
+ });
24
+
25
+ it("rejects too-long bytes32 strings", () => {
26
+ logTest("rejects too-long bytes32 strings", {});
27
+ assert.throws(() => qc.encodeBytes32String("x".repeat(33)), /max 32/i);
28
+ });
29
+
30
+ it("rejects invalid parseUnits inputs", () => {
31
+ logTest("rejects invalid parseUnits inputs", {});
32
+ assert.throws(() => qc.parseUnits("", 18), /invalid/i);
33
+ assert.throws(() => qc.parseUnits("1.234", 2), /exceeds decimals/i);
34
+ });
35
+ });