genlayer 0.38.9 → 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,67 @@
1
+ import { Command } from "commander";
2
+ import { SchemaAction } from "../../src/commands/contracts/schema";
3
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
4
+ import { initializeContractsCommands } from "../../src/commands/contracts";
5
+
6
+ vi.mock("../../src/commands/contracts/schema");
7
+ vi.mock("esbuild", () => ({
8
+ buildSync: vi.fn(),
9
+ }));
10
+
11
+ describe("schema 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("SchemaAction.schema is called with default options", async () => {
25
+ program.parse(["node", "test", "schema", "0xMockedContract"]);
26
+ expect(SchemaAction).toHaveBeenCalledTimes(1);
27
+ expect(SchemaAction.prototype.schema).toHaveBeenCalledWith({
28
+ contractAddress: "0xMockedContract",
29
+ });
30
+ });
31
+
32
+ test("SchemaAction.schema is called with custom RPC URL", async () => {
33
+ program.parse([
34
+ "node",
35
+ "test",
36
+ "schema",
37
+ "0xMockedContract",
38
+ "--rpc",
39
+ "https://custom-rpc-url.com"
40
+ ]);
41
+ expect(SchemaAction).toHaveBeenCalledTimes(1);
42
+ expect(SchemaAction.prototype.schema).toHaveBeenCalledWith({
43
+ contractAddress: "0xMockedContract",
44
+ rpc: "https://custom-rpc-url.com"
45
+ });
46
+ });
47
+
48
+ test("SchemaAction is instantiated when the schema command is executed", async () => {
49
+ program.parse(["node", "test", "schema", "0xMockedContract"]);
50
+ expect(SchemaAction).toHaveBeenCalledTimes(1);
51
+ });
52
+
53
+ test("throws error for unrecognized options", async () => {
54
+ const schemaCommand = program.commands.find((cmd) => cmd.name() === "schema");
55
+ schemaCommand?.exitOverride();
56
+ expect(() => program.parse(["node", "test", "schema", "0xMockedContract", "--unknown"]))
57
+ .toThrowError("error: unknown option '--unknown'");
58
+ });
59
+
60
+ test("SchemaAction.schema is called without throwing errors for valid options", async () => {
61
+ program.parse(["node", "test", "schema", "0xMockedContract"]);
62
+ vi.mocked(SchemaAction.prototype.schema).mockResolvedValueOnce(undefined);
63
+ expect(() =>
64
+ program.parse(["node", "test", "schema", "0xMockedContract"])
65
+ ).not.toThrow();
66
+ });
67
+ });
@@ -0,0 +1,329 @@
1
+ import {Command} from "commander";
2
+ import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
3
+ import {initializeStakingCommands} from "../../src/commands/staking";
4
+ import {ValidatorJoinAction} from "../../src/commands/staking/validatorJoin";
5
+ import {ValidatorDepositAction} from "../../src/commands/staking/validatorDeposit";
6
+ import {ValidatorExitAction} from "../../src/commands/staking/validatorExit";
7
+ import {ValidatorClaimAction} from "../../src/commands/staking/validatorClaim";
8
+ import {ValidatorPrimeAction} from "../../src/commands/staking/validatorPrime";
9
+ import {SetOperatorAction} from "../../src/commands/staking/setOperator";
10
+ import {SetIdentityAction} from "../../src/commands/staking/setIdentity";
11
+ import {DelegatorJoinAction} from "../../src/commands/staking/delegatorJoin";
12
+ import {DelegatorExitAction} from "../../src/commands/staking/delegatorExit";
13
+ import {DelegatorClaimAction} from "../../src/commands/staking/delegatorClaim";
14
+ import {StakingInfoAction} from "../../src/commands/staking/stakingInfo";
15
+
16
+ vi.mock("../../src/commands/staking/validatorJoin");
17
+ vi.mock("../../src/commands/staking/validatorDeposit");
18
+ vi.mock("../../src/commands/staking/validatorExit");
19
+ vi.mock("../../src/commands/staking/validatorClaim");
20
+ vi.mock("../../src/commands/staking/validatorPrime");
21
+ vi.mock("../../src/commands/staking/setOperator");
22
+ vi.mock("../../src/commands/staking/setIdentity");
23
+ vi.mock("../../src/commands/staking/delegatorJoin");
24
+ vi.mock("../../src/commands/staking/delegatorExit");
25
+ vi.mock("../../src/commands/staking/delegatorClaim");
26
+ vi.mock("../../src/commands/staking/stakingInfo");
27
+
28
+ describe("staking commands", () => {
29
+ let program: Command;
30
+
31
+ beforeEach(() => {
32
+ program = new Command();
33
+ initializeStakingCommands(program);
34
+ vi.clearAllMocks();
35
+ });
36
+
37
+ afterEach(() => {
38
+ vi.restoreAllMocks();
39
+ });
40
+
41
+ describe("validator-join", () => {
42
+ test("calls ValidatorJoinAction.execute with amount", async () => {
43
+ program.parse(["node", "test", "staking", "validator-join", "--amount", "42000gen"]);
44
+
45
+ expect(ValidatorJoinAction).toHaveBeenCalledTimes(1);
46
+ expect(ValidatorJoinAction.prototype.execute).toHaveBeenCalledWith({
47
+ amount: "42000gen",
48
+ });
49
+ });
50
+
51
+ test("calls ValidatorJoinAction.execute with operator", async () => {
52
+ program.parse([
53
+ "node",
54
+ "test",
55
+ "staking",
56
+ "validator-join",
57
+ "--amount",
58
+ "42000gen",
59
+ "--operator",
60
+ "0xOperator",
61
+ ]);
62
+
63
+ expect(ValidatorJoinAction.prototype.execute).toHaveBeenCalledWith({
64
+ amount: "42000gen",
65
+ operator: "0xOperator",
66
+ });
67
+ });
68
+
69
+ test("accepts staking-address option", async () => {
70
+ program.parse([
71
+ "node",
72
+ "test",
73
+ "staking",
74
+ "validator-join",
75
+ "--amount",
76
+ "42000",
77
+ "--staking-address",
78
+ "0xStaking",
79
+ ]);
80
+
81
+ expect(ValidatorJoinAction.prototype.execute).toHaveBeenCalledWith(
82
+ expect.objectContaining({stakingAddress: "0xStaking"}),
83
+ );
84
+ });
85
+ });
86
+
87
+ describe("validator-deposit", () => {
88
+ test("calls ValidatorDepositAction.execute", async () => {
89
+ program.parse(["node", "test", "staking", "validator-deposit", "--validator", "0x1234567890123456789012345678901234567890", "--amount", "1000gen"]);
90
+
91
+ expect(ValidatorDepositAction).toHaveBeenCalledTimes(1);
92
+ expect(ValidatorDepositAction.prototype.execute).toHaveBeenCalledWith({
93
+ validator: "0x1234567890123456789012345678901234567890",
94
+ amount: "1000gen",
95
+ });
96
+ });
97
+ });
98
+
99
+ describe("validator-exit", () => {
100
+ test("calls ValidatorExitAction.execute", async () => {
101
+ program.parse(["node", "test", "staking", "validator-exit", "--validator", "0x1234567890123456789012345678901234567890", "--shares", "100"]);
102
+
103
+ expect(ValidatorExitAction).toHaveBeenCalledTimes(1);
104
+ expect(ValidatorExitAction.prototype.execute).toHaveBeenCalledWith({
105
+ validator: "0x1234567890123456789012345678901234567890",
106
+ shares: "100",
107
+ });
108
+ });
109
+ });
110
+
111
+ describe("validator-claim", () => {
112
+ test("calls ValidatorClaimAction.execute", async () => {
113
+ program.parse(["node", "test", "staking", "validator-claim", "--validator", "0xValidator"]);
114
+
115
+ expect(ValidatorClaimAction).toHaveBeenCalledTimes(1);
116
+ expect(ValidatorClaimAction.prototype.execute).toHaveBeenCalledWith({
117
+ validator: "0xValidator",
118
+ });
119
+ });
120
+ });
121
+
122
+ describe("delegator-join", () => {
123
+ test("calls DelegatorJoinAction.execute", async () => {
124
+ program.parse([
125
+ "node",
126
+ "test",
127
+ "staking",
128
+ "delegator-join",
129
+ "--validator",
130
+ "0xValidator",
131
+ "--amount",
132
+ "42gen",
133
+ ]);
134
+
135
+ expect(DelegatorJoinAction).toHaveBeenCalledTimes(1);
136
+ expect(DelegatorJoinAction.prototype.execute).toHaveBeenCalledWith({
137
+ validator: "0xValidator",
138
+ amount: "42gen",
139
+ });
140
+ });
141
+ });
142
+
143
+ describe("delegator-exit", () => {
144
+ test("calls DelegatorExitAction.execute", async () => {
145
+ program.parse([
146
+ "node",
147
+ "test",
148
+ "staking",
149
+ "delegator-exit",
150
+ "--validator",
151
+ "0xValidator",
152
+ "--shares",
153
+ "50",
154
+ ]);
155
+
156
+ expect(DelegatorExitAction).toHaveBeenCalledTimes(1);
157
+ expect(DelegatorExitAction.prototype.execute).toHaveBeenCalledWith({
158
+ validator: "0xValidator",
159
+ shares: "50",
160
+ });
161
+ });
162
+ });
163
+
164
+ describe("delegator-claim", () => {
165
+ test("calls DelegatorClaimAction.execute", async () => {
166
+ program.parse([
167
+ "node",
168
+ "test",
169
+ "staking",
170
+ "delegator-claim",
171
+ "--validator",
172
+ "0xValidator",
173
+ "--delegator",
174
+ "0xDelegator",
175
+ ]);
176
+
177
+ expect(DelegatorClaimAction).toHaveBeenCalledTimes(1);
178
+ expect(DelegatorClaimAction.prototype.execute).toHaveBeenCalledWith({
179
+ validator: "0xValidator",
180
+ delegator: "0xDelegator",
181
+ });
182
+ });
183
+ });
184
+
185
+ describe("validator-info", () => {
186
+ test("calls StakingInfoAction.getValidatorInfo", async () => {
187
+ program.parse(["node", "test", "staking", "validator-info", "--validator", "0xValidator"]);
188
+
189
+ expect(StakingInfoAction).toHaveBeenCalledTimes(1);
190
+ expect(StakingInfoAction.prototype.getValidatorInfo).toHaveBeenCalledWith({
191
+ validator: "0xValidator",
192
+ });
193
+ });
194
+ });
195
+
196
+ describe("epoch-info", () => {
197
+ test("calls StakingInfoAction.getEpochInfo", async () => {
198
+ program.parse(["node", "test", "staking", "epoch-info"]);
199
+
200
+ expect(StakingInfoAction).toHaveBeenCalledTimes(1);
201
+ expect(StakingInfoAction.prototype.getEpochInfo).toHaveBeenCalledWith({});
202
+ });
203
+ });
204
+
205
+ describe("active-validators", () => {
206
+ test("calls StakingInfoAction.listActiveValidators", async () => {
207
+ program.parse(["node", "test", "staking", "active-validators"]);
208
+
209
+ expect(StakingInfoAction).toHaveBeenCalledTimes(1);
210
+ expect(StakingInfoAction.prototype.listActiveValidators).toHaveBeenCalledWith({});
211
+ });
212
+ });
213
+
214
+ describe("validator-prime", () => {
215
+ test("calls ValidatorPrimeAction.execute", async () => {
216
+ program.parse(["node", "test", "staking", "validator-prime", "--validator", "0xValidator"]);
217
+
218
+ expect(ValidatorPrimeAction).toHaveBeenCalledTimes(1);
219
+ expect(ValidatorPrimeAction.prototype.execute).toHaveBeenCalledWith({
220
+ validator: "0xValidator",
221
+ });
222
+ });
223
+ });
224
+
225
+ describe("set-operator", () => {
226
+ test("calls SetOperatorAction.execute", async () => {
227
+ program.parse([
228
+ "node",
229
+ "test",
230
+ "staking",
231
+ "set-operator",
232
+ "--validator",
233
+ "0xValidator",
234
+ "--operator",
235
+ "0xOperator",
236
+ ]);
237
+
238
+ expect(SetOperatorAction).toHaveBeenCalledTimes(1);
239
+ expect(SetOperatorAction.prototype.execute).toHaveBeenCalledWith({
240
+ validator: "0xValidator",
241
+ operator: "0xOperator",
242
+ });
243
+ });
244
+ });
245
+
246
+ describe("set-identity", () => {
247
+ test("calls SetIdentityAction.execute with required fields", async () => {
248
+ program.parse([
249
+ "node",
250
+ "test",
251
+ "staking",
252
+ "set-identity",
253
+ "--validator",
254
+ "0xValidator",
255
+ "--moniker",
256
+ "My Validator",
257
+ ]);
258
+
259
+ expect(SetIdentityAction).toHaveBeenCalledTimes(1);
260
+ expect(SetIdentityAction.prototype.execute).toHaveBeenCalledWith({
261
+ validator: "0xValidator",
262
+ moniker: "My Validator",
263
+ });
264
+ });
265
+
266
+ test("calls SetIdentityAction.execute with all optional fields", async () => {
267
+ program.parse([
268
+ "node",
269
+ "test",
270
+ "staking",
271
+ "set-identity",
272
+ "--validator",
273
+ "0xValidator",
274
+ "--moniker",
275
+ "My Validator",
276
+ "--website",
277
+ "https://example.com",
278
+ "--twitter",
279
+ "myhandle",
280
+ "--github",
281
+ "mygithub",
282
+ ]);
283
+
284
+ expect(SetIdentityAction.prototype.execute).toHaveBeenCalledWith({
285
+ validator: "0xValidator",
286
+ moniker: "My Validator",
287
+ website: "https://example.com",
288
+ twitter: "myhandle",
289
+ github: "mygithub",
290
+ });
291
+ });
292
+ });
293
+
294
+ describe("delegation-info", () => {
295
+ test("calls StakingInfoAction.getStakeInfo", async () => {
296
+ program.parse([
297
+ "node",
298
+ "test",
299
+ "staking",
300
+ "delegation-info",
301
+ "--validator",
302
+ "0xValidator",
303
+ ]);
304
+
305
+ expect(StakingInfoAction).toHaveBeenCalledTimes(1);
306
+ expect(StakingInfoAction.prototype.getStakeInfo).toHaveBeenCalledWith({
307
+ validator: "0xValidator",
308
+ });
309
+ });
310
+
311
+ test("calls StakingInfoAction.getStakeInfo with delegator", async () => {
312
+ program.parse([
313
+ "node",
314
+ "test",
315
+ "staking",
316
+ "delegation-info",
317
+ "--validator",
318
+ "0xValidator",
319
+ "--delegator",
320
+ "0xDelegator",
321
+ ]);
322
+
323
+ expect(StakingInfoAction.prototype.getStakeInfo).toHaveBeenCalledWith({
324
+ validator: "0xValidator",
325
+ delegator: "0xDelegator",
326
+ });
327
+ });
328
+ });
329
+ });
@@ -0,0 +1,27 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeGeneralCommands } from "../../src/commands/general";
4
+ import { StopAction } from "../../src/commands/general/stop";
5
+
6
+ vi.mock("../../src/commands/general/stop");
7
+
8
+ describe("stop command", () => {
9
+ let program: Command;
10
+
11
+ beforeEach(() => {
12
+ program = new Command();
13
+ initializeGeneralCommands(program);
14
+
15
+ vi.clearAllMocks();
16
+ });
17
+
18
+ afterEach(() => {
19
+ vi.restoreAllMocks();
20
+ });
21
+
22
+ test("doesn't require arguments or options", async () => {
23
+ expect(() => program.parse(["node", "test", "stop"])).not.toThrow();
24
+ expect(StopAction).toHaveBeenCalledTimes(1);
25
+ expect(StopAction.prototype.stop).toHaveBeenCalledWith();
26
+ });
27
+ });
@@ -0,0 +1,105 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeGeneralCommands } from "../../src/commands/general";
4
+ import { getCommand, getCommandOption } from "../utils";
5
+ import { StartAction } from "../../src/commands/general/start";
6
+
7
+ vi.mock("../../src/commands/general/start");
8
+
9
+ describe("up command", () => {
10
+ let upCommand: Command;
11
+ let program: Command;
12
+
13
+ beforeEach(() => {
14
+ program = new Command();
15
+ initializeGeneralCommands(program);
16
+
17
+ upCommand = getCommand(program, "up");
18
+ vi.clearAllMocks();
19
+ });
20
+
21
+ afterEach(() => {
22
+ vi.restoreAllMocks();
23
+ });
24
+
25
+ test("doesn't require arguments or options", async () => {
26
+ expect(() => program.parse(["node", "test", "up"])).not.toThrow();
27
+ expect(StartAction).toHaveBeenCalledTimes(1);
28
+ expect(StartAction.prototype.execute).toHaveBeenCalledWith(
29
+ expect.objectContaining({
30
+ resetValidators: false,
31
+ numValidators: "5",
32
+ headless: false,
33
+ resetDb: false,
34
+ ollama: false,
35
+ })
36
+ );
37
+ });
38
+
39
+ test("option --reset-validators is accepted", async () => {
40
+ expect(() => program.parse(["node", "test", "up", "--reset-validators"])).not.toThrow();
41
+ });
42
+
43
+ test("option --reset-validators default value is false", async () => {
44
+ const resetValidatorsOption = getCommandOption(upCommand, "--reset-validators");
45
+ expect(resetValidatorsOption?.defaultValue).toBe(false);
46
+ });
47
+
48
+ test("option --numValidators is accepted", async () => {
49
+ expect(() => program.parse(["node", "test", "up", "--numValidators", "10"])).not.toThrow();
50
+ });
51
+
52
+ test("option --numValidators default value is 5", async () => {
53
+ const numValidatorsOption = getCommandOption(upCommand, "--numValidators");
54
+ expect(numValidatorsOption?.defaultValue).toBe("5");
55
+ });
56
+
57
+ test("unrecognized option is not accepted", async () => {
58
+ upCommand?.exitOverride();
59
+ expect(() => program.parse(["node", "test", "up", "-unknown"])).toThrowError(
60
+ "error: unknown option '-unknown'"
61
+ );
62
+ expect(() => program.parse(["node", "test", "up", "--unknownOption"])).toThrowError(
63
+ "error: unknown option '--unknownOption'"
64
+ );
65
+ });
66
+
67
+ test("action is called with default options", async () => {
68
+ program.parse(["node", "test", "up"]);
69
+ expect(StartAction).toHaveBeenCalledTimes(1);
70
+ expect(StartAction.prototype.execute).toHaveBeenCalledWith(
71
+ expect.objectContaining({
72
+ resetValidators: false,
73
+ numValidators: "5",
74
+ headless: false,
75
+ resetDb: false,
76
+ ollama: false,
77
+ })
78
+ );
79
+ });
80
+
81
+ test("action is called with custom options", async () => {
82
+ program.parse([
83
+ "node",
84
+ "test",
85
+ "up",
86
+ "--reset-validators",
87
+ "--numValidators",
88
+ "10",
89
+ "--headless",
90
+ "--reset-db",
91
+ "--ollama",
92
+ ]);
93
+
94
+ expect(StartAction).toHaveBeenCalledTimes(1);
95
+ expect(StartAction.prototype.execute).toHaveBeenCalledWith(
96
+ expect.objectContaining({
97
+ resetValidators: true,
98
+ numValidators: "10",
99
+ headless: true,
100
+ resetDb: true,
101
+ ollama: true,
102
+ })
103
+ );
104
+ });
105
+ });
@@ -0,0 +1,45 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeUpdateCommands } from "../../src/commands/update";
4
+ import { OllamaAction } from "../../src/commands/update/ollama";
5
+
6
+ vi.mock("../../src/commands/update/ollama");
7
+
8
+ describe("ollama command", () => {
9
+ let program: Command;
10
+
11
+ beforeEach(() => {
12
+ program = new Command();
13
+ initializeUpdateCommands(program);
14
+
15
+ const mockConfig = { defaultOllamaModel: "default-model" };
16
+ });
17
+
18
+ afterEach(() => {
19
+ vi.restoreAllMocks();
20
+ });
21
+
22
+ test("OllamaAction.updateModel is called with model option", async () => {
23
+ program.parse(["node", "test", "update", "ollama", "--model", "mocked_model"]);
24
+ expect(OllamaAction).toHaveBeenCalledTimes(1);
25
+ expect(OllamaAction.prototype.updateModel).toHaveBeenCalledWith("mocked_model");
26
+ });
27
+
28
+ test("OllamaAction.updateModel is called with default model", async () => {
29
+ program.parse(["node", "test", "update", "ollama"]);
30
+ expect(OllamaAction).toHaveBeenCalledTimes(1);
31
+ expect(OllamaAction.prototype.updateModel).toHaveBeenCalledWith("");
32
+ });
33
+
34
+ test("OllamaAction.removeModel is called with model option", async () => {
35
+ program.parse(["node", "test", "update", "ollama", "--model", "mocked_model", "--remove"]);
36
+ expect(OllamaAction).toHaveBeenCalledTimes(1);
37
+ expect(OllamaAction.prototype.removeModel).toHaveBeenCalledWith("mocked_model");
38
+ });
39
+
40
+ test("OllamaAction.removeModel is called with default model", async () => {
41
+ program.parse(["node", "test", "update", "ollama", "--remove"]);
42
+ expect(OllamaAction).toHaveBeenCalledTimes(1);
43
+ expect(OllamaAction.prototype.removeModel).toHaveBeenCalledWith("");
44
+ });
45
+ });
@@ -0,0 +1,76 @@
1
+ import {Command} from "commander";
2
+ import {WriteAction} from "../../src/commands/contracts/write";
3
+ import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
4
+ import {initializeContractsCommands} from "../../src/commands/contracts";
5
+
6
+ vi.mock("../../src/commands/contracts/write");
7
+ vi.mock("esbuild", () => ({
8
+ buildSync: vi.fn(),
9
+ }));
10
+
11
+ describe("write 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("WriteAction.write is called with default options", async () => {
25
+ program.parse(["node", "test", "write", "0xMockedContract", "setData"]);
26
+ expect(WriteAction).toHaveBeenCalledTimes(1);
27
+ expect(WriteAction.prototype.write).toHaveBeenCalledWith({
28
+ contractAddress: "0xMockedContract",
29
+ method: "setData",
30
+ args: [],
31
+ });
32
+ });
33
+
34
+ test("WriteAction.write is called with positional arguments and options", async () => {
35
+ program.parse([
36
+ "node",
37
+ "test",
38
+ "write",
39
+ "0xMockedContract",
40
+ "updateCounter",
41
+ "--args",
42
+ "100",
43
+ "someString",
44
+ "true",
45
+ "--rpc",
46
+ "https://custom-rpc-url-for-write.com",
47
+ ]);
48
+ expect(WriteAction).toHaveBeenCalledTimes(1);
49
+ expect(WriteAction.prototype.write).toHaveBeenCalledWith({
50
+ contractAddress: "0xMockedContract",
51
+ method: "updateCounter",
52
+ args: [100, "someString", true],
53
+ rpc: "https://custom-rpc-url-for-write.com",
54
+ });
55
+ });
56
+
57
+ test("WriteAction is instantiated when the write command is executed", async () => {
58
+ program.parse(["node", "test", "write", "0xMockedContract", "anotherMethod"]);
59
+ expect(WriteAction).toHaveBeenCalledTimes(1);
60
+ });
61
+
62
+ test("throws error for unrecognized options", async () => {
63
+ const writeCommand = program.commands.find(cmd => cmd.name() === "write");
64
+ writeCommand?.exitOverride();
65
+ expect(() =>
66
+ program.parse(["node", "test", "write", "0xMockedContract", "someMethod", "--invalid-option"]),
67
+ ).toThrowError("error: unknown option '--invalid-option'");
68
+ });
69
+
70
+ test("WriteAction.write is called without throwing errors for valid options", async () => {
71
+ program.parse(["node", "test", "write", "0xMockedContract", "validMethod"]);
72
+ vi.mocked(WriteAction.prototype.write).mockResolvedValueOnce(undefined);
73
+ // Need to parse again inside expect to ensure the mockResolvedValueOnce is used for the assertion context
74
+ expect(() => program.parse(["node", "test", "write", "0xMockedContract", "validMethod"])).not.toThrow();
75
+ });
76
+ });