quantumcoin 7.0.3 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npmjs.yaml +22 -22
- package/.gitignore +15 -15
- package/LICENSE +21 -21
- package/README-SDK.md +756 -754
- package/README.md +165 -150
- package/SPEC.md +3845 -3843
- package/config.d.ts +50 -50
- package/config.js +115 -115
- package/examples/AllSolidityTypes.sol +184 -184
- package/examples/SimpleIERC20.sol +74 -74
- package/examples/events.js +41 -35
- package/examples/events.ts +35 -0
- package/examples/example-generator-sdk-js.js +100 -95
- package/examples/example-generator-sdk-js.ts +77 -0
- package/examples/example-generator-sdk-ts.js +100 -95
- package/examples/example-generator-sdk-ts.ts +77 -0
- package/examples/example.js +72 -61
- package/examples/example.ts +61 -0
- package/examples/offline-signing.js +79 -73
- package/examples/offline-signing.ts +66 -0
- package/examples/package-lock.json +48 -57
- package/examples/package.json +32 -16
- package/examples/read-operations.js +32 -27
- package/examples/read-operations.ts +31 -0
- package/examples/sdk-generator-erc20.inline.json +251 -251
- package/examples/solidity-types.ts +43 -43
- package/examples/wallet-offline.js +35 -29
- package/examples/wallet-offline.ts +34 -0
- package/generate-sdk.js +1824 -1490
- package/index.js +12 -12
- package/package.json +95 -75
- package/scripts/copy-declarations.js +31 -0
- package/scripts/run-all-one-by-one.js +151 -0
- package/src/abi/fragments.d.ts +42 -42
- package/src/abi/fragments.js +63 -63
- package/src/abi/index.d.ts +13 -13
- package/src/abi/index.js +9 -9
- package/src/abi/interface.d.ts +128 -132
- package/src/abi/interface.js +590 -590
- package/src/abi/js-abi-coder.d.ts +8 -0
- package/src/abi/js-abi-coder.js +474 -474
- package/src/constants.d.ts +66 -61
- package/src/constants.js +101 -94
- package/src/contract/contract-factory.d.ts +28 -28
- package/src/contract/contract-factory.js +105 -105
- package/src/contract/contract.d.ts +113 -114
- package/src/contract/contract.js +354 -354
- package/src/contract/index.d.ts +9 -9
- package/src/contract/index.js +9 -9
- package/src/errors/index.d.ts +92 -92
- package/src/errors/index.js +188 -188
- package/src/generator/index.d.ts +74 -0
- package/src/generator/index.js +1404 -1404
- package/src/index.d.ts +125 -127
- package/src/index.js +41 -41
- package/src/internal/hex.d.ts +61 -61
- package/src/internal/hex.js +144 -144
- package/src/providers/extra-providers.d.ts +139 -128
- package/src/providers/extra-providers.js +600 -575
- package/src/providers/index.d.ts +17 -16
- package/src/providers/index.js +10 -10
- package/src/providers/json-rpc-provider.d.ts +12 -12
- package/src/providers/json-rpc-provider.js +79 -79
- package/src/providers/provider.d.ts +207 -203
- package/src/providers/provider.js +392 -371
- package/src/types/index.d.ts +214 -462
- package/src/types/index.js +9 -9
- package/src/utils/address.d.ts +72 -72
- package/src/utils/address.js +181 -182
- package/src/utils/encoding.d.ts +120 -120
- package/src/utils/encoding.js +306 -306
- package/src/utils/hashing.d.ts +82 -76
- package/src/utils/hashing.js +313 -298
- package/src/utils/index.d.ts +65 -55
- package/src/utils/index.js +13 -13
- package/src/utils/result.d.ts +57 -57
- package/src/utils/result.js +128 -128
- package/src/utils/rlp.d.ts +12 -12
- package/src/utils/rlp.js +200 -200
- package/src/utils/units.d.ts +29 -29
- package/src/utils/units.js +107 -107
- package/src/wallet/index.d.ts +10 -10
- package/src/wallet/index.js +8 -8
- package/src/wallet/wallet.d.ts +160 -160
- package/src/wallet/wallet.js +483 -489
- package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
- package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -231
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -368
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
- package/test/e2e/helpers.js +59 -47
- package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
- package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -151
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
- package/test/e2e/transactional.test.js +245 -191
- package/test/e2e/transactional.test.ts +208 -0
- package/test/e2e/typed-generator.e2e.test.js +407 -404
- package/test/e2e/typed-generator.e2e.test.ts +337 -0
- package/test/fixtures/ConstructorParam.sol +23 -23
- package/test/fixtures/MultiContracts.sol +37 -37
- package/test/fixtures/SimpleStorage.sol +18 -18
- package/test/fixtures/StakingContract.abi.json +1 -1
- package/test/integration/ipc-provider.test.js +49 -44
- package/test/integration/ipc-provider.test.ts +44 -0
- package/test/integration/provider.test.js +88 -72
- package/test/integration/provider.test.ts +85 -0
- package/test/integration/ws-provider.test.js +41 -33
- package/test/integration/ws-provider.test.ts +38 -0
- package/test/security/malformed-input.test.js +37 -31
- package/test/security/malformed-input.test.ts +35 -0
- package/test/unit/_encrypted-output.txt +6 -0
- package/test/unit/_log-encrypted-jsons.js +45 -0
- package/test/unit/_write-keystore-fixture.js +16 -0
- package/test/unit/abi-interface.test.js +103 -98
- package/test/unit/abi-interface.test.ts +102 -0
- package/test/unit/address-wallet.test.js +355 -257
- package/test/unit/address-wallet.test.ts +342 -0
- package/test/unit/browser-provider.test.js +85 -82
- package/test/unit/browser-provider.test.ts +79 -0
- package/test/unit/contract.test.js +85 -82
- package/test/unit/contract.test.ts +83 -0
- package/test/unit/encoding-units-rlp.test.js +92 -89
- package/test/unit/encoding-units-rlp.test.ts +91 -0
- package/test/unit/errors.test.js +77 -74
- package/test/unit/errors.test.ts +76 -0
- package/test/unit/filter-by-blockhash.test.js +55 -52
- package/test/unit/filter-by-blockhash.test.ts +54 -0
- package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
- package/test/unit/generate-contract-cli.test.js +42 -39
- package/test/unit/generate-contract-cli.test.ts +41 -0
- package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
- package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
- package/test/unit/generator.test.js +102 -99
- package/test/unit/generator.test.ts +101 -0
- package/test/unit/hashing.test.js +68 -54
- package/test/unit/hashing.test.ts +67 -0
- package/test/unit/init.test.js +39 -36
- package/test/unit/init.test.ts +38 -0
- package/test/unit/interface.test.js +56 -53
- package/test/unit/interface.test.ts +54 -0
- package/test/unit/internal-hex.test.js +50 -47
- package/test/unit/internal-hex.test.ts +49 -0
- package/test/unit/populate-transaction.test.js +65 -62
- package/test/unit/populate-transaction.test.ts +64 -0
- package/test/unit/providers.test.js +200 -144
- package/test/unit/providers.test.ts +196 -0
- package/test/unit/result.test.js +80 -77
- package/test/unit/result.test.ts +79 -0
- package/test/unit/solidity-types.test.js +49 -46
- package/test/unit/solidity-types.test.ts +39 -0
- package/test/unit/utils.test.js +57 -54
- package/test/unit/utils.test.ts +56 -0
- package/test/verbose-logger.js +74 -0
- package/tsconfig.build.json +14 -0
|
@@ -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
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
assert.ok(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} catch (e) {
|
|
53
|
-
t.skip(`network unavailable: ${e && e.message ? e.message : String(e)}`);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
assert.throws(() => qc.
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("rejects
|
|
27
|
-
|
|
28
|
-
assert.throws(() => qc.
|
|
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
|
+
});
|