genlayer 0.32.0 → 0.32.2
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 +4 -0
- package/README.md +1 -1
- package/dist/index.js +1425 -222
- package/docs/delegator-guide.md +6 -6
- package/docs/validator-guide.md +51 -18
- package/package.json +2 -2
- package/src/commands/account/create.ts +10 -4
- package/src/commands/account/export.ts +106 -0
- package/src/commands/account/import.ts +85 -31
- package/src/commands/account/index.ts +77 -18
- package/src/commands/account/list.ts +34 -0
- package/src/commands/account/lock.ts +16 -7
- package/src/commands/account/remove.ts +30 -0
- package/src/commands/account/send.ts +14 -8
- package/src/commands/account/show.ts +22 -8
- package/src/commands/account/unlock.ts +20 -10
- package/src/commands/account/use.ts +21 -0
- package/src/commands/network/index.ts +18 -3
- package/src/commands/network/setNetwork.ts +38 -22
- package/src/commands/staking/StakingAction.ts +51 -19
- package/src/commands/staking/delegatorJoin.ts +2 -0
- package/src/commands/staking/index.ts +29 -2
- package/src/commands/staking/setIdentity.ts +5 -0
- package/src/commands/staking/stakingInfo.ts +29 -21
- package/src/commands/staking/wizard.ts +809 -0
- package/src/lib/actions/BaseAction.ts +71 -45
- package/src/lib/config/ConfigFileManager.ts +143 -0
- package/src/lib/config/KeychainManager.ts +68 -8
- package/tests/actions/create.test.ts +30 -10
- package/tests/actions/deploy.test.ts +7 -0
- package/tests/actions/lock.test.ts +28 -8
- package/tests/actions/unlock.test.ts +44 -26
- package/tests/commands/account.test.ts +43 -18
- package/tests/commands/network.test.ts +10 -10
- package/tests/commands/staking.test.ts +122 -0
- package/tests/libs/baseAction.test.ts +64 -41
- package/tests/libs/configFileManager.test.ts +8 -1
- package/tests/libs/keychainManager.test.ts +62 -18
- package/src/lib/interfaces/KeystoreData.ts +0 -5
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
2
|
import {UnlockAccountAction} from "../../src/commands/account/unlock";
|
|
3
|
-
import {readFileSync, existsSync} from "fs";
|
|
3
|
+
import {readFileSync, existsSync, mkdirSync, writeFileSync, readdirSync, unlinkSync, copyFileSync} from "fs";
|
|
4
4
|
import {ethers} from "ethers";
|
|
5
5
|
import inquirer from "inquirer";
|
|
6
|
+
import os from "os";
|
|
6
7
|
|
|
7
8
|
vi.mock("fs");
|
|
8
9
|
vi.mock("ethers");
|
|
9
10
|
vi.mock("inquirer");
|
|
11
|
+
vi.mock("os");
|
|
10
12
|
|
|
11
13
|
describe("UnlockAccountAction", () => {
|
|
12
14
|
let unlockAction: UnlockAccountAction;
|
|
15
|
+
// Standard web3 keystore format
|
|
13
16
|
const mockKeystoreData = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
17
27
|
};
|
|
18
28
|
const mockWallet = {
|
|
19
29
|
privateKey: "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
|
|
20
30
|
};
|
|
31
|
+
const mockKeystorePath = "/mocked/home/.genlayer/keystores/default.json";
|
|
21
32
|
|
|
22
33
|
beforeEach(() => {
|
|
23
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
|
+
|
|
24
40
|
unlockAction = new UnlockAccountAction();
|
|
25
|
-
|
|
41
|
+
|
|
26
42
|
// Mock the BaseAction methods
|
|
27
43
|
vi.spyOn(unlockAction as any, "startSpinner").mockImplementation(() => {});
|
|
28
44
|
vi.spyOn(unlockAction as any, "setSpinnerText").mockImplementation(() => {});
|
|
@@ -30,13 +46,14 @@ describe("UnlockAccountAction", () => {
|
|
|
30
46
|
vi.spyOn(unlockAction as any, "succeedSpinner").mockImplementation(() => {});
|
|
31
47
|
vi.spyOn(unlockAction as any, "failSpinner").mockImplementation(() => {});
|
|
32
48
|
vi.spyOn(unlockAction as any, "promptPassword").mockResolvedValue("test-password");
|
|
33
|
-
vi.spyOn(unlockAction as any, "
|
|
49
|
+
vi.spyOn(unlockAction as any, "getKeystorePath").mockReturnValue(mockKeystorePath);
|
|
50
|
+
vi.spyOn(unlockAction as any, "resolveAccountName").mockReturnValue("default");
|
|
34
51
|
vi.spyOn(unlockAction as any, "isValidKeystoreFormat").mockReturnValue(true);
|
|
35
|
-
|
|
52
|
+
|
|
36
53
|
// Mock keychainManager
|
|
37
54
|
vi.spyOn(unlockAction["keychainManager"], "isKeychainAvailable").mockResolvedValue(true);
|
|
38
55
|
vi.spyOn(unlockAction["keychainManager"], "storePrivateKey").mockResolvedValue();
|
|
39
|
-
|
|
56
|
+
|
|
40
57
|
// Mock fs and ethers
|
|
41
58
|
vi.mocked(existsSync).mockReturnValue(true);
|
|
42
59
|
vi.mocked(readFileSync).mockReturnValue(JSON.stringify(mockKeystoreData));
|
|
@@ -52,15 +69,15 @@ describe("UnlockAccountAction", () => {
|
|
|
52
69
|
|
|
53
70
|
expect(unlockAction["startSpinner"]).toHaveBeenCalledWith("Checking keychain availability...");
|
|
54
71
|
expect(unlockAction["keychainManager"].isKeychainAvailable).toHaveBeenCalled();
|
|
55
|
-
expect(unlockAction["setSpinnerText"]).toHaveBeenCalledWith("Checking for
|
|
56
|
-
expect(unlockAction["
|
|
57
|
-
expect(existsSync).toHaveBeenCalledWith(
|
|
72
|
+
expect(unlockAction["setSpinnerText"]).toHaveBeenCalledWith("Checking for account 'default'...");
|
|
73
|
+
expect(unlockAction["getKeystorePath"]).toHaveBeenCalledWith("default");
|
|
74
|
+
expect(existsSync).toHaveBeenCalledWith(mockKeystorePath);
|
|
58
75
|
expect(unlockAction["stopSpinner"]).toHaveBeenCalled();
|
|
59
|
-
expect(unlockAction["promptPassword"]).toHaveBeenCalledWith("Enter password to unlock
|
|
60
|
-
expect(readFileSync).toHaveBeenCalledWith(
|
|
61
|
-
expect(ethers.Wallet.fromEncryptedJson).toHaveBeenCalledWith(mockKeystoreData
|
|
62
|
-
expect(unlockAction["keychainManager"].storePrivateKey).toHaveBeenCalledWith(mockWallet.privateKey);
|
|
63
|
-
expect(unlockAction["succeedSpinner"]).toHaveBeenCalledWith("Account unlocked! Private key cached in OS keychain.");
|
|
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.");
|
|
64
81
|
});
|
|
65
82
|
|
|
66
83
|
test("fails when keychain is not available", async () => {
|
|
@@ -73,21 +90,12 @@ describe("UnlockAccountAction", () => {
|
|
|
73
90
|
expect(unlockAction["keychainManager"].storePrivateKey).not.toHaveBeenCalled();
|
|
74
91
|
});
|
|
75
92
|
|
|
76
|
-
test("fails when no keystore file is found", async () => {
|
|
77
|
-
vi.spyOn(unlockAction as any, "getConfigByKey").mockReturnValue(null);
|
|
78
|
-
|
|
79
|
-
await unlockAction.execute();
|
|
80
|
-
|
|
81
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("No account found. Run 'genlayer account create' first.");
|
|
82
|
-
expect(unlockAction["promptPassword"]).not.toHaveBeenCalled();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
93
|
test("fails when keystore file does not exist", async () => {
|
|
86
94
|
vi.mocked(existsSync).mockReturnValue(false);
|
|
87
95
|
|
|
88
96
|
await unlockAction.execute();
|
|
89
97
|
|
|
90
|
-
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("
|
|
98
|
+
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Account 'default' not found. Run 'genlayer account create --name default' first.");
|
|
91
99
|
expect(unlockAction["promptPassword"]).not.toHaveBeenCalled();
|
|
92
100
|
});
|
|
93
101
|
|
|
@@ -118,4 +126,14 @@ describe("UnlockAccountAction", () => {
|
|
|
118
126
|
|
|
119
127
|
expect(unlockAction["failSpinner"]).toHaveBeenCalledWith("Failed to unlock account.", mockError);
|
|
120
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
|
+
});
|
|
121
139
|
});
|
|
@@ -8,6 +8,12 @@ import { LockAccountAction } from "../../src/commands/account/lock";
|
|
|
8
8
|
vi.mock("../../src/commands/account/create");
|
|
9
9
|
vi.mock("../../src/commands/account/unlock");
|
|
10
10
|
vi.mock("../../src/commands/account/lock");
|
|
11
|
+
vi.mock("../../src/commands/account/show");
|
|
12
|
+
vi.mock("../../src/commands/account/import");
|
|
13
|
+
vi.mock("../../src/commands/account/send");
|
|
14
|
+
vi.mock("../../src/commands/account/list");
|
|
15
|
+
vi.mock("../../src/commands/account/use");
|
|
16
|
+
vi.mock("../../src/commands/account/remove");
|
|
11
17
|
|
|
12
18
|
describe("account create command", () => {
|
|
13
19
|
let program: Command;
|
|
@@ -22,51 +28,54 @@ describe("account create command", () => {
|
|
|
22
28
|
vi.restoreAllMocks();
|
|
23
29
|
});
|
|
24
30
|
|
|
25
|
-
test("CreateAccountAction.execute is called with
|
|
26
|
-
program.parse(["node", "test", "account", "create"]);
|
|
31
|
+
test("CreateAccountAction.execute is called with name option", async () => {
|
|
32
|
+
program.parse(["node", "test", "account", "create", "--name", "main"]);
|
|
27
33
|
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
28
34
|
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
29
|
-
|
|
35
|
+
name: "main",
|
|
30
36
|
overwrite: false,
|
|
37
|
+
setActive: true,
|
|
31
38
|
});
|
|
32
39
|
});
|
|
33
40
|
|
|
34
|
-
test("CreateAccountAction.execute is called with custom
|
|
35
|
-
program.parse(["node", "test", "account", "create", "--
|
|
41
|
+
test("CreateAccountAction.execute is called with custom name option", async () => {
|
|
42
|
+
program.parse(["node", "test", "account", "create", "--name", "validator"]);
|
|
36
43
|
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
37
44
|
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
38
|
-
|
|
45
|
+
name: "validator",
|
|
39
46
|
overwrite: false,
|
|
47
|
+
setActive: true,
|
|
40
48
|
});
|
|
41
49
|
});
|
|
42
50
|
|
|
43
51
|
test("CreateAccountAction.execute is called with overwrite enabled", async () => {
|
|
44
|
-
program.parse(["node", "test", "account", "create", "--overwrite"]);
|
|
52
|
+
program.parse(["node", "test", "account", "create", "--name", "main", "--overwrite"]);
|
|
45
53
|
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
46
54
|
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
47
|
-
|
|
55
|
+
name: "main",
|
|
48
56
|
overwrite: true,
|
|
57
|
+
setActive: true,
|
|
49
58
|
});
|
|
50
59
|
});
|
|
51
60
|
|
|
52
|
-
test("CreateAccountAction.execute is called with
|
|
53
|
-
program.parse(["node", "test", "account", "create", "--
|
|
61
|
+
test("CreateAccountAction.execute is called with no-set-active option", async () => {
|
|
62
|
+
program.parse(["node", "test", "account", "create", "--name", "operator", "--no-set-active"]);
|
|
54
63
|
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
55
64
|
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
56
|
-
|
|
57
|
-
overwrite:
|
|
65
|
+
name: "operator",
|
|
66
|
+
overwrite: false,
|
|
67
|
+
setActive: false,
|
|
58
68
|
});
|
|
59
69
|
});
|
|
60
70
|
|
|
61
71
|
test("CreateAccountAction is instantiated when the command is executed", async () => {
|
|
62
|
-
program.parse(["node", "test", "account", "create"]);
|
|
72
|
+
program.parse(["node", "test", "account", "create", "--name", "main"]);
|
|
63
73
|
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
64
74
|
});
|
|
65
75
|
|
|
66
|
-
test("CreateAccountAction.execute is called without throwing errors
|
|
67
|
-
program.parse(["node", "test", "account", "create"]);
|
|
76
|
+
test("CreateAccountAction.execute is called without throwing errors", async () => {
|
|
68
77
|
vi.mocked(CreateAccountAction.prototype.execute).mockReturnValue(Promise.resolve());
|
|
69
|
-
expect(() => program.parse(["node", "test", "account", "create"])).not.toThrow();
|
|
78
|
+
expect(() => program.parse(["node", "test", "account", "create", "--name", "main"])).not.toThrow();
|
|
70
79
|
});
|
|
71
80
|
});
|
|
72
81
|
|
|
@@ -86,7 +95,15 @@ describe("account unlock command", () => {
|
|
|
86
95
|
test("UnlockAccountAction is instantiated and execute is called", async () => {
|
|
87
96
|
program.parse(["node", "test", "account", "unlock"]);
|
|
88
97
|
expect(UnlockAccountAction).toHaveBeenCalledTimes(1);
|
|
89
|
-
expect(UnlockAccountAction.prototype.execute).
|
|
98
|
+
expect(UnlockAccountAction.prototype.execute).toHaveBeenCalledWith({});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("UnlockAccountAction.execute is called with account option", async () => {
|
|
102
|
+
program.parse(["node", "test", "account", "unlock", "--account", "validator"]);
|
|
103
|
+
expect(UnlockAccountAction).toHaveBeenCalledTimes(1);
|
|
104
|
+
expect(UnlockAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
105
|
+
account: "validator",
|
|
106
|
+
});
|
|
90
107
|
});
|
|
91
108
|
|
|
92
109
|
test("UnlockAccountAction.execute is called without throwing errors", async () => {
|
|
@@ -111,7 +128,15 @@ describe("account lock command", () => {
|
|
|
111
128
|
test("LockAccountAction is instantiated and execute is called", async () => {
|
|
112
129
|
program.parse(["node", "test", "account", "lock"]);
|
|
113
130
|
expect(LockAccountAction).toHaveBeenCalledTimes(1);
|
|
114
|
-
expect(LockAccountAction.prototype.execute).
|
|
131
|
+
expect(LockAccountAction.prototype.execute).toHaveBeenCalledWith({});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("LockAccountAction.execute is called with account option", async () => {
|
|
135
|
+
program.parse(["node", "test", "account", "lock", "--account", "validator"]);
|
|
136
|
+
expect(LockAccountAction).toHaveBeenCalledTimes(1);
|
|
137
|
+
expect(LockAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
138
|
+
account: "validator",
|
|
139
|
+
});
|
|
115
140
|
});
|
|
116
141
|
|
|
117
142
|
test("LockAccountAction.execute is called without throwing errors", async () => {
|
|
@@ -18,43 +18,43 @@ describe("network commands", () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test("NetworkActions.setNetwork is called with the correct network name", async () => {
|
|
21
|
-
program.parse(["node", "test", "network", "localnet"]);
|
|
21
|
+
program.parse(["node", "test", "network", "set", "localnet"]);
|
|
22
22
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
23
23
|
expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("localnet");
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
test("NetworkActions.setNetwork is called with testnet-asimov", async () => {
|
|
27
|
-
program.parse(["node", "test", "network", "testnet-asimov"]);
|
|
27
|
+
program.parse(["node", "test", "network", "set", "testnet-asimov"]);
|
|
28
28
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
29
29
|
expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("testnet-asimov");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test("NetworkActions.setNetwork is called with studionet", async () => {
|
|
33
|
-
program.parse(["node", "test", "network", "studionet"]);
|
|
33
|
+
program.parse(["node", "test", "network", "set", "studionet"]);
|
|
34
34
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
35
35
|
expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("studionet");
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
test("NetworkActions.setNetwork is called without a network name", async () => {
|
|
39
|
-
program.parse(["node", "test", "network"]);
|
|
39
|
+
program.parse(["node", "test", "network", "set"]);
|
|
40
40
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
41
41
|
expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith(undefined);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
test("NetworkActions is instantiated when the command is executed", async () => {
|
|
45
|
-
program.parse(["node", "test", "network", "localnet"]);
|
|
45
|
+
program.parse(["node", "test", "network", "set", "localnet"]);
|
|
46
46
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test("NetworkActions.setNetwork is called without throwing errors for valid network", async () => {
|
|
50
|
-
program.parse(["node", "test", "network", "localnet"]);
|
|
50
|
+
program.parse(["node", "test", "network", "set", "localnet"]);
|
|
51
51
|
vi.mocked(NetworkActions.prototype.setNetwork).mockResolvedValue();
|
|
52
|
-
expect(() => program.parse(["node", "test", "network", "localnet"])).not.toThrow();
|
|
52
|
+
expect(() => program.parse(["node", "test", "network", "set", "localnet"])).not.toThrow();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
test("NetworkActions.
|
|
56
|
-
program.parse(["node", "test", "network", ""]);
|
|
55
|
+
test("NetworkActions.showInfo is called for network info", async () => {
|
|
56
|
+
program.parse(["node", "test", "network", "info"]);
|
|
57
57
|
expect(NetworkActions).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(NetworkActions.prototype.
|
|
58
|
+
expect(NetworkActions.prototype.showInfo).toHaveBeenCalled();
|
|
59
59
|
});
|
|
60
60
|
});
|
|
@@ -5,6 +5,9 @@ import {ValidatorJoinAction} from "../../src/commands/staking/validatorJoin";
|
|
|
5
5
|
import {ValidatorDepositAction} from "../../src/commands/staking/validatorDeposit";
|
|
6
6
|
import {ValidatorExitAction} from "../../src/commands/staking/validatorExit";
|
|
7
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";
|
|
8
11
|
import {DelegatorJoinAction} from "../../src/commands/staking/delegatorJoin";
|
|
9
12
|
import {DelegatorExitAction} from "../../src/commands/staking/delegatorExit";
|
|
10
13
|
import {DelegatorClaimAction} from "../../src/commands/staking/delegatorClaim";
|
|
@@ -14,6 +17,9 @@ vi.mock("../../src/commands/staking/validatorJoin");
|
|
|
14
17
|
vi.mock("../../src/commands/staking/validatorDeposit");
|
|
15
18
|
vi.mock("../../src/commands/staking/validatorExit");
|
|
16
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");
|
|
17
23
|
vi.mock("../../src/commands/staking/delegatorJoin");
|
|
18
24
|
vi.mock("../../src/commands/staking/delegatorExit");
|
|
19
25
|
vi.mock("../../src/commands/staking/delegatorClaim");
|
|
@@ -208,4 +214,120 @@ describe("staking commands", () => {
|
|
|
208
214
|
expect(StakingInfoAction.prototype.listActiveValidators).toHaveBeenCalledWith({});
|
|
209
215
|
});
|
|
210
216
|
});
|
|
217
|
+
|
|
218
|
+
describe("validator-prime", () => {
|
|
219
|
+
test("calls ValidatorPrimeAction.execute", async () => {
|
|
220
|
+
program.parse(["node", "test", "staking", "validator-prime", "--validator", "0xValidator"]);
|
|
221
|
+
|
|
222
|
+
expect(ValidatorPrimeAction).toHaveBeenCalledTimes(1);
|
|
223
|
+
expect(ValidatorPrimeAction.prototype.execute).toHaveBeenCalledWith({
|
|
224
|
+
validator: "0xValidator",
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("set-operator", () => {
|
|
230
|
+
test("calls SetOperatorAction.execute", async () => {
|
|
231
|
+
program.parse([
|
|
232
|
+
"node",
|
|
233
|
+
"test",
|
|
234
|
+
"staking",
|
|
235
|
+
"set-operator",
|
|
236
|
+
"--validator",
|
|
237
|
+
"0xValidator",
|
|
238
|
+
"--operator",
|
|
239
|
+
"0xOperator",
|
|
240
|
+
]);
|
|
241
|
+
|
|
242
|
+
expect(SetOperatorAction).toHaveBeenCalledTimes(1);
|
|
243
|
+
expect(SetOperatorAction.prototype.execute).toHaveBeenCalledWith({
|
|
244
|
+
validator: "0xValidator",
|
|
245
|
+
operator: "0xOperator",
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("set-identity", () => {
|
|
251
|
+
test("calls SetIdentityAction.execute with required fields", async () => {
|
|
252
|
+
program.parse([
|
|
253
|
+
"node",
|
|
254
|
+
"test",
|
|
255
|
+
"staking",
|
|
256
|
+
"set-identity",
|
|
257
|
+
"--validator",
|
|
258
|
+
"0xValidator",
|
|
259
|
+
"--moniker",
|
|
260
|
+
"My Validator",
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
expect(SetIdentityAction).toHaveBeenCalledTimes(1);
|
|
264
|
+
expect(SetIdentityAction.prototype.execute).toHaveBeenCalledWith({
|
|
265
|
+
validator: "0xValidator",
|
|
266
|
+
moniker: "My Validator",
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("calls SetIdentityAction.execute with all optional fields", async () => {
|
|
271
|
+
program.parse([
|
|
272
|
+
"node",
|
|
273
|
+
"test",
|
|
274
|
+
"staking",
|
|
275
|
+
"set-identity",
|
|
276
|
+
"--validator",
|
|
277
|
+
"0xValidator",
|
|
278
|
+
"--moniker",
|
|
279
|
+
"My Validator",
|
|
280
|
+
"--website",
|
|
281
|
+
"https://example.com",
|
|
282
|
+
"--twitter",
|
|
283
|
+
"myhandle",
|
|
284
|
+
"--github",
|
|
285
|
+
"mygithub",
|
|
286
|
+
]);
|
|
287
|
+
|
|
288
|
+
expect(SetIdentityAction.prototype.execute).toHaveBeenCalledWith({
|
|
289
|
+
validator: "0xValidator",
|
|
290
|
+
moniker: "My Validator",
|
|
291
|
+
website: "https://example.com",
|
|
292
|
+
twitter: "myhandle",
|
|
293
|
+
github: "mygithub",
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("delegation-info", () => {
|
|
299
|
+
test("calls StakingInfoAction.getStakeInfo", async () => {
|
|
300
|
+
program.parse([
|
|
301
|
+
"node",
|
|
302
|
+
"test",
|
|
303
|
+
"staking",
|
|
304
|
+
"delegation-info",
|
|
305
|
+
"--validator",
|
|
306
|
+
"0xValidator",
|
|
307
|
+
]);
|
|
308
|
+
|
|
309
|
+
expect(StakingInfoAction).toHaveBeenCalledTimes(1);
|
|
310
|
+
expect(StakingInfoAction.prototype.getStakeInfo).toHaveBeenCalledWith({
|
|
311
|
+
validator: "0xValidator",
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("calls StakingInfoAction.getStakeInfo with delegator", async () => {
|
|
316
|
+
program.parse([
|
|
317
|
+
"node",
|
|
318
|
+
"test",
|
|
319
|
+
"staking",
|
|
320
|
+
"delegation-info",
|
|
321
|
+
"--validator",
|
|
322
|
+
"0xValidator",
|
|
323
|
+
"--delegator",
|
|
324
|
+
"0xDelegator",
|
|
325
|
+
]);
|
|
326
|
+
|
|
327
|
+
expect(StakingInfoAction.prototype.getStakeInfo).toHaveBeenCalledWith({
|
|
328
|
+
validator: "0xValidator",
|
|
329
|
+
delegator: "0xDelegator",
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
211
333
|
});
|