quantumcoin 7.0.2 → 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 -756
- package/README.md +165 -152
- package/SPEC.md +3845 -3845
- 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 -0
- 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 -1383
- 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 -105
- package/src/contract/contract.js +354 -312
- 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 -1201
- 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 -196
- package/src/providers/provider.js +392 -359
- 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 -361
- 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 -144
- 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 -402
- 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 -98
- 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 -0
- 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,402 +1,407 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @testCategory e2e
|
|
3
|
-
* @blockchainRequired write
|
|
4
|
-
* @transactional true
|
|
5
|
-
*
|
|
6
|
-
* End-to-end test for the typed contract generator:
|
|
7
|
-
* - Compiles a Solidity contract with a constructor parameter
|
|
8
|
-
* - Generates a standalone typed-contract package into a temp folder
|
|
9
|
-
* - Runs `npm install`
|
|
10
|
-
* - Verifies tests/examples were generated
|
|
11
|
-
* - Runs the generated package tests against the provided JSON-RPC URL
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const { describe, it } = require("node:test");
|
|
15
|
-
const assert = require("node:assert/strict");
|
|
16
|
-
const fs = require("node:fs");
|
|
17
|
-
const path = require("node:path");
|
|
18
|
-
const os = require("node:os");
|
|
19
|
-
const { execFileSync, spawnSync } = require("node:child_process");
|
|
20
|
-
|
|
21
|
-
const { getRpcUrl, getChainId, getSolcPath, assertSolcExists } = require("./helpers");
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
"--
|
|
109
|
-
|
|
110
|
-
"--package
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
assert.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
132
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
133
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
134
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
135
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
136
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "
|
|
137
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
138
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
139
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
fs.writeFileSync(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
"--
|
|
236
|
-
|
|
237
|
-
"--package
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
"
|
|
241
|
-
|
|
242
|
-
"
|
|
243
|
-
"
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
assert.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "
|
|
259
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "
|
|
260
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
261
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
262
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
270
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
assert.ok(
|
|
274
|
-
assert.ok(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
"--
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
"--package-
|
|
338
|
-
|
|
339
|
-
"--package-
|
|
340
|
-
|
|
341
|
-
"--package-
|
|
342
|
-
"
|
|
343
|
-
"--package-
|
|
344
|
-
"
|
|
345
|
-
"--
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
assert.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "
|
|
358
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
359
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
360
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
364
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
370
|
-
assert.ok(fs.existsSync(path.join(pkgRoot, "
|
|
371
|
-
|
|
372
|
-
// Verify
|
|
373
|
-
|
|
374
|
-
assert.ok(
|
|
375
|
-
assert.ok(
|
|
376
|
-
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory e2e
|
|
3
|
+
* @blockchainRequired write
|
|
4
|
+
* @transactional true
|
|
5
|
+
*
|
|
6
|
+
* End-to-end test for the typed contract generator:
|
|
7
|
+
* - Compiles a Solidity contract with a constructor parameter
|
|
8
|
+
* - Generates a standalone typed-contract package into a temp folder
|
|
9
|
+
* - Runs `npm install`
|
|
10
|
+
* - Verifies tests/examples were generated
|
|
11
|
+
* - Runs the generated package tests against the provided JSON-RPC URL
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { describe, it } = require("node:test");
|
|
15
|
+
const assert = require("node:assert/strict");
|
|
16
|
+
const fs = require("node:fs");
|
|
17
|
+
const path = require("node:path");
|
|
18
|
+
const os = require("node:os");
|
|
19
|
+
const { execFileSync, spawnSync } = require("node:child_process");
|
|
20
|
+
|
|
21
|
+
const { getRpcUrl, getChainId, getSolcPath, assertSolcExists, logE2eConfig } = require("./helpers");
|
|
22
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
23
|
+
|
|
24
|
+
function getNpmCmd() {
|
|
25
|
+
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function run(cmd, args, cwd, env) {
|
|
29
|
+
const res = spawnSync(cmd, args, {
|
|
30
|
+
cwd,
|
|
31
|
+
env,
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
stdio: "pipe",
|
|
34
|
+
shell: false,
|
|
35
|
+
windowsHide: true,
|
|
36
|
+
});
|
|
37
|
+
if (res.error) throw res.error;
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function _quoteIfNeeded(s) {
|
|
42
|
+
if (typeof s !== "string") return s;
|
|
43
|
+
return /[ \t"]/g.test(s) ? `"${s.replace(/"/g, '\\"')}"` : s;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function runNpm(args, cwd, env) {
|
|
47
|
+
if (process.platform === "win32") {
|
|
48
|
+
const cmd = `${getNpmCmd()} ${args.map(_quoteIfNeeded).join(" ")}`;
|
|
49
|
+
return run("cmd.exe", ["/d", "/s", "/c", cmd], cwd, env);
|
|
50
|
+
}
|
|
51
|
+
return run(getNpmCmd(), args, cwd, env);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function compileSolidity({ solcPath, solPath, contractName }) {
|
|
55
|
+
const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
|
|
56
|
+
const parsed = JSON.parse(out);
|
|
57
|
+
const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(`:${contractName}`));
|
|
58
|
+
if (!key) throw new Error(`Compiled contract ${contractName} not found in solc output`);
|
|
59
|
+
const c = parsed.contracts[key];
|
|
60
|
+
const abi = JSON.parse(c.abi);
|
|
61
|
+
const bin = c.bin || "";
|
|
62
|
+
return { abi, bin };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe("typed contract generator package e2e", () => {
|
|
66
|
+
it("generates a package and runs its transactional tests", async (t) => {
|
|
67
|
+
logSuite("typed contract generator package e2e");
|
|
68
|
+
logTest("generates a package and runs its transactional tests", {});
|
|
69
|
+
const rpcUrl = getRpcUrl();
|
|
70
|
+
if (!rpcUrl) {
|
|
71
|
+
t.skip("QC_RPC_URL not provided");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
logE2eConfig();
|
|
75
|
+
const chainId = getChainId();
|
|
76
|
+
const solcPath = getSolcPath();
|
|
77
|
+
assertSolcExists(solcPath);
|
|
78
|
+
|
|
79
|
+
const repoRoot = path.resolve(__dirname, "..", "..");
|
|
80
|
+
const fixtureSol = path.join(repoRoot, "test", "fixtures", "ConstructorParam.sol");
|
|
81
|
+
const contractName = "ConstructorParam";
|
|
82
|
+
|
|
83
|
+
const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-"));
|
|
84
|
+
const pkgName = `qcgen-${Date.now()}`;
|
|
85
|
+
const pkgDir = tmpBase;
|
|
86
|
+
const pkgRoot = path.join(pkgDir, pkgName);
|
|
87
|
+
|
|
88
|
+
let succeeded = false;
|
|
89
|
+
try {
|
|
90
|
+
// 1) Compile fixture to ABI + BIN
|
|
91
|
+
const { abi, bin } = compileSolidity({ solcPath, solPath: fixtureSol, contractName });
|
|
92
|
+
|
|
93
|
+
const abiPath = path.join(tmpBase, `${contractName}.abi.json`);
|
|
94
|
+
const binPath = path.join(tmpBase, `${contractName}.bin`);
|
|
95
|
+
fs.writeFileSync(abiPath, JSON.stringify(abi, null, 2), "utf8");
|
|
96
|
+
fs.writeFileSync(binPath, bin.trim().startsWith("0x") ? bin.trim() : `0x${bin.trim()}`, "utf8");
|
|
97
|
+
|
|
98
|
+
// 2) Generate package
|
|
99
|
+
const generatorCli = path.join(repoRoot, "generate-sdk.js");
|
|
100
|
+
const gen = run(
|
|
101
|
+
process.execPath,
|
|
102
|
+
[
|
|
103
|
+
generatorCli,
|
|
104
|
+
"--abi",
|
|
105
|
+
abiPath,
|
|
106
|
+
"--bin",
|
|
107
|
+
binPath,
|
|
108
|
+
"--name",
|
|
109
|
+
contractName,
|
|
110
|
+
"--create-package",
|
|
111
|
+
"--package-dir",
|
|
112
|
+
pkgDir,
|
|
113
|
+
"--package-name",
|
|
114
|
+
pkgName,
|
|
115
|
+
"--package-description",
|
|
116
|
+
"Temporary typed-contract package generated by quantumcoin.js e2e tests",
|
|
117
|
+
"--package-author",
|
|
118
|
+
"quantumcoin.js test",
|
|
119
|
+
"--package-license",
|
|
120
|
+
"MIT",
|
|
121
|
+
"--package-version",
|
|
122
|
+
"0.0.1",
|
|
123
|
+
"--non-interactive",
|
|
124
|
+
],
|
|
125
|
+
repoRoot,
|
|
126
|
+
process.env,
|
|
127
|
+
);
|
|
128
|
+
assert.equal(gen.status, 0, `generator failed:\n${gen.stdout}\n${gen.stderr}`);
|
|
129
|
+
|
|
130
|
+
// 3) Verify expected files exist
|
|
131
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "package.json")));
|
|
132
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "tsconfig.json")));
|
|
133
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", `${contractName}.ts`)));
|
|
134
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", `${contractName}__factory.ts`)));
|
|
135
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", `${contractName}.e2e.test.js`)));
|
|
136
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "deploy.js")));
|
|
137
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "read-operations.js")));
|
|
138
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "write-operations.js")));
|
|
139
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "events.js")));
|
|
140
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.js")));
|
|
141
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.d.ts")));
|
|
142
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "README.md")));
|
|
143
|
+
|
|
144
|
+
// This test uses ABI+BIN input, so Solidity source comments are not available here.
|
|
145
|
+
// Ensure the doc build ran and included the contract name.
|
|
146
|
+
const readme = fs.readFileSync(path.join(pkgRoot, "README.md"), "utf8");
|
|
147
|
+
assert.ok(readme.includes(contractName));
|
|
148
|
+
|
|
149
|
+
// 4) Install deps (generator runs install+build, but keep this idempotent)
|
|
150
|
+
if (!fs.existsSync(path.join(pkgRoot, "node_modules"))) {
|
|
151
|
+
const install = runNpm(["install", "--no-fund", "--no-audit"], pkgRoot, process.env);
|
|
152
|
+
assert.equal(install.status, 0, `npm install failed:\n${install.stdout}\n${install.stderr}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 5) Run generated tests against the configured chain
|
|
156
|
+
const env = {
|
|
157
|
+
...process.env,
|
|
158
|
+
QC_RPC_URL: rpcUrl,
|
|
159
|
+
QC_CHAIN_ID: String(chainId),
|
|
160
|
+
};
|
|
161
|
+
const testRun = runNpm(["test"], pkgRoot, env);
|
|
162
|
+
assert.equal(testRun.status, 0, `generated package tests failed:\n${testRun.stdout}\n${testRun.stderr}`);
|
|
163
|
+
|
|
164
|
+
succeeded = true;
|
|
165
|
+
} finally {
|
|
166
|
+
// Keep artifacts on failure for debugging.
|
|
167
|
+
if (succeeded) {
|
|
168
|
+
fs.rmSync(tmpBase, { recursive: true, force: true });
|
|
169
|
+
} else {
|
|
170
|
+
// eslint-disable-next-line no-console
|
|
171
|
+
console.error("Generated package kept at:", pkgRoot);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, { timeout: 1_800_000 });
|
|
175
|
+
|
|
176
|
+
it("generates a package from artifacts JSON input (multiple contracts) and runs its transactional tests", async (t) => {
|
|
177
|
+
const rpcUrl = getRpcUrl();
|
|
178
|
+
if (!rpcUrl) {
|
|
179
|
+
t.skip("QC_RPC_URL not provided");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const chainId = getChainId();
|
|
184
|
+
const solcPath = getSolcPath();
|
|
185
|
+
assertSolcExists(solcPath);
|
|
186
|
+
|
|
187
|
+
const repoRoot = path.resolve(__dirname, "..", "..");
|
|
188
|
+
const fixtureCtorSol = path.join(repoRoot, "test", "fixtures", "ConstructorParam.sol");
|
|
189
|
+
const fixtureMultiSol = path.join(repoRoot, "test", "fixtures", "MultiContracts.sol");
|
|
190
|
+
|
|
191
|
+
const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-json-"));
|
|
192
|
+
const pkgName = `qcgen-json-${Date.now()}`;
|
|
193
|
+
const pkgDir = tmpBase;
|
|
194
|
+
const pkgRoot = path.join(pkgDir, pkgName);
|
|
195
|
+
|
|
196
|
+
let succeeded = false;
|
|
197
|
+
try {
|
|
198
|
+
// Compile 2 contracts into ABI+BIN pairs
|
|
199
|
+
const ctorName = "ConstructorParam";
|
|
200
|
+
const alphaName = "Alpha";
|
|
201
|
+
|
|
202
|
+
const { abi: ctorAbi, bin: ctorBin } = compileSolidity({ solcPath, solPath: fixtureCtorSol, contractName: ctorName });
|
|
203
|
+
const { abi: alphaAbi, bin: alphaBin } = compileSolidity({ solcPath, solPath: fixtureMultiSol, contractName: alphaName });
|
|
204
|
+
|
|
205
|
+
const ctorAbiPath = path.join(tmpBase, `${ctorName}.abi.json`);
|
|
206
|
+
const ctorBinPath = path.join(tmpBase, `${ctorName}.bin`);
|
|
207
|
+
fs.writeFileSync(ctorAbiPath, JSON.stringify(ctorAbi, null, 2), "utf8");
|
|
208
|
+
fs.writeFileSync(ctorBinPath, ctorBin.trim().startsWith("0x") ? ctorBin.trim() : `0x${ctorBin.trim()}`, "utf8");
|
|
209
|
+
|
|
210
|
+
const alphaAbiPath = path.join(tmpBase, `${alphaName}.abi.json`);
|
|
211
|
+
const alphaBinPath = path.join(tmpBase, `${alphaName}.bin`);
|
|
212
|
+
fs.writeFileSync(alphaAbiPath, JSON.stringify(alphaAbi, null, 2), "utf8");
|
|
213
|
+
fs.writeFileSync(alphaBinPath, alphaBin.trim().startsWith("0x") ? alphaBin.trim() : `0x${alphaBin.trim()}`, "utf8");
|
|
214
|
+
|
|
215
|
+
const artifactsJsonPath = path.join(tmpBase, "artifacts.json");
|
|
216
|
+
fs.writeFileSync(
|
|
217
|
+
artifactsJsonPath,
|
|
218
|
+
JSON.stringify(
|
|
219
|
+
[
|
|
220
|
+
{ abi: path.basename(alphaAbiPath), bin: path.basename(alphaBinPath) },
|
|
221
|
+
{ abi: path.basename(ctorAbiPath), bin: path.basename(ctorBinPath) },
|
|
222
|
+
],
|
|
223
|
+
null,
|
|
224
|
+
2,
|
|
225
|
+
),
|
|
226
|
+
"utf8",
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Generate package using artifacts JSON input
|
|
230
|
+
const generatorCli = path.join(repoRoot, "generate-sdk.js");
|
|
231
|
+
const gen = run(
|
|
232
|
+
process.execPath,
|
|
233
|
+
[
|
|
234
|
+
generatorCli,
|
|
235
|
+
"--artifacts-json",
|
|
236
|
+
artifactsJsonPath,
|
|
237
|
+
"--create-package",
|
|
238
|
+
"--package-dir",
|
|
239
|
+
pkgDir,
|
|
240
|
+
"--package-name",
|
|
241
|
+
pkgName,
|
|
242
|
+
"--package-description",
|
|
243
|
+
"Temporary typed-contract package generated from artifacts JSON input",
|
|
244
|
+
"--package-author",
|
|
245
|
+
"quantumcoin.js test",
|
|
246
|
+
"--package-license",
|
|
247
|
+
"MIT",
|
|
248
|
+
"--package-version",
|
|
249
|
+
"0.0.1",
|
|
250
|
+
"--non-interactive",
|
|
251
|
+
],
|
|
252
|
+
repoRoot,
|
|
253
|
+
process.env,
|
|
254
|
+
);
|
|
255
|
+
assert.equal(gen.status, 0, `generator failed:\n${gen.stdout}\n${gen.stderr}`);
|
|
256
|
+
|
|
257
|
+
// Verify multiple contracts were generated
|
|
258
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Alpha.ts")));
|
|
259
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Alpha__factory.ts")));
|
|
260
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "ConstructorParam.ts")));
|
|
261
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "ConstructorParam__factory.ts")));
|
|
262
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "index.ts")));
|
|
263
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.js")));
|
|
264
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.d.ts")));
|
|
265
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "README.md")));
|
|
266
|
+
|
|
267
|
+
// Verify tests exist for each contract
|
|
268
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "Alpha.e2e.test.js")));
|
|
269
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "ConstructorParam.e2e.test.js")));
|
|
270
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "all-contracts.e2e.test.js")));
|
|
271
|
+
|
|
272
|
+
// Multi-contract packages use per-contract example filenames.
|
|
273
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "deploy-Alpha.js")));
|
|
274
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "examples", "deploy-ConstructorParam.js")));
|
|
275
|
+
|
|
276
|
+
const readme = fs.readFileSync(path.join(pkgRoot, "README.md"), "utf8");
|
|
277
|
+
assert.ok(readme.includes("Alpha"));
|
|
278
|
+
assert.ok(readme.includes("ConstructorParam"));
|
|
279
|
+
|
|
280
|
+
// Install deps + run tests against chain
|
|
281
|
+
if (!fs.existsSync(path.join(pkgRoot, "node_modules"))) {
|
|
282
|
+
const install = runNpm(["install", "--no-fund", "--no-audit"], pkgRoot, process.env);
|
|
283
|
+
assert.equal(install.status, 0, `npm install failed:\n${install.stdout}\n${install.stderr}`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const env = {
|
|
287
|
+
...process.env,
|
|
288
|
+
QC_RPC_URL: rpcUrl,
|
|
289
|
+
QC_CHAIN_ID: String(chainId),
|
|
290
|
+
};
|
|
291
|
+
const testRun = runNpm(["test"], pkgRoot, env);
|
|
292
|
+
assert.equal(testRun.status, 0, `generated package tests failed:\n${testRun.stdout}\n${testRun.stderr}`);
|
|
293
|
+
|
|
294
|
+
succeeded = true;
|
|
295
|
+
} finally {
|
|
296
|
+
if (succeeded) {
|
|
297
|
+
fs.rmSync(tmpBase, { recursive: true, force: true });
|
|
298
|
+
} else {
|
|
299
|
+
// eslint-disable-next-line no-console
|
|
300
|
+
console.error("Generated package kept at:", pkgRoot);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}, { timeout: 1_800_000 });
|
|
304
|
+
|
|
305
|
+
it("generates a package from Solidity input (multiple contracts) and runs its transactional tests", async (t) => {
|
|
306
|
+
const rpcUrl = getRpcUrl();
|
|
307
|
+
if (!rpcUrl) {
|
|
308
|
+
t.skip("QC_RPC_URL not provided");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const chainId = getChainId();
|
|
313
|
+
const solcPath = getSolcPath();
|
|
314
|
+
assertSolcExists(solcPath);
|
|
315
|
+
|
|
316
|
+
const repoRoot = path.resolve(__dirname, "..", "..");
|
|
317
|
+
const fixtureSol = path.join(repoRoot, "test", "fixtures", "MultiContracts.sol");
|
|
318
|
+
|
|
319
|
+
const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-sol-"));
|
|
320
|
+
const pkgName = `qcgen-sol-${Date.now()}`;
|
|
321
|
+
const pkgDir = tmpBase;
|
|
322
|
+
const pkgRoot = path.join(pkgDir, pkgName);
|
|
323
|
+
|
|
324
|
+
let succeeded = false;
|
|
325
|
+
try {
|
|
326
|
+
// Generate package directly from Solidity sources
|
|
327
|
+
const generatorCli = path.join(repoRoot, "generate-sdk.js");
|
|
328
|
+
const gen = run(
|
|
329
|
+
process.execPath,
|
|
330
|
+
[
|
|
331
|
+
generatorCli,
|
|
332
|
+
"--sol",
|
|
333
|
+
fixtureSol,
|
|
334
|
+
"--solc",
|
|
335
|
+
solcPath,
|
|
336
|
+
"--create-package",
|
|
337
|
+
"--package-dir",
|
|
338
|
+
pkgDir,
|
|
339
|
+
"--package-name",
|
|
340
|
+
pkgName,
|
|
341
|
+
"--package-description",
|
|
342
|
+
"Temporary typed-contract package generated from Solidity input",
|
|
343
|
+
"--package-author",
|
|
344
|
+
"quantumcoin.js test",
|
|
345
|
+
"--package-license",
|
|
346
|
+
"MIT",
|
|
347
|
+
"--package-version",
|
|
348
|
+
"0.0.1",
|
|
349
|
+
"--non-interactive",
|
|
350
|
+
],
|
|
351
|
+
repoRoot,
|
|
352
|
+
process.env,
|
|
353
|
+
);
|
|
354
|
+
assert.equal(gen.status, 0, `generator failed:\n${gen.stdout}\n${gen.stderr}`);
|
|
355
|
+
|
|
356
|
+
// Verify multiple contracts were generated
|
|
357
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Alpha.ts")));
|
|
358
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Alpha__factory.ts")));
|
|
359
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Beta.ts")));
|
|
360
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "Beta__factory.ts")));
|
|
361
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "src", "index.ts")));
|
|
362
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.js")));
|
|
363
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "index.d.ts")));
|
|
364
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "README.md")));
|
|
365
|
+
|
|
366
|
+
// Verify artifacts were emitted
|
|
367
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "artifacts", "Alpha.abi.json")));
|
|
368
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "artifacts", "Alpha.bin")));
|
|
369
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "artifacts", "Beta.abi.json")));
|
|
370
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "artifacts", "Beta.bin")));
|
|
371
|
+
|
|
372
|
+
// Verify tests exist for each contract
|
|
373
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "Alpha.e2e.test.js")));
|
|
374
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "Beta.e2e.test.js")));
|
|
375
|
+
assert.ok(fs.existsSync(path.join(pkgRoot, "test", "e2e", "all-contracts.e2e.test.js")));
|
|
376
|
+
|
|
377
|
+
// Verify Solidity comments were propagated into generated TS
|
|
378
|
+
const alphaTs = fs.readFileSync(path.join(pkgRoot, "src", "Alpha.ts"), "utf8");
|
|
379
|
+
assert.ok(alphaTs.includes("Alpha contract for multi-contract generator test."));
|
|
380
|
+
assert.ok(alphaTs.includes("Set a new value in Alpha."));
|
|
381
|
+
|
|
382
|
+
// Install deps + run tests against chain
|
|
383
|
+
if (!fs.existsSync(path.join(pkgRoot, "node_modules"))) {
|
|
384
|
+
const install = runNpm(["install", "--no-fund", "--no-audit"], pkgRoot, process.env);
|
|
385
|
+
assert.equal(install.status, 0, `npm install failed:\n${install.stdout}\n${install.stderr}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const env = {
|
|
389
|
+
...process.env,
|
|
390
|
+
QC_RPC_URL: rpcUrl,
|
|
391
|
+
QC_CHAIN_ID: String(chainId),
|
|
392
|
+
};
|
|
393
|
+
const testRun = runNpm(["test"], pkgRoot, env);
|
|
394
|
+
assert.equal(testRun.status, 0, `generated package tests failed:\n${testRun.stdout}\n${testRun.stderr}`);
|
|
395
|
+
|
|
396
|
+
succeeded = true;
|
|
397
|
+
} finally {
|
|
398
|
+
if (succeeded) {
|
|
399
|
+
fs.rmSync(tmpBase, { recursive: true, force: true });
|
|
400
|
+
} else {
|
|
401
|
+
// eslint-disable-next-line no-console
|
|
402
|
+
console.error("Generated package kept at:", pkgRoot);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}, { timeout: 1_800_000 });
|
|
406
|
+
});
|
|
407
|
+
|