genlayer 0.12.1 → 0.12.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-beta.yml +2 -2
- package/.github/workflows/publish.yml +2 -2
- package/.github/workflows/validate-code.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.js +24736 -108331
- package/docker-compose.yml +1 -1
- package/esbuild.config.dev.js +18 -0
- package/esbuild.config.js +10 -5
- package/esbuild.config.prod.js +16 -0
- package/eslint.config.js +59 -0
- package/package.json +12 -9
- package/scripts/postinstall.js +10 -6
- package/src/commands/config/getSetReset.ts +25 -18
- package/src/commands/contracts/deploy.ts +105 -25
- package/src/commands/contracts/index.ts +5 -1
- package/src/commands/general/index.ts +10 -4
- package/src/commands/general/init.ts +136 -189
- package/src/commands/general/start.ts +76 -77
- package/src/commands/general/stop.ts +6 -5
- package/src/commands/keygen/create.ts +9 -11
- package/src/commands/update/index.ts +3 -8
- package/src/commands/update/ollama.ts +56 -56
- package/src/commands/validators/validators.ts +48 -55
- package/src/lib/actions/BaseAction.ts +75 -4
- package/src/lib/config/simulator.ts +1 -1
- package/src/lib/services/simulator.ts +3 -2
- package/tests/actions/create.test.ts +18 -30
- package/tests/actions/deploy.test.ts +200 -30
- package/tests/actions/getSetReset.test.ts +29 -42
- package/tests/actions/init.test.ts +240 -475
- package/tests/actions/ollama.test.ts +40 -55
- package/tests/actions/start.test.ts +107 -108
- package/tests/actions/stop.test.ts +23 -4
- package/tests/actions/validators.test.ts +273 -142
- package/tests/commands/call.test.ts +4 -1
- package/tests/commands/deploy.test.ts +11 -0
- package/tests/commands/init.test.ts +11 -12
- package/tests/commands/up.test.ts +31 -23
- package/tests/commands/update.test.ts +2 -5
- package/tests/libs/baseAction.test.ts +175 -0
- package/tests/services/simulator.test.ts +15 -0
- package/.eslintrc.js +0 -58
- package/esbuild.config.dev +0 -16
- package/esbuild.config.prod +0 -16
|
@@ -17,6 +17,15 @@ describe("ValidatorsAction", () => {
|
|
|
17
17
|
beforeEach(() => {
|
|
18
18
|
vi.clearAllMocks();
|
|
19
19
|
validatorsAction = new ValidatorsAction();
|
|
20
|
+
|
|
21
|
+
vi.spyOn(validatorsAction as any, "logSuccess").mockImplementation(() => {});
|
|
22
|
+
vi.spyOn(validatorsAction as any, "logError").mockImplementation(() => {});
|
|
23
|
+
vi.spyOn(validatorsAction as any, "startSpinner").mockImplementation(() => {});
|
|
24
|
+
vi.spyOn(validatorsAction as any, "succeedSpinner").mockImplementation(() => {});
|
|
25
|
+
vi.spyOn(validatorsAction as any, "failSpinner").mockImplementation(() => {});
|
|
26
|
+
vi.spyOn(validatorsAction as any, "log").mockImplementation(() => {});
|
|
27
|
+
vi.spyOn(validatorsAction as any, "stopSpinner").mockImplementation(() => {});
|
|
28
|
+
vi.spyOn(validatorsAction as any, "setSpinnerText").mockImplementation(() => {});
|
|
20
29
|
});
|
|
21
30
|
|
|
22
31
|
afterEach(() => {
|
|
@@ -29,30 +38,44 @@ describe("ValidatorsAction", () => {
|
|
|
29
38
|
const mockResponse = { result: { id: 1, name: "Validator1" } };
|
|
30
39
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
31
40
|
|
|
32
|
-
console.log = vi.fn();
|
|
33
|
-
|
|
34
41
|
await validatorsAction.getValidator({ address: mockAddress });
|
|
35
42
|
|
|
43
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(
|
|
44
|
+
`Fetching validator with address: ${mockAddress}`
|
|
45
|
+
);
|
|
46
|
+
|
|
36
47
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
37
48
|
method: "sim_getValidator",
|
|
38
49
|
params: [mockAddress],
|
|
39
50
|
});
|
|
40
|
-
|
|
51
|
+
|
|
52
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
53
|
+
`Successfully fetched validator with address: ${mockAddress}`,
|
|
54
|
+
mockResponse.result
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
41
58
|
});
|
|
42
59
|
|
|
43
60
|
test("should fetch all validators when no address is provided", async () => {
|
|
44
61
|
const mockResponse = { result: [{ id: 1 }, { id: 2 }] };
|
|
45
62
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
46
63
|
|
|
47
|
-
console.log = vi.fn();
|
|
48
|
-
|
|
49
64
|
await validatorsAction.getValidator({});
|
|
50
65
|
|
|
66
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching all validators...");
|
|
67
|
+
|
|
51
68
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
52
69
|
method: "sim_getAllValidators",
|
|
53
70
|
params: [],
|
|
54
71
|
});
|
|
55
|
-
|
|
72
|
+
|
|
73
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
74
|
+
"Successfully fetched all validators.",
|
|
75
|
+
mockResponse.result
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
56
79
|
});
|
|
57
80
|
|
|
58
81
|
test("should log an error if an exception occurs while fetching a specific validator", async () => {
|
|
@@ -61,15 +84,19 @@ describe("ValidatorsAction", () => {
|
|
|
61
84
|
|
|
62
85
|
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
63
86
|
|
|
64
|
-
console.error = vi.fn();
|
|
65
|
-
|
|
66
87
|
await validatorsAction.getValidator({ address: mockAddress });
|
|
67
88
|
|
|
89
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(
|
|
90
|
+
`Fetching validator with address: ${mockAddress}`
|
|
91
|
+
);
|
|
92
|
+
|
|
68
93
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
69
94
|
method: "sim_getValidator",
|
|
70
95
|
params: [mockAddress],
|
|
71
96
|
});
|
|
72
|
-
|
|
97
|
+
|
|
98
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error fetching validators", mockError);
|
|
99
|
+
expect(validatorsAction["succeedSpinner"]).not.toHaveBeenCalled();
|
|
73
100
|
});
|
|
74
101
|
|
|
75
102
|
test("should log an error if an exception occurs while fetching all validators", async () => {
|
|
@@ -77,63 +104,78 @@ describe("ValidatorsAction", () => {
|
|
|
77
104
|
|
|
78
105
|
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
79
106
|
|
|
80
|
-
console.error = vi.fn();
|
|
81
|
-
|
|
82
107
|
await validatorsAction.getValidator({});
|
|
83
108
|
|
|
109
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching all validators...");
|
|
110
|
+
|
|
84
111
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
85
112
|
method: "sim_getAllValidators",
|
|
86
113
|
params: [],
|
|
87
114
|
});
|
|
88
|
-
|
|
115
|
+
|
|
116
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error fetching validators", mockError);
|
|
117
|
+
expect(validatorsAction["succeedSpinner"]).not.toHaveBeenCalled();
|
|
89
118
|
});
|
|
90
119
|
});
|
|
91
120
|
|
|
92
121
|
describe("deleteValidator", () => {
|
|
93
|
-
test("should delete a specific validator", async () =>
|
|
94
|
-
const mockAddress = "
|
|
122
|
+
test("should delete a specific validator", async () => {
|
|
123
|
+
const mockAddress = "0x725a9D2D572E8833059a3e9a844791aF185C5Ff4";
|
|
95
124
|
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: true });
|
|
96
|
-
vi.mocked(rpcClient.request).mockResolvedValue({ result:
|
|
97
|
-
|
|
98
|
-
console.log = vi.fn();
|
|
125
|
+
vi.mocked(rpcClient.request).mockResolvedValue({ result: mockAddress });
|
|
99
126
|
|
|
100
127
|
await validatorsAction.deleteValidator({ address: mockAddress });
|
|
101
128
|
|
|
102
|
-
expect(
|
|
129
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(
|
|
130
|
+
`Deleting validator with address: ${mockAddress}`
|
|
131
|
+
);
|
|
132
|
+
|
|
103
133
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
104
134
|
method: "sim_deleteValidator",
|
|
105
135
|
params: [mockAddress],
|
|
106
136
|
});
|
|
107
|
-
|
|
137
|
+
|
|
138
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
139
|
+
`Deleted Address: ${mockAddress}`
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
108
143
|
});
|
|
109
144
|
|
|
110
145
|
test("should delete all validators when no address is provided", async () => {
|
|
111
146
|
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: true });
|
|
112
147
|
vi.mocked(rpcClient.request).mockResolvedValue({});
|
|
113
148
|
|
|
114
|
-
console.log = vi.fn();
|
|
115
|
-
|
|
116
149
|
await validatorsAction.deleteValidator({});
|
|
117
150
|
|
|
118
|
-
expect(
|
|
151
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(
|
|
152
|
+
"Deleting all validators..."
|
|
153
|
+
);
|
|
154
|
+
|
|
119
155
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
120
156
|
method: "sim_deleteAllValidators",
|
|
121
157
|
params: [],
|
|
122
158
|
});
|
|
123
|
-
|
|
159
|
+
|
|
160
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
161
|
+
"Successfully deleted all validators"
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
124
165
|
});
|
|
125
166
|
|
|
126
167
|
test("should abort deletion if user declines confirmation", async () => {
|
|
127
168
|
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: false });
|
|
128
169
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
await validatorsAction.deleteValidator({ address: "mocked_address" })
|
|
170
|
+
await validatorsAction.deleteValidator({ address: "mocked_address" });
|
|
132
171
|
|
|
133
172
|
expect(inquirer.prompt).toHaveBeenCalled();
|
|
134
|
-
expect(
|
|
173
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("Operation aborted!");
|
|
135
174
|
expect(rpcClient.request).not.toHaveBeenCalled();
|
|
175
|
+
expect(validatorsAction["startSpinner"]).not.toHaveBeenCalled();
|
|
176
|
+
expect(validatorsAction["succeedSpinner"]).not.toHaveBeenCalled();
|
|
136
177
|
});
|
|
178
|
+
|
|
137
179
|
});
|
|
138
180
|
|
|
139
181
|
describe("countValidators", () => {
|
|
@@ -141,15 +183,17 @@ describe("ValidatorsAction", () => {
|
|
|
141
183
|
const mockResponse = { result: 42 };
|
|
142
184
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
143
185
|
|
|
144
|
-
console.log = vi.fn();
|
|
145
|
-
|
|
146
186
|
await validatorsAction.countValidators();
|
|
147
187
|
|
|
188
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Counting all validators...");
|
|
189
|
+
|
|
148
190
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
149
191
|
method: "sim_countValidators",
|
|
150
192
|
params: [],
|
|
151
193
|
});
|
|
152
|
-
|
|
194
|
+
|
|
195
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Total Validators: 42");
|
|
196
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
153
197
|
});
|
|
154
198
|
|
|
155
199
|
test("should log an error if an exception occurs while counting validators", async () => {
|
|
@@ -157,16 +201,19 @@ describe("ValidatorsAction", () => {
|
|
|
157
201
|
|
|
158
202
|
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
159
203
|
|
|
160
|
-
console.error = vi.fn();
|
|
161
|
-
|
|
162
204
|
await validatorsAction.countValidators();
|
|
163
205
|
|
|
206
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Counting all validators...");
|
|
207
|
+
|
|
164
208
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
165
209
|
method: "sim_countValidators",
|
|
166
210
|
params: [],
|
|
167
211
|
});
|
|
168
|
-
|
|
212
|
+
|
|
213
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error counting validators", mockError);
|
|
214
|
+
expect(validatorsAction["succeedSpinner"]).not.toHaveBeenCalled();
|
|
169
215
|
});
|
|
216
|
+
|
|
170
217
|
});
|
|
171
218
|
|
|
172
219
|
describe("createValidator", () => {
|
|
@@ -192,14 +239,37 @@ describe("ValidatorsAction", () => {
|
|
|
192
239
|
.mockResolvedValueOnce({ selectedProvider: "Provider1" })
|
|
193
240
|
.mockResolvedValueOnce({ selectedModel: "Model1" });
|
|
194
241
|
|
|
195
|
-
console.log = vi.fn();
|
|
196
|
-
|
|
197
242
|
await validatorsAction.createValidator({ stake: "10" });
|
|
198
243
|
|
|
244
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
245
|
+
|
|
199
246
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
200
247
|
method: "sim_getProvidersAndModels",
|
|
201
248
|
params: [],
|
|
202
249
|
});
|
|
250
|
+
|
|
251
|
+
expect(validatorsAction["stopSpinner"]).toHaveBeenCalled();
|
|
252
|
+
|
|
253
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
254
|
+
{
|
|
255
|
+
type: "list",
|
|
256
|
+
name: "selectedProvider",
|
|
257
|
+
message: "Select a provider:",
|
|
258
|
+
choices: ["Provider1"],
|
|
259
|
+
},
|
|
260
|
+
]);
|
|
261
|
+
|
|
262
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
263
|
+
{
|
|
264
|
+
type: "list",
|
|
265
|
+
name: "selectedModel",
|
|
266
|
+
message: "Select a model:",
|
|
267
|
+
choices: ["Model1"],
|
|
268
|
+
},
|
|
269
|
+
]);
|
|
270
|
+
|
|
271
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating validator...");
|
|
272
|
+
|
|
203
273
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
204
274
|
method: "sim_createValidator",
|
|
205
275
|
params: [
|
|
@@ -211,30 +281,46 @@ describe("ValidatorsAction", () => {
|
|
|
211
281
|
{ api_key_env_var: "KEY1" },
|
|
212
282
|
],
|
|
213
283
|
});
|
|
214
|
-
|
|
284
|
+
|
|
285
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
286
|
+
"Validator successfully created:",
|
|
287
|
+
mockResponse.result
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
215
291
|
});
|
|
216
292
|
|
|
217
293
|
test("should log an error for invalid stake", async () => {
|
|
218
|
-
console.error = vi.fn();
|
|
219
294
|
|
|
220
295
|
await validatorsAction.createValidator({ stake: "invalid" });
|
|
221
296
|
|
|
222
|
-
expect(
|
|
297
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith(
|
|
298
|
+
"Invalid stake. Please provide a positive integer."
|
|
299
|
+
);
|
|
300
|
+
|
|
223
301
|
expect(rpcClient.request).not.toHaveBeenCalled();
|
|
302
|
+
expect(validatorsAction["startSpinner"]).not.toHaveBeenCalled();
|
|
303
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
224
304
|
});
|
|
225
305
|
|
|
226
306
|
test("should log an error if no providers or models are available", async () => {
|
|
227
307
|
vi.mocked(rpcClient.request).mockResolvedValueOnce({ result: [] });
|
|
228
308
|
|
|
229
|
-
console.error = vi.fn();
|
|
230
|
-
|
|
231
309
|
await validatorsAction.createValidator({ stake: "10" });
|
|
232
310
|
|
|
311
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
312
|
+
|
|
233
313
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
234
314
|
method: "sim_getProvidersAndModels",
|
|
235
315
|
params: [],
|
|
236
316
|
});
|
|
237
|
-
|
|
317
|
+
|
|
318
|
+
expect(validatorsAction["stopSpinner"]).toHaveBeenCalled();
|
|
319
|
+
|
|
320
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("No providers or models available.");
|
|
321
|
+
|
|
322
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
323
|
+
expect(validatorsAction["succeedSpinner"]).not.toHaveBeenCalled();
|
|
238
324
|
});
|
|
239
325
|
|
|
240
326
|
test("should log an error if no models are available for the selected provider", async () => {
|
|
@@ -245,11 +331,22 @@ describe("ValidatorsAction", () => {
|
|
|
245
331
|
vi.mocked(rpcClient.request).mockResolvedValueOnce({ result: mockProvidersAndModels });
|
|
246
332
|
vi.mocked(inquirer.prompt).mockResolvedValueOnce({ selectedProvider: "Provider1" });
|
|
247
333
|
|
|
248
|
-
console.error = vi.fn();
|
|
249
|
-
|
|
250
334
|
await validatorsAction.createValidator({ stake: "10" });
|
|
251
335
|
|
|
252
|
-
expect(
|
|
336
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
337
|
+
|
|
338
|
+
expect(validatorsAction["stopSpinner"]).toHaveBeenCalled();
|
|
339
|
+
|
|
340
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
341
|
+
{
|
|
342
|
+
type: "list",
|
|
343
|
+
name: "selectedProvider",
|
|
344
|
+
message: "Select a provider:",
|
|
345
|
+
choices: ["Provider1"],
|
|
346
|
+
},
|
|
347
|
+
]);
|
|
348
|
+
|
|
349
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("No models available for the selected provider.");
|
|
253
350
|
});
|
|
254
351
|
|
|
255
352
|
test("should log an error if selected model details are not found", async () => {
|
|
@@ -267,22 +364,42 @@ describe("ValidatorsAction", () => {
|
|
|
267
364
|
.mockResolvedValueOnce({ selectedProvider: "Provider1" })
|
|
268
365
|
.mockResolvedValueOnce({ selectedModel: "NonExistentModel" });
|
|
269
366
|
|
|
270
|
-
console.error = vi.fn();
|
|
271
|
-
|
|
272
367
|
await validatorsAction.createValidator({ stake: "10" });
|
|
273
368
|
|
|
274
|
-
expect(
|
|
369
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
370
|
+
|
|
371
|
+
expect(validatorsAction["stopSpinner"]).toHaveBeenCalled();
|
|
372
|
+
|
|
373
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
374
|
+
{
|
|
375
|
+
type: "list",
|
|
376
|
+
name: "selectedProvider",
|
|
377
|
+
message: "Select a provider:",
|
|
378
|
+
choices: ["Provider1"],
|
|
379
|
+
},
|
|
380
|
+
]);
|
|
381
|
+
|
|
382
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
383
|
+
{
|
|
384
|
+
type: "list",
|
|
385
|
+
name: "selectedModel",
|
|
386
|
+
message: "Select a model:",
|
|
387
|
+
choices: ["Model1"],
|
|
388
|
+
},
|
|
389
|
+
]);
|
|
390
|
+
|
|
391
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("Selected model details not found.");
|
|
275
392
|
});
|
|
276
393
|
|
|
277
394
|
test("should log an error if an exception occurs during the process", async () => {
|
|
278
395
|
const mockError = new Error("Unexpected error");
|
|
279
396
|
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
280
397
|
|
|
281
|
-
console.error = vi.fn();
|
|
282
|
-
|
|
283
398
|
await validatorsAction.createValidator({ stake: "10" });
|
|
284
399
|
|
|
285
|
-
expect(
|
|
400
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
401
|
+
|
|
402
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error creating validator", mockError);
|
|
286
403
|
});
|
|
287
404
|
|
|
288
405
|
test("should use user-provided config if specified", async () => {
|
|
@@ -307,11 +424,22 @@ describe("ValidatorsAction", () => {
|
|
|
307
424
|
.mockResolvedValueOnce({ selectedProvider: "Provider1" })
|
|
308
425
|
.mockResolvedValueOnce({ selectedModel: "Model1" });
|
|
309
426
|
|
|
310
|
-
console.log = vi.fn();
|
|
311
|
-
|
|
312
427
|
const customConfig = '{"custom_key":"custom_value"}';
|
|
313
428
|
await validatorsAction.createValidator({ stake: "10", config: customConfig });
|
|
314
429
|
|
|
430
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Fetching available providers and models...");
|
|
431
|
+
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
432
|
+
method: "sim_getProvidersAndModels",
|
|
433
|
+
params: [],
|
|
434
|
+
});
|
|
435
|
+
expect(validatorsAction["stopSpinner"]).toHaveBeenCalled();
|
|
436
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
437
|
+
{ type: "list", name: "selectedProvider", message: "Select a provider:", choices: ["Provider1"] },
|
|
438
|
+
]);
|
|
439
|
+
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
440
|
+
{ type: "list", name: "selectedModel", message: "Select a model:", choices: ["Model1"] },
|
|
441
|
+
]);
|
|
442
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating validator...");
|
|
315
443
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
316
444
|
method: "sim_createValidator",
|
|
317
445
|
params: [
|
|
@@ -323,84 +451,100 @@ describe("ValidatorsAction", () => {
|
|
|
323
451
|
{ api_key_env_var: "KEY1" },
|
|
324
452
|
],
|
|
325
453
|
});
|
|
326
|
-
expect(
|
|
454
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Validator successfully created:", mockResponse.result);
|
|
455
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test("should log an error if model is provided without provider", async () => {
|
|
459
|
+
vi.spyOn(validatorsAction as any, "logError").mockImplementation(() => {});
|
|
460
|
+
|
|
461
|
+
await validatorsAction.createValidator({ stake: "10", model: "Model1" });
|
|
462
|
+
|
|
463
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("You must specify a provider if using a model.");
|
|
464
|
+
expect(rpcClient.request).not.toHaveBeenCalled();
|
|
327
465
|
});
|
|
328
466
|
});
|
|
467
|
+
|
|
329
468
|
describe("createRandomValidators", () => {
|
|
330
469
|
test("should create random validators with valid count and providers", async () => {
|
|
331
470
|
const mockResponse = { result: { success: true } };
|
|
332
471
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
333
472
|
|
|
334
|
-
console.log = vi.fn();
|
|
335
|
-
|
|
336
473
|
await validatorsAction.createRandomValidators({ count: "5", providers: ["Provider1", "Provider2"], models: [] });
|
|
337
474
|
|
|
475
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating 5 random validator(s)...");
|
|
476
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Providers: Provider1, Provider2");
|
|
477
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Models: All");
|
|
478
|
+
|
|
338
479
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
339
480
|
method: "sim_createRandomValidators",
|
|
340
481
|
params: [5, 1, 10, ["Provider1", "Provider2"], []],
|
|
341
482
|
});
|
|
342
|
-
|
|
343
|
-
expect(
|
|
344
|
-
expect(
|
|
483
|
+
|
|
484
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Random validators successfully created", mockResponse.result);
|
|
485
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
345
486
|
});
|
|
346
487
|
|
|
347
488
|
test("should create random validators with valid count, providers and models", async () => {
|
|
348
489
|
const mockResponse = { result: { success: true } };
|
|
349
490
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
350
491
|
|
|
351
|
-
console.log = vi.fn();
|
|
352
|
-
|
|
353
492
|
await validatorsAction.createRandomValidators({ count: "10", providers: ["Provider3"], models: ["Model1", "Model2"] });
|
|
354
493
|
|
|
494
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating 10 random validator(s)...");
|
|
495
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Providers: Provider3");
|
|
496
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Models: Model1, Model2");
|
|
497
|
+
|
|
355
498
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
356
499
|
method: "sim_createRandomValidators",
|
|
357
500
|
params: [10, 1, 10, ["Provider3"], ["Model1", "Model2"]],
|
|
358
501
|
});
|
|
359
|
-
|
|
360
|
-
expect(
|
|
361
|
-
expect(
|
|
362
|
-
expect(console.log).toHaveBeenCalledWith("Random validators successfully created:", mockResponse.result);
|
|
502
|
+
|
|
503
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Random validators successfully created", mockResponse.result);
|
|
504
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
363
505
|
});
|
|
364
506
|
|
|
365
507
|
test("should create random validators with default provider message when providers list is empty", async () => {
|
|
366
508
|
const mockResponse = { result: { success: true } };
|
|
367
509
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
368
510
|
|
|
369
|
-
console.log = vi.fn();
|
|
370
|
-
|
|
371
511
|
await validatorsAction.createRandomValidators({ count: "3", providers: [], models: [] });
|
|
372
512
|
|
|
513
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating 3 random validator(s)...");
|
|
514
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Providers: All");
|
|
515
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Models: All");
|
|
516
|
+
|
|
373
517
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
374
518
|
method: "sim_createRandomValidators",
|
|
375
519
|
params: [3, 1, 10, [], []],
|
|
376
520
|
});
|
|
377
|
-
|
|
378
|
-
expect(
|
|
379
|
-
expect(
|
|
521
|
+
|
|
522
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Random validators successfully created", mockResponse.result);
|
|
523
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
380
524
|
});
|
|
381
525
|
|
|
382
526
|
test("should throw an error for invalid count", async () => {
|
|
383
|
-
console.error = vi.fn();
|
|
384
|
-
|
|
385
527
|
await validatorsAction.createRandomValidators({ count: "invalid", providers: ["Provider1"], models: [] });
|
|
386
528
|
|
|
387
|
-
expect(
|
|
529
|
+
expect(validatorsAction["logError"]).toHaveBeenCalledWith("Invalid count. Please provide a positive integer.");
|
|
388
530
|
expect(rpcClient.request).not.toHaveBeenCalled();
|
|
531
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
389
532
|
});
|
|
390
533
|
|
|
391
534
|
test("should log an error if rpc request fails", async () => {
|
|
392
535
|
const mockError = new Error("RPC failure");
|
|
393
536
|
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
394
537
|
|
|
395
|
-
console.error = vi.fn();
|
|
396
|
-
|
|
397
538
|
await validatorsAction.createRandomValidators({ count: "5", providers: ["Provider1"], models: [] });
|
|
398
539
|
|
|
540
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith("Creating 5 random validator(s)...");
|
|
541
|
+
|
|
399
542
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
400
543
|
method: "sim_createRandomValidators",
|
|
401
544
|
params: [5, 1, 10, ["Provider1"], []],
|
|
402
545
|
});
|
|
403
|
-
|
|
546
|
+
|
|
547
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error creating random validators", mockError);
|
|
404
548
|
});
|
|
405
549
|
});
|
|
406
550
|
|
|
@@ -422,14 +566,17 @@ describe("ValidatorsAction", () => {
|
|
|
422
566
|
.mockResolvedValueOnce(mockCurrentValidator)
|
|
423
567
|
.mockResolvedValueOnce(mockResponse);
|
|
424
568
|
|
|
425
|
-
console.log = vi.fn();
|
|
426
|
-
|
|
427
569
|
await validatorsAction.updateValidator({ address: mockAddress, stake: "200" });
|
|
428
570
|
|
|
571
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(`Fetching validator with address: ${mockAddress}...`);
|
|
429
572
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
430
573
|
method: "sim_getValidator",
|
|
431
574
|
params: [mockAddress],
|
|
432
575
|
});
|
|
576
|
+
|
|
577
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Current Validator Details:", mockCurrentValidator.result);
|
|
578
|
+
expect(validatorsAction["setSpinnerText"]).toHaveBeenCalledWith("Updating Validator...");
|
|
579
|
+
|
|
433
580
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
434
581
|
method: "sim_updateValidator",
|
|
435
582
|
params: [
|
|
@@ -440,7 +587,9 @@ describe("ValidatorsAction", () => {
|
|
|
440
587
|
{ max_tokens: 500 },
|
|
441
588
|
],
|
|
442
589
|
});
|
|
443
|
-
|
|
590
|
+
|
|
591
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Validator successfully updated", mockResponse.result);
|
|
592
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
444
593
|
});
|
|
445
594
|
|
|
446
595
|
test("should fetch and update a validator with new provider and model", async () => {
|
|
@@ -460,18 +609,17 @@ describe("ValidatorsAction", () => {
|
|
|
460
609
|
.mockResolvedValueOnce(mockCurrentValidator)
|
|
461
610
|
.mockResolvedValueOnce(mockResponse);
|
|
462
611
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
await validatorsAction.updateValidator({
|
|
466
|
-
address: mockAddress,
|
|
467
|
-
provider: "Provider2",
|
|
468
|
-
model: "Model2",
|
|
469
|
-
});
|
|
612
|
+
await validatorsAction.updateValidator({ address: mockAddress, provider: "Provider2", model: "Model2" });
|
|
470
613
|
|
|
614
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(`Fetching validator with address: ${mockAddress}...`);
|
|
471
615
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
472
616
|
method: "sim_getValidator",
|
|
473
617
|
params: [mockAddress],
|
|
474
618
|
});
|
|
619
|
+
|
|
620
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Current Validator Details:", mockCurrentValidator.result);
|
|
621
|
+
expect(validatorsAction["setSpinnerText"]).toHaveBeenCalledWith("Updating Validator...");
|
|
622
|
+
|
|
475
623
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
476
624
|
method: "sim_updateValidator",
|
|
477
625
|
params: [
|
|
@@ -482,7 +630,9 @@ describe("ValidatorsAction", () => {
|
|
|
482
630
|
{ max_tokens: 500 },
|
|
483
631
|
],
|
|
484
632
|
});
|
|
485
|
-
|
|
633
|
+
|
|
634
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Validator successfully updated", mockResponse.result);
|
|
635
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
486
636
|
});
|
|
487
637
|
|
|
488
638
|
test("should fetch and update a validator with new config", async () => {
|
|
@@ -502,15 +652,18 @@ describe("ValidatorsAction", () => {
|
|
|
502
652
|
.mockResolvedValueOnce(mockCurrentValidator)
|
|
503
653
|
.mockResolvedValueOnce(mockResponse);
|
|
504
654
|
|
|
505
|
-
console.log = vi.fn();
|
|
506
|
-
|
|
507
655
|
const newConfig = '{"max_tokens":1000}';
|
|
508
656
|
await validatorsAction.updateValidator({ address: mockAddress, config: newConfig });
|
|
509
657
|
|
|
658
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(`Fetching validator with address: ${mockAddress}...`);
|
|
510
659
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
511
660
|
method: "sim_getValidator",
|
|
512
661
|
params: [mockAddress],
|
|
513
662
|
});
|
|
663
|
+
|
|
664
|
+
expect(validatorsAction["log"]).toHaveBeenCalledWith("Current Validator Details:", mockCurrentValidator.result);
|
|
665
|
+
expect(validatorsAction["setSpinnerText"]).toHaveBeenCalledWith("Updating Validator...");
|
|
666
|
+
|
|
514
667
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
515
668
|
method: "sim_updateValidator",
|
|
516
669
|
params: [
|
|
@@ -521,28 +674,9 @@ describe("ValidatorsAction", () => {
|
|
|
521
674
|
{ max_tokens: 1000 },
|
|
522
675
|
],
|
|
523
676
|
});
|
|
524
|
-
expect(console.log).toHaveBeenCalledWith("Validator successfully updated:", mockResponse.result);
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
test("should throw an error if validator is not found", async () => {
|
|
528
|
-
const mockAddress = "mocked_address";
|
|
529
|
-
const mockResponse = { result: null };
|
|
530
|
-
|
|
531
|
-
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
532
677
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
await validatorsAction.updateValidator({ address: mockAddress });
|
|
536
|
-
|
|
537
|
-
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
538
|
-
method: "sim_getValidator",
|
|
539
|
-
params: [mockAddress],
|
|
540
|
-
});
|
|
541
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
542
|
-
"Error updating validator:",
|
|
543
|
-
new Error(`Validator with address ${mockAddress} not found.`)
|
|
544
|
-
);
|
|
545
|
-
expect(rpcClient.request).toHaveBeenCalledTimes(1);
|
|
678
|
+
expect(validatorsAction["succeedSpinner"]).toHaveBeenCalledWith("Validator successfully updated", mockResponse.result);
|
|
679
|
+
expect(validatorsAction["failSpinner"]).not.toHaveBeenCalled();
|
|
546
680
|
});
|
|
547
681
|
|
|
548
682
|
test("should log an error if updateValidator RPC call fails", async () => {
|
|
@@ -562,7 +696,7 @@ describe("ValidatorsAction", () => {
|
|
|
562
696
|
.mockResolvedValueOnce(mockCurrentValidator)
|
|
563
697
|
.mockRejectedValueOnce(mockError);
|
|
564
698
|
|
|
565
|
-
|
|
699
|
+
vi.spyOn(validatorsAction as any, "failSpinner").mockImplementation(() => {});
|
|
566
700
|
|
|
567
701
|
await validatorsAction.updateValidator({ address: mockAddress, stake: "200" });
|
|
568
702
|
|
|
@@ -570,6 +704,7 @@ describe("ValidatorsAction", () => {
|
|
|
570
704
|
method: "sim_getValidator",
|
|
571
705
|
params: [mockAddress],
|
|
572
706
|
});
|
|
707
|
+
|
|
573
708
|
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
574
709
|
method: "sim_updateValidator",
|
|
575
710
|
params: [
|
|
@@ -580,40 +715,36 @@ describe("ValidatorsAction", () => {
|
|
|
580
715
|
{ max_tokens: 500 },
|
|
581
716
|
],
|
|
582
717
|
});
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
});
|
|
586
|
-
test("should log an error for invalid stake value", async () => {
|
|
587
|
-
const mockAddress = "mocked_address";
|
|
588
|
-
const mockCurrentValidator = {
|
|
589
|
-
result: {
|
|
590
|
-
address: "mocked_address",
|
|
591
|
-
stake: 100,
|
|
592
|
-
provider: "Provider1",
|
|
593
|
-
model: "Model1",
|
|
594
|
-
config: { max_tokens: 500 },
|
|
595
|
-
},
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
vi.mocked(rpcClient.request).mockResolvedValue(mockCurrentValidator);
|
|
599
|
-
|
|
600
|
-
console.error = vi.fn();
|
|
601
|
-
|
|
602
|
-
await validatorsAction.updateValidator({ address: mockAddress, stake: "-10" });
|
|
603
|
-
|
|
604
|
-
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
605
|
-
method: "sim_getValidator",
|
|
606
|
-
params: [mockAddress],
|
|
718
|
+
|
|
719
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Error updating validator", mockError);
|
|
607
720
|
});
|
|
608
|
-
expect(console.error).toHaveBeenCalledWith("Invalid stake value. Stake must be a positive integer.");
|
|
609
|
-
expect(rpcClient.request).toHaveBeenCalledTimes(1);
|
|
610
|
-
});
|
|
611
|
-
test("should log an error if model is provided without provider", async () => {
|
|
612
|
-
console.error = vi.fn();
|
|
613
721
|
|
|
614
|
-
|
|
722
|
+
test("should log an error for invalid stake value", async () => {
|
|
723
|
+
const mockAddress = "mocked_address";
|
|
724
|
+
const mockCurrentValidator = {
|
|
725
|
+
result: {
|
|
726
|
+
address: "mocked_address",
|
|
727
|
+
stake: 100,
|
|
728
|
+
provider: "Provider1",
|
|
729
|
+
model: "Model1",
|
|
730
|
+
config: { max_tokens: 500 },
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
vi.mocked(rpcClient.request).mockResolvedValue(mockCurrentValidator);
|
|
615
735
|
|
|
616
|
-
|
|
617
|
-
|
|
736
|
+
vi.spyOn(validatorsAction as any, "failSpinner").mockImplementation(() => {});
|
|
737
|
+
|
|
738
|
+
await validatorsAction.updateValidator({ address: mockAddress, stake: "-10" });
|
|
739
|
+
|
|
740
|
+
expect(validatorsAction["startSpinner"]).toHaveBeenCalledWith(`Fetching validator with address: ${mockAddress}...`);
|
|
741
|
+
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
742
|
+
method: "sim_getValidator",
|
|
743
|
+
params: [mockAddress],
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
expect(validatorsAction["failSpinner"]).toHaveBeenCalledWith("Invalid stake value. Stake must be a positive integer.");
|
|
747
|
+
expect(rpcClient.request).toHaveBeenCalledTimes(1);
|
|
748
|
+
});
|
|
618
749
|
});
|
|
619
750
|
});
|