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,102 +0,0 @@
|
|
|
1
|
-
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
|
-
import {createClient, createAccount} from "genlayer-js";
|
|
3
|
-
import {WriteAction} from "../../src/commands/contracts/write";
|
|
4
|
-
|
|
5
|
-
vi.mock("genlayer-js");
|
|
6
|
-
|
|
7
|
-
describe("WriteAction", () => {
|
|
8
|
-
let writeAction: WriteAction;
|
|
9
|
-
const mockClient = {
|
|
10
|
-
writeContract: vi.fn(),
|
|
11
|
-
waitForTransactionReceipt: vi.fn(),
|
|
12
|
-
initializeConsensusSmartContract: vi.fn(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const mockPrivateKey = "mocked_private_key";
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
vi.clearAllMocks();
|
|
19
|
-
vi.mocked(createClient).mockReturnValue(mockClient as any);
|
|
20
|
-
vi.mocked(createAccount).mockReturnValue({privateKey: mockPrivateKey} as any);
|
|
21
|
-
writeAction = new WriteAction();
|
|
22
|
-
vi.spyOn(writeAction as any, "getAccount").mockResolvedValue({privateKey: mockPrivateKey});
|
|
23
|
-
|
|
24
|
-
vi.spyOn(writeAction as any, "startSpinner").mockImplementation(() => {});
|
|
25
|
-
vi.spyOn(writeAction as any, "succeedSpinner").mockImplementation(() => {});
|
|
26
|
-
vi.spyOn(writeAction as any, "failSpinner").mockImplementation(() => {});
|
|
27
|
-
vi.spyOn(writeAction as any, "log").mockImplementation(() => {});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
vi.restoreAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("calls writeContract successfully", async () => {
|
|
35
|
-
const options = {args: [42, "Update"]};
|
|
36
|
-
const mockHash = "0xMockedTransactionHash";
|
|
37
|
-
const mockReceipt = {status: "success"};
|
|
38
|
-
|
|
39
|
-
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
|
|
40
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
|
|
41
|
-
|
|
42
|
-
await writeAction.write({
|
|
43
|
-
contractAddress: "0xMockedContract",
|
|
44
|
-
method: "updateData",
|
|
45
|
-
...options,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(mockClient.writeContract).toHaveBeenCalledWith({
|
|
49
|
-
address: "0xMockedContract",
|
|
50
|
-
functionName: "updateData",
|
|
51
|
-
args: [42, "Update"],
|
|
52
|
-
value: 0n,
|
|
53
|
-
});
|
|
54
|
-
expect(writeAction["log"]).toHaveBeenCalledWith("Write Transaction Hash:", mockHash);
|
|
55
|
-
expect(writeAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
56
|
-
"Write operation successfully executed",
|
|
57
|
-
mockReceipt,
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("handles writeContract errors", async () => {
|
|
62
|
-
vi.mocked(mockClient.writeContract).mockRejectedValue(new Error("Mocked write error"));
|
|
63
|
-
|
|
64
|
-
await writeAction.write({contractAddress: "0xMockedContract", method: "updateData", args: [1]});
|
|
65
|
-
|
|
66
|
-
expect(writeAction["failSpinner"]).toHaveBeenCalledWith(
|
|
67
|
-
"Error during write operation",
|
|
68
|
-
expect.any(Error),
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("uses custom RPC URL for write operations", async () => {
|
|
73
|
-
const options = {args: [42, "Update"], rpc: "https://custom-rpc-url.com"};
|
|
74
|
-
const mockHash = "0xMockedTransactionHash";
|
|
75
|
-
const mockReceipt = {status: "success"};
|
|
76
|
-
|
|
77
|
-
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
|
|
78
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
|
|
79
|
-
|
|
80
|
-
await writeAction.write({
|
|
81
|
-
contractAddress: "0xMockedContract",
|
|
82
|
-
method: "updateData",
|
|
83
|
-
...options,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
87
|
-
expect.objectContaining({
|
|
88
|
-
endpoint: "https://custom-rpc-url.com",
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
expect(mockClient.writeContract).toHaveBeenCalledWith({
|
|
92
|
-
address: "0xMockedContract",
|
|
93
|
-
functionName: "updateData",
|
|
94
|
-
args: [42, "Update"],
|
|
95
|
-
value: 0n,
|
|
96
|
-
});
|
|
97
|
-
expect(writeAction["succeedSpinner"]).toHaveBeenCalledWith(
|
|
98
|
-
"Write operation successfully executed",
|
|
99
|
-
mockReceipt,
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
3
|
-
import { initializeAccountCommands } from "../../src/commands/account";
|
|
4
|
-
import { CreateAccountAction } from "../../src/commands/account/create";
|
|
5
|
-
import { UnlockAccountAction } from "../../src/commands/account/unlock";
|
|
6
|
-
import { LockAccountAction } from "../../src/commands/account/lock";
|
|
7
|
-
|
|
8
|
-
vi.mock("../../src/commands/account/create");
|
|
9
|
-
vi.mock("../../src/commands/account/unlock");
|
|
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");
|
|
17
|
-
|
|
18
|
-
describe("account create command", () => {
|
|
19
|
-
let program: Command;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
program = new Command();
|
|
23
|
-
initializeAccountCommands(program);
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
vi.restoreAllMocks();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("CreateAccountAction.execute is called with name option", async () => {
|
|
32
|
-
program.parse(["node", "test", "account", "create", "--name", "main"]);
|
|
33
|
-
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
34
|
-
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
35
|
-
name: "main",
|
|
36
|
-
overwrite: false,
|
|
37
|
-
setActive: true,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("CreateAccountAction.execute is called with custom name option", async () => {
|
|
42
|
-
program.parse(["node", "test", "account", "create", "--name", "validator"]);
|
|
43
|
-
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
44
|
-
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
45
|
-
name: "validator",
|
|
46
|
-
overwrite: false,
|
|
47
|
-
setActive: true,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("CreateAccountAction.execute is called with overwrite enabled", async () => {
|
|
52
|
-
program.parse(["node", "test", "account", "create", "--name", "main", "--overwrite"]);
|
|
53
|
-
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
55
|
-
name: "main",
|
|
56
|
-
overwrite: true,
|
|
57
|
-
setActive: true,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("CreateAccountAction.execute is called with no-set-active option", async () => {
|
|
62
|
-
program.parse(["node", "test", "account", "create", "--name", "operator", "--no-set-active"]);
|
|
63
|
-
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
64
|
-
expect(CreateAccountAction.prototype.execute).toHaveBeenCalledWith({
|
|
65
|
-
name: "operator",
|
|
66
|
-
overwrite: false,
|
|
67
|
-
setActive: false,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("CreateAccountAction is instantiated when the command is executed", async () => {
|
|
72
|
-
program.parse(["node", "test", "account", "create", "--name", "main"]);
|
|
73
|
-
expect(CreateAccountAction).toHaveBeenCalledTimes(1);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("CreateAccountAction.execute is called without throwing errors", async () => {
|
|
77
|
-
vi.mocked(CreateAccountAction.prototype.execute).mockReturnValue(Promise.resolve());
|
|
78
|
-
expect(() => program.parse(["node", "test", "account", "create", "--name", "main"])).not.toThrow();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("account unlock command", () => {
|
|
83
|
-
let program: Command;
|
|
84
|
-
|
|
85
|
-
beforeEach(() => {
|
|
86
|
-
program = new Command();
|
|
87
|
-
initializeAccountCommands(program);
|
|
88
|
-
vi.clearAllMocks();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
afterEach(() => {
|
|
92
|
-
vi.restoreAllMocks();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test("UnlockAccountAction is instantiated and execute is called", async () => {
|
|
96
|
-
program.parse(["node", "test", "account", "unlock"]);
|
|
97
|
-
expect(UnlockAccountAction).toHaveBeenCalledTimes(1);
|
|
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
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("UnlockAccountAction.execute is called without throwing errors", async () => {
|
|
110
|
-
vi.mocked(UnlockAccountAction.prototype.execute).mockResolvedValue();
|
|
111
|
-
expect(() => program.parse(["node", "test", "account", "unlock"])).not.toThrow();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe("account lock command", () => {
|
|
116
|
-
let program: Command;
|
|
117
|
-
|
|
118
|
-
beforeEach(() => {
|
|
119
|
-
program = new Command();
|
|
120
|
-
initializeAccountCommands(program);
|
|
121
|
-
vi.clearAllMocks();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
afterEach(() => {
|
|
125
|
-
vi.restoreAllMocks();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("LockAccountAction is instantiated and execute is called", async () => {
|
|
129
|
-
program.parse(["node", "test", "account", "lock"]);
|
|
130
|
-
expect(LockAccountAction).toHaveBeenCalledTimes(1);
|
|
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
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("LockAccountAction.execute is called without throwing errors", async () => {
|
|
143
|
-
vi.mocked(LockAccountAction.prototype.execute).mockResolvedValue();
|
|
144
|
-
expect(() => program.parse(["node", "test", "account", "lock"])).not.toThrow();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {Command} from "commander";
|
|
2
|
-
import {AppealAction} from "../../src/commands/transactions/appeal";
|
|
3
|
-
import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
|
|
4
|
-
import {initializeTransactionsCommands} from "../../src/commands/transactions";
|
|
5
|
-
|
|
6
|
-
vi.mock("../../src/commands/transactions/appeal");
|
|
7
|
-
|
|
8
|
-
describe("appeal command", () => {
|
|
9
|
-
let program: Command;
|
|
10
|
-
const mockTxId = "0x1234567890123456789012345678901234567890123456789012345678901234";
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
program = new Command();
|
|
14
|
-
initializeTransactionsCommands(program);
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
vi.restoreAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("AppealAction.appeal is called with default options", async () => {
|
|
23
|
-
program.parse(["node", "test", "appeal", mockTxId]);
|
|
24
|
-
expect(AppealAction).toHaveBeenCalledTimes(1);
|
|
25
|
-
expect(AppealAction.prototype.appeal).toHaveBeenCalledWith({
|
|
26
|
-
txId: mockTxId,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("AppealAction.appeal is called with custom RPC URL", async () => {
|
|
31
|
-
program.parse([
|
|
32
|
-
"node",
|
|
33
|
-
"test",
|
|
34
|
-
"appeal",
|
|
35
|
-
mockTxId,
|
|
36
|
-
"--rpc",
|
|
37
|
-
"https://custom-rpc-url-for-appeal.com",
|
|
38
|
-
]);
|
|
39
|
-
expect(AppealAction).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(AppealAction.prototype.appeal).toHaveBeenCalledWith({
|
|
41
|
-
txId: mockTxId,
|
|
42
|
-
rpc: "https://custom-rpc-url-for-appeal.com",
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("AppealAction is instantiated when the appeal command is executed", async () => {
|
|
47
|
-
program.parse(["node", "test", "appeal", mockTxId]);
|
|
48
|
-
expect(AppealAction).toHaveBeenCalledTimes(1);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("throws error for unrecognized options", async () => {
|
|
52
|
-
const appealCommand = program.commands.find(cmd => cmd.name() === "appeal");
|
|
53
|
-
appealCommand?.exitOverride();
|
|
54
|
-
expect(() =>
|
|
55
|
-
program.parse(["node", "test", "appeal", mockTxId, "--invalid-option"]),
|
|
56
|
-
).toThrowError("error: unknown option '--invalid-option'");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { CallAction } from "../../src/commands/contracts/call";
|
|
3
|
-
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
4
|
-
import { initializeContractsCommands } from "../../src/commands/contracts";
|
|
5
|
-
|
|
6
|
-
vi.mock("../../src/commands/contracts/call");
|
|
7
|
-
vi.mock("esbuild", () => ({
|
|
8
|
-
buildSync: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe("call command", () => {
|
|
12
|
-
let program: Command;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
program = new Command();
|
|
16
|
-
initializeContractsCommands(program);
|
|
17
|
-
vi.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
vi.restoreAllMocks();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("CallAction.call is called with default options", async () => {
|
|
25
|
-
program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
|
|
26
|
-
expect(CallAction).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(CallAction.prototype.call).toHaveBeenCalledWith({
|
|
28
|
-
contractAddress: "0xMockedContract",
|
|
29
|
-
method: "getData",
|
|
30
|
-
args: []
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("CallAction.call is called with positional arguments", async () => {
|
|
35
|
-
program.parse([
|
|
36
|
-
"node",
|
|
37
|
-
"test",
|
|
38
|
-
"call",
|
|
39
|
-
"0xMockedContract",
|
|
40
|
-
"updateData",
|
|
41
|
-
"--args",
|
|
42
|
-
"1",
|
|
43
|
-
"2",
|
|
44
|
-
"Hello",
|
|
45
|
-
"false",
|
|
46
|
-
"true",
|
|
47
|
-
"--rpc",
|
|
48
|
-
"https://custom-rpc-url.com"
|
|
49
|
-
]);
|
|
50
|
-
expect(CallAction).toHaveBeenCalledTimes(1);
|
|
51
|
-
expect(CallAction.prototype.call).toHaveBeenCalledWith({
|
|
52
|
-
contractAddress: "0xMockedContract",
|
|
53
|
-
method: "updateData",
|
|
54
|
-
args: [1, 2, "Hello", false, true],
|
|
55
|
-
rpc: "https://custom-rpc-url.com"
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("CallAction is instantiated when the call command is executed", async () => {
|
|
60
|
-
program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
|
|
61
|
-
expect(CallAction).toHaveBeenCalledTimes(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("throws error for unrecognized options", async () => {
|
|
65
|
-
const callCommand = program.commands.find((cmd) => cmd.name() === "call");
|
|
66
|
-
callCommand?.exitOverride();
|
|
67
|
-
expect(() => program.parse(["node", "test", "call", "0xMockedContract", "getData", "--unknown"]))
|
|
68
|
-
.toThrowError("error: unknown option '--unknown'");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("CallAction.call is called without throwing errors for valid options", async () => {
|
|
72
|
-
program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
|
|
73
|
-
vi.mocked(CallAction.prototype.call).mockResolvedValueOnce(undefined);
|
|
74
|
-
expect(() =>
|
|
75
|
-
program.parse(["node", "test", "call", "0xMockedContract", "getData"])
|
|
76
|
-
).not.toThrow();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { CodeAction } from "../../src/commands/contracts/code";
|
|
3
|
-
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
4
|
-
import { initializeContractsCommands } from "../../src/commands/contracts";
|
|
5
|
-
|
|
6
|
-
vi.mock("../../src/commands/contracts/code");
|
|
7
|
-
vi.mock("esbuild", () => ({
|
|
8
|
-
buildSync: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe("code command", () => {
|
|
12
|
-
let program: Command;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
program = new Command();
|
|
16
|
-
initializeContractsCommands(program);
|
|
17
|
-
vi.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
vi.restoreAllMocks();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("CodeAction.code is called with default options", async () => {
|
|
25
|
-
program.parse(["node", "test", "code", "0xMockedContract"]);
|
|
26
|
-
expect(CodeAction).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(CodeAction.prototype.code).toHaveBeenCalledWith({
|
|
28
|
-
contractAddress: "0xMockedContract",
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("CodeAction.code is called with custom RPC URL", async () => {
|
|
33
|
-
program.parse([
|
|
34
|
-
"node",
|
|
35
|
-
"test",
|
|
36
|
-
"code",
|
|
37
|
-
"0xMockedContract",
|
|
38
|
-
"--rpc",
|
|
39
|
-
"https://custom-rpc-url.com"
|
|
40
|
-
]);
|
|
41
|
-
expect(CodeAction).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(CodeAction.prototype.code).toHaveBeenCalledWith({
|
|
43
|
-
contractAddress: "0xMockedContract",
|
|
44
|
-
rpc: "https://custom-rpc-url.com"
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("CodeAction is instantiated when the code command is executed", async () => {
|
|
49
|
-
program.parse(["node", "test", "code", "0xMockedContract"]);
|
|
50
|
-
expect(CodeAction).toHaveBeenCalledTimes(1);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("throws error for unrecognized options", async () => {
|
|
54
|
-
const codeCommand = program.commands.find((cmd) => cmd.name() === "code");
|
|
55
|
-
codeCommand?.exitOverride();
|
|
56
|
-
expect(() => program.parse(["node", "test", "code", "0xMockedContract", "--unknown"]))
|
|
57
|
-
.toThrowError("error: unknown option '--unknown'");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("CodeAction.code is called without throwing errors for valid options", async () => {
|
|
61
|
-
program.parse(["node", "test", "code", "0xMockedContract"]);
|
|
62
|
-
vi.mocked(CodeAction.prototype.code).mockResolvedValueOnce(undefined as any);
|
|
63
|
-
expect(() =>
|
|
64
|
-
program.parse(["node", "test", "code", "0xMockedContract"])
|
|
65
|
-
).not.toThrow();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
3
|
-
import { initializeConfigCommands } from "../../src/commands/config";
|
|
4
|
-
import { ConfigActions } from "../../src/commands/config/getSetReset";
|
|
5
|
-
|
|
6
|
-
vi.mock("../../src/commands/config/getSetReset");
|
|
7
|
-
|
|
8
|
-
describe("config commands", () => {
|
|
9
|
-
let program: Command;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
program = new Command();
|
|
13
|
-
initializeConfigCommands(program);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
vi.restoreAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("ConfigActions.set is called with the correct key-value pair", async () => {
|
|
21
|
-
program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
|
|
22
|
-
expect(ConfigActions).toHaveBeenCalledTimes(1);
|
|
23
|
-
expect(ConfigActions.prototype.set).toHaveBeenCalledWith("defaultNetwork=testnet");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("ConfigActions.get is called with a specific key", async () => {
|
|
27
|
-
program.parse(["node", "test", "config", "get", "defaultNetwork"]);
|
|
28
|
-
expect(ConfigActions).toHaveBeenCalledTimes(1);
|
|
29
|
-
expect(ConfigActions.prototype.get).toHaveBeenCalledWith("defaultNetwork");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("ConfigActions.get is called without a key", async () => {
|
|
33
|
-
program.parse(["node", "test", "config", "get"]);
|
|
34
|
-
expect(ConfigActions).toHaveBeenCalledTimes(1);
|
|
35
|
-
expect(ConfigActions.prototype.get).toHaveBeenCalledWith(undefined);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("ConfigActions.reset is called with the correct key", async () => {
|
|
39
|
-
program.parse(["node", "test", "config", "reset", "defaultNetwork"]);
|
|
40
|
-
expect(ConfigActions).toHaveBeenCalledTimes(1);
|
|
41
|
-
expect(ConfigActions.prototype.reset).toHaveBeenCalledWith("defaultNetwork");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("ConfigActions is instantiated when the command is executed", async () => {
|
|
45
|
-
program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
|
|
46
|
-
expect(ConfigActions).toHaveBeenCalledTimes(1);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("ConfigActions.set is called without throwing errors for valid input", async () => {
|
|
50
|
-
program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"]);
|
|
51
|
-
vi.mocked(ConfigActions.prototype.set).mockReturnValue();
|
|
52
|
-
expect(() => program.parse(["node", "test", "config", "set", "defaultNetwork=testnet"])).not.toThrow();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
|
|
3
|
-
import { initializeContractsCommands } from "../../src/commands/contracts";
|
|
4
|
-
import { DeployAction } from "../../src/commands/contracts/deploy";
|
|
5
|
-
|
|
6
|
-
vi.mock("../../src/commands/contracts/deploy");
|
|
7
|
-
vi.mock("esbuild", () => ({
|
|
8
|
-
buildSync: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe("deploy command", () => {
|
|
12
|
-
let program: Command;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
program = new Command();
|
|
16
|
-
initializeContractsCommands(program);
|
|
17
|
-
vi.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
vi.restoreAllMocks();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("DeployAction.deploy is called with default options", async () => {
|
|
25
|
-
program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
|
|
26
|
-
expect(DeployAction).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
|
|
28
|
-
contract: "./path/to/contract",
|
|
29
|
-
args: [],
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("DeployAction.deploy is called with positional arguments", async () => {
|
|
34
|
-
program.parse([
|
|
35
|
-
"node",
|
|
36
|
-
"test",
|
|
37
|
-
"deploy",
|
|
38
|
-
"--contract",
|
|
39
|
-
"./path/to/contract",
|
|
40
|
-
"--args",
|
|
41
|
-
"1",
|
|
42
|
-
"2",
|
|
43
|
-
"3",
|
|
44
|
-
"--rpc",
|
|
45
|
-
"https://custom-rpc-url.com"
|
|
46
|
-
]);
|
|
47
|
-
expect(DeployAction).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
|
|
49
|
-
contract: "./path/to/contract",
|
|
50
|
-
args: [1, 2, 3],
|
|
51
|
-
rpc: "https://custom-rpc-url.com"
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("DeployAction is instantiated when the deploy command is executed", async () => {
|
|
56
|
-
program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
|
|
57
|
-
expect(DeployAction).toHaveBeenCalledTimes(1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("throws error for unrecognized options", async () => {
|
|
61
|
-
const deployCommand = program.commands.find((cmd) => cmd.name() === "deploy");
|
|
62
|
-
deployCommand?.exitOverride();
|
|
63
|
-
expect(() => program.parse(["node", "test", "deploy", "--unknown"])).toThrowError(
|
|
64
|
-
"error: unknown option '--unknown'"
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("DeployAction.deploy is called without throwing errors for valid options", async () => {
|
|
69
|
-
program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
|
|
70
|
-
vi.mocked(DeployAction.prototype.deploy).mockResolvedValueOnce(undefined);
|
|
71
|
-
expect(() =>
|
|
72
|
-
program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"])
|
|
73
|
-
).not.toThrow();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("DeployAction.deployScripts is called without throwing errors", async () => {
|
|
77
|
-
program.parse(["node", "test", "deploy"]);
|
|
78
|
-
vi.mocked(DeployAction.prototype.deployScripts).mockResolvedValueOnce(undefined);
|
|
79
|
-
expect(() =>
|
|
80
|
-
program.parse(["node", "test", "deploy"])
|
|
81
|
-
).not.toThrow();
|
|
82
|
-
});
|
|
83
|
-
});
|