genlayer 0.34.0 → 0.34.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -3
- package/package.json +11 -2
- package/.eslintignore +0 -2
- package/.github/workflows/cli-docs.yml +0 -121
- package/.github/workflows/publish-beta.yml +0 -41
- package/.github/workflows/publish.yml +0 -43
- package/.github/workflows/validate-code.yml +0 -47
- package/.prettierignore +0 -19
- package/.prettierrc +0 -12
- package/.release-it.json +0 -64
- package/CHANGELOG.md +0 -425
- package/CLAUDE.md +0 -55
- package/CONTRIBUTING.md +0 -117
- package/docker-compose.yml +0 -154
- package/docs/delegator-guide.md +0 -203
- package/docs/validator-guide.md +0 -329
- package/esbuild.config.dev.js +0 -17
- package/esbuild.config.js +0 -22
- package/esbuild.config.prod.js +0 -17
- package/eslint.config.js +0 -60
- package/renovate.json +0 -22
- package/src/commands/account/create.ts +0 -30
- package/src/commands/account/export.ts +0 -106
- package/src/commands/account/import.ts +0 -135
- package/src/commands/account/index.ts +0 -129
- package/src/commands/account/list.ts +0 -34
- package/src/commands/account/lock.ts +0 -39
- package/src/commands/account/remove.ts +0 -30
- package/src/commands/account/send.ts +0 -162
- package/src/commands/account/show.ts +0 -74
- package/src/commands/account/unlock.ts +0 -56
- package/src/commands/account/use.ts +0 -21
- package/src/commands/config/getSetReset.ts +0 -51
- package/src/commands/config/index.ts +0 -30
- package/src/commands/contracts/call.ts +0 -39
- package/src/commands/contracts/code.ts +0 -33
- package/src/commands/contracts/deploy.ts +0 -157
- package/src/commands/contracts/index.ts +0 -86
- package/src/commands/contracts/schema.ts +0 -31
- package/src/commands/contracts/write.ts +0 -49
- package/src/commands/general/index.ts +0 -45
- package/src/commands/general/init.ts +0 -179
- package/src/commands/general/start.ts +0 -116
- package/src/commands/general/stop.ts +0 -26
- package/src/commands/localnet/index.ts +0 -100
- package/src/commands/localnet/validators.ts +0 -269
- package/src/commands/network/index.ts +0 -29
- package/src/commands/network/setNetwork.ts +0 -77
- package/src/commands/scaffold/index.ts +0 -16
- package/src/commands/scaffold/new.ts +0 -34
- package/src/commands/staking/StakingAction.ts +0 -279
- package/src/commands/staking/delegatorClaim.ts +0 -41
- package/src/commands/staking/delegatorExit.ts +0 -56
- package/src/commands/staking/delegatorJoin.ts +0 -44
- package/src/commands/staking/index.ts +0 -357
- package/src/commands/staking/setIdentity.ts +0 -78
- package/src/commands/staking/setOperator.ts +0 -46
- package/src/commands/staking/stakingInfo.ts +0 -584
- package/src/commands/staking/validatorClaim.ts +0 -43
- package/src/commands/staking/validatorDeposit.ts +0 -48
- package/src/commands/staking/validatorExit.ts +0 -63
- package/src/commands/staking/validatorHistory.ts +0 -298
- package/src/commands/staking/validatorJoin.ts +0 -47
- package/src/commands/staking/validatorPrime.ts +0 -73
- package/src/commands/staking/wizard.ts +0 -809
- package/src/commands/transactions/appeal.ts +0 -39
- package/src/commands/transactions/index.ts +0 -39
- package/src/commands/transactions/receipt.ts +0 -90
- package/src/commands/update/index.ts +0 -25
- package/src/commands/update/ollama.ts +0 -103
- package/src/lib/actions/BaseAction.ts +0 -299
- package/src/lib/clients/jsonRpcClient.ts +0 -41
- package/src/lib/clients/system.ts +0 -73
- package/src/lib/config/ConfigFileManager.ts +0 -194
- package/src/lib/config/KeychainManager.ts +0 -89
- package/src/lib/config/simulator.ts +0 -68
- package/src/lib/config/text.ts +0 -2
- package/src/lib/errors/missingRequirement.ts +0 -9
- package/src/lib/errors/versionRequired.ts +0 -9
- package/src/lib/interfaces/ISimulatorService.ts +0 -37
- package/src/lib/services/simulator.ts +0 -351
- package/src/types/node-fetch.d.ts +0 -1
- package/tests/actions/appeal.test.ts +0 -99
- package/tests/actions/call.test.ts +0 -94
- package/tests/actions/code.test.ts +0 -87
- package/tests/actions/create.test.ts +0 -65
- package/tests/actions/deploy.test.ts +0 -420
- package/tests/actions/getSetReset.test.ts +0 -88
- package/tests/actions/init.test.ts +0 -467
- package/tests/actions/lock.test.ts +0 -86
- package/tests/actions/new.test.ts +0 -80
- package/tests/actions/ollama.test.ts +0 -193
- package/tests/actions/receipt.test.ts +0 -261
- package/tests/actions/schema.test.ts +0 -94
- package/tests/actions/setNetwork.test.ts +0 -160
- package/tests/actions/staking.test.ts +0 -279
- package/tests/actions/start.test.ts +0 -235
- package/tests/actions/stop.test.ts +0 -77
- package/tests/actions/unlock.test.ts +0 -139
- package/tests/actions/validators.test.ts +0 -750
- package/tests/actions/write.test.ts +0 -102
- package/tests/commands/account.test.ts +0 -146
- package/tests/commands/appeal.test.ts +0 -58
- package/tests/commands/call.test.ts +0 -78
- package/tests/commands/code.test.ts +0 -69
- package/tests/commands/config.test.ts +0 -54
- package/tests/commands/deploy.test.ts +0 -83
- package/tests/commands/init.test.ts +0 -101
- package/tests/commands/localnet.test.ts +0 -131
- package/tests/commands/network.test.ts +0 -60
- package/tests/commands/new.test.ts +0 -68
- package/tests/commands/receipt.test.ts +0 -142
- package/tests/commands/schema.test.ts +0 -67
- package/tests/commands/staking.test.ts +0 -329
- package/tests/commands/stop.test.ts +0 -27
- package/tests/commands/up.test.ts +0 -105
- package/tests/commands/update.test.ts +0 -45
- package/tests/commands/write.test.ts +0 -76
- package/tests/index.test.ts +0 -56
- package/tests/libs/baseAction.test.ts +0 -516
- package/tests/libs/configFileManager.test.ts +0 -117
- package/tests/libs/jsonRpcClient.test.ts +0 -59
- package/tests/libs/keychainManager.test.ts +0 -156
- package/tests/libs/system.test.ts +0 -148
- package/tests/services/simulator.test.ts +0 -705
- package/tests/utils.ts +0 -13
- package/tsconfig.json +0 -120
- package/vitest.config.ts +0 -12
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
|
-
import {KeychainManager} from "../../src/lib/config/KeychainManager";
|
|
3
|
-
import keytar from "keytar";
|
|
4
|
-
|
|
5
|
-
vi.mock("keytar");
|
|
6
|
-
|
|
7
|
-
describe("KeychainManager", () => {
|
|
8
|
-
let keychainManager: KeychainManager;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
vi.clearAllMocks();
|
|
12
|
-
keychainManager = new KeychainManager();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
vi.restoreAllMocks();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("isKeychainAvailable", () => {
|
|
20
|
-
test("returns true when keychain is available", async () => {
|
|
21
|
-
vi.mocked(keytar.findCredentials).mockResolvedValue([]);
|
|
22
|
-
|
|
23
|
-
const result = await keychainManager.isKeychainAvailable();
|
|
24
|
-
|
|
25
|
-
expect(result).toBe(true);
|
|
26
|
-
expect(keytar.findCredentials).toHaveBeenCalledWith("test-service");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("returns false when keychain is not available", async () => {
|
|
30
|
-
vi.mocked(keytar.findCredentials).mockRejectedValue(new Error("Keychain not available"));
|
|
31
|
-
|
|
32
|
-
const result = await keychainManager.isKeychainAvailable();
|
|
33
|
-
|
|
34
|
-
expect(result).toBe(false);
|
|
35
|
-
expect(keytar.findCredentials).toHaveBeenCalledWith("test-service");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("storePrivateKey", () => {
|
|
40
|
-
test("successfully stores private key", async () => {
|
|
41
|
-
const privateKey = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
|
|
42
|
-
vi.mocked(keytar.setPassword).mockResolvedValue();
|
|
43
|
-
|
|
44
|
-
await keychainManager.storePrivateKey("main", privateKey);
|
|
45
|
-
|
|
46
|
-
expect(keytar.setPassword).toHaveBeenCalledWith("genlayer-cli", "account:main", privateKey);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("handles storage error", async () => {
|
|
50
|
-
const privateKey = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
|
|
51
|
-
vi.mocked(keytar.setPassword).mockRejectedValue(new Error("Storage failed"));
|
|
52
|
-
|
|
53
|
-
await expect(keychainManager.storePrivateKey("main", privateKey)).rejects.toThrow("Storage failed");
|
|
54
|
-
expect(keytar.setPassword).toHaveBeenCalledWith("genlayer-cli", "account:main", privateKey);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("getPrivateKey", () => {
|
|
59
|
-
test("returns private key when it exists", async () => {
|
|
60
|
-
const expectedKey = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
|
|
61
|
-
vi.mocked(keytar.getPassword).mockResolvedValue(expectedKey);
|
|
62
|
-
|
|
63
|
-
const result = await keychainManager.getPrivateKey("main");
|
|
64
|
-
|
|
65
|
-
expect(result).toBe(expectedKey);
|
|
66
|
-
expect(keytar.getPassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("returns null when private key does not exist", async () => {
|
|
70
|
-
vi.mocked(keytar.getPassword).mockResolvedValue(null);
|
|
71
|
-
|
|
72
|
-
const result = await keychainManager.getPrivateKey("main");
|
|
73
|
-
|
|
74
|
-
expect(result).toBeNull();
|
|
75
|
-
expect(keytar.getPassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("returns null on retrieval error", async () => {
|
|
79
|
-
vi.mocked(keytar.getPassword).mockRejectedValue(new Error("Retrieval failed"));
|
|
80
|
-
|
|
81
|
-
const result = await keychainManager.getPrivateKey("main");
|
|
82
|
-
|
|
83
|
-
expect(result).toBeNull();
|
|
84
|
-
expect(keytar.getPassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("removePrivateKey", () => {
|
|
89
|
-
test("successfully removes private key", async () => {
|
|
90
|
-
vi.mocked(keytar.deletePassword).mockResolvedValue(true);
|
|
91
|
-
|
|
92
|
-
const result = await keychainManager.removePrivateKey("main");
|
|
93
|
-
|
|
94
|
-
expect(result).toBe(true);
|
|
95
|
-
expect(keytar.deletePassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("returns false when key does not exist", async () => {
|
|
99
|
-
vi.mocked(keytar.deletePassword).mockResolvedValue(false);
|
|
100
|
-
|
|
101
|
-
const result = await keychainManager.removePrivateKey("main");
|
|
102
|
-
|
|
103
|
-
expect(result).toBe(false);
|
|
104
|
-
expect(keytar.deletePassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("returns false on removal error", async () => {
|
|
108
|
-
vi.mocked(keytar.deletePassword).mockRejectedValue(new Error("Removal failed"));
|
|
109
|
-
|
|
110
|
-
const result = await keychainManager.removePrivateKey("main");
|
|
111
|
-
|
|
112
|
-
expect(result).toBe(false);
|
|
113
|
-
expect(keytar.deletePassword).toHaveBeenCalledWith("genlayer-cli", "account:main");
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("listUnlockedAccounts", () => {
|
|
118
|
-
test("returns list of unlocked account names", async () => {
|
|
119
|
-
vi.mocked(keytar.findCredentials).mockResolvedValue([
|
|
120
|
-
{account: "account:main", password: "key1"},
|
|
121
|
-
{account: "account:validator", password: "key2"},
|
|
122
|
-
{account: "other:something", password: "key3"},
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
const result = await keychainManager.listUnlockedAccounts();
|
|
126
|
-
|
|
127
|
-
expect(result).toEqual(["main", "validator"]);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("returns empty array when no accounts", async () => {
|
|
131
|
-
vi.mocked(keytar.findCredentials).mockResolvedValue([]);
|
|
132
|
-
|
|
133
|
-
const result = await keychainManager.listUnlockedAccounts();
|
|
134
|
-
|
|
135
|
-
expect(result).toEqual([]);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("isAccountUnlocked", () => {
|
|
140
|
-
test("returns true when account is unlocked", async () => {
|
|
141
|
-
vi.mocked(keytar.getPassword).mockResolvedValue("some-key");
|
|
142
|
-
|
|
143
|
-
const result = await keychainManager.isAccountUnlocked("main");
|
|
144
|
-
|
|
145
|
-
expect(result).toBe(true);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test("returns false when account is locked", async () => {
|
|
149
|
-
vi.mocked(keytar.getPassword).mockResolvedValue(null);
|
|
150
|
-
|
|
151
|
-
const result = await keychainManager.isAccountUnlocked("main");
|
|
152
|
-
|
|
153
|
-
expect(result).toBe(false);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import util from "node:util";
|
|
3
|
-
import {
|
|
4
|
-
checkCommand,
|
|
5
|
-
executeCommand,
|
|
6
|
-
openUrl,
|
|
7
|
-
getVersion
|
|
8
|
-
} from "../../src/lib/clients/system";
|
|
9
|
-
import { MissingRequirementError } from "../../src/lib/errors/missingRequirement";
|
|
10
|
-
import open from "open";
|
|
11
|
-
|
|
12
|
-
vi.mock("open");
|
|
13
|
-
vi.mock("util");
|
|
14
|
-
|
|
15
|
-
describe("System Functions - Success Paths", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
vi.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("openUrl opens URL successfully", async () => {
|
|
21
|
-
const openSpy = vi.mocked(open).mockResolvedValue({} as any);
|
|
22
|
-
const url = "https://example.com";
|
|
23
|
-
await openUrl(url);
|
|
24
|
-
expect(openSpy).toHaveBeenCalledWith(url);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("getVersion retrieves tool version", async () => {
|
|
28
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.resolve({
|
|
29
|
-
stdout: "git v1.2.3",
|
|
30
|
-
stderr: ""
|
|
31
|
-
}));
|
|
32
|
-
const version = await getVersion("git");
|
|
33
|
-
expect(version).toBe("1.2.3");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("checkCommand verifies a command exists", async () => {
|
|
37
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.resolve({ stdout: "", stderr: "" }));
|
|
38
|
-
const result = await checkCommand("node --version", "node");
|
|
39
|
-
expect(result).toBe(undefined);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("executeCommand executes a command successfully", async () => {
|
|
43
|
-
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("linux");
|
|
44
|
-
vi.mocked(util.promisify).mockReturnValueOnce((param: string) => Promise.resolve({
|
|
45
|
-
stdout: param,
|
|
46
|
-
stderr: ""
|
|
47
|
-
}));
|
|
48
|
-
const result = await executeCommand({
|
|
49
|
-
linux: "echo linux",
|
|
50
|
-
win32: "echo win32",
|
|
51
|
-
darwin: "echo darwin",
|
|
52
|
-
},
|
|
53
|
-
"echo");
|
|
54
|
-
expect(result.stdout).toBe("echo linux");
|
|
55
|
-
platformSpy.mockRestore();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("System Functions - Error Paths", () => {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
vi.clearAllMocks();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("getVersion throws an error if the command fails", async () => {
|
|
65
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.resolve({
|
|
66
|
-
stdout: "",
|
|
67
|
-
stderr: "command not found"
|
|
68
|
-
}));
|
|
69
|
-
const toolName = "nonexistent";
|
|
70
|
-
await expect(getVersion(toolName)).rejects.toThrow(`Error getting ${toolName} version.`);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("getVersion returns '' if stdout is empty", async () => {
|
|
74
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.resolve({
|
|
75
|
-
stdout: "",
|
|
76
|
-
stderr: ""
|
|
77
|
-
}));
|
|
78
|
-
const result = await getVersion('git');
|
|
79
|
-
expect(result).toBe("");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("getVersion throw error if stdout undefined", async () => {
|
|
83
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.resolve({
|
|
84
|
-
stderr: ""
|
|
85
|
-
}));
|
|
86
|
-
const toolName = "nonexistent";
|
|
87
|
-
await expect(getVersion(toolName)).rejects.toThrow(`Error getting ${toolName} version.`);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("checkCommand returns false if the command does not exist", async () => {
|
|
91
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.reject({
|
|
92
|
-
stdout: "",
|
|
93
|
-
stderr: "command not found"
|
|
94
|
-
}));
|
|
95
|
-
const toolName = 'nonexistent';
|
|
96
|
-
await expect(checkCommand(`${toolName} --version`, toolName)).rejects.toThrow(new MissingRequirementError(toolName));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test("executeCommand throws an error if the command fails", async () => {
|
|
100
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.reject(new Error("Execution failed")));
|
|
101
|
-
await expect(executeCommand({
|
|
102
|
-
linux: "echo hello",
|
|
103
|
-
win32: "echo hello",
|
|
104
|
-
darwin: "echo hello",
|
|
105
|
-
},
|
|
106
|
-
"echo")).rejects.toThrow("Execution failed");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("throws error when command execution fails", async () => {
|
|
110
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.reject(new Error("Execution error.")));
|
|
111
|
-
await expect(executeCommand({
|
|
112
|
-
linux: "echo no toolname",
|
|
113
|
-
win32: "echo no toolname",
|
|
114
|
-
darwin: "echo no toolname",
|
|
115
|
-
})).rejects.toThrow(
|
|
116
|
-
"Error executing echo no toolname: Execution error."
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("throws error when command execution fails (toolname)", async () => {
|
|
121
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.reject(new Error("Execution error.")));
|
|
122
|
-
await expect(executeCommand({
|
|
123
|
-
linux: "echo linux",
|
|
124
|
-
win32: "echo win32",
|
|
125
|
-
darwin: "echo darwin",
|
|
126
|
-
},
|
|
127
|
-
"echo")).rejects.toThrow(
|
|
128
|
-
"Error executing echo: Execution error."
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("throws an error for unsupported platform in executeCommand", () => {
|
|
133
|
-
const unsupportedPlatform = "unsupportedOS";
|
|
134
|
-
const originalPlatform = process.platform;
|
|
135
|
-
Object.defineProperty(process, "platform", {
|
|
136
|
-
value: unsupportedPlatform,
|
|
137
|
-
});
|
|
138
|
-
const cmdsByPlatform = {
|
|
139
|
-
linux: "echo Linux",
|
|
140
|
-
darwin: "echo macOS",
|
|
141
|
-
win32: "echo Windows",
|
|
142
|
-
};
|
|
143
|
-
expect(executeCommand(cmdsByPlatform)).rejects.toThrow(
|
|
144
|
-
`Unsupported platform: ${unsupportedPlatform}.`
|
|
145
|
-
);
|
|
146
|
-
Object.defineProperty(process, "platform", { value: originalPlatform });
|
|
147
|
-
});
|
|
148
|
-
});
|