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,110 +1,113 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description generate-sdk.js artifacts JSON input (multi-contract)
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
- const fs = require("node:fs");
11
- const os = require("node:os");
12
- const path = require("node:path");
13
- const { spawnSync } = require("node:child_process");
14
-
15
- describe("generate-sdk.js --artifacts-json", () => {
16
- it("generates typed files for multiple ABI+BIN pairs (no package scaffold)", () => {
17
- const repoRoot = path.resolve(__dirname, "..", "..");
18
- const cli = path.join(repoRoot, "generate-sdk.js");
19
-
20
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-"));
21
- const outDir = path.join(tmp, "out");
22
-
23
- const alphaAbi = [
24
- { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
25
- ];
26
- const betaAbi = [
27
- { type: "function", name: "set", stateMutability: "nonpayable", inputs: [{ name: "value", type: "uint256" }], outputs: [] },
28
- ];
29
- const gammaAbi = [
30
- { type: "function", name: "ping", stateMutability: "pure", inputs: [], outputs: [{ name: "", type: "bool" }] },
31
- ];
32
-
33
- fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
34
- fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
35
- fs.writeFileSync(path.join(tmp, "Beta.abi.json"), JSON.stringify(betaAbi, null, 2), "utf8");
36
- fs.writeFileSync(path.join(tmp, "Beta.bin"), "0x6000", "utf8");
37
-
38
- const artifactsJsonPath = path.join(tmp, "artifacts.json");
39
- fs.writeFileSync(
40
- artifactsJsonPath,
41
- JSON.stringify(
42
- [
43
- { abi: "./Alpha.abi.json", bin: "./Alpha.bin" },
44
- { abi: "./Beta.abi.json", bin: "./Beta.bin" },
45
- // Inline string form: abi is a JSON string; bin is inline bytecode (string).
46
- { name: "Gamma", abi: JSON.stringify(gammaAbi), bin: "6000" },
47
- ],
48
- null,
49
- 2,
50
- ),
51
- "utf8",
52
- );
53
-
54
- const res = spawnSync(
55
- process.execPath,
56
- [cli, "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
57
- { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
58
- );
59
-
60
- assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
61
-
62
- assert.ok(fs.existsSync(path.join(outDir, "types.ts")));
63
- assert.ok(fs.existsSync(path.join(outDir, "index.ts")));
64
- assert.ok(fs.existsSync(path.join(outDir, "Alpha.ts")));
65
- assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.ts")));
66
- assert.ok(fs.existsSync(path.join(outDir, "Beta.ts")));
67
- assert.ok(fs.existsSync(path.join(outDir, "Beta__factory.ts")));
68
- assert.ok(fs.existsSync(path.join(outDir, "Gamma.ts")));
69
- assert.ok(fs.existsSync(path.join(outDir, "Gamma__factory.ts")));
70
- });
71
-
72
- it("supports --lang js (generates JS source + .d.ts types)", () => {
73
- const repoRoot = path.resolve(__dirname, "..", "..");
74
- const cli = path.join(repoRoot, "generate-sdk.js");
75
-
76
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-js-"));
77
- const outDir = path.join(tmp, "out");
78
-
79
- const alphaAbi = [
80
- { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
81
- ];
82
- fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
83
- fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
84
-
85
- const artifactsJsonPath = path.join(tmp, "artifacts.json");
86
- fs.writeFileSync(artifactsJsonPath, JSON.stringify([{ abi: "./Alpha.abi.json", bin: "./Alpha.bin" }], null, 2), "utf8");
87
-
88
- const res = spawnSync(
89
- process.execPath,
90
- [cli, "--lang", "js", "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
91
- { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
92
- );
93
-
94
- assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
95
-
96
- assert.ok(fs.existsSync(path.join(outDir, "types.js")));
97
- assert.ok(fs.existsSync(path.join(outDir, "types.d.ts")));
98
- assert.ok(fs.existsSync(path.join(outDir, "index.js")));
99
- assert.ok(fs.existsSync(path.join(outDir, "index.d.ts")));
100
- assert.ok(fs.existsSync(path.join(outDir, "Alpha.js")));
101
- assert.ok(fs.existsSync(path.join(outDir, "Alpha.d.ts")));
102
- assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.js")));
103
- assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.d.ts")));
104
-
105
- // Ensure generated types re-export core Solidity types (no local re-definition).
106
- const typesDts = fs.readFileSync(path.join(outDir, "types.d.ts"), "utf8");
107
- assert.ok(typesDts.includes('from "quantumcoin/types"'), "expected generated types.d.ts to reference quantumcoin/types");
108
- });
109
- });
110
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description generate-sdk.js artifacts JSON input (multi-contract)
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+ const fs = require("node:fs");
11
+ const os = require("node:os");
12
+ const path = require("node:path");
13
+ const { spawnSync } = require("node:child_process");
14
+ const { logSuite, logTest } = require("../verbose-logger");
15
+
16
+ describe("generate-sdk.js --artifacts-json", () => {
17
+ logSuite("generate-sdk.js --artifacts-json");
18
+ it("generates typed files for multiple ABI+BIN pairs (no package scaffold)", () => {
19
+ logTest("generates typed files for multiple ABI+BIN pairs (no package scaffold)", {});
20
+ const repoRoot = path.resolve(__dirname, "..", "..");
21
+ const cli = path.join(repoRoot, "generate-sdk.js");
22
+
23
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-"));
24
+ const outDir = path.join(tmp, "out");
25
+
26
+ const alphaAbi = [
27
+ { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
28
+ ];
29
+ const betaAbi = [
30
+ { type: "function", name: "set", stateMutability: "nonpayable", inputs: [{ name: "value", type: "uint256" }], outputs: [] },
31
+ ];
32
+ const gammaAbi = [
33
+ { type: "function", name: "ping", stateMutability: "pure", inputs: [], outputs: [{ name: "", type: "bool" }] },
34
+ ];
35
+
36
+ fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
37
+ fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
38
+ fs.writeFileSync(path.join(tmp, "Beta.abi.json"), JSON.stringify(betaAbi, null, 2), "utf8");
39
+ fs.writeFileSync(path.join(tmp, "Beta.bin"), "0x6000", "utf8");
40
+
41
+ const artifactsJsonPath = path.join(tmp, "artifacts.json");
42
+ fs.writeFileSync(
43
+ artifactsJsonPath,
44
+ JSON.stringify(
45
+ [
46
+ { abi: "./Alpha.abi.json", bin: "./Alpha.bin" },
47
+ { abi: "./Beta.abi.json", bin: "./Beta.bin" },
48
+ // Inline string form: abi is a JSON string; bin is inline bytecode (string).
49
+ { name: "Gamma", abi: JSON.stringify(gammaAbi), bin: "6000" },
50
+ ],
51
+ null,
52
+ 2,
53
+ ),
54
+ "utf8",
55
+ );
56
+
57
+ const res = spawnSync(
58
+ process.execPath,
59
+ [cli, "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
60
+ { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
61
+ );
62
+
63
+ assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
64
+
65
+ assert.ok(fs.existsSync(path.join(outDir, "types.ts")));
66
+ assert.ok(fs.existsSync(path.join(outDir, "index.ts")));
67
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.ts")));
68
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.ts")));
69
+ assert.ok(fs.existsSync(path.join(outDir, "Beta.ts")));
70
+ assert.ok(fs.existsSync(path.join(outDir, "Beta__factory.ts")));
71
+ assert.ok(fs.existsSync(path.join(outDir, "Gamma.ts")));
72
+ assert.ok(fs.existsSync(path.join(outDir, "Gamma__factory.ts")));
73
+ });
74
+
75
+ it("supports --lang js (generates JS source + .d.ts types)", () => {
76
+ const repoRoot = path.resolve(__dirname, "..", "..");
77
+ const cli = path.join(repoRoot, "generate-sdk.js");
78
+
79
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-js-"));
80
+ const outDir = path.join(tmp, "out");
81
+
82
+ const alphaAbi = [
83
+ { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
84
+ ];
85
+ fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
86
+ fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
87
+
88
+ const artifactsJsonPath = path.join(tmp, "artifacts.json");
89
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([{ abi: "./Alpha.abi.json", bin: "./Alpha.bin" }], null, 2), "utf8");
90
+
91
+ const res = spawnSync(
92
+ process.execPath,
93
+ [cli, "--lang", "js", "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
94
+ { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
95
+ );
96
+
97
+ assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
98
+
99
+ assert.ok(fs.existsSync(path.join(outDir, "types.js")));
100
+ assert.ok(fs.existsSync(path.join(outDir, "types.d.ts")));
101
+ assert.ok(fs.existsSync(path.join(outDir, "index.js")));
102
+ assert.ok(fs.existsSync(path.join(outDir, "index.d.ts")));
103
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.js")));
104
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.d.ts")));
105
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.js")));
106
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.d.ts")));
107
+
108
+ // Ensure generated types re-export core Solidity types (no local re-definition).
109
+ const typesDts = fs.readFileSync(path.join(outDir, "types.d.ts"), "utf8");
110
+ assert.ok(typesDts.includes('from "quantumcoin/types"'), "expected generated types.d.ts to reference quantumcoin/types");
111
+ });
112
+ });
113
+
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description generate-sdk.js artifacts JSON input (multi-contract)
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import fs from "node:fs";
11
+ import os from "node:os";
12
+ import path from "node:path";
13
+ import { spawnSync } from "node:child_process";
14
+ import { logSuite, logTest } from "../verbose-logger";
15
+
16
+ describe("generate-sdk.js --artifacts-json", () => {
17
+ logSuite("generate-sdk.js --artifacts-json");
18
+ it("generates typed files for multiple ABI+BIN pairs (no package scaffold)", () => {
19
+ logTest("generates typed files for multiple ABI+BIN pairs (no package scaffold)", {});
20
+ const repoRoot = path.resolve(__dirname, "..", "..");
21
+ const cli = path.join(repoRoot, "generate-sdk.js");
22
+
23
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-"));
24
+ const outDir = path.join(tmp, "out");
25
+
26
+ const alphaAbi = [
27
+ { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
28
+ ];
29
+ const betaAbi = [
30
+ { type: "function", name: "set", stateMutability: "nonpayable", inputs: [{ name: "value", type: "uint256" }], outputs: [] },
31
+ ];
32
+ const gammaAbi = [
33
+ { type: "function", name: "ping", stateMutability: "pure", inputs: [], outputs: [{ name: "", type: "bool" }] },
34
+ ];
35
+
36
+ fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
37
+ fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
38
+ fs.writeFileSync(path.join(tmp, "Beta.abi.json"), JSON.stringify(betaAbi, null, 2), "utf8");
39
+ fs.writeFileSync(path.join(tmp, "Beta.bin"), "0x6000", "utf8");
40
+
41
+ const artifactsJsonPath = path.join(tmp, "artifacts.json");
42
+ fs.writeFileSync(
43
+ artifactsJsonPath,
44
+ JSON.stringify(
45
+ [
46
+ { abi: "./Alpha.abi.json", bin: "./Alpha.bin" },
47
+ { abi: "./Beta.abi.json", bin: "./Beta.bin" },
48
+ { name: "Gamma", abi: JSON.stringify(gammaAbi), bin: "6000" },
49
+ ],
50
+ null,
51
+ 2,
52
+ ),
53
+ "utf8",
54
+ );
55
+
56
+ const res = spawnSync(
57
+ process.execPath,
58
+ [cli, "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
59
+ { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
60
+ );
61
+
62
+ assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
63
+
64
+ assert.ok(fs.existsSync(path.join(outDir, "types.ts")));
65
+ assert.ok(fs.existsSync(path.join(outDir, "index.ts")));
66
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.ts")));
67
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.ts")));
68
+ assert.ok(fs.existsSync(path.join(outDir, "Beta.ts")));
69
+ assert.ok(fs.existsSync(path.join(outDir, "Beta__factory.ts")));
70
+ assert.ok(fs.existsSync(path.join(outDir, "Gamma.ts")));
71
+ assert.ok(fs.existsSync(path.join(outDir, "Gamma__factory.ts")));
72
+ });
73
+
74
+ it("supports --lang js (generates JS source + .d.ts types)", () => {
75
+ const repoRoot = path.resolve(__dirname, "..", "..");
76
+ const cli = path.join(repoRoot, "generate-sdk.js");
77
+
78
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-artjson-js-"));
79
+ const outDir = path.join(tmp, "out");
80
+
81
+ const alphaAbi = [
82
+ { type: "function", name: "get", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
83
+ ];
84
+ fs.writeFileSync(path.join(tmp, "Alpha.abi.json"), JSON.stringify(alphaAbi, null, 2), "utf8");
85
+ fs.writeFileSync(path.join(tmp, "Alpha.bin"), "0x6000", "utf8");
86
+
87
+ const artifactsJsonPath = path.join(tmp, "artifacts.json");
88
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([{ abi: "./Alpha.abi.json", bin: "./Alpha.bin" }], null, 2), "utf8");
89
+
90
+ const res = spawnSync(
91
+ process.execPath,
92
+ [cli, "--lang", "js", "--artifacts-json", artifactsJsonPath, "--out", outDir, "--non-interactive"],
93
+ { cwd: repoRoot, encoding: "utf8", stdio: "pipe", shell: false, windowsHide: true },
94
+ );
95
+
96
+ assert.equal(res.status, 0, `generator failed:\n${res.stdout}\n${res.stderr}`);
97
+
98
+ assert.ok(fs.existsSync(path.join(outDir, "types.js")));
99
+ assert.ok(fs.existsSync(path.join(outDir, "types.d.ts")));
100
+ assert.ok(fs.existsSync(path.join(outDir, "index.js")));
101
+ assert.ok(fs.existsSync(path.join(outDir, "index.d.ts")));
102
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.js")));
103
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha.d.ts")));
104
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.js")));
105
+ assert.ok(fs.existsSync(path.join(outDir, "Alpha__factory.d.ts")));
106
+
107
+ const typesDts = fs.readFileSync(path.join(outDir, "types.d.ts"), "utf8");
108
+ assert.ok(typesDts.includes('from "quantumcoin/types"'), "expected generated types.d.ts to reference quantumcoin/types");
109
+ });
110
+ });
@@ -1,99 +1,102 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Typed contract generator (file output shape)
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
- const fs = require("node:fs");
11
- const os = require("node:os");
12
- const path = require("node:path");
13
-
14
- const { generate, generateFromArtifacts } = require("../../src/generator");
15
-
16
- describe("typed contract generator", () => {
17
- it("generates contract + factory + types + index files", () => {
18
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-"));
19
- const abiPath = path.join(tmp, "Test.abi.json");
20
- const binPath = path.join(tmp, "Test.bin");
21
- const outDir = path.join(tmp, "out");
22
-
23
- const abi = [
24
- {
25
- type: "function",
26
- name: "balanceOf",
27
- stateMutability: "view",
28
- inputs: [{ name: "account", type: "address" }],
29
- outputs: [{ name: "", type: "uint256" }],
30
- },
31
- {
32
- type: "function",
33
- name: "transfer",
34
- stateMutability: "nonpayable",
35
- inputs: [
36
- { name: "to", type: "address" },
37
- { name: "amount", type: "uint256" },
38
- ],
39
- outputs: [{ name: "", type: "bool" }],
40
- },
41
- ];
42
-
43
- fs.writeFileSync(abiPath, JSON.stringify(abi, null, 2), "utf8");
44
- fs.writeFileSync(binPath, "0x6000", "utf8");
45
-
46
- const res = generate({ abiPath, binPath, outDir, contractName: "TestToken" });
47
- assert.ok(fs.existsSync(res.contractFile));
48
- assert.ok(fs.existsSync(res.factoryFile));
49
- assert.ok(fs.existsSync(res.typesFile));
50
- assert.ok(fs.existsSync(res.indexFile));
51
-
52
- const contractSrc = fs.readFileSync(res.contractFile, "utf8");
53
- assert.ok(contractSrc.includes("export class TestToken"));
54
- assert.ok(contractSrc.includes("async balanceOf"));
55
- assert.ok(contractSrc.includes("async transfer"));
56
- assert.ok(contractSrc.includes("populateTransaction"));
57
-
58
- const factorySrc = fs.readFileSync(res.factoryFile, "utf8");
59
- assert.ok(factorySrc.includes("export class TestToken__factory"));
60
- });
61
-
62
- it("includes injected docs in generated TypeScript", () => {
63
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-docs-"));
64
- const outDir = path.join(tmp, "out");
65
-
66
- const abi = [
67
- {
68
- type: "function",
69
- name: "set",
70
- stateMutability: "nonpayable",
71
- inputs: [{ name: "value", type: "uint256" }],
72
- outputs: [],
73
- },
74
- ];
75
-
76
- const res = generateFromArtifacts({
77
- outDir,
78
- artifacts: [
79
- {
80
- contractName: "DocToken",
81
- abi,
82
- bytecode: "0x6000",
83
- docs: {
84
- contract: "Example contract doc from Solidity.",
85
- functions: {
86
- set: "Example function doc from Solidity.",
87
- },
88
- },
89
- },
90
- ],
91
- });
92
-
93
- const contractFile = res.contracts[0].contractFile;
94
- const src = fs.readFileSync(contractFile, "utf8");
95
- assert.ok(src.includes("Example contract doc from Solidity."));
96
- assert.ok(src.includes("Example function doc from Solidity."));
97
- });
98
- });
99
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Typed contract generator (file output shape)
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+ const fs = require("node:fs");
11
+ const os = require("node:os");
12
+ const path = require("node:path");
13
+
14
+ const { generate, generateFromArtifacts } = require("../../src/generator");
15
+ const { logSuite, logTest } = require("../verbose-logger");
16
+
17
+ describe("typed contract generator", () => {
18
+ logSuite("typed contract generator");
19
+ it("generates contract + factory + types + index files", () => {
20
+ logTest("generates contract + factory + types + index files", {});
21
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-"));
22
+ const abiPath = path.join(tmp, "Test.abi.json");
23
+ const binPath = path.join(tmp, "Test.bin");
24
+ const outDir = path.join(tmp, "out");
25
+
26
+ const abi = [
27
+ {
28
+ type: "function",
29
+ name: "balanceOf",
30
+ stateMutability: "view",
31
+ inputs: [{ name: "account", type: "address" }],
32
+ outputs: [{ name: "", type: "uint256" }],
33
+ },
34
+ {
35
+ type: "function",
36
+ name: "transfer",
37
+ stateMutability: "nonpayable",
38
+ inputs: [
39
+ { name: "to", type: "address" },
40
+ { name: "amount", type: "uint256" },
41
+ ],
42
+ outputs: [{ name: "", type: "bool" }],
43
+ },
44
+ ];
45
+
46
+ fs.writeFileSync(abiPath, JSON.stringify(abi, null, 2), "utf8");
47
+ fs.writeFileSync(binPath, "0x6000", "utf8");
48
+
49
+ const res = generate({ abiPath, binPath, outDir, contractName: "TestToken" });
50
+ assert.ok(fs.existsSync(res.contractFile));
51
+ assert.ok(fs.existsSync(res.factoryFile));
52
+ assert.ok(fs.existsSync(res.typesFile));
53
+ assert.ok(fs.existsSync(res.indexFile));
54
+
55
+ const contractSrc = fs.readFileSync(res.contractFile, "utf8");
56
+ assert.ok(contractSrc.includes("export class TestToken"));
57
+ assert.ok(contractSrc.includes("async balanceOf"));
58
+ assert.ok(contractSrc.includes("async transfer"));
59
+ assert.ok(contractSrc.includes("populateTransaction"));
60
+
61
+ const factorySrc = fs.readFileSync(res.factoryFile, "utf8");
62
+ assert.ok(factorySrc.includes("export class TestToken__factory"));
63
+ });
64
+
65
+ it("includes injected docs in generated TypeScript", () => {
66
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-docs-"));
67
+ const outDir = path.join(tmp, "out");
68
+
69
+ const abi = [
70
+ {
71
+ type: "function",
72
+ name: "set",
73
+ stateMutability: "nonpayable",
74
+ inputs: [{ name: "value", type: "uint256" }],
75
+ outputs: [],
76
+ },
77
+ ];
78
+
79
+ const res = generateFromArtifacts({
80
+ outDir,
81
+ artifacts: [
82
+ {
83
+ contractName: "DocToken",
84
+ abi,
85
+ bytecode: "0x6000",
86
+ docs: {
87
+ contract: "Example contract doc from Solidity.",
88
+ functions: {
89
+ set: "Example function doc from Solidity.",
90
+ },
91
+ },
92
+ },
93
+ ],
94
+ });
95
+
96
+ const contractFile = res.contracts[0].contractFile;
97
+ const src = fs.readFileSync(contractFile, "utf8");
98
+ assert.ok(src.includes("Example contract doc from Solidity."));
99
+ assert.ok(src.includes("Example function doc from Solidity."));
100
+ });
101
+ });
102
+
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Typed contract generator (file output shape)
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import fs from "node:fs";
11
+ import os from "node:os";
12
+ import path from "node:path";
13
+
14
+ import { generate, generateFromArtifacts } from "../../src/generator";
15
+ import { logSuite, logTest } from "../verbose-logger";
16
+
17
+ describe("typed contract generator", () => {
18
+ logSuite("typed contract generator");
19
+ it("generates contract + factory + types + index files", () => {
20
+ logTest("generates contract + factory + types + index files", {});
21
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-"));
22
+ const abiPath = path.join(tmp, "Test.abi.json");
23
+ const binPath = path.join(tmp, "Test.bin");
24
+ const outDir = path.join(tmp, "out");
25
+
26
+ const abi = [
27
+ {
28
+ type: "function",
29
+ name: "balanceOf",
30
+ stateMutability: "view",
31
+ inputs: [{ name: "account", type: "address" }],
32
+ outputs: [{ name: "", type: "uint256" }],
33
+ },
34
+ {
35
+ type: "function",
36
+ name: "transfer",
37
+ stateMutability: "nonpayable",
38
+ inputs: [
39
+ { name: "to", type: "address" },
40
+ { name: "amount", type: "uint256" },
41
+ ],
42
+ outputs: [{ name: "", type: "bool" }],
43
+ },
44
+ ];
45
+
46
+ fs.writeFileSync(abiPath, JSON.stringify(abi, null, 2), "utf8");
47
+ fs.writeFileSync(binPath, "0x6000", "utf8");
48
+
49
+ const res = generate({ abiPath, binPath, outDir, contractName: "TestToken" });
50
+ assert.ok(fs.existsSync(res.contractFile));
51
+ assert.ok(fs.existsSync(res.factoryFile));
52
+ assert.ok(fs.existsSync(res.typesFile));
53
+ assert.ok(fs.existsSync(res.indexFile));
54
+
55
+ const contractSrc = fs.readFileSync(res.contractFile, "utf8");
56
+ assert.ok(contractSrc.includes("export class TestToken"));
57
+ assert.ok(contractSrc.includes("async balanceOf"));
58
+ assert.ok(contractSrc.includes("async transfer"));
59
+ assert.ok(contractSrc.includes("populateTransaction"));
60
+
61
+ const factorySrc = fs.readFileSync(res.factoryFile, "utf8");
62
+ assert.ok(factorySrc.includes("export class TestToken__factory"));
63
+ });
64
+
65
+ it("includes injected docs in generated TypeScript", () => {
66
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-docs-"));
67
+ const outDir = path.join(tmp, "out");
68
+
69
+ const abi = [
70
+ {
71
+ type: "function",
72
+ name: "set",
73
+ stateMutability: "nonpayable",
74
+ inputs: [{ name: "value", type: "uint256" }],
75
+ outputs: [],
76
+ },
77
+ ];
78
+
79
+ const res = generateFromArtifacts({
80
+ outDir,
81
+ artifacts: [
82
+ {
83
+ contractName: "DocToken",
84
+ abi,
85
+ bytecode: "0x6000",
86
+ docs: {
87
+ contract: "Example contract doc from Solidity.",
88
+ functions: {
89
+ set: "Example function doc from Solidity.",
90
+ },
91
+ },
92
+ },
93
+ ],
94
+ });
95
+
96
+ const contractFile = res.contracts[0].contractFile;
97
+ const src = fs.readFileSync(contractFile, "utf8");
98
+ assert.ok(src.includes("Example contract doc from Solidity."));
99
+ assert.ok(src.includes("Example function doc from Solidity."));
100
+ });
101
+ });