genlayer 0.10.1 → 0.11.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/CHANGELOG.md +14 -0
- package/dist/index.js +347 -29
- package/docker-compose.yml +12 -2
- package/package.json +1 -1
- package/src/commands/general/init.ts +5 -1
- package/src/commands/update/index.ts +5 -1
- package/src/commands/update/ollama.ts +69 -8
- package/src/commands/validators/index.ts +94 -0
- package/src/commands/validators/validators.ts +274 -0
- package/src/index.ts +2 -0
- package/src/lib/actions/BaseAction.ts +19 -0
- package/src/lib/clients/jsonRpcClient.ts +19 -20
- package/src/lib/config/simulator.ts +1 -1
- package/src/lib/services/simulator.ts +2 -2
- package/tests/actions/init.test.ts +37 -2
- package/tests/actions/ollama.test.ts +88 -9
- package/tests/actions/validators.test.ts +619 -0
- package/tests/commands/update.test.ts +5 -0
- package/tests/commands/validator.test.ts +127 -0
- package/tests/index.test.ts +4 -0
- package/tests/libs/jsonRpcClient.test.ts +2 -3
- package/tests/services/simulator.test.ts +15 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
3
|
+
import { initializeValidatorCommands } from "../../src/commands/validators";
|
|
4
|
+
import { ValidatorsAction } from "../../src/commands/validators/validators";
|
|
5
|
+
|
|
6
|
+
vi.mock("../../src/commands/validators/validators");
|
|
7
|
+
|
|
8
|
+
describe("validators command", () => {
|
|
9
|
+
let program: Command;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
program = new Command();
|
|
13
|
+
initializeValidatorCommands(program);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
vi.restoreAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("ValidatorsAction.getValidator is called with address option", async () => {
|
|
21
|
+
program.parse(["node", "test", "validators", "get", "--address", "mocked_address"]);
|
|
22
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
23
|
+
expect(ValidatorsAction.prototype.getValidator).toHaveBeenCalledWith({
|
|
24
|
+
address: "mocked_address",
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("ValidatorsAction.getValidator is called without address option", async () => {
|
|
29
|
+
program.parse(["node", "test", "validators", "get"]);
|
|
30
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(ValidatorsAction.prototype.getValidator).toHaveBeenCalledWith({});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("ValidatorsAction.deleteValidator is called with address option", async () => {
|
|
35
|
+
program.parse(["node", "test", "validators", "delete", "--address", "mocked_address"]);
|
|
36
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
37
|
+
expect(ValidatorsAction.prototype.deleteValidator).toHaveBeenCalledWith({
|
|
38
|
+
address: "mocked_address",
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("ValidatorsAction.deleteValidator is called without address option", async () => {
|
|
43
|
+
program.parse(["node", "test", "validators", "delete"]);
|
|
44
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(ValidatorsAction.prototype.deleteValidator).toHaveBeenCalledWith({});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("ValidatorsAction.countValidators is called", async () => {
|
|
49
|
+
program.parse(["node", "test", "validators", "count"]);
|
|
50
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(ValidatorsAction.prototype.countValidators).toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("ValidatorsAction.updateValidator is called with all options", async () => {
|
|
55
|
+
program.parse([
|
|
56
|
+
"node",
|
|
57
|
+
"test",
|
|
58
|
+
"validators",
|
|
59
|
+
"update",
|
|
60
|
+
"mocked_address",
|
|
61
|
+
"--stake",
|
|
62
|
+
"10",
|
|
63
|
+
"--provider",
|
|
64
|
+
"mocked_provider",
|
|
65
|
+
"--model",
|
|
66
|
+
"mocked_model",
|
|
67
|
+
'--config',
|
|
68
|
+
'{"max_tokens":500}',
|
|
69
|
+
]);
|
|
70
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(ValidatorsAction.prototype.updateValidator).toHaveBeenCalledWith({
|
|
72
|
+
address: "mocked_address",
|
|
73
|
+
stake: "10",
|
|
74
|
+
provider: "mocked_provider",
|
|
75
|
+
model: "mocked_model",
|
|
76
|
+
config: '{"max_tokens":500}',
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("ValidatorsAction.createRandomValidators is called with count and providers", async () => {
|
|
81
|
+
program.parse([
|
|
82
|
+
"node",
|
|
83
|
+
"test",
|
|
84
|
+
"validators",
|
|
85
|
+
"create-random",
|
|
86
|
+
"--count",
|
|
87
|
+
"3",
|
|
88
|
+
"--providers",
|
|
89
|
+
"provider1",
|
|
90
|
+
"provider2",
|
|
91
|
+
]);
|
|
92
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(ValidatorsAction.prototype.createRandomValidators).toHaveBeenCalledWith({
|
|
94
|
+
count: "3",
|
|
95
|
+
providers: ["provider1", "provider2"],
|
|
96
|
+
models: []
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("ValidatorsAction.createValidator is called with default stake", async () => {
|
|
101
|
+
program.parse(["node", "test", "validators", "create"]);
|
|
102
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
103
|
+
expect(ValidatorsAction.prototype.createValidator).toHaveBeenCalledWith({
|
|
104
|
+
stake: "1",
|
|
105
|
+
config: undefined,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("ValidatorsAction.createValidator is called with stake and config", async () => {
|
|
110
|
+
program.parse([
|
|
111
|
+
"node",
|
|
112
|
+
"test",
|
|
113
|
+
"validators",
|
|
114
|
+
"create",
|
|
115
|
+
"--stake",
|
|
116
|
+
"5",
|
|
117
|
+
'--config',
|
|
118
|
+
'{"temperature":0.8}',
|
|
119
|
+
]);
|
|
120
|
+
expect(ValidatorsAction).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(ValidatorsAction.prototype.createValidator).toHaveBeenCalledWith({
|
|
122
|
+
stake: "5",
|
|
123
|
+
config: '{"temperature":0.8}',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
});
|
package/tests/index.test.ts
CHANGED
|
@@ -25,6 +25,10 @@ vi.mock("../src/commands/config", () => ({
|
|
|
25
25
|
initializeConfigCommands: vi.fn(),
|
|
26
26
|
}));
|
|
27
27
|
|
|
28
|
+
vi.mock("../src/commands/validators", () => ({
|
|
29
|
+
initializeValidatorCommands: vi.fn(),
|
|
30
|
+
}));
|
|
31
|
+
|
|
28
32
|
vi.mock("../src/commands/update", () => ({
|
|
29
33
|
initializeUpdateCommands: vi.fn(),
|
|
30
34
|
}));
|
|
@@ -40,6 +40,7 @@ describe("JsonRpcClient - Successful and Unsuccessful Requests", () => {
|
|
|
40
40
|
test("should return null when the fetch response is not ok", async () => {
|
|
41
41
|
(fetch as Mock).mockResolvedValueOnce({
|
|
42
42
|
ok: false,
|
|
43
|
+
statusText: "Something went wrong",
|
|
43
44
|
json: async () => ({ error: "Something went wrong" }),
|
|
44
45
|
});
|
|
45
46
|
|
|
@@ -48,9 +49,7 @@ describe("JsonRpcClient - Successful and Unsuccessful Requests", () => {
|
|
|
48
49
|
params: ["param1", "param2"],
|
|
49
50
|
};
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(response).toBeNull();
|
|
52
|
+
await expect(rpcClient.request(params)).rejects.toThrowError("Something went wrong");
|
|
54
53
|
expect(fetch).toHaveBeenCalledWith(mockServerUrl, {
|
|
55
54
|
method: "POST",
|
|
56
55
|
headers: { "Content-Type": "application/json" },
|
|
@@ -200,7 +200,7 @@ describe("SimulatorService - Basic Tests", () => {
|
|
|
200
200
|
const mockResponse = { success: true };
|
|
201
201
|
vi.mocked(rpcClient.request).mockResolvedValue(mockResponse);
|
|
202
202
|
const result = await simulatorService.deleteAllValidators();
|
|
203
|
-
expect(rpcClient.request).toHaveBeenCalledWith({ method: "
|
|
203
|
+
expect(rpcClient.request).toHaveBeenCalledWith({ method: "sim_deleteAllValidators", params: [] });
|
|
204
204
|
expect(result).toBe(mockResponse);
|
|
205
205
|
});
|
|
206
206
|
|
|
@@ -465,4 +465,18 @@ describe('normalizeLocalnetVersion', () => {
|
|
|
465
465
|
mockExit.mockRestore();
|
|
466
466
|
mockConsoleError.mockRestore();
|
|
467
467
|
});
|
|
468
|
+
test("should log an error if an exception occurs while cleaning the database", async () => {
|
|
469
|
+
const mockError = new Error("Database cleanup error");
|
|
470
|
+
vi.mocked(rpcClient.request).mockRejectedValue(mockError);
|
|
471
|
+
|
|
472
|
+
console.error = vi.fn();
|
|
473
|
+
|
|
474
|
+
await simulatorService.cleanDatabase();
|
|
475
|
+
|
|
476
|
+
expect(rpcClient.request).toHaveBeenCalledWith({
|
|
477
|
+
method: "sim_clearDbTables",
|
|
478
|
+
params: [['current_state', 'transactions']],
|
|
479
|
+
});
|
|
480
|
+
expect(console.error).toHaveBeenCalledWith(mockError);
|
|
481
|
+
});
|
|
468
482
|
});
|