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,77 +0,0 @@
|
|
|
1
|
-
import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
|
|
2
|
-
import { StopAction } from "../../src/commands/general/stop";
|
|
3
|
-
import { SimulatorService } from "../../src/lib/services/simulator";
|
|
4
|
-
import { ISimulatorService } from "../../src/lib/interfaces/ISimulatorService";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
import inquirer from "inquirer";
|
|
8
|
-
|
|
9
|
-
vi.mock("../../src/lib/services/simulator");
|
|
10
|
-
vi.mock("inquirer");
|
|
11
|
-
|
|
12
|
-
describe("StopAction", () => {
|
|
13
|
-
let stopAction: StopAction;
|
|
14
|
-
let mockSimulatorService: ISimulatorService;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
vi.clearAllMocks();
|
|
18
|
-
|
|
19
|
-
mockSimulatorService = {
|
|
20
|
-
stopDockerContainers: vi.fn(),
|
|
21
|
-
} as unknown as ISimulatorService;
|
|
22
|
-
|
|
23
|
-
SimulatorService.prototype.stopDockerContainers = mockSimulatorService.stopDockerContainers;
|
|
24
|
-
|
|
25
|
-
stopAction = new StopAction();
|
|
26
|
-
(stopAction as any).simulatorService = mockSimulatorService;
|
|
27
|
-
|
|
28
|
-
vi.spyOn(stopAction as any, "startSpinner").mockImplementation(() => {});
|
|
29
|
-
vi.spyOn(stopAction as any, "succeedSpinner").mockImplementation(() => {});
|
|
30
|
-
vi.spyOn(stopAction as any, "failSpinner").mockImplementation(() => {});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
vi.restoreAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("should stop containers if user confirms", async () => {
|
|
38
|
-
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: true });
|
|
39
|
-
|
|
40
|
-
await stopAction.stop();
|
|
41
|
-
|
|
42
|
-
expect(inquirer.prompt).toHaveBeenCalledWith([
|
|
43
|
-
{
|
|
44
|
-
type: "confirm",
|
|
45
|
-
name: "confirmAction",
|
|
46
|
-
message: chalk.yellow("Are you sure you want to stop all running GenLayer containers? This will halt all active processes."),
|
|
47
|
-
default: true,
|
|
48
|
-
},
|
|
49
|
-
]);
|
|
50
|
-
expect(mockSimulatorService.stopDockerContainers).toHaveBeenCalled();
|
|
51
|
-
expect(stopAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
52
|
-
"All running GenLayer containers have been successfully stopped."
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("should abort if user cancels", async () => {
|
|
57
|
-
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: false });
|
|
58
|
-
|
|
59
|
-
await stopAction.stop();
|
|
60
|
-
|
|
61
|
-
expect(inquirer.prompt).toHaveBeenCalled();
|
|
62
|
-
expect(mockSimulatorService.stopDockerContainers).not.toHaveBeenCalled();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("should handle errors and call failSpinner", async () => {
|
|
66
|
-
vi.mocked(inquirer.prompt).mockResolvedValue({ confirmAction: true });
|
|
67
|
-
const error = new Error("Test Error");
|
|
68
|
-
mockSimulatorService.stopDockerContainers = vi.fn().mockRejectedValue(error);
|
|
69
|
-
|
|
70
|
-
await stopAction.stop();
|
|
71
|
-
|
|
72
|
-
expect(stopAction["failSpinner"]).toHaveBeenCalledWith(
|
|
73
|
-
"An error occurred while stopping the containers.",
|
|
74
|
-
error
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
|
-
import {UnlockAccountAction} from "../../src/commands/account/unlock";
|
|
3
|
-
import {readFileSync, existsSync, mkdirSync, writeFileSync, readdirSync, unlinkSync, copyFileSync} from "fs";
|
|
4
|
-
import {ethers} from "ethers";
|
|
5
|
-
import inquirer from "inquirer";
|
|
6
|
-
import os from "os";
|
|
7
|
-
|
|
8
|
-
vi.mock("fs");
|
|
9
|
-
vi.mock("ethers");
|
|
10
|
-
vi.mock("inquirer");
|
|
11
|
-
vi.mock("os");
|
|
12
|
-
|
|
13
|
-
describe("UnlockAccountAction", () => {
|
|
14
|
-
let unlockAction: UnlockAccountAction;
|
|
15
|
-
// Standard web3 keystore format
|
|
16
|
-
const mockKeystoreData = {
|
|
17
|
-
address: "1234567890123456789012345678901234567890",
|
|
18
|
-
crypto: {
|
|
19
|
-
cipher: "aes-128-ctr",
|
|
20
|
-
ciphertext: "test",
|
|
21
|
-
cipherparams: {iv: "test"},
|
|
22
|
-
kdf: "scrypt",
|
|
23
|
-
kdfparams: {},
|
|
24
|
-
mac: "test"
|
|
25
|
-
},
|
|
26
|
-
version: 3
|
|
27
|
-
};
|
|
28
|
-
const mockWallet = {
|
|
29
|
-
privateKey: "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
|
|
30
|
-
};
|
|
31
|
-
const mockKeystorePath = "/mocked/home/.genlayer/keystores/default.json";
|
|
32
|
-
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
vi.clearAllMocks();
|
|
35
|
-
// Setup mocks before creating the action (needed for constructor)
|
|
36
|
-
vi.mocked(os.homedir).mockReturnValue("/mocked/home");
|
|
37
|
-
vi.mocked(existsSync).mockReturnValue(true);
|
|
38
|
-
vi.mocked(readFileSync).mockReturnValue(JSON.stringify({activeAccount: "default"}));
|
|
39
|
-
|
|
40
|
-
unlockAction = new UnlockAccountAction();
|
|
41
|
-
|
|
42
|
-
// Mock the BaseAction methods
|
|
43
|
-
vi.spyOn(unlockAction as any, "startSpinner").mockImplementation(() => {});
|
|
44
|
-
vi.spyOn(unlockAction as any, "setSpinnerText").mockImplementation(() => {});
|
|
45
|
-
vi.spyOn(unlockAction as any, "stopSpinner").mockImplementation(() => {});
|
|
46
|
-
vi.spyOn(unlockAction as any, "succeedSpinner").mockImplementation(() => {});
|
|
47
|
-
vi.spyOn(unlockAction as any, "failSpinner").mockImplementation(() => {});
|
|
48
|
-
vi.spyOn(unlockAction as any, "promptPassword").mockResolvedValue("test-password");
|
|
49
|
-
vi.spyOn(unlockAction as any, "getKeystorePath").mockReturnValue(mockKeystorePath);
|
|
50
|
-
vi.spyOn(unlockAction as any, "resolveAccountName").mockReturnValue("default");
|
|
51
|
-
vi.spyOn(unlockAction as any, "isValidKeystoreFormat").mockReturnValue(true);
|
|
52
|
-
|
|
53
|
-
// Mock keychainManager
|
|
54
|
-
vi.spyOn(unlockAction["keychainManager"], "isKeychainAvailable").mockResolvedValue(true);
|
|
55
|
-
vi.spyOn(unlockAction["keychainManager"], "storePrivateKey").mockResolvedValue();
|
|
56
|
-
|
|
57
|
-
// Mock fs and ethers
|
|
58
|
-
vi.mocked(existsSync).mockReturnValue(true);
|
|
59
|
-
vi.mocked(readFileSync).mockReturnValue(JSON.stringify(mockKeystoreData));
|
|
60
|
-
vi.mocked(ethers.Wallet.fromEncryptedJson).mockResolvedValue(mockWallet as any);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
afterEach(() => {
|
|
64
|
-
vi.restoreAllMocks();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("successfully unlocks wallet when all conditions are met", async () => {
|
|
68
|
-
await unlockAction.execute();
|
|
69
|
-
|
|
70
|
-
expect(unlockAction["startSpinner"]).toHaveBeenCalledWith("Checking keychain availability...");
|
|
71
|
-
expect(unlockAction["keychainManager"].isKeychainAvailable).toHaveBeenCalled();
|
|
72
|
-
expect(unlockAction["setSpinnerText"]).toHaveBeenCalledWith("Checking for account 'default'...");
|
|
73
|
-
expect(unlockAction["getKeystorePath"]).toHaveBeenCalledWith("default");
|
|
74
|
-
expect(existsSync).toHaveBeenCalledWith(mockKeystorePath);
|
|
75
|
-
expect(unlockAction["stopSpinner"]).toHaveBeenCalled();
|
|
76
|
-
expect(unlockAction["promptPassword"]).toHaveBeenCalledWith("Enter password to unlock 'default':");
|
|
77
|
-
expect(readFileSync).toHaveBeenCalledWith(mockKeystorePath, "utf-8");
|
|
78
|
-
expect(ethers.Wallet.fromEncryptedJson).toHaveBeenCalledWith(JSON.stringify(mockKeystoreData), "test-password");
|
|
79
|
-
expect(unlockAction["keychainManager"].storePrivateKey).toHaveBeenCalledWith("default", mockWallet.privateKey);
|
|
80
|
-
expect(unlockAction["succeedSpinner"]).toHaveBeenCalledWith("Account 'default' unlocked! Private key cached in OS keychain.");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("fails when keychain is not available", async () => {
|
|
84
|
-
vi.spyOn(unlockAction["keychainManager"], "isKeychainAvailable").mockResolvedValue(false);
|
|
85
|
-
|
|
86
|
-
await unlockAction.execute();
|
|
87
|
-
|
|
88
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("OS keychain is not available. This command requires a supported keychain (e.g. macOS Keychain, Windows Credential Manager, or GNOME Keyring).");
|
|
89
|
-
expect(unlockAction["promptPassword"]).not.toHaveBeenCalled();
|
|
90
|
-
expect(unlockAction["keychainManager"].storePrivateKey).not.toHaveBeenCalled();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("fails when keystore file does not exist", async () => {
|
|
94
|
-
vi.mocked(existsSync).mockReturnValue(false);
|
|
95
|
-
|
|
96
|
-
await unlockAction.execute();
|
|
97
|
-
|
|
98
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Account 'default' not found. Run 'genlayer account create --name default' first.");
|
|
99
|
-
expect(unlockAction["promptPassword"]).not.toHaveBeenCalled();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("fails when keystore format is invalid", async () => {
|
|
103
|
-
vi.spyOn(unlockAction as any, "isValidKeystoreFormat").mockReturnValue(false);
|
|
104
|
-
|
|
105
|
-
await unlockAction.execute();
|
|
106
|
-
|
|
107
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Invalid keystore format.");
|
|
108
|
-
expect(unlockAction["promptPassword"]).not.toHaveBeenCalled();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("handles error during wallet decryption", async () => {
|
|
112
|
-
const mockError = new Error("Decryption failed");
|
|
113
|
-
vi.mocked(ethers.Wallet.fromEncryptedJson).mockRejectedValue(mockError);
|
|
114
|
-
|
|
115
|
-
await unlockAction.execute();
|
|
116
|
-
|
|
117
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Failed to unlock account.", mockError);
|
|
118
|
-
expect(unlockAction["keychainManager"].storePrivateKey).not.toHaveBeenCalled();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("handles error during key storage", async () => {
|
|
122
|
-
const mockError = new Error("Storage failed");
|
|
123
|
-
vi.spyOn(unlockAction["keychainManager"], "storePrivateKey").mockRejectedValue(mockError);
|
|
124
|
-
|
|
125
|
-
await unlockAction.execute();
|
|
126
|
-
|
|
127
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Failed to unlock account.", mockError);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("uses account option when provided", async () => {
|
|
131
|
-
vi.spyOn(unlockAction as any, "resolveAccountName").mockReturnValue("validator");
|
|
132
|
-
vi.spyOn(unlockAction as any, "getKeystorePath").mockReturnValue("/mocked/home/.genlayer/keystores/validator.json");
|
|
133
|
-
|
|
134
|
-
await unlockAction.execute({account: "validator"});
|
|
135
|
-
|
|
136
|
-
expect(unlockAction["accountOverride"]).toBe("validator");
|
|
137
|
-
expect(unlockAction["setSpinnerText"]).toHaveBeenCalledWith("Checking for account 'validator'...");
|
|
138
|
-
});
|
|
139
|
-
});
|