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,82 +1,85 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Contract behavior that can be tested offline (overrides, listeners)
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("Contract", () => {
15
- it("_invoke treats last arg as overrides only when object-like (null is NOT overrides)", async () => {
16
- await Initialize(null);
17
- const addr = qc.Wallet.createRandom().address;
18
- const abi = [
19
- { type: "function", name: "viewFn", stateMutability: "view", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
20
- { type: "function", name: "writeFn", stateMutability: "nonpayable", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
21
- ];
22
-
23
- const c = new qc.Contract(addr, abi, null);
24
-
25
- /** @type {any[]} */
26
- const seen = [];
27
- c.call = async (methodName, args, overrides) => {
28
- seen.push({ kind: "call", methodName, args, overrides });
29
- return "ok";
30
- };
31
- c.send = async (methodName, args, overrides) => {
32
- seen.push({ kind: "send", methodName, args, overrides });
33
- return { hash: "0x" + "22".repeat(32) };
34
- };
35
-
36
- // Overrides object extracted
37
- await c._invoke("viewFn", [1n, { gasLimit: 123 }]);
38
- // Passing null is NOT treated as overrides (it becomes a second argument)
39
- await c._invoke("viewFn", [1n, null]);
40
- // State-changing path chooses send()
41
- await c._invoke("writeFn", [1n, { gasLimit: 456 }]);
42
-
43
- assert.deepEqual(seen[0], { kind: "call", methodName: "viewFn", args: [1n], overrides: { gasLimit: 123 } });
44
- assert.deepEqual(seen[1], { kind: "call", methodName: "viewFn", args: [1n, null], overrides: undefined });
45
- assert.deepEqual(seen[2], { kind: "send", methodName: "writeFn", args: [1n], overrides: { gasLimit: 456 } });
46
- });
47
-
48
- it("removeAllListeners clears all when event omitted vs null, and clears one event when provided", async () => {
49
- await Initialize(null);
50
- const addr = qc.Wallet.createRandom().address;
51
- const c = new qc.Contract(addr, [], null);
52
-
53
- const cb1 = () => {};
54
- const cb2 = () => {};
55
- c.on("A", cb1);
56
- c.on("B", cb2);
57
-
58
- c.removeAllListeners("A");
59
- // B remains
60
- assert.equal(c._listeners.get("A")?.length || 0, 0);
61
- assert.equal(c._listeners.get("B")?.length || 0, 1);
62
-
63
- c.removeAllListeners(null); // treated as "no event"
64
- assert.equal(c._listeners.size, 0);
65
-
66
- c.on("C", cb1);
67
- c.removeAllListeners(); // omitted => clear all
68
- assert.equal(c._listeners.size, 0);
69
- });
70
- });
71
-
72
- describe("ContractTransactionReceipt", () => {
73
- it("getEvent/getEvents filter logs by eventName", () => {
74
- const receipt = new qc.ContractTransactionReceipt({
75
- logs: [{ eventName: "A", data: 1 }, { eventName: "B", data: 2 }, { eventName: "A", data: 3 }],
76
- });
77
- assert.deepEqual(receipt.getEvents("A").map((l) => l.data), [1, 3]);
78
- assert.equal(receipt.getEvent("B").data, 2);
79
- assert.equal(receipt.getEvent("Missing"), null);
80
- });
81
- });
82
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Contract behavior that can be tested offline (overrides, listeners)
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+
11
+ const { Initialize } = require("../../config");
12
+ const qc = require("../../index");
13
+ const { logSuite, logTest } = require("../verbose-logger");
14
+
15
+ describe("Contract", () => {
16
+ logSuite("Contract");
17
+ it("_invoke treats last arg as overrides only when object-like (null is NOT overrides)", async () => {
18
+ logTest("_invoke treats last arg as overrides only when object-like (null is NOT overrides)", {});
19
+ await Initialize(null);
20
+ const addr = qc.Wallet.createRandom().address;
21
+ const abi = [
22
+ { type: "function", name: "viewFn", stateMutability: "view", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
23
+ { type: "function", name: "writeFn", stateMutability: "nonpayable", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
24
+ ];
25
+
26
+ const c = new qc.Contract(addr, abi, null);
27
+
28
+ /** @type {any[]} */
29
+ const seen = [];
30
+ c.call = async (methodName, args, overrides) => {
31
+ seen.push({ kind: "call", methodName, args, overrides });
32
+ return "ok";
33
+ };
34
+ c.send = async (methodName, args, overrides) => {
35
+ seen.push({ kind: "send", methodName, args, overrides });
36
+ return { hash: "0x" + "22".repeat(32) };
37
+ };
38
+
39
+ // Overrides object extracted
40
+ await c._invoke("viewFn", [1n, { gasLimit: 123 }]);
41
+ // Passing null is NOT treated as overrides (it becomes a second argument)
42
+ await c._invoke("viewFn", [1n, null]);
43
+ // State-changing path chooses send()
44
+ await c._invoke("writeFn", [1n, { gasLimit: 456 }]);
45
+
46
+ assert.deepEqual(seen[0], { kind: "call", methodName: "viewFn", args: [1n], overrides: { gasLimit: 123 } });
47
+ assert.deepEqual(seen[1], { kind: "call", methodName: "viewFn", args: [1n, null], overrides: undefined });
48
+ assert.deepEqual(seen[2], { kind: "send", methodName: "writeFn", args: [1n], overrides: { gasLimit: 456 } });
49
+ });
50
+
51
+ it("removeAllListeners clears all when event omitted vs null, and clears one event when provided", async () => {
52
+ await Initialize(null);
53
+ const addr = qc.Wallet.createRandom().address;
54
+ const c = new qc.Contract(addr, [], null);
55
+
56
+ const cb1 = () => {};
57
+ const cb2 = () => {};
58
+ c.on("A", cb1);
59
+ c.on("B", cb2);
60
+
61
+ c.removeAllListeners("A");
62
+ // B remains
63
+ assert.equal(c._listeners.get("A")?.length || 0, 0);
64
+ assert.equal(c._listeners.get("B")?.length || 0, 1);
65
+
66
+ c.removeAllListeners(null); // treated as "no event"
67
+ assert.equal(c._listeners.size, 0);
68
+
69
+ c.on("C", cb1);
70
+ c.removeAllListeners(); // omitted => clear all
71
+ assert.equal(c._listeners.size, 0);
72
+ });
73
+ });
74
+
75
+ describe("ContractTransactionReceipt", () => {
76
+ it("getEvent/getEvents filter logs by eventName", () => {
77
+ const receipt = new qc.ContractTransactionReceipt({
78
+ logs: [{ eventName: "A", data: 1 }, { eventName: "B", data: 2 }, { eventName: "A", data: 3 }],
79
+ });
80
+ assert.deepEqual(receipt.getEvents("A").map((l) => l.data), [1, 3]);
81
+ assert.equal(receipt.getEvent("B").data, 2);
82
+ assert.equal(receipt.getEvent("Missing"), null);
83
+ });
84
+ });
85
+
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Contract behavior that can be tested offline (overrides, listeners)
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("Contract", () => {
16
+ logSuite("Contract");
17
+ it("_invoke treats last arg as overrides only when object-like (null is NOT overrides)", async () => {
18
+ logTest("_invoke treats last arg as overrides only when object-like (null is NOT overrides)", {});
19
+ await Initialize(null);
20
+ const addr = qc.Wallet.createRandom().address;
21
+ const abi = [
22
+ { type: "function", name: "viewFn", stateMutability: "view", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
23
+ { type: "function", name: "writeFn", stateMutability: "nonpayable", inputs: [{ name: "x", type: "uint256" }], outputs: [] },
24
+ ];
25
+
26
+ const c = new qc.Contract(addr, abi, null);
27
+
28
+ const seen: { kind: string; methodName: string; args: unknown[]; overrides?: unknown }[] = [];
29
+ c.call = async (methodName: string, args: unknown[], overrides?: unknown) => {
30
+ seen.push({ kind: "call", methodName, args, overrides });
31
+ return "ok";
32
+ };
33
+ c.send = async (methodName: string, args: unknown[], overrides?: unknown) => {
34
+ seen.push({ kind: "send", methodName, args, overrides });
35
+ return { hash: "0x" + "22".repeat(32) };
36
+ };
37
+
38
+ await c._invoke("viewFn", [1n, { gasLimit: 123 }]);
39
+ await c._invoke("viewFn", [1n, null]);
40
+ await c._invoke("writeFn", [1n, { gasLimit: 456 }]);
41
+
42
+ assert.deepEqual(seen[0], { kind: "call", methodName: "viewFn", args: [1n], overrides: { gasLimit: 123 } });
43
+ assert.deepEqual(seen[1], { kind: "call", methodName: "viewFn", args: [1n, null], overrides: undefined });
44
+ assert.deepEqual(seen[2], { kind: "send", methodName: "writeFn", args: [1n], overrides: { gasLimit: 456 } });
45
+ });
46
+
47
+ it("removeAllListeners clears all when event omitted vs null, and clears one event when provided", async () => {
48
+ await Initialize(null);
49
+ const addr = qc.Wallet.createRandom().address;
50
+ const c = new qc.Contract(addr, [], null);
51
+
52
+ const cb1 = () => {};
53
+ const cb2 = () => {};
54
+ c.on("A", cb1);
55
+ c.on("B", cb2);
56
+
57
+ c.removeAllListeners("A");
58
+ assert.equal(c._listeners.get("A")?.length || 0, 0);
59
+ assert.equal(c._listeners.get("B")?.length || 0, 1);
60
+
61
+ c.removeAllListeners(null);
62
+ assert.equal(c._listeners.size, 0);
63
+
64
+ c.on("C", cb1);
65
+ c.removeAllListeners();
66
+ assert.equal(c._listeners.size, 0);
67
+ });
68
+ });
69
+
70
+ describe("ContractTransactionReceipt", () => {
71
+ it("getEvent/getEvents filter logs by eventName", () => {
72
+ const receipt = new qc.ContractTransactionReceipt({
73
+ logs: [
74
+ { eventName: "A", data: 1 },
75
+ { eventName: "B", data: 2 },
76
+ { eventName: "A", data: 3 },
77
+ ],
78
+ });
79
+ assert.deepEqual(receipt.getEvents("A").map((l) => l.data), [1, 3]);
80
+ assert.equal(receipt.getEvent("B").data, 2);
81
+ assert.equal(receipt.getEvent("Missing"), null);
82
+ });
83
+ });
@@ -1,89 +1,92 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Encoding + units + RLP edge cases (optional params, negative paths)
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
-
11
- const qc = require("../../index");
12
-
13
- describe("Encoding", () => {
14
- it("toHex/hexlify normalize strings and bytes", () => {
15
- assert.equal(qc.toHex("0x0A"), "0x0a");
16
- assert.equal(qc.hexlify(new Uint8Array([0x0a])), "0x0a");
17
- });
18
-
19
- it("concat concatenates and rejects non-array", () => {
20
- const out = qc.concat([new Uint8Array([1, 2]), "0x03"]);
21
- assert.equal(out, "0x010203");
22
- assert.throws(() => qc.concat("nope"));
23
- });
24
-
25
- it("stripZerosLeft removes leading zeros", () => {
26
- assert.equal(qc.stripZerosLeft("0x0000"), "0x");
27
- assert.equal(qc.stripZerosLeft("0x000001"), "0x01");
28
- });
29
-
30
- it("zeroPad throws when value exceeds length", () => {
31
- assert.throws(() => qc.zeroPad("0x1234", 1));
32
- assert.equal(qc.zeroPad("0x12", 2), "0x0012");
33
- });
34
-
35
- it("base64 encode/decode roundtrip", () => {
36
- const b = qc.toUtf8Bytes("hello");
37
- const b64 = qc.encodeBase64(b);
38
- const out = qc.decodeBase64(b64);
39
- assert.equal(qc.toUtf8String(out), "hello");
40
- });
41
-
42
- it("isBytesLike returns true for hex and Uint8Array", () => {
43
- assert.equal(qc.isBytesLike("0x1234"), true);
44
- assert.equal(qc.isBytesLike(new Uint8Array([1, 2, 3])), true);
45
- assert.equal(qc.isBytesLike("not-hex"), false);
46
- });
47
-
48
- it("solidityPacked helpers throw (not implemented)", () => {
49
- assert.throws(() => qc.solidityPacked(), /not implemented/i);
50
- assert.throws(() => qc.solidityPackedKeccak256(), /not implemented/i);
51
- assert.throws(() => qc.solidityPackedSha256(), /not implemented/i);
52
- });
53
- });
54
-
55
- describe("Units", () => {
56
- it("parseUnits defaults decimals when omitted vs null", () => {
57
- const a = qc.parseUnits("1.5");
58
- const b = qc.parseUnits("1.5", null);
59
- assert.equal(a, 1500000000000000000n);
60
- assert.equal(a, b);
61
- });
62
-
63
- it("formatUnits defaults decimals when omitted vs null", () => {
64
- const a = qc.formatUnits(1500000000000000000n);
65
- const b = qc.formatUnits(1500000000000000000n, null);
66
- assert.equal(a, "1.5");
67
- assert.equal(a, b);
68
- });
69
- });
70
-
71
- describe("RLP", () => {
72
- it("decodeRlp rejects non-string input", () => {
73
- assert.throws(() => qc.decodeRlp(123));
74
- });
75
-
76
- it("decodeRlp rejects trailing data", () => {
77
- const encoded = qc.encodeRlp("0x01");
78
- const withTrailing = "0x" + encoded.slice(2) + "00";
79
- assert.throws(() => qc.decodeRlp(withTrailing), /trailing data/i);
80
- });
81
-
82
- it("encodeRlp supports null as empty bytes", () => {
83
- const encoded = qc.encodeRlp(null);
84
- assert.ok(typeof encoded === "string" && encoded.startsWith("0x"));
85
- const decoded = qc.decodeRlp(encoded);
86
- assert.equal(decoded, "0x");
87
- });
88
- });
89
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Encoding + units + RLP edge cases (optional params, negative paths)
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("Encoding", () => {
15
+ logSuite("Encoding");
16
+ it("toHex/hexlify normalize strings and bytes", () => {
17
+ logTest("toHex/hexlify normalize strings and bytes", {});
18
+ assert.equal(qc.toHex("0x0A"), "0x0a");
19
+ assert.equal(qc.hexlify(new Uint8Array([0x0a])), "0x0a");
20
+ });
21
+
22
+ it("concat concatenates and rejects non-array", () => {
23
+ const out = qc.concat([new Uint8Array([1, 2]), "0x03"]);
24
+ assert.equal(out, "0x010203");
25
+ assert.throws(() => qc.concat("nope"));
26
+ });
27
+
28
+ it("stripZerosLeft removes leading zeros", () => {
29
+ assert.equal(qc.stripZerosLeft("0x0000"), "0x");
30
+ assert.equal(qc.stripZerosLeft("0x000001"), "0x01");
31
+ });
32
+
33
+ it("zeroPad throws when value exceeds length", () => {
34
+ assert.throws(() => qc.zeroPad("0x1234", 1));
35
+ assert.equal(qc.zeroPad("0x12", 2), "0x0012");
36
+ });
37
+
38
+ it("base64 encode/decode roundtrip", () => {
39
+ const b = qc.toUtf8Bytes("hello");
40
+ const b64 = qc.encodeBase64(b);
41
+ const out = qc.decodeBase64(b64);
42
+ assert.equal(qc.toUtf8String(out), "hello");
43
+ });
44
+
45
+ it("isBytesLike returns true for hex and Uint8Array", () => {
46
+ assert.equal(qc.isBytesLike("0x1234"), true);
47
+ assert.equal(qc.isBytesLike(new Uint8Array([1, 2, 3])), true);
48
+ assert.equal(qc.isBytesLike("not-hex"), false);
49
+ });
50
+
51
+ it("solidityPacked helpers throw (not implemented)", () => {
52
+ assert.throws(() => qc.solidityPacked(), /not implemented/i);
53
+ assert.throws(() => qc.solidityPackedKeccak256(), /not implemented/i);
54
+ assert.throws(() => qc.solidityPackedSha256(), /not implemented/i);
55
+ });
56
+ });
57
+
58
+ describe("Units", () => {
59
+ it("parseUnits defaults decimals when omitted vs null", () => {
60
+ const a = qc.parseUnits("1.5");
61
+ const b = qc.parseUnits("1.5", null);
62
+ assert.equal(a, 1500000000000000000n);
63
+ assert.equal(a, b);
64
+ });
65
+
66
+ it("formatUnits defaults decimals when omitted vs null", () => {
67
+ const a = qc.formatUnits(1500000000000000000n);
68
+ const b = qc.formatUnits(1500000000000000000n, null);
69
+ assert.equal(a, "1.5");
70
+ assert.equal(a, b);
71
+ });
72
+ });
73
+
74
+ describe("RLP", () => {
75
+ it("decodeRlp rejects non-string input", () => {
76
+ assert.throws(() => qc.decodeRlp(123));
77
+ });
78
+
79
+ it("decodeRlp rejects trailing data", () => {
80
+ const encoded = qc.encodeRlp("0x01");
81
+ const withTrailing = "0x" + encoded.slice(2) + "00";
82
+ assert.throws(() => qc.decodeRlp(withTrailing), /trailing data/i);
83
+ });
84
+
85
+ it("encodeRlp supports null as empty bytes", () => {
86
+ const encoded = qc.encodeRlp(null);
87
+ assert.ok(typeof encoded === "string" && encoded.startsWith("0x"));
88
+ const decoded = qc.decodeRlp(encoded);
89
+ assert.equal(decoded, "0x");
90
+ });
91
+ });
92
+
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Encoding + units + RLP edge cases (optional params, negative paths)
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("Encoding", () => {
15
+ logSuite("Encoding");
16
+ it("toHex/hexlify normalize strings and bytes", () => {
17
+ logTest("toHex/hexlify normalize strings and bytes", {});
18
+ assert.equal(qc.toHex("0x0A"), "0x0a");
19
+ assert.equal(qc.hexlify(new Uint8Array([0x0a])), "0x0a");
20
+ });
21
+
22
+ it("concat concatenates and rejects non-array", () => {
23
+ const out = qc.concat([new Uint8Array([1, 2]), "0x03"]);
24
+ assert.equal(out, "0x010203");
25
+ assert.throws(() => qc.concat("nope" as unknown as (string | Uint8Array)[]));
26
+ });
27
+
28
+ it("stripZerosLeft removes leading zeros", () => {
29
+ assert.equal(qc.stripZerosLeft("0x0000"), "0x");
30
+ assert.equal(qc.stripZerosLeft("0x000001"), "0x01");
31
+ });
32
+
33
+ it("zeroPad throws when value exceeds length", () => {
34
+ assert.throws(() => qc.zeroPad("0x1234", 1));
35
+ assert.equal(qc.zeroPad("0x12", 2), "0x0012");
36
+ });
37
+
38
+ it("base64 encode/decode roundtrip", () => {
39
+ const b = qc.toUtf8Bytes("hello");
40
+ const b64 = qc.encodeBase64(b);
41
+ const out = qc.decodeBase64(b64);
42
+ assert.equal(qc.toUtf8String(out), "hello");
43
+ });
44
+
45
+ it("isBytesLike returns true for hex and Uint8Array", () => {
46
+ assert.equal(qc.isBytesLike("0x1234"), true);
47
+ assert.equal(qc.isBytesLike(new Uint8Array([1, 2, 3])), true);
48
+ assert.equal(qc.isBytesLike("not-hex"), false);
49
+ });
50
+
51
+ it("solidityPacked helpers throw (not implemented)", () => {
52
+ assert.throws(() => qc.solidityPacked(), /not implemented/i);
53
+ assert.throws(() => qc.solidityPackedKeccak256(), /not implemented/i);
54
+ assert.throws(() => qc.solidityPackedSha256(), /not implemented/i);
55
+ });
56
+ });
57
+
58
+ describe("Units", () => {
59
+ it("parseUnits defaults decimals when omitted vs null", () => {
60
+ const a = qc.parseUnits("1.5");
61
+ const b = qc.parseUnits("1.5", null);
62
+ assert.equal(a, 1500000000000000000n);
63
+ assert.equal(a, b);
64
+ });
65
+
66
+ it("formatUnits defaults decimals when omitted vs null", () => {
67
+ const a = qc.formatUnits(1500000000000000000n);
68
+ const b = qc.formatUnits(1500000000000000000n, null);
69
+ assert.equal(a, "1.5");
70
+ assert.equal(a, b);
71
+ });
72
+ });
73
+
74
+ describe("RLP", () => {
75
+ it("decodeRlp rejects non-string input", () => {
76
+ assert.throws(() => qc.decodeRlp(123 as unknown as string));
77
+ });
78
+
79
+ it("decodeRlp rejects trailing data", () => {
80
+ const encoded = qc.encodeRlp("0x01");
81
+ const withTrailing = "0x" + encoded.slice(2) + "00";
82
+ assert.throws(() => qc.decodeRlp(withTrailing), /trailing data/i);
83
+ });
84
+
85
+ it("encodeRlp supports null as empty bytes", () => {
86
+ const encoded = qc.encodeRlp(null);
87
+ assert.ok(typeof encoded === "string" && encoded.startsWith("0x"));
88
+ const decoded = qc.decodeRlp(encoded);
89
+ assert.equal(decoded, "0x");
90
+ });
91
+ });