genlayer 0.34.0 → 0.34.3

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 (128) hide show
  1. package/dist/index.js +13 -3
  2. package/package.json +11 -2
  3. package/.eslintignore +0 -2
  4. package/.github/workflows/cli-docs.yml +0 -121
  5. package/.github/workflows/publish-beta.yml +0 -41
  6. package/.github/workflows/publish.yml +0 -43
  7. package/.github/workflows/validate-code.yml +0 -47
  8. package/.prettierignore +0 -19
  9. package/.prettierrc +0 -12
  10. package/.release-it.json +0 -64
  11. package/CHANGELOG.md +0 -425
  12. package/CLAUDE.md +0 -55
  13. package/CONTRIBUTING.md +0 -117
  14. package/docker-compose.yml +0 -154
  15. package/docs/delegator-guide.md +0 -203
  16. package/docs/validator-guide.md +0 -329
  17. package/esbuild.config.dev.js +0 -17
  18. package/esbuild.config.js +0 -22
  19. package/esbuild.config.prod.js +0 -17
  20. package/eslint.config.js +0 -60
  21. package/renovate.json +0 -22
  22. package/src/commands/account/create.ts +0 -30
  23. package/src/commands/account/export.ts +0 -106
  24. package/src/commands/account/import.ts +0 -135
  25. package/src/commands/account/index.ts +0 -129
  26. package/src/commands/account/list.ts +0 -34
  27. package/src/commands/account/lock.ts +0 -39
  28. package/src/commands/account/remove.ts +0 -30
  29. package/src/commands/account/send.ts +0 -162
  30. package/src/commands/account/show.ts +0 -74
  31. package/src/commands/account/unlock.ts +0 -56
  32. package/src/commands/account/use.ts +0 -21
  33. package/src/commands/config/getSetReset.ts +0 -51
  34. package/src/commands/config/index.ts +0 -30
  35. package/src/commands/contracts/call.ts +0 -39
  36. package/src/commands/contracts/code.ts +0 -33
  37. package/src/commands/contracts/deploy.ts +0 -157
  38. package/src/commands/contracts/index.ts +0 -86
  39. package/src/commands/contracts/schema.ts +0 -31
  40. package/src/commands/contracts/write.ts +0 -49
  41. package/src/commands/general/index.ts +0 -45
  42. package/src/commands/general/init.ts +0 -179
  43. package/src/commands/general/start.ts +0 -116
  44. package/src/commands/general/stop.ts +0 -26
  45. package/src/commands/localnet/index.ts +0 -100
  46. package/src/commands/localnet/validators.ts +0 -269
  47. package/src/commands/network/index.ts +0 -29
  48. package/src/commands/network/setNetwork.ts +0 -77
  49. package/src/commands/scaffold/index.ts +0 -16
  50. package/src/commands/scaffold/new.ts +0 -34
  51. package/src/commands/staking/StakingAction.ts +0 -279
  52. package/src/commands/staking/delegatorClaim.ts +0 -41
  53. package/src/commands/staking/delegatorExit.ts +0 -56
  54. package/src/commands/staking/delegatorJoin.ts +0 -44
  55. package/src/commands/staking/index.ts +0 -357
  56. package/src/commands/staking/setIdentity.ts +0 -78
  57. package/src/commands/staking/setOperator.ts +0 -46
  58. package/src/commands/staking/stakingInfo.ts +0 -584
  59. package/src/commands/staking/validatorClaim.ts +0 -43
  60. package/src/commands/staking/validatorDeposit.ts +0 -48
  61. package/src/commands/staking/validatorExit.ts +0 -63
  62. package/src/commands/staking/validatorHistory.ts +0 -298
  63. package/src/commands/staking/validatorJoin.ts +0 -47
  64. package/src/commands/staking/validatorPrime.ts +0 -73
  65. package/src/commands/staking/wizard.ts +0 -809
  66. package/src/commands/transactions/appeal.ts +0 -39
  67. package/src/commands/transactions/index.ts +0 -39
  68. package/src/commands/transactions/receipt.ts +0 -90
  69. package/src/commands/update/index.ts +0 -25
  70. package/src/commands/update/ollama.ts +0 -103
  71. package/src/lib/actions/BaseAction.ts +0 -299
  72. package/src/lib/clients/jsonRpcClient.ts +0 -41
  73. package/src/lib/clients/system.ts +0 -73
  74. package/src/lib/config/ConfigFileManager.ts +0 -194
  75. package/src/lib/config/KeychainManager.ts +0 -89
  76. package/src/lib/config/simulator.ts +0 -68
  77. package/src/lib/config/text.ts +0 -2
  78. package/src/lib/errors/missingRequirement.ts +0 -9
  79. package/src/lib/errors/versionRequired.ts +0 -9
  80. package/src/lib/interfaces/ISimulatorService.ts +0 -37
  81. package/src/lib/services/simulator.ts +0 -351
  82. package/src/types/node-fetch.d.ts +0 -1
  83. package/tests/actions/appeal.test.ts +0 -99
  84. package/tests/actions/call.test.ts +0 -94
  85. package/tests/actions/code.test.ts +0 -87
  86. package/tests/actions/create.test.ts +0 -65
  87. package/tests/actions/deploy.test.ts +0 -420
  88. package/tests/actions/getSetReset.test.ts +0 -88
  89. package/tests/actions/init.test.ts +0 -467
  90. package/tests/actions/lock.test.ts +0 -86
  91. package/tests/actions/new.test.ts +0 -80
  92. package/tests/actions/ollama.test.ts +0 -193
  93. package/tests/actions/receipt.test.ts +0 -261
  94. package/tests/actions/schema.test.ts +0 -94
  95. package/tests/actions/setNetwork.test.ts +0 -160
  96. package/tests/actions/staking.test.ts +0 -279
  97. package/tests/actions/start.test.ts +0 -235
  98. package/tests/actions/stop.test.ts +0 -77
  99. package/tests/actions/unlock.test.ts +0 -139
  100. package/tests/actions/validators.test.ts +0 -750
  101. package/tests/actions/write.test.ts +0 -102
  102. package/tests/commands/account.test.ts +0 -146
  103. package/tests/commands/appeal.test.ts +0 -58
  104. package/tests/commands/call.test.ts +0 -78
  105. package/tests/commands/code.test.ts +0 -69
  106. package/tests/commands/config.test.ts +0 -54
  107. package/tests/commands/deploy.test.ts +0 -83
  108. package/tests/commands/init.test.ts +0 -101
  109. package/tests/commands/localnet.test.ts +0 -131
  110. package/tests/commands/network.test.ts +0 -60
  111. package/tests/commands/new.test.ts +0 -68
  112. package/tests/commands/receipt.test.ts +0 -142
  113. package/tests/commands/schema.test.ts +0 -67
  114. package/tests/commands/staking.test.ts +0 -329
  115. package/tests/commands/stop.test.ts +0 -27
  116. package/tests/commands/up.test.ts +0 -105
  117. package/tests/commands/update.test.ts +0 -45
  118. package/tests/commands/write.test.ts +0 -76
  119. package/tests/index.test.ts +0 -56
  120. package/tests/libs/baseAction.test.ts +0 -516
  121. package/tests/libs/configFileManager.test.ts +0 -117
  122. package/tests/libs/jsonRpcClient.test.ts +0 -59
  123. package/tests/libs/keychainManager.test.ts +0 -156
  124. package/tests/libs/system.test.ts +0 -148
  125. package/tests/services/simulator.test.ts +0 -705
  126. package/tests/utils.ts +0 -13
  127. package/tsconfig.json +0 -120
  128. package/vitest.config.ts +0 -12
@@ -1,420 +0,0 @@
1
- import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
2
- import fs from "fs";
3
- import os from "os";
4
- import {createClient, createAccount} from "genlayer-js";
5
- import {DeployAction, DeployOptions} from "../../src/commands/contracts/deploy";
6
- import {buildSync} from "esbuild";
7
- import {pathToFileURL} from "url";
8
-
9
- vi.mock("fs");
10
- vi.mock("os");
11
- vi.mock("genlayer-js");
12
- vi.mock("esbuild", () => ({
13
- buildSync: vi.fn(),
14
- }));
15
-
16
- describe("DeployAction", () => {
17
- let deployer: DeployAction;
18
- const mockClient = {
19
- deployContract: vi.fn(),
20
- waitForTransactionReceipt: vi.fn(),
21
- initializeConsensusSmartContract: vi.fn(),
22
- };
23
-
24
- const mockPrivateKey = "mocked_private_key";
25
-
26
- beforeEach(() => {
27
- vi.clearAllMocks();
28
- // Setup mocks before creating the action (needed for constructor)
29
- vi.mocked(os.homedir).mockReturnValue("/mocked/home");
30
- vi.mocked(fs.existsSync).mockReturnValue(true);
31
- vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify({activeAccount: "default"}));
32
-
33
- vi.mocked(createClient).mockReturnValue(mockClient as any);
34
- vi.mocked(createAccount).mockReturnValue({privateKey: mockPrivateKey} as any);
35
- deployer = new DeployAction();
36
- vi.spyOn(deployer as any, "getAccount").mockResolvedValue({privateKey: mockPrivateKey});
37
- vi.spyOn(deployer as any, "getConfig").mockReturnValue({});
38
-
39
- vi.spyOn(deployer as any, "startSpinner").mockImplementation(() => {});
40
- vi.spyOn(deployer as any, "succeedSpinner").mockImplementation(() => {});
41
- vi.spyOn(deployer as any, "failSpinner").mockImplementation(() => {});
42
- vi.spyOn(deployer as any, "setSpinnerText").mockImplementation(() => {});
43
- vi.spyOn(deployer as any, "log").mockImplementation(() => {});
44
- });
45
-
46
- afterEach(() => {
47
- vi.restoreAllMocks();
48
- });
49
-
50
- test("reads contract code successfully", () => {
51
- const contractPath = "/mocked/contract/path";
52
- const contractContent = "contract code";
53
- vi.mocked(fs.existsSync).mockReturnValue(true);
54
- vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
55
-
56
- const result = deployer["readContractCode"](contractPath);
57
-
58
- expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
59
- expect(fs.readFileSync).toHaveBeenCalledWith(contractPath, "utf-8");
60
- expect(result).toBe(contractContent);
61
- });
62
-
63
- test("throws error if contract file is missing", () => {
64
- const contractPath = "/mocked/contract/path";
65
- vi.mocked(fs.existsSync).mockReturnValue(false);
66
-
67
- expect(() => deployer["readContractCode"](contractPath)).toThrowError(
68
- `Contract file not found: ${contractPath}`,
69
- );
70
- expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
71
- });
72
-
73
- test("deploys contract with args", async () => {
74
- const options: DeployOptions = {
75
- contract: "/mocked/contract/path",
76
- args: [1, 2, 3],
77
- };
78
- const contractContent = "contract code";
79
-
80
- vi.mocked(fs.existsSync).mockReturnValue(true);
81
- vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
82
- vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
83
- vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
84
- data: {contract_address: "0xdasdsadasdasdada"},
85
- });
86
-
87
- await deployer.deploy(options);
88
-
89
- expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
90
- expect(mockClient.deployContract).toHaveBeenCalledWith({
91
- code: contractContent,
92
- args: [1, 2, 3],
93
- leaderOnly: false,
94
- });
95
- expect(mockClient.deployContract).toHaveReturnedWith(Promise.resolve("mocked_tx_hash"));
96
- });
97
-
98
- test("throws error for missing contract", async () => {
99
- const options: DeployOptions = {};
100
-
101
- await deployer.deploy(options);
102
-
103
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("No contract specified for deployment.");
104
- expect(mockClient.deployContract).not.toHaveBeenCalled();
105
- });
106
-
107
- test("handles deployment errors", async () => {
108
- const options: DeployOptions = {
109
- contract: "/mocked/contract/path",
110
- args: [1, 2, 3],
111
- };
112
- const contractContent = "contract code";
113
-
114
- vi.mocked(fs.existsSync).mockReturnValue(true);
115
- vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
116
- vi.mocked(mockClient.deployContract).mockRejectedValue(new Error("Mocked deployment error"));
117
-
118
- await deployer.deploy(options);
119
-
120
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("Error deploying contract", expect.any(Error));
121
- expect(mockClient.deployContract).toHaveBeenCalled();
122
- });
123
-
124
- test("handles empty contract code", async () => {
125
- const options: DeployOptions = {
126
- contract: "/mocked/contract/path",
127
- };
128
-
129
- vi.mocked(fs.existsSync).mockReturnValue(true);
130
- vi.mocked(fs.readFileSync).mockReturnValue("");
131
-
132
- await deployer.deploy(options);
133
-
134
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("Contract code is empty.");
135
- expect(mockClient.deployContract).not.toHaveBeenCalled();
136
- });
137
-
138
- test("deployScripts executes scripts in order", async () => {
139
- vi.mocked(fs.existsSync).mockReturnValue(true);
140
- vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js", "10_last.ts"] as any);
141
-
142
- vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
143
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
144
-
145
- await deployer.deployScripts();
146
-
147
- expect(deployer["setSpinnerText"]).toHaveBeenCalledWith("Found 3 deploy scripts. Executing...");
148
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), undefined);
149
- expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
150
- expect.stringMatching(/2_second.js/),
151
- undefined,
152
- undefined,
153
- );
154
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/10_last.ts/), undefined);
155
- });
156
-
157
- test("executeTsScript transpiles and executes TypeScript", async () => {
158
- const filePath = "/mocked/script.ts";
159
- const outFile = "/mocked/script.compiled.js";
160
-
161
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
162
- vi.mocked(buildSync).mockImplementation((() => {}) as any);
163
-
164
- await deployer["executeTsScript"](filePath);
165
-
166
- expect(deployer["startSpinner"]).toHaveBeenCalledWith(`Transpiling TypeScript file: ${filePath}`);
167
- expect(buildSync).toHaveBeenCalledWith({
168
- entryPoints: [filePath],
169
- outfile: outFile,
170
- bundle: false,
171
- platform: "node",
172
- format: "esm",
173
- target: "es2020",
174
- sourcemap: false,
175
- });
176
-
177
- expect(deployer["executeJsScript"]).toHaveBeenCalledWith(filePath, outFile, undefined);
178
- expect(fs.unlinkSync).toHaveBeenCalledWith(outFile);
179
- });
180
-
181
- test("deployScripts fails when deploy folder is missing", async () => {
182
- vi.mocked(fs.existsSync).mockReturnValue(false);
183
-
184
- await deployer.deployScripts();
185
-
186
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("No deploy folder found.");
187
- });
188
-
189
- test("deployScripts sorts and executes scripts correctly", async () => {
190
- vi.mocked(fs.existsSync).mockReturnValue(true);
191
- vi.mocked(fs.readdirSync).mockReturnValue(["10_last.ts", "2_second.js", "1_first.ts"] as any);
192
-
193
- vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
194
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
195
-
196
- await deployer.deployScripts();
197
-
198
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
199
- expect.stringContaining("1_first.ts"),
200
- undefined,
201
- );
202
- expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
203
- expect.stringContaining("2_second.js"),
204
- undefined,
205
- undefined,
206
- );
207
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
208
- expect.stringContaining("10_last.ts"),
209
- undefined,
210
- );
211
- });
212
-
213
- test("deployScripts fails when no scripts are found", async () => {
214
- vi.mocked(fs.existsSync).mockReturnValue(true);
215
- vi.mocked(fs.readdirSync).mockReturnValue([]);
216
-
217
- await deployer.deployScripts();
218
-
219
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("No deploy scripts found.");
220
- });
221
-
222
- test("deployScripts handles script execution errors", async () => {
223
- vi.mocked(fs.existsSync).mockReturnValue(true);
224
- vi.mocked(fs.readdirSync).mockReturnValue(["1_failing.ts"] as any);
225
- vi.spyOn(deployer as any, "executeTsScript").mockRejectedValue(new Error("Script error"));
226
-
227
- await deployer.deployScripts();
228
-
229
- expect(deployer["failSpinner"]).toHaveBeenCalledWith(
230
- expect.stringContaining("Error executing script:"),
231
- expect.any(Error),
232
- );
233
- });
234
-
235
- test("executeJsScript fails gracefully", async () => {
236
- const filePath = "/mocked/script.js";
237
-
238
- await deployer["executeJsScript"](filePath);
239
-
240
- expect(deployer["failSpinner"]).toHaveBeenCalledWith(
241
- expect.stringContaining("Error executing:"),
242
- expect.any(Error),
243
- );
244
- });
245
-
246
- test("deploy fails when contract code is empty", async () => {
247
- const options: DeployOptions = {contract: "/mocked/contract/path"};
248
-
249
- vi.mocked(fs.existsSync).mockReturnValue(true);
250
- vi.mocked(fs.readFileSync).mockReturnValue("");
251
-
252
- await deployer.deploy(options);
253
-
254
- expect(deployer["failSpinner"]).toHaveBeenCalledWith("Contract code is empty.");
255
- });
256
-
257
- test("deployScripts correctly sorts mixed numbered and non-numbered scripts", async () => {
258
- vi.mocked(fs.existsSync).mockReturnValue(true);
259
- vi.mocked(fs.readdirSync).mockReturnValue([
260
- "script.ts",
261
- "2alpha_script.ts",
262
- "3alpha_script.ts",
263
- "blpha_script.ts",
264
- "clpha_script.ts",
265
- ] as any);
266
-
267
- vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
268
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
269
-
270
- await deployer.deployScripts();
271
-
272
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringContaining("script.ts"), undefined);
273
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
274
- expect.stringContaining("2alpha_script.ts"),
275
- undefined,
276
- );
277
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
278
- expect.stringContaining("3alpha_script.ts"),
279
- undefined,
280
- );
281
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
282
- expect.stringContaining("blpha_script.ts"),
283
- undefined,
284
- );
285
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
286
- expect.stringContaining("clpha_script.ts"),
287
- undefined,
288
- );
289
- });
290
-
291
- test("executeJsScript fails if module has no default export", async () => {
292
- const filePath = "/mocked/script.js";
293
-
294
- vi.doMock(pathToFileURL(filePath).href, () => ({default: "Not a function"}));
295
-
296
- await deployer["executeJsScript"](filePath);
297
-
298
- expect(deployer["failSpinner"]).toHaveBeenCalledWith(
299
- expect.stringContaining('No "default" function found in:'),
300
- );
301
- });
302
-
303
- test("executeJsScript successfully executes a script", async () => {
304
- const filePath = "/mocked/script.js";
305
- const mockFn = vi.fn(); // This mock function simulates the script execution
306
-
307
- vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
308
-
309
- await deployer["executeJsScript"](filePath);
310
-
311
- expect(mockFn).toHaveBeenCalledWith(mockClient);
312
-
313
- expect(deployer["succeedSpinner"]).toHaveBeenCalledWith(`Successfully executed: ${filePath}`);
314
- });
315
-
316
- test("executeTsScript fails when buildSync throws an error", async () => {
317
- const filePath = "/mocked/script.ts";
318
- const error = new Error("Build failed");
319
-
320
- vi.mocked(buildSync).mockImplementation(() => {
321
- throw error; // Simulate an error during transpilation
322
- });
323
-
324
- await deployer["executeTsScript"](filePath);
325
-
326
- expect(deployer["failSpinner"]).toHaveBeenCalledWith(`Error executing: ${filePath}`, error);
327
- });
328
-
329
- test("deploys contract with rpc option", async () => {
330
- const options: DeployOptions = {
331
- contract: "/mocked/contract/path",
332
- args: [1, 2, 3],
333
- rpc: "https://custom-rpc-url.com",
334
- };
335
- const contractContent = "contract code";
336
-
337
- vi.mocked(fs.existsSync).mockReturnValue(true);
338
- vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
339
- vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
340
- vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
341
- data: {contract_address: "0xdasdsadasdasdada"},
342
- });
343
-
344
- await deployer.deploy(options);
345
-
346
- expect(createClient).toHaveBeenCalledWith(
347
- expect.objectContaining({
348
- endpoint: "https://custom-rpc-url.com",
349
- }),
350
- );
351
- expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
352
- expect(mockClient.deployContract).toHaveBeenCalledWith({
353
- code: contractContent,
354
- args: [1, 2, 3],
355
- leaderOnly: false,
356
- });
357
- });
358
-
359
- test("executeJsScript uses rpc url when provided", async () => {
360
- const filePath = "/mocked/script.js";
361
- const rpcUrl = "https://custom-rpc-url.com";
362
- const mockFn = vi.fn();
363
-
364
- vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
365
-
366
- await deployer["executeJsScript"](filePath, undefined, rpcUrl);
367
-
368
- expect(createClient).toHaveBeenCalledWith(
369
- expect.objectContaining({
370
- endpoint: rpcUrl,
371
- }),
372
- );
373
- expect(mockFn).toHaveBeenCalledWith(mockClient);
374
- expect(deployer["succeedSpinner"]).toHaveBeenCalledWith(`Successfully executed: ${filePath}`);
375
- });
376
-
377
- test("executeTsScript passes rpc url to executeJsScript", async () => {
378
- const filePath = "/mocked/script.ts";
379
- const outFile = "/mocked/script.compiled.js";
380
- const rpcUrl = "https://custom-rpc-url.com";
381
-
382
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
383
- vi.mocked(buildSync).mockImplementation((() => {}) as any);
384
-
385
- await deployer["executeTsScript"](filePath, rpcUrl);
386
-
387
- expect(deployer["startSpinner"]).toHaveBeenCalledWith(`Transpiling TypeScript file: ${filePath}`);
388
- expect(buildSync).toHaveBeenCalledWith({
389
- entryPoints: [filePath],
390
- outfile: outFile,
391
- bundle: false,
392
- platform: "node",
393
- format: "esm",
394
- target: "es2020",
395
- sourcemap: false,
396
- });
397
-
398
- expect(deployer["executeJsScript"]).toHaveBeenCalledWith(filePath, outFile, rpcUrl);
399
- expect(fs.unlinkSync).toHaveBeenCalledWith(outFile);
400
- });
401
-
402
- test("deployScripts passes rpc url to script execution methods", async () => {
403
- const rpcUrl = "https://custom-rpc-url.com";
404
-
405
- vi.mocked(fs.existsSync).mockReturnValue(true);
406
- vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js"] as any);
407
-
408
- vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
409
- vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
410
-
411
- await deployer.deployScripts({rpc: rpcUrl});
412
-
413
- expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), rpcUrl);
414
- expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
415
- expect.stringMatching(/2_second.js/),
416
- undefined,
417
- rpcUrl,
418
- );
419
- });
420
- });
@@ -1,88 +0,0 @@
1
- import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
2
- import { ConfigActions } from "../../src/commands/config/getSetReset";
3
- import { ConfigFileManager } from "../../src/lib/config/ConfigFileManager";
4
-
5
- vi.mock("../../src/lib/config/ConfigFileManager");
6
-
7
- describe("ConfigActions", () => {
8
- let configActions: ConfigActions;
9
-
10
- beforeEach(() => {
11
- configActions = new ConfigActions();
12
- vi.clearAllMocks();
13
-
14
- vi.spyOn(configActions as any, "startSpinner").mockImplementation(() => {});
15
- vi.spyOn(configActions as any, "succeedSpinner").mockImplementation(() => {});
16
- vi.spyOn(configActions as any, "failSpinner").mockImplementation(() => {});
17
- });
18
-
19
- afterEach(() => {
20
- vi.restoreAllMocks();
21
- });
22
-
23
- test("set method writes key-value pair to the configuration", () => {
24
- configActions.set("defaultNetwork=testnet");
25
-
26
- expect(configActions["writeConfig"]).toHaveBeenCalledWith("defaultNetwork", "testnet");
27
- expect(configActions["startSpinner"]).toHaveBeenCalledWith("Updating configuration: defaultNetwork");
28
- expect(configActions["succeedSpinner"]).toHaveBeenCalledWith("Configuration successfully updated");
29
- });
30
-
31
- test("set method fails for invalid format", () => {
32
- configActions.set("invalidFormat");
33
-
34
- expect(configActions["failSpinner"]).toHaveBeenCalledWith("Invalid format. Use 'key=value'.");
35
- expect(configActions["writeConfig"]).not.toHaveBeenCalled();
36
- });
37
-
38
- test("get method retrieves value for a specific key", () => {
39
- vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue("testnet");
40
-
41
- configActions.get("defaultNetwork");
42
-
43
- expect(configActions["getConfigByKey"]).toHaveBeenCalledWith("defaultNetwork");
44
- expect(configActions["startSpinner"]).toHaveBeenCalledWith("Retrieving value for: defaultNetwork");
45
- expect(configActions["succeedSpinner"]).toHaveBeenCalledWith("Configuration successfully retrieved", "defaultNetwork=testnet");
46
- });
47
-
48
- test("get method prints failure message when key does not exist", () => {
49
- vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(null);
50
-
51
- configActions.get("nonexistentKey");
52
-
53
- expect(configActions["getConfigByKey"]).toHaveBeenCalledWith("nonexistentKey");
54
- expect(configActions["failSpinner"]).toHaveBeenCalledWith("No configuration found for 'nonexistentKey'.");
55
- });
56
-
57
- test("get method retrieves the entire configuration when no key is provided", () => {
58
- const mockConfig = { defaultNetwork: "testnet" };
59
- vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue(mockConfig);
60
-
61
- configActions.get();
62
-
63
- expect(configActions["getConfig"]).toHaveBeenCalled();
64
- expect(configActions["startSpinner"]).toHaveBeenCalledWith("Retrieving all configurations");
65
- expect(configActions["succeedSpinner"]).toHaveBeenCalledWith("All configurations successfully retrieved", JSON.stringify(mockConfig, null, 2));
66
- });
67
-
68
- test("reset method removes key from configuration", () => {
69
- const mockConfig = { defaultNetwork: "testnet" };
70
- vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue(mockConfig);
71
-
72
- configActions.reset("defaultNetwork");
73
-
74
- expect(configActions["getConfig"]).toHaveBeenCalled();
75
- expect(configActions["startSpinner"]).toHaveBeenCalledWith("Resetting configuration: defaultNetwork");
76
- expect(configActions["writeConfig"]).toHaveBeenCalledWith("defaultNetwork", undefined);
77
- expect(configActions["succeedSpinner"]).toHaveBeenCalledWith("Configuration successfully reset");
78
- });
79
-
80
- test("reset method prints failure message when key does not exist", () => {
81
- vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue({});
82
-
83
- configActions.reset("nonexistentKey");
84
-
85
- expect(configActions["getConfig"]).toHaveBeenCalled();
86
- expect(configActions["failSpinner"]).toHaveBeenCalledWith("Configuration key 'nonexistentKey' does not exist.");
87
- });
88
- });