quantumcoin 7.0.3 → 7.0.5
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 +758 -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 +596 -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 +208 -203
- package/src/providers/provider.js +393 -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 +168 -160
- package/src/wallet/wallet.js +500 -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 +141 -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 +392 -257
- package/test/unit/address-wallet.test.ts +379 -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,54 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @testCategory unit
|
|
3
|
-
* @blockchainRequired false
|
|
4
|
-
* @transactional false
|
|
5
|
-
* @description Hashing helpers (optional params, deterministic behavior)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { describe, it } = require("node:test");
|
|
9
|
-
const assert = require("node:assert/strict");
|
|
10
|
-
|
|
11
|
-
const qc = require("../../index");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Hashing helpers (optional params, deterministic behavior)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { describe, it } = require("node:test");
|
|
9
|
+
const assert = require("node:assert/strict");
|
|
10
|
+
|
|
11
|
+
const qc = require("../../index");
|
|
12
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
13
|
+
|
|
14
|
+
describe("Hashing", () => {
|
|
15
|
+
logSuite("Hashing");
|
|
16
|
+
it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
|
|
17
|
+
logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
|
|
18
|
+
const out = qc.keccak256(new Uint8Array([]));
|
|
19
|
+
assert.equal(typeof out, "string");
|
|
20
|
+
assert.ok(out.startsWith("0x"));
|
|
21
|
+
assert.equal(out.length, 66);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("sha256/sha512/ripemd160 output lengths are correct", () => {
|
|
25
|
+
const data = qc.toUtf8Bytes("hello");
|
|
26
|
+
assert.equal(qc.sha256(data).length, 66);
|
|
27
|
+
assert.equal(qc.sha512(data).length, 130);
|
|
28
|
+
assert.equal(qc.ripemd160(data).length, 42);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("randomBytes returns requested length", () => {
|
|
32
|
+
const b = qc.randomBytes(16);
|
|
33
|
+
assert.ok(b instanceof Uint8Array);
|
|
34
|
+
assert.equal(b.length, 16);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
|
|
38
|
+
const pw = qc.toUtf8Bytes("password");
|
|
39
|
+
const salt = qc.toUtf8Bytes("salt");
|
|
40
|
+
|
|
41
|
+
const a = qc.pbkdf2(pw, salt, 1, 32);
|
|
42
|
+
const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
|
|
43
|
+
const c = qc.pbkdf2(pw, salt, 1, 32, null);
|
|
44
|
+
|
|
45
|
+
assert.equal(a, b);
|
|
46
|
+
assert.equal(a, c);
|
|
47
|
+
assert.ok(a.startsWith("0x") && a.length === 66);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("computeHmac produces a hex string", () => {
|
|
51
|
+
const key = qc.toUtf8Bytes("key");
|
|
52
|
+
const data = qc.toUtf8Bytes("data");
|
|
53
|
+
const out = qc.computeHmac("sha256", key, data);
|
|
54
|
+
assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("hashMessage follows EIP-191 / ethers.js pattern (prefix + length + message, keccak256)", () => {
|
|
58
|
+
// Known digest from ethers.js hashMessage("Hello World")
|
|
59
|
+
const expectedHelloWorld = "0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2";
|
|
60
|
+
assert.equal(qc.hashMessage("Hello World"), expectedHelloWorld);
|
|
61
|
+
// String and UTF-8 bytes of same content produce the same digest
|
|
62
|
+
assert.equal(qc.hashMessage("Hello World"), qc.hashMessage(qc.toUtf8Bytes("Hello World")));
|
|
63
|
+
// Empty message
|
|
64
|
+
const emptyDigest = qc.hashMessage("");
|
|
65
|
+
assert.ok(emptyDigest.startsWith("0x") && emptyDigest.length === 66);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Hashing helpers (optional params, deterministic behavior)
|
|
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("Hashing", () => {
|
|
15
|
+
logSuite("Hashing");
|
|
16
|
+
it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
|
|
17
|
+
logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
|
|
18
|
+
const out = qc.keccak256(new Uint8Array([]));
|
|
19
|
+
assert.equal(typeof out, "string");
|
|
20
|
+
assert.ok(out.startsWith("0x"));
|
|
21
|
+
assert.equal(out.length, 66);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("sha256/sha512/ripemd160 output lengths are correct", () => {
|
|
25
|
+
const data = qc.toUtf8Bytes("hello");
|
|
26
|
+
assert.equal(qc.sha256(data).length, 66);
|
|
27
|
+
assert.equal(qc.sha512(data).length, 130);
|
|
28
|
+
assert.equal(qc.ripemd160(data).length, 42);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("randomBytes returns requested length", () => {
|
|
32
|
+
const b = qc.randomBytes(16);
|
|
33
|
+
assert.ok(b instanceof Uint8Array);
|
|
34
|
+
assert.equal(b.length, 16);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
|
|
38
|
+
const pw = qc.toUtf8Bytes("password");
|
|
39
|
+
const salt = qc.toUtf8Bytes("salt");
|
|
40
|
+
|
|
41
|
+
const a = qc.pbkdf2(pw, salt, 1, 32);
|
|
42
|
+
const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
|
|
43
|
+
const c = qc.pbkdf2(pw, salt, 1, 32, null);
|
|
44
|
+
|
|
45
|
+
assert.equal(a, b);
|
|
46
|
+
assert.equal(a, c);
|
|
47
|
+
assert.ok(a.startsWith("0x") && a.length === 66);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("computeHmac produces a hex string", () => {
|
|
51
|
+
const key = qc.toUtf8Bytes("key");
|
|
52
|
+
const data = qc.toUtf8Bytes("data");
|
|
53
|
+
const out = qc.computeHmac("sha256", key, data);
|
|
54
|
+
assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("hashMessage follows EIP-191 / ethers.js pattern (prefix + length + message, keccak256)", () => {
|
|
58
|
+
// Known digest from ethers.js hashMessage("Hello World")
|
|
59
|
+
const expectedHelloWorld = "0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2";
|
|
60
|
+
assert.equal(qc.hashMessage("Hello World"), expectedHelloWorld);
|
|
61
|
+
// String and UTF-8 bytes of same content produce the same digest
|
|
62
|
+
assert.equal(qc.hashMessage("Hello World"), qc.hashMessage(qc.toUtf8Bytes("Hello World")));
|
|
63
|
+
// Empty message
|
|
64
|
+
const emptyDigest = qc.hashMessage("");
|
|
65
|
+
assert.ok(emptyDigest.startsWith("0x") && emptyDigest.length === 66);
|
|
66
|
+
});
|
|
67
|
+
});
|
package/test/unit/init.test.js
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @testCategory unit
|
|
3
|
-
* @blockchainRequired false
|
|
4
|
-
* @transactional false
|
|
5
|
-
* @description SDK initialization and basic constants
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { describe, it } = require("node:test");
|
|
9
|
-
const assert = require("node:assert/strict");
|
|
10
|
-
|
|
11
|
-
const { Initialize, isInitialized, Config } = require("../../config");
|
|
12
|
-
const qc = require("../../index");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
assert.equal(qc.
|
|
27
|
-
assert.equal(qc.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description SDK initialization and basic constants
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { describe, it } = require("node:test");
|
|
9
|
+
const assert = require("node:assert/strict");
|
|
10
|
+
|
|
11
|
+
const { Initialize, isInitialized, Config } = require("../../config");
|
|
12
|
+
const qc = require("../../index");
|
|
13
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
14
|
+
|
|
15
|
+
describe("Initialize()", () => {
|
|
16
|
+
logSuite("Initialize()");
|
|
17
|
+
it("initializes with default config (null)", async () => {
|
|
18
|
+
logTest("initializes with default config (null)", {});
|
|
19
|
+
const ok = await Initialize(null);
|
|
20
|
+
assert.equal(ok, true);
|
|
21
|
+
assert.equal(isInitialized(), true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("exposes constants with QuantumCoin address size", async () => {
|
|
25
|
+
await Initialize(null);
|
|
26
|
+
assert.equal(typeof qc.version, "string");
|
|
27
|
+
assert.equal(qc.ZeroAddress.length, 66);
|
|
28
|
+
assert.equal(qc.ZeroHash.length, 66);
|
|
29
|
+
assert.equal(qc.ZeroAddress, "0x" + "00".repeat(32));
|
|
30
|
+
assert.equal(qc.WeiPerEther, 1000000000000000000n);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("Config defaults match SPEC.md", () => {
|
|
34
|
+
const cfg = new Config();
|
|
35
|
+
assert.equal(cfg.chainId, 123123);
|
|
36
|
+
assert.equal(cfg.rpcEndpoint, "https://public.rpc.quantumcoinapi.com");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description SDK initialization and basic constants
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
|
|
11
|
+
import { Initialize, isInitialized, Config } from "../../config";
|
|
12
|
+
import qc from "../../index";
|
|
13
|
+
import { logSuite, logTest } from "../verbose-logger";
|
|
14
|
+
|
|
15
|
+
describe("Initialize()", () => {
|
|
16
|
+
logSuite("Initialize()");
|
|
17
|
+
it("initializes with default config (null)", async () => {
|
|
18
|
+
logTest("initializes with default config (null)", {});
|
|
19
|
+
const ok = await Initialize(null);
|
|
20
|
+
assert.equal(ok, true);
|
|
21
|
+
assert.equal(isInitialized(), true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("exposes constants with QuantumCoin address size", async () => {
|
|
25
|
+
await Initialize(null);
|
|
26
|
+
assert.equal(typeof qc.version, "string");
|
|
27
|
+
assert.equal(qc.ZeroAddress.length, 66);
|
|
28
|
+
assert.equal(qc.ZeroHash.length, 66);
|
|
29
|
+
assert.equal(qc.ZeroAddress, "0x" + "00".repeat(32));
|
|
30
|
+
assert.equal(qc.WeiPerEther, 1000000000000000000n);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("Config defaults match SPEC.md", () => {
|
|
34
|
+
const cfg = new Config();
|
|
35
|
+
assert.equal(cfg.chainId, 123123);
|
|
36
|
+
assert.equal(cfg.rpcEndpoint, "https://public.rpc.quantumcoinapi.com");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @testCategory unit
|
|
3
|
-
* @blockchainRequired false
|
|
4
|
-
* @description Interface.parseLog (event decoding) using quantum-coin-js-sdk decodeEventLog
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { describe, it } = require("node:test");
|
|
8
|
-
const assert = require("node:assert/strict");
|
|
9
|
-
|
|
10
|
-
const { Initialize } = require("../../config");
|
|
11
|
-
const qc = require("../../index");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
assert.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
assert.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
assert.equal(parsed.args
|
|
49
|
-
assert.equal(parsed.args
|
|
50
|
-
assert.equal(BigInt(parsed.args
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @description Interface.parseLog (event decoding) using quantum-coin-js-sdk decodeEventLog
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { describe, it } = require("node:test");
|
|
8
|
+
const assert = require("node:assert/strict");
|
|
9
|
+
|
|
10
|
+
const { Initialize } = require("../../config");
|
|
11
|
+
const qc = require("../../index");
|
|
12
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
13
|
+
|
|
14
|
+
describe("Interface.parseLog", () => {
|
|
15
|
+
logSuite("Interface.parseLog");
|
|
16
|
+
it("parses an encoded event log and returns LogDescription-like result", async () => {
|
|
17
|
+
logTest("parses an encoded event log and returns LogDescription-like result", {});
|
|
18
|
+
await Initialize(null);
|
|
19
|
+
|
|
20
|
+
const abi = [
|
|
21
|
+
{
|
|
22
|
+
name: "Transfer",
|
|
23
|
+
type: "event",
|
|
24
|
+
anonymous: false,
|
|
25
|
+
inputs: [
|
|
26
|
+
{ name: "from", type: "address", indexed: true },
|
|
27
|
+
{ name: "to", type: "address", indexed: true },
|
|
28
|
+
{ name: "value", type: "uint256", indexed: false },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const iface = new qc.Interface(abi);
|
|
34
|
+
const from = qc.Wallet.createRandom().address;
|
|
35
|
+
const to = qc.Wallet.createRandom().address;
|
|
36
|
+
const value = 123n;
|
|
37
|
+
|
|
38
|
+
const encoded = iface.encodeEventLog("Transfer", [from, to, value]);
|
|
39
|
+
assert.ok(Array.isArray(encoded.topics) && encoded.topics.length >= 1);
|
|
40
|
+
assert.ok(typeof encoded.data === "string");
|
|
41
|
+
|
|
42
|
+
const parsed = iface.parseLog({ topics: encoded.topics, data: encoded.data });
|
|
43
|
+
assert.equal(parsed.name, "Transfer");
|
|
44
|
+
assert.ok(parsed.topic && parsed.topic.startsWith("0x"));
|
|
45
|
+
assert.ok(parsed.signature.includes("Transfer("));
|
|
46
|
+
|
|
47
|
+
// Args should be array-like and have named keys
|
|
48
|
+
assert.equal(parsed.args.from.toLowerCase(), from.toLowerCase());
|
|
49
|
+
assert.equal(parsed.args.to.toLowerCase(), to.toLowerCase());
|
|
50
|
+
assert.equal(BigInt(parsed.args.value), value);
|
|
51
|
+
assert.equal(parsed.args[0].toLowerCase(), from.toLowerCase());
|
|
52
|
+
assert.equal(parsed.args[1].toLowerCase(), to.toLowerCase());
|
|
53
|
+
assert.equal(BigInt(parsed.args[2]), value);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @description Interface.parseLog (event decoding) using quantum-coin-js-sdk decodeEventLog
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
|
|
10
|
+
import { Initialize } from "../../config";
|
|
11
|
+
import qc from "../../index";
|
|
12
|
+
import { logSuite, logTest } from "../verbose-logger";
|
|
13
|
+
|
|
14
|
+
describe("Interface.parseLog", () => {
|
|
15
|
+
logSuite("Interface.parseLog");
|
|
16
|
+
it("parses an encoded event log and returns LogDescription-like result", async () => {
|
|
17
|
+
logTest("parses an encoded event log and returns LogDescription-like result", {});
|
|
18
|
+
await Initialize(null);
|
|
19
|
+
|
|
20
|
+
const abi = [
|
|
21
|
+
{
|
|
22
|
+
name: "Transfer",
|
|
23
|
+
type: "event",
|
|
24
|
+
anonymous: false,
|
|
25
|
+
inputs: [
|
|
26
|
+
{ name: "from", type: "address", indexed: true },
|
|
27
|
+
{ name: "to", type: "address", indexed: true },
|
|
28
|
+
{ name: "value", type: "uint256", indexed: false },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const iface = new qc.Interface(abi);
|
|
34
|
+
const from = qc.Wallet.createRandom().address;
|
|
35
|
+
const to = qc.Wallet.createRandom().address;
|
|
36
|
+
const value = 123n;
|
|
37
|
+
|
|
38
|
+
const encoded = iface.encodeEventLog("Transfer", [from, to, value]);
|
|
39
|
+
assert.ok(Array.isArray(encoded.topics) && encoded.topics.length >= 1);
|
|
40
|
+
assert.ok(typeof encoded.data === "string");
|
|
41
|
+
|
|
42
|
+
const parsed = iface.parseLog({ topics: encoded.topics, data: encoded.data });
|
|
43
|
+
assert.equal(parsed.name, "Transfer");
|
|
44
|
+
assert.ok(parsed.topic && parsed.topic.startsWith("0x"));
|
|
45
|
+
assert.ok(parsed.signature.includes("Transfer("));
|
|
46
|
+
|
|
47
|
+
assert.equal(parsed.args.from.toLowerCase(), from.toLowerCase());
|
|
48
|
+
assert.equal(parsed.args.to.toLowerCase(), to.toLowerCase());
|
|
49
|
+
assert.equal(BigInt(parsed.args.value), value);
|
|
50
|
+
assert.equal(parsed.args[0].toLowerCase(), from.toLowerCase());
|
|
51
|
+
assert.equal(parsed.args[1].toLowerCase(), to.toLowerCase());
|
|
52
|
+
assert.equal(BigInt(parsed.args[2]), value);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @testCategory unit
|
|
3
|
-
* @blockchainRequired false
|
|
4
|
-
* @transactional false
|
|
5
|
-
* @description Internal hex utilities (optional params, edge cases)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { describe, it } = require("node:test");
|
|
9
|
-
const assert = require("node:assert/strict");
|
|
10
|
-
|
|
11
|
-
const { normalizeHex, isHexString, hexToBytes, bytesToHex, arrayify } = require("../../src/internal/hex");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
assert.equal(normalizeHex("
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
assert.equal(isHexString(h32
|
|
27
|
-
|
|
28
|
-
assert.equal(isHexString(
|
|
29
|
-
assert.equal(isHexString(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
assert.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Internal hex utilities (optional params, edge cases)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { describe, it } = require("node:test");
|
|
9
|
+
const assert = require("node:assert/strict");
|
|
10
|
+
|
|
11
|
+
const { normalizeHex, isHexString, hexToBytes, bytesToHex, arrayify } = require("../../src/internal/hex");
|
|
12
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
13
|
+
|
|
14
|
+
describe("internal/hex", () => {
|
|
15
|
+
logSuite("internal/hex");
|
|
16
|
+
it("normalizeHex lowercases, adds 0x, pads odd length", () => {
|
|
17
|
+
logTest("normalizeHex lowercases, adds 0x, pads odd length", {});
|
|
18
|
+
assert.equal(normalizeHex("aa"), "0xaa");
|
|
19
|
+
assert.equal(normalizeHex("0xAa"), "0xaa");
|
|
20
|
+
assert.equal(normalizeHex("0xa"), "0x0a");
|
|
21
|
+
assert.equal(normalizeHex("0x0A"), "0x0a");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("isHexString validates and supports optional lengthBytes", () => {
|
|
25
|
+
const h32 = "0x" + "11".repeat(32);
|
|
26
|
+
assert.equal(isHexString(h32), true);
|
|
27
|
+
assert.equal(isHexString(h32, 32), true);
|
|
28
|
+
assert.equal(isHexString(h32, null), true); // optional param passed as null => ignored
|
|
29
|
+
assert.equal(isHexString(h32, 31), false);
|
|
30
|
+
|
|
31
|
+
assert.equal(isHexString("0x"), false);
|
|
32
|
+
assert.equal(isHexString("0x0"), false); // odd length after 0x
|
|
33
|
+
assert.equal(isHexString("0xzz"), false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("hexToBytes/bytesToHex roundtrip", () => {
|
|
37
|
+
const h = "0x1234abcd";
|
|
38
|
+
const b = hexToBytes(h);
|
|
39
|
+
assert.ok(b instanceof Uint8Array);
|
|
40
|
+
assert.equal(bytesToHex(b), h);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("arrayify accepts hex string and Uint8Array; rejects others", () => {
|
|
44
|
+
assert.deepEqual(arrayify("0x1234"), new Uint8Array([0x12, 0x34]));
|
|
45
|
+
assert.deepEqual(arrayify(new Uint8Array([1, 2, 3])), new Uint8Array([1, 2, 3]));
|
|
46
|
+
assert.throws(() => arrayify("not-hex"));
|
|
47
|
+
assert.throws(() => arrayify(123));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory unit
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Internal hex utilities (optional params, edge cases)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it } from "node:test";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
|
|
11
|
+
import { normalizeHex, isHexString, hexToBytes, bytesToHex, arrayify } from "../../src/internal/hex";
|
|
12
|
+
import { logSuite, logTest } from "../verbose-logger";
|
|
13
|
+
|
|
14
|
+
describe("internal/hex", () => {
|
|
15
|
+
logSuite("internal/hex");
|
|
16
|
+
it("normalizeHex lowercases, adds 0x, pads odd length", () => {
|
|
17
|
+
logTest("normalizeHex lowercases, adds 0x, pads odd length", {});
|
|
18
|
+
assert.equal(normalizeHex("aa"), "0xaa");
|
|
19
|
+
assert.equal(normalizeHex("0xAa"), "0xaa");
|
|
20
|
+
assert.equal(normalizeHex("0xa"), "0x0a");
|
|
21
|
+
assert.equal(normalizeHex("0x0A"), "0x0a");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("isHexString validates and supports optional lengthBytes", () => {
|
|
25
|
+
const h32 = "0x" + "11".repeat(32);
|
|
26
|
+
assert.equal(isHexString(h32), true);
|
|
27
|
+
assert.equal(isHexString(h32, 32), true);
|
|
28
|
+
assert.equal(isHexString(h32, null), true); // optional param passed as null => ignored
|
|
29
|
+
assert.equal(isHexString(h32, 31), false);
|
|
30
|
+
|
|
31
|
+
assert.equal(isHexString("0x"), false);
|
|
32
|
+
assert.equal(isHexString("0x0"), false); // odd length after 0x
|
|
33
|
+
assert.equal(isHexString("0xzz"), false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("hexToBytes/bytesToHex roundtrip", () => {
|
|
37
|
+
const h = "0x1234abcd";
|
|
38
|
+
const b = hexToBytes(h);
|
|
39
|
+
assert.ok(b instanceof Uint8Array);
|
|
40
|
+
assert.equal(bytesToHex(b), h);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("arrayify accepts hex string and Uint8Array; rejects others", () => {
|
|
44
|
+
assert.deepEqual(arrayify("0x1234"), new Uint8Array([0x12, 0x34]));
|
|
45
|
+
assert.deepEqual(arrayify(new Uint8Array([1, 2, 3])), new Uint8Array([1, 2, 3]));
|
|
46
|
+
assert.throws(() => arrayify("not-hex"));
|
|
47
|
+
assert.throws(() => arrayify(123 as unknown));
|
|
48
|
+
});
|
|
49
|
+
});
|