genlayer 0.38.8 → 0.38.10

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 (205) hide show
  1. package/.eslintignore +2 -0
  2. package/.github/workflows/cli-docs.yml +124 -0
  3. package/.github/workflows/publish.yml +55 -0
  4. package/.github/workflows/smoke.yml +27 -0
  5. package/.github/workflows/validate-code.yml +51 -0
  6. package/.prettierignore +19 -0
  7. package/.prettierrc +12 -0
  8. package/.release-it.json +66 -0
  9. package/CHANGELOG.md +545 -0
  10. package/CLAUDE.md +55 -0
  11. package/CONTRIBUTING.md +117 -0
  12. package/dist/index.js +221 -62
  13. package/docs/api-references/_meta.json +9 -0
  14. package/docs/api-references/accounts/_meta.json +3 -0
  15. package/docs/api-references/accounts/account/create.mdx +19 -0
  16. package/docs/api-references/accounts/account/export.mdx +19 -0
  17. package/docs/api-references/accounts/account/import.mdx +22 -0
  18. package/docs/api-references/accounts/account/list.mdx +15 -0
  19. package/docs/api-references/accounts/account/lock.mdx +16 -0
  20. package/docs/api-references/accounts/account/remove.mdx +20 -0
  21. package/docs/api-references/accounts/account/send.mdx +24 -0
  22. package/docs/api-references/accounts/account/show.mdx +17 -0
  23. package/docs/api-references/accounts/account/unlock.mdx +17 -0
  24. package/docs/api-references/accounts/account/use.mdx +19 -0
  25. package/docs/api-references/accounts/account.mdx +32 -0
  26. package/docs/api-references/configuration/_meta.json +4 -0
  27. package/docs/api-references/configuration/config/get.mdx +21 -0
  28. package/docs/api-references/configuration/config/reset.mdx +21 -0
  29. package/docs/api-references/configuration/config/set.mdx +21 -0
  30. package/docs/api-references/configuration/config.mdx +25 -0
  31. package/docs/api-references/configuration/network/info.mdx +15 -0
  32. package/docs/api-references/configuration/network/list.mdx +15 -0
  33. package/docs/api-references/configuration/network/set.mdx +21 -0
  34. package/docs/api-references/configuration/network.mdx +25 -0
  35. package/docs/api-references/contracts/_meta.json +7 -0
  36. package/docs/api-references/contracts/call.mdx +21 -0
  37. package/docs/api-references/contracts/code.mdx +20 -0
  38. package/docs/api-references/contracts/deploy.mdx +17 -0
  39. package/docs/api-references/contracts/schema.mdx +20 -0
  40. package/docs/api-references/contracts/write.mdx +21 -0
  41. package/docs/api-references/environment/_meta.json +7 -0
  42. package/docs/api-references/environment/init.mdx +20 -0
  43. package/docs/api-references/environment/new.mdx +21 -0
  44. package/docs/api-references/environment/stop.mdx +15 -0
  45. package/docs/api-references/environment/up.mdx +20 -0
  46. package/docs/api-references/environment/update/ollama.mdx +16 -0
  47. package/docs/api-references/environment/update.mdx +23 -0
  48. package/docs/api-references/index.mdx +35 -0
  49. package/docs/api-references/localnet/_meta.json +3 -0
  50. package/docs/api-references/localnet/localnet/validators/count.mdx +15 -0
  51. package/docs/api-references/localnet/localnet/validators/create-random.mdx +16 -0
  52. package/docs/api-references/localnet/localnet/validators/create.mdx +19 -0
  53. package/docs/api-references/localnet/localnet/validators/delete.mdx +16 -0
  54. package/docs/api-references/localnet/localnet/validators/get.mdx +16 -0
  55. package/docs/api-references/localnet/localnet/validators/update.mdx +23 -0
  56. package/docs/api-references/localnet/localnet/validators.mdx +28 -0
  57. package/docs/api-references/localnet/localnet.mdx +23 -0
  58. package/docs/api-references/staking/_meta.json +3 -0
  59. package/docs/api-references/staking/staking/active-validators.mdx +18 -0
  60. package/docs/api-references/staking/staking/banned-validators.mdx +18 -0
  61. package/docs/api-references/staking/staking/delegation-info.mdx +25 -0
  62. package/docs/api-references/staking/staking/delegator-claim.mdx +26 -0
  63. package/docs/api-references/staking/staking/delegator-exit.mdx +26 -0
  64. package/docs/api-references/staking/staking/delegator-join.mdx +26 -0
  65. package/docs/api-references/staking/staking/epoch-info.mdx +19 -0
  66. package/docs/api-references/staking/staking/prime-all.mdx +20 -0
  67. package/docs/api-references/staking/staking/quarantined-validators.mdx +18 -0
  68. package/docs/api-references/staking/staking/set-identity.mdx +33 -0
  69. package/docs/api-references/staking/staking/set-operator.mdx +26 -0
  70. package/docs/api-references/staking/staking/validator-claim.mdx +24 -0
  71. package/docs/api-references/staking/staking/validator-deposit.mdx +25 -0
  72. package/docs/api-references/staking/staking/validator-exit.mdx +25 -0
  73. package/docs/api-references/staking/staking/validator-history.mdx +29 -0
  74. package/docs/api-references/staking/staking/validator-info.mdx +25 -0
  75. package/docs/api-references/staking/staking/validator-join.mdx +22 -0
  76. package/docs/api-references/staking/staking/validator-prime.mdx +25 -0
  77. package/docs/api-references/staking/staking/validators.mdx +19 -0
  78. package/docs/api-references/staking/staking/wizard.mdx +20 -0
  79. package/docs/api-references/staking/staking.mdx +42 -0
  80. package/docs/api-references/transactions/_meta.json +6 -0
  81. package/docs/api-references/transactions/appeal-bond.mdx +20 -0
  82. package/docs/api-references/transactions/appeal.mdx +21 -0
  83. package/docs/api-references/transactions/receipt.mdx +25 -0
  84. package/docs/api-references/transactions/trace.mdx +21 -0
  85. package/docs/delegator-guide.md +203 -0
  86. package/docs/validator-guide.md +329 -0
  87. package/esbuild.config.dev.js +17 -0
  88. package/esbuild.config.js +22 -0
  89. package/esbuild.config.prod.js +17 -0
  90. package/eslint.config.js +60 -0
  91. package/package.json +2 -11
  92. package/renovate.json +22 -0
  93. package/scripts/generate-cli-docs.mjs +68 -5
  94. package/src/commands/account/create.ts +30 -0
  95. package/src/commands/account/export.ts +106 -0
  96. package/src/commands/account/import.ts +135 -0
  97. package/src/commands/account/index.ts +129 -0
  98. package/src/commands/account/list.ts +34 -0
  99. package/src/commands/account/lock.ts +39 -0
  100. package/src/commands/account/remove.ts +30 -0
  101. package/src/commands/account/send.ts +162 -0
  102. package/src/commands/account/show.ts +74 -0
  103. package/src/commands/account/unlock.ts +56 -0
  104. package/src/commands/account/use.ts +21 -0
  105. package/src/commands/config/getSetReset.ts +51 -0
  106. package/src/commands/config/index.ts +30 -0
  107. package/src/commands/contracts/call.ts +39 -0
  108. package/src/commands/contracts/code.ts +33 -0
  109. package/src/commands/contracts/deploy.ts +161 -0
  110. package/src/commands/contracts/index.ts +150 -0
  111. package/src/commands/contracts/schema.ts +31 -0
  112. package/src/commands/contracts/write.ts +49 -0
  113. package/src/commands/general/index.ts +45 -0
  114. package/src/commands/general/init.ts +180 -0
  115. package/src/commands/general/start.ts +128 -0
  116. package/src/commands/general/stop.ts +26 -0
  117. package/src/commands/localnet/index.ts +100 -0
  118. package/src/commands/localnet/validators.ts +269 -0
  119. package/src/commands/network/index.ts +29 -0
  120. package/src/commands/network/setNetwork.ts +77 -0
  121. package/src/commands/scaffold/index.ts +16 -0
  122. package/src/commands/scaffold/new.ts +34 -0
  123. package/src/commands/staking/StakingAction.ts +279 -0
  124. package/src/commands/staking/delegatorClaim.ts +41 -0
  125. package/src/commands/staking/delegatorExit.ts +56 -0
  126. package/src/commands/staking/delegatorJoin.ts +44 -0
  127. package/src/commands/staking/index.ts +357 -0
  128. package/src/commands/staking/setIdentity.ts +78 -0
  129. package/src/commands/staking/setOperator.ts +46 -0
  130. package/src/commands/staking/stakingInfo.ts +584 -0
  131. package/src/commands/staking/validatorClaim.ts +43 -0
  132. package/src/commands/staking/validatorDeposit.ts +48 -0
  133. package/src/commands/staking/validatorExit.ts +63 -0
  134. package/src/commands/staking/validatorHistory.ts +300 -0
  135. package/src/commands/staking/validatorJoin.ts +47 -0
  136. package/src/commands/staking/validatorPrime.ts +73 -0
  137. package/src/commands/staking/wizard.ts +809 -0
  138. package/src/commands/transactions/appeal.ts +83 -0
  139. package/src/commands/transactions/index.ts +60 -0
  140. package/src/commands/transactions/receipt.ts +90 -0
  141. package/src/commands/transactions/trace.ts +42 -0
  142. package/src/commands/update/index.ts +25 -0
  143. package/src/commands/update/ollama.ts +103 -0
  144. package/src/lib/actions/BaseAction.ts +301 -0
  145. package/src/lib/clients/jsonRpcClient.ts +41 -0
  146. package/src/lib/clients/system.ts +73 -0
  147. package/src/lib/config/ConfigFileManager.ts +194 -0
  148. package/src/lib/config/KeychainManager.ts +89 -0
  149. package/src/lib/config/simulator.ts +68 -0
  150. package/src/lib/config/text.ts +2 -0
  151. package/src/lib/errors/missingRequirement.ts +9 -0
  152. package/src/lib/errors/versionRequired.ts +9 -0
  153. package/src/lib/interfaces/ISimulatorService.ts +39 -0
  154. package/src/lib/services/simulator.ts +386 -0
  155. package/src/types/node-fetch.d.ts +1 -0
  156. package/tests/actions/appeal.test.ts +141 -0
  157. package/tests/actions/call.test.ts +94 -0
  158. package/tests/actions/code.test.ts +87 -0
  159. package/tests/actions/create.test.ts +65 -0
  160. package/tests/actions/deploy.test.ts +420 -0
  161. package/tests/actions/getSetReset.test.ts +88 -0
  162. package/tests/actions/init.test.ts +483 -0
  163. package/tests/actions/lock.test.ts +86 -0
  164. package/tests/actions/new.test.ts +80 -0
  165. package/tests/actions/ollama.test.ts +193 -0
  166. package/tests/actions/receipt.test.ts +261 -0
  167. package/tests/actions/schema.test.ts +94 -0
  168. package/tests/actions/setNetwork.test.ts +161 -0
  169. package/tests/actions/staking.test.ts +280 -0
  170. package/tests/actions/start.test.ts +257 -0
  171. package/tests/actions/stop.test.ts +77 -0
  172. package/tests/actions/unlock.test.ts +139 -0
  173. package/tests/actions/validators.test.ts +750 -0
  174. package/tests/actions/write.test.ts +102 -0
  175. package/tests/commands/account.test.ts +146 -0
  176. package/tests/commands/appeal.test.ts +97 -0
  177. package/tests/commands/call.test.ts +78 -0
  178. package/tests/commands/code.test.ts +69 -0
  179. package/tests/commands/config.test.ts +54 -0
  180. package/tests/commands/deploy.test.ts +83 -0
  181. package/tests/commands/init.test.ts +101 -0
  182. package/tests/commands/localnet.test.ts +131 -0
  183. package/tests/commands/network.test.ts +60 -0
  184. package/tests/commands/new.test.ts +68 -0
  185. package/tests/commands/parseArg.test.ts +156 -0
  186. package/tests/commands/receipt.test.ts +142 -0
  187. package/tests/commands/schema.test.ts +67 -0
  188. package/tests/commands/staking.test.ts +329 -0
  189. package/tests/commands/stop.test.ts +27 -0
  190. package/tests/commands/up.test.ts +105 -0
  191. package/tests/commands/update.test.ts +45 -0
  192. package/tests/commands/write.test.ts +76 -0
  193. package/tests/index.test.ts +56 -0
  194. package/tests/libs/baseAction.test.ts +535 -0
  195. package/tests/libs/configFileManager.test.ts +118 -0
  196. package/tests/libs/jsonRpcClient.test.ts +59 -0
  197. package/tests/libs/keychainManager.test.ts +156 -0
  198. package/tests/libs/platformCommands.test.ts +78 -0
  199. package/tests/libs/system.test.ts +148 -0
  200. package/tests/services/simulator.test.ts +789 -0
  201. package/tests/smoke.test.ts +134 -0
  202. package/tests/utils.ts +13 -0
  203. package/tsconfig.json +120 -0
  204. package/vitest.config.ts +13 -0
  205. package/vitest.smoke.config.ts +17 -0
@@ -0,0 +1,102 @@
1
+ import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
2
+ import {createClient, createAccount} from "genlayer-js";
3
+ import {WriteAction} from "../../src/commands/contracts/write";
4
+
5
+ vi.mock("genlayer-js");
6
+
7
+ describe("WriteAction", () => {
8
+ let writeAction: WriteAction;
9
+ const mockClient = {
10
+ writeContract: vi.fn(),
11
+ waitForTransactionReceipt: vi.fn(),
12
+ initializeConsensusSmartContract: vi.fn(),
13
+ };
14
+
15
+ const mockPrivateKey = "mocked_private_key";
16
+
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ vi.mocked(createClient).mockReturnValue(mockClient as any);
20
+ vi.mocked(createAccount).mockReturnValue({privateKey: mockPrivateKey} as any);
21
+ writeAction = new WriteAction();
22
+ vi.spyOn(writeAction as any, "getAccount").mockResolvedValue({privateKey: mockPrivateKey});
23
+
24
+ vi.spyOn(writeAction as any, "startSpinner").mockImplementation(() => {});
25
+ vi.spyOn(writeAction as any, "succeedSpinner").mockImplementation(() => {});
26
+ vi.spyOn(writeAction as any, "failSpinner").mockImplementation(() => {});
27
+ vi.spyOn(writeAction as any, "log").mockImplementation(() => {});
28
+ });
29
+
30
+ afterEach(() => {
31
+ vi.restoreAllMocks();
32
+ });
33
+
34
+ test("calls writeContract successfully", async () => {
35
+ const options = {args: [42, "Update"]};
36
+ const mockHash = "0xMockedTransactionHash";
37
+ const mockReceipt = {status: "success"};
38
+
39
+ vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
40
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
41
+
42
+ await writeAction.write({
43
+ contractAddress: "0xMockedContract",
44
+ method: "updateData",
45
+ ...options,
46
+ });
47
+
48
+ expect(mockClient.writeContract).toHaveBeenCalledWith({
49
+ address: "0xMockedContract",
50
+ functionName: "updateData",
51
+ args: [42, "Update"],
52
+ value: 0n,
53
+ });
54
+ expect(writeAction["log"]).toHaveBeenCalledWith("Write Transaction Hash:", mockHash);
55
+ expect(writeAction["succeedSpinner"]).toHaveBeenCalledWith(
56
+ "Write operation successfully executed",
57
+ mockReceipt,
58
+ );
59
+ });
60
+
61
+ test("handles writeContract errors", async () => {
62
+ vi.mocked(mockClient.writeContract).mockRejectedValue(new Error("Mocked write error"));
63
+
64
+ await writeAction.write({contractAddress: "0xMockedContract", method: "updateData", args: [1]});
65
+
66
+ expect(writeAction["failSpinner"]).toHaveBeenCalledWith(
67
+ "Error during write operation",
68
+ expect.any(Error),
69
+ );
70
+ });
71
+
72
+ test("uses custom RPC URL for write operations", async () => {
73
+ const options = {args: [42, "Update"], rpc: "https://custom-rpc-url.com"};
74
+ const mockHash = "0xMockedTransactionHash";
75
+ const mockReceipt = {status: "success"};
76
+
77
+ vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
78
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
79
+
80
+ await writeAction.write({
81
+ contractAddress: "0xMockedContract",
82
+ method: "updateData",
83
+ ...options,
84
+ });
85
+
86
+ expect(createClient).toHaveBeenCalledWith(
87
+ expect.objectContaining({
88
+ endpoint: "https://custom-rpc-url.com",
89
+ }),
90
+ );
91
+ expect(mockClient.writeContract).toHaveBeenCalledWith({
92
+ address: "0xMockedContract",
93
+ functionName: "updateData",
94
+ args: [42, "Update"],
95
+ value: 0n,
96
+ });
97
+ expect(writeAction["succeedSpinner"]).toHaveBeenCalledWith(
98
+ "Write operation successfully executed",
99
+ mockReceipt,
100
+ );
101
+ });
102
+ });
@@ -0,0 +1,146 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeAccountCommands } from "../../src/commands/account";
4
+ import { CreateAccountAction } from "../../src/commands/account/create";
5
+ import { UnlockAccountAction } from "../../src/commands/account/unlock";
6
+ import { LockAccountAction } from "../../src/commands/account/lock";
7
+
8
+ vi.mock("../../src/commands/account/create");
9
+ vi.mock("../../src/commands/account/unlock");
10
+ vi.mock("../../src/commands/account/lock");
11
+ vi.mock("../../src/commands/account/show");
12
+ vi.mock("../../src/commands/account/import");
13
+ vi.mock("../../src/commands/account/send");
14
+ vi.mock("../../src/commands/account/list");
15
+ vi.mock("../../src/commands/account/use");
16
+ vi.mock("../../src/commands/account/remove");
17
+
18
+ describe("account create command", () => {
19
+ let program: Command;
20
+
21
+ beforeEach(() => {
22
+ program = new Command();
23
+ initializeAccountCommands(program);
24
+ vi.clearAllMocks();
25
+ });
26
+
27
+ afterEach(() => {
28
+ vi.restoreAllMocks();
29
+ });
30
+
31
+ test("CreateAccountAction.execute is called with name option", async () => {
32
+ program.parse(["node", "test", "account", "create", "--name", "main"]);
33
+ expect(CreateAccountAction).toHaveBeenCalledTimes(1);
34
+ expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
35
+ name: "main",
36
+ overwrite: false,
37
+ setActive: true,
38
+ });
39
+ });
40
+
41
+ test("CreateAccountAction.execute is called with custom name option", async () => {
42
+ program.parse(["node", "test", "account", "create", "--name", "validator"]);
43
+ expect(CreateAccountAction).toHaveBeenCalledTimes(1);
44
+ expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
45
+ name: "validator",
46
+ overwrite: false,
47
+ setActive: true,
48
+ });
49
+ });
50
+
51
+ test("CreateAccountAction.execute is called with overwrite enabled", async () => {
52
+ program.parse(["node", "test", "account", "create", "--name", "main", "--overwrite"]);
53
+ expect(CreateAccountAction).toHaveBeenCalledTimes(1);
54
+ expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
55
+ name: "main",
56
+ overwrite: true,
57
+ setActive: true,
58
+ });
59
+ });
60
+
61
+ test("CreateAccountAction.execute is called with no-set-active option", async () => {
62
+ program.parse(["node", "test", "account", "create", "--name", "operator", "--no-set-active"]);
63
+ expect(CreateAccountAction).toHaveBeenCalledTimes(1);
64
+ expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
65
+ name: "operator",
66
+ overwrite: false,
67
+ setActive: false,
68
+ });
69
+ });
70
+
71
+ test("CreateAccountAction is instantiated when the command is executed", async () => {
72
+ program.parse(["node", "test", "account", "create", "--name", "main"]);
73
+ expect(CreateAccountAction).toHaveBeenCalledTimes(1);
74
+ });
75
+
76
+ test("CreateAccountAction.execute is called without throwing errors", async () => {
77
+ vi.mocked(CreateAccountAction.prototype.execute).mockReturnValue(Promise.resolve());
78
+ expect(() => program.parse(["node", "test", "account", "create", "--name", "main"])).not.toThrow();
79
+ });
80
+ });
81
+
82
+ describe("account unlock command", () => {
83
+ let program: Command;
84
+
85
+ beforeEach(() => {
86
+ program = new Command();
87
+ initializeAccountCommands(program);
88
+ vi.clearAllMocks();
89
+ });
90
+
91
+ afterEach(() => {
92
+ vi.restoreAllMocks();
93
+ });
94
+
95
+ test("UnlockAccountAction is instantiated and execute is called", async () => {
96
+ program.parse(["node", "test", "account", "unlock"]);
97
+ expect(UnlockAccountAction).toHaveBeenCalledTimes(1);
98
+ expect(UnlockAccountAction.prototype.execute).toHaveBeenCalledWith({});
99
+ });
100
+
101
+ test("UnlockAccountAction.execute is called with account option", async () => {
102
+ program.parse(["node", "test", "account", "unlock", "--account", "validator"]);
103
+ expect(UnlockAccountAction).toHaveBeenCalledTimes(1);
104
+ expect(UnlockAccountAction.prototype.execute).toHaveBeenCalledWith({
105
+ account: "validator",
106
+ });
107
+ });
108
+
109
+ test("UnlockAccountAction.execute is called without throwing errors", async () => {
110
+ vi.mocked(UnlockAccountAction.prototype.execute).mockResolvedValue();
111
+ expect(() => program.parse(["node", "test", "account", "unlock"])).not.toThrow();
112
+ });
113
+ });
114
+
115
+ describe("account lock command", () => {
116
+ let program: Command;
117
+
118
+ beforeEach(() => {
119
+ program = new Command();
120
+ initializeAccountCommands(program);
121
+ vi.clearAllMocks();
122
+ });
123
+
124
+ afterEach(() => {
125
+ vi.restoreAllMocks();
126
+ });
127
+
128
+ test("LockAccountAction is instantiated and execute is called", async () => {
129
+ program.parse(["node", "test", "account", "lock"]);
130
+ expect(LockAccountAction).toHaveBeenCalledTimes(1);
131
+ expect(LockAccountAction.prototype.execute).toHaveBeenCalledWith({});
132
+ });
133
+
134
+ test("LockAccountAction.execute is called with account option", async () => {
135
+ program.parse(["node", "test", "account", "lock", "--account", "validator"]);
136
+ expect(LockAccountAction).toHaveBeenCalledTimes(1);
137
+ expect(LockAccountAction.prototype.execute).toHaveBeenCalledWith({
138
+ account: "validator",
139
+ });
140
+ });
141
+
142
+ test("LockAccountAction.execute is called without throwing errors", async () => {
143
+ vi.mocked(LockAccountAction.prototype.execute).mockResolvedValue();
144
+ expect(() => program.parse(["node", "test", "account", "lock"])).not.toThrow();
145
+ });
146
+ });
@@ -0,0 +1,97 @@
1
+ import {Command} from "commander";
2
+ import {AppealAction} from "../../src/commands/transactions/appeal";
3
+ import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
4
+ import {initializeTransactionsCommands} from "../../src/commands/transactions";
5
+
6
+ vi.mock("../../src/commands/transactions/appeal");
7
+
8
+ describe("appeal command", () => {
9
+ let program: Command;
10
+ const mockTxId = "0x1234567890123456789012345678901234567890123456789012345678901234";
11
+
12
+ beforeEach(() => {
13
+ program = new Command();
14
+ initializeTransactionsCommands(program);
15
+ vi.clearAllMocks();
16
+ });
17
+
18
+ afterEach(() => {
19
+ vi.restoreAllMocks();
20
+ });
21
+
22
+ test("AppealAction.appeal is called with default options", async () => {
23
+ program.parse(["node", "test", "appeal", mockTxId]);
24
+ expect(AppealAction).toHaveBeenCalledTimes(1);
25
+ expect(AppealAction.prototype.appeal).toHaveBeenCalledWith({
26
+ txId: mockTxId,
27
+ });
28
+ });
29
+
30
+ test("AppealAction.appeal is called with custom RPC URL", async () => {
31
+ program.parse([
32
+ "node",
33
+ "test",
34
+ "appeal",
35
+ mockTxId,
36
+ "--rpc",
37
+ "https://custom-rpc-url-for-appeal.com",
38
+ ]);
39
+ expect(AppealAction).toHaveBeenCalledTimes(1);
40
+ expect(AppealAction.prototype.appeal).toHaveBeenCalledWith({
41
+ txId: mockTxId,
42
+ rpc: "https://custom-rpc-url-for-appeal.com",
43
+ });
44
+ });
45
+
46
+ test("AppealAction.appeal is called with --bond option", async () => {
47
+ program.parse(["node", "test", "appeal", mockTxId, "--bond", "500gen"]);
48
+ expect(AppealAction.prototype.appeal).toHaveBeenCalledWith({
49
+ txId: mockTxId,
50
+ bond: "500gen",
51
+ });
52
+ });
53
+
54
+ test("AppealAction is instantiated when the appeal command is executed", async () => {
55
+ program.parse(["node", "test", "appeal", mockTxId]);
56
+ expect(AppealAction).toHaveBeenCalledTimes(1);
57
+ });
58
+
59
+ test("throws error for unrecognized options", async () => {
60
+ const appealCommand = program.commands.find(cmd => cmd.name() === "appeal");
61
+ appealCommand?.exitOverride();
62
+ expect(() =>
63
+ program.parse(["node", "test", "appeal", mockTxId, "--invalid-option"]),
64
+ ).toThrowError("error: unknown option '--invalid-option'");
65
+ });
66
+ });
67
+
68
+ describe("appeal-bond command", () => {
69
+ let program: Command;
70
+ const mockTxId = "0x1234567890123456789012345678901234567890123456789012345678901234";
71
+
72
+ beforeEach(() => {
73
+ program = new Command();
74
+ initializeTransactionsCommands(program);
75
+ vi.clearAllMocks();
76
+ });
77
+
78
+ afterEach(() => {
79
+ vi.restoreAllMocks();
80
+ });
81
+
82
+ test("AppealAction.appealBond is called with txId", async () => {
83
+ program.parse(["node", "test", "appeal-bond", mockTxId]);
84
+ expect(AppealAction).toHaveBeenCalledTimes(1);
85
+ expect(AppealAction.prototype.appealBond).toHaveBeenCalledWith({
86
+ txId: mockTxId,
87
+ });
88
+ });
89
+
90
+ test("AppealAction.appealBond is called with custom RPC URL", async () => {
91
+ program.parse(["node", "test", "appeal-bond", mockTxId, "--rpc", "https://custom.com"]);
92
+ expect(AppealAction.prototype.appealBond).toHaveBeenCalledWith({
93
+ txId: mockTxId,
94
+ rpc: "https://custom.com",
95
+ });
96
+ });
97
+ });
@@ -0,0 +1,78 @@
1
+ import { Command } from "commander";
2
+ import { CallAction } from "../../src/commands/contracts/call";
3
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
4
+ import { initializeContractsCommands } from "../../src/commands/contracts";
5
+
6
+ vi.mock("../../src/commands/contracts/call");
7
+ vi.mock("esbuild", () => ({
8
+ buildSync: vi.fn(),
9
+ }));
10
+
11
+ describe("call command", () => {
12
+ let program: Command;
13
+
14
+ beforeEach(() => {
15
+ program = new Command();
16
+ initializeContractsCommands(program);
17
+ vi.clearAllMocks();
18
+ });
19
+
20
+ afterEach(() => {
21
+ vi.restoreAllMocks();
22
+ });
23
+
24
+ test("CallAction.call is called with default options", async () => {
25
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
26
+ expect(CallAction).toHaveBeenCalledTimes(1);
27
+ expect(CallAction.prototype.call).toHaveBeenCalledWith({
28
+ contractAddress: "0xMockedContract",
29
+ method: "getData",
30
+ args: []
31
+ });
32
+ });
33
+
34
+ test("CallAction.call is called with positional arguments", async () => {
35
+ program.parse([
36
+ "node",
37
+ "test",
38
+ "call",
39
+ "0xMockedContract",
40
+ "updateData",
41
+ "--args",
42
+ "1",
43
+ "2",
44
+ "Hello",
45
+ "false",
46
+ "true",
47
+ "--rpc",
48
+ "https://custom-rpc-url.com"
49
+ ]);
50
+ expect(CallAction).toHaveBeenCalledTimes(1);
51
+ expect(CallAction.prototype.call).toHaveBeenCalledWith({
52
+ contractAddress: "0xMockedContract",
53
+ method: "updateData",
54
+ args: [1, 2, "Hello", false, true],
55
+ rpc: "https://custom-rpc-url.com"
56
+ });
57
+ });
58
+
59
+ test("CallAction is instantiated when the call command is executed", async () => {
60
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
61
+ expect(CallAction).toHaveBeenCalledTimes(1);
62
+ });
63
+
64
+ test("throws error for unrecognized options", async () => {
65
+ const callCommand = program.commands.find((cmd) => cmd.name() === "call");
66
+ callCommand?.exitOverride();
67
+ expect(() => program.parse(["node", "test", "call", "0xMockedContract", "getData", "--unknown"]))
68
+ .toThrowError("error: unknown option '--unknown'");
69
+ });
70
+
71
+ test("CallAction.call is called without throwing errors for valid options", async () => {
72
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
73
+ vi.mocked(CallAction.prototype.call).mockResolvedValueOnce(undefined);
74
+ expect(() =>
75
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"])
76
+ ).not.toThrow();
77
+ });
78
+ });
@@ -0,0 +1,69 @@
1
+ import { Command } from "commander";
2
+ import { CodeAction } from "../../src/commands/contracts/code";
3
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
4
+ import { initializeContractsCommands } from "../../src/commands/contracts";
5
+
6
+ vi.mock("../../src/commands/contracts/code");
7
+ vi.mock("esbuild", () => ({
8
+ buildSync: vi.fn(),
9
+ }));
10
+
11
+ describe("code command", () => {
12
+ let program: Command;
13
+
14
+ beforeEach(() => {
15
+ program = new Command();
16
+ initializeContractsCommands(program);
17
+ vi.clearAllMocks();
18
+ });
19
+
20
+ afterEach(() => {
21
+ vi.restoreAllMocks();
22
+ });
23
+
24
+ test("CodeAction.code is called with default options", async () => {
25
+ program.parse(["node", "test", "code", "0xMockedContract"]);
26
+ expect(CodeAction).toHaveBeenCalledTimes(1);
27
+ expect(CodeAction.prototype.code).toHaveBeenCalledWith({
28
+ contractAddress: "0xMockedContract",
29
+ });
30
+ });
31
+
32
+ test("CodeAction.code is called with custom RPC URL", async () => {
33
+ program.parse([
34
+ "node",
35
+ "test",
36
+ "code",
37
+ "0xMockedContract",
38
+ "--rpc",
39
+ "https://custom-rpc-url.com"
40
+ ]);
41
+ expect(CodeAction).toHaveBeenCalledTimes(1);
42
+ expect(CodeAction.prototype.code).toHaveBeenCalledWith({
43
+ contractAddress: "0xMockedContract",
44
+ rpc: "https://custom-rpc-url.com"
45
+ });
46
+ });
47
+
48
+ test("CodeAction is instantiated when the code command is executed", async () => {
49
+ program.parse(["node", "test", "code", "0xMockedContract"]);
50
+ expect(CodeAction).toHaveBeenCalledTimes(1);
51
+ });
52
+
53
+ test("throws error for unrecognized options", async () => {
54
+ const codeCommand = program.commands.find((cmd) => cmd.name() === "code");
55
+ codeCommand?.exitOverride();
56
+ expect(() => program.parse(["node", "test", "code", "0xMockedContract", "--unknown"]))
57
+ .toThrowError("error: unknown option '--unknown'");
58
+ });
59
+
60
+ test("CodeAction.code is called without throwing errors for valid options", async () => {
61
+ program.parse(["node", "test", "code", "0xMockedContract"]);
62
+ vi.mocked(CodeAction.prototype.code).mockResolvedValueOnce(undefined as any);
63
+ expect(() =>
64
+ program.parse(["node", "test", "code", "0xMockedContract"])
65
+ ).not.toThrow();
66
+ });
67
+ });
68
+
69
+
@@ -0,0 +1,54 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeConfigCommands } from "../../src/commands/config";
4
+ import { ConfigActions } from "../../src/commands/config/getSetReset";
5
+
6
+ vi.mock("../../src/commands/config/getSetReset");
7
+
8
+ describe("config commands", () => {
9
+ let program: Command;
10
+
11
+ beforeEach(() => {
12
+ program = new Command();
13
+ initializeConfigCommands(program);
14
+ });
15
+
16
+ afterEach(() => {
17
+ vi.restoreAllMocks();
18
+ });
19
+
20
+ test("ConfigActions.set is called with the correct key-value pair", async () => {
21
+ program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
22
+ expect(ConfigActions).toHaveBeenCalledTimes(1);
23
+ expect(ConfigActions.prototype.set).toHaveBeenCalledWith("defaultNetwork=testnet");
24
+ });
25
+
26
+ test("ConfigActions.get is called with a specific key", async () => {
27
+ program.parse(["node", "test", "config", "get", "defaultNetwork"]);
28
+ expect(ConfigActions).toHaveBeenCalledTimes(1);
29
+ expect(ConfigActions.prototype.get).toHaveBeenCalledWith("defaultNetwork");
30
+ });
31
+
32
+ test("ConfigActions.get is called without a key", async () => {
33
+ program.parse(["node", "test", "config", "get"]);
34
+ expect(ConfigActions).toHaveBeenCalledTimes(1);
35
+ expect(ConfigActions.prototype.get).toHaveBeenCalledWith(undefined);
36
+ });
37
+
38
+ test("ConfigActions.reset is called with the correct key", async () => {
39
+ program.parse(["node", "test", "config", "reset", "defaultNetwork"]);
40
+ expect(ConfigActions).toHaveBeenCalledTimes(1);
41
+ expect(ConfigActions.prototype.reset).toHaveBeenCalledWith("defaultNetwork");
42
+ });
43
+
44
+ test("ConfigActions is instantiated when the command is executed", async () => {
45
+ program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
46
+ expect(ConfigActions).toHaveBeenCalledTimes(1);
47
+ });
48
+
49
+ test("ConfigActions.set is called without throwing errors for valid input", async () => {
50
+ program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
51
+ vi.mocked(ConfigActions.prototype.set).mockReturnValue();
52
+ expect(() => program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"])).not.toThrow();
53
+ });
54
+ });
@@ -0,0 +1,83 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeContractsCommands } from "../../src/commands/contracts";
4
+ import { DeployAction } from "../../src/commands/contracts/deploy";
5
+
6
+ vi.mock("../../src/commands/contracts/deploy");
7
+ vi.mock("esbuild", () => ({
8
+ buildSync: vi.fn(),
9
+ }));
10
+
11
+ describe("deploy command", () => {
12
+ let program: Command;
13
+
14
+ beforeEach(() => {
15
+ program = new Command();
16
+ initializeContractsCommands(program);
17
+ vi.clearAllMocks();
18
+ });
19
+
20
+ afterEach(() => {
21
+ vi.restoreAllMocks();
22
+ });
23
+
24
+ test("DeployAction.deploy is called with default options", async () => {
25
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
26
+ expect(DeployAction).toHaveBeenCalledTimes(1);
27
+ expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
28
+ contract: "./path/to/contract",
29
+ args: [],
30
+ });
31
+ });
32
+
33
+ test("DeployAction.deploy is called with positional arguments", async () => {
34
+ program.parse([
35
+ "node",
36
+ "test",
37
+ "deploy",
38
+ "--contract",
39
+ "./path/to/contract",
40
+ "--args",
41
+ "1",
42
+ "2",
43
+ "3",
44
+ "--rpc",
45
+ "https://custom-rpc-url.com"
46
+ ]);
47
+ expect(DeployAction).toHaveBeenCalledTimes(1);
48
+ expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
49
+ contract: "./path/to/contract",
50
+ args: [1, 2, 3],
51
+ rpc: "https://custom-rpc-url.com"
52
+ });
53
+ });
54
+
55
+ test("DeployAction is instantiated when the deploy command is executed", async () => {
56
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
57
+ expect(DeployAction).toHaveBeenCalledTimes(1);
58
+ });
59
+
60
+ test("throws error for unrecognized options", async () => {
61
+ const deployCommand = program.commands.find((cmd) => cmd.name() === "deploy");
62
+ deployCommand?.exitOverride();
63
+ expect(() => program.parse(["node", "test", "deploy", "--unknown"])).toThrowError(
64
+ "error: unknown option '--unknown'"
65
+ );
66
+ });
67
+
68
+ test("DeployAction.deploy is called without throwing errors for valid options", async () => {
69
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
70
+ vi.mocked(DeployAction.prototype.deploy).mockResolvedValueOnce(undefined);
71
+ expect(() =>
72
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"])
73
+ ).not.toThrow();
74
+ });
75
+
76
+ test("DeployAction.deployScripts is called without throwing errors", async () => {
77
+ program.parse(["node", "test", "deploy"]);
78
+ vi.mocked(DeployAction.prototype.deployScripts).mockResolvedValueOnce(undefined);
79
+ expect(() =>
80
+ program.parse(["node", "test", "deploy"])
81
+ ).not.toThrow();
82
+ });
83
+ });