genlayer 0.7.0 → 0.8.1-beta.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.
@@ -0,0 +1,139 @@
1
+ import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
2
+ import fs from "fs";
3
+ import { createClient, createAccount } from "genlayer-js";
4
+ import { DeployAction, DeployOptions } from "../../src/commands/contracts/deploy";
5
+ import { getPrivateKey } from "../../src/lib/accounts/getPrivateKey";
6
+
7
+ vi.mock("fs");
8
+ vi.mock("genlayer-js");
9
+ vi.mock("../../src/lib/accounts/getPrivateKey");
10
+
11
+ describe("Deploy Action", () => {
12
+ let deployer: DeployAction;
13
+ const mockClient = {
14
+ deployContract: vi.fn(),
15
+ waitForTransactionReceipt: vi.fn()
16
+ };
17
+
18
+ const mockPrivateKey = "mocked_private_key";
19
+
20
+ beforeEach(() => {
21
+ vi.clearAllMocks();
22
+ vi.mocked(createClient).mockReturnValue(mockClient as any);
23
+ vi.mocked(createAccount).mockReturnValue({ privateKey: mockPrivateKey } as any);
24
+ vi.mocked(getPrivateKey).mockReturnValue(mockPrivateKey);
25
+ deployer = new DeployAction();
26
+ });
27
+
28
+ afterEach(() => {
29
+ vi.restoreAllMocks();
30
+ });
31
+
32
+ test("reads contract code successfully", () => {
33
+ const contractPath = "/mocked/contract/path";
34
+ const contractContent = "contract code";
35
+ vi.mocked(fs.existsSync).mockReturnValue(true);
36
+ vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
37
+
38
+ const result = deployer["readContractCode"](contractPath);
39
+
40
+ expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
41
+ expect(fs.readFileSync).toHaveBeenCalledWith(contractPath, "utf-8");
42
+ expect(result).toBe(contractContent);
43
+ });
44
+
45
+ test("throws error if contract file is missing", () => {
46
+ const contractPath = "/mocked/contract/path";
47
+ vi.mocked(fs.existsSync).mockReturnValue(false);
48
+
49
+ expect(() => deployer["readContractCode"](contractPath)).toThrowError(
50
+ `Contract file not found: ${contractPath}`
51
+ );
52
+ expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
53
+ });
54
+
55
+
56
+ test("deploys contract with args", async () => {
57
+ const options: DeployOptions = {
58
+ contract: "/mocked/contract/path",
59
+ args: [1, 2, 3],
60
+ };
61
+ const contractContent = "contract code";
62
+
63
+ vi.mocked(fs.existsSync).mockReturnValue(true);
64
+ vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
65
+ vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
66
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({data: {contractAddress: '0xdasdsadasdasdada'}});
67
+
68
+ await deployer.deploy(options);
69
+
70
+ expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
71
+ expect(mockClient.deployContract).toHaveBeenCalledWith({
72
+ code: contractContent,
73
+ args: [1, 2, 3],
74
+ leaderOnly: false,
75
+ });
76
+ expect(mockClient.deployContract).toHaveResolvedWith("mocked_tx_hash");
77
+ });
78
+
79
+ test("throws error for both args and kwargs", async () => {
80
+ const options: DeployOptions = {
81
+ contract: "/mocked/contract/path",
82
+ args: [1, 2, 3],
83
+ kwargs: "key1=value1,key2=42",
84
+ };
85
+
86
+ await expect(deployer.deploy(options)).rejects.toThrowError(
87
+ "Invalid usage: Please specify either `args` or `kwargs`, but not both."
88
+ );
89
+
90
+ expect(fs.readFileSync).not.toHaveBeenCalled();
91
+ expect(mockClient.deployContract).not.toHaveBeenCalled();
92
+ });
93
+
94
+ test("throws error for missing contract", async () => {
95
+ const options: DeployOptions = {
96
+ };
97
+
98
+ await deployer.deploy(options);
99
+
100
+ expect(fs.readFileSync).not.toHaveBeenCalled();
101
+ expect(mockClient.deployContract).not.toHaveBeenCalled();
102
+ });
103
+
104
+ test("handles deployment errors", async () => {
105
+ const options: DeployOptions = {
106
+ contract: "/mocked/contract/path",
107
+ args: [1, 2, 3],
108
+ };
109
+ const contractContent = "contract code";
110
+
111
+ vi.mocked(fs.existsSync).mockReturnValue(true);
112
+ vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
113
+ vi.mocked(mockClient.deployContract).mockRejectedValue(
114
+ new Error("Mocked deployment error")
115
+ );
116
+
117
+ await expect(deployer.deploy(options)).rejects.toThrowError(
118
+ "Contract deployment failed."
119
+ );
120
+
121
+ expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
122
+ expect(mockClient.deployContract).toHaveBeenCalled();
123
+ });
124
+
125
+ test("throws error if contract code is empty", async () => {
126
+ const options: DeployOptions = {
127
+ contract: "/mocked/contract/path",
128
+ };
129
+
130
+ vi.mocked(fs.existsSync).mockReturnValue(true);
131
+ vi.mocked(fs.readFileSync).mockReturnValue("");
132
+
133
+ await deployer.deploy(options);
134
+
135
+ expect(fs.existsSync).toHaveBeenCalledWith(options.contract);
136
+ expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
137
+ expect(mockClient.deployContract).not.toHaveBeenCalled();
138
+ });
139
+ });
@@ -0,0 +1,101 @@
1
+ import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
2
+ import { ConfigActions } from "../../src/commands/config/getSetReset";
3
+ import { ConfigFileManager } from "../../src/lib/config/ConfigFileManager";
4
+
5
+ vi.mock("../../src/lib/config/ConfigFileManager");
6
+
7
+ describe("ConfigActions", () => {
8
+ let configActions: ConfigActions;
9
+
10
+ beforeEach(() => {
11
+ configActions = new ConfigActions();
12
+ vi.clearAllMocks();
13
+ });
14
+
15
+ new ConfigFileManager();
16
+
17
+ afterEach(() => {
18
+ vi.restoreAllMocks();
19
+ });
20
+
21
+ test("set method writes key-value pair to the configuration", () => {
22
+ const consoleLogSpy = vi.spyOn(console, "log");
23
+
24
+ configActions.set("defaultNetwork=testnet");
25
+
26
+ expect(configActions["configManager"].writeConfig).toHaveBeenCalledWith("defaultNetwork", "testnet");
27
+ expect(consoleLogSpy).toHaveBeenCalledWith("Configuration updated: defaultNetwork=testnet");
28
+ });
29
+
30
+ test("set method throws error for invalid format", () => {
31
+ const consoleErrorSpy = vi.spyOn(console, "error");
32
+ const processExitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
33
+ throw new Error("process.exit");
34
+ });
35
+
36
+ expect(() => configActions.set("invalidFormat")).toThrowError("process.exit");
37
+
38
+ expect(consoleErrorSpy).toHaveBeenCalledWith("Invalid format. Use key=value.");
39
+ expect(processExitSpy).toHaveBeenCalledWith(1);
40
+ });
41
+
42
+ test("get method retrieves value for a specific key", () => {
43
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue("testnet");
44
+
45
+ const consoleLogSpy = vi.spyOn(console, "log");
46
+
47
+ configActions.get("defaultNetwork");
48
+
49
+ expect(configActions["configManager"].getConfigByKey).toHaveBeenCalledWith("defaultNetwork");
50
+ expect(consoleLogSpy).toHaveBeenCalledWith("defaultNetwork=testnet");
51
+ });
52
+
53
+ test("get method prints message when key has no value", () => {
54
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(null);
55
+
56
+ const consoleLogSpy = vi.spyOn(console, "log");
57
+
58
+ configActions.get("nonexistentKey");
59
+
60
+ expect(configActions["configManager"].getConfigByKey).toHaveBeenCalledWith("nonexistentKey");
61
+ expect(consoleLogSpy).toHaveBeenCalledWith("No value set for key: nonexistentKey");
62
+ });
63
+
64
+ test("get method retrieves the entire configuration when no key is provided", () => {
65
+ const mockConfig = { defaultNetwork: "testnet" };
66
+ vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue(mockConfig);
67
+
68
+ const consoleLogSpy = vi.spyOn(console, "log");
69
+
70
+ configActions.get();
71
+
72
+ expect(configActions["configManager"].getConfig).toHaveBeenCalledTimes(1);
73
+ expect(consoleLogSpy).toHaveBeenCalledWith("Current configuration:", JSON.stringify(mockConfig, null, 2));
74
+ });
75
+
76
+ test("reset method removes key from configuration", () => {
77
+ const mockConfig = { defaultNetwork: "testnet" };
78
+ vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue(mockConfig);
79
+
80
+ const consoleLogSpy = vi.spyOn(console, "log");
81
+
82
+ configActions.reset("defaultNetwork");
83
+
84
+ expect(configActions["configManager"].getConfig).toHaveBeenCalledTimes(1);
85
+ expect(configActions["configManager"].writeConfig).toHaveBeenCalledWith("defaultNetwork", undefined);
86
+ expect(consoleLogSpy).toHaveBeenCalledWith("Configuration key reset: defaultNetwork");
87
+ });
88
+
89
+ test("reset method prints message when key does not exist", () => {
90
+ const mockConfig = {};
91
+ vi.mocked(ConfigFileManager.prototype.getConfig).mockReturnValue(mockConfig);
92
+
93
+ const consoleLogSpy = vi.spyOn(console, "log");
94
+
95
+ configActions.reset("nonexistentKey");
96
+
97
+ expect(configActions["configManager"].getConfig).toHaveBeenCalledTimes(1);
98
+ expect(configActions["configManager"].writeConfig).not.toHaveBeenCalled();
99
+ expect(consoleLogSpy).toHaveBeenCalledWith("Key does not exist in the configuration: nonexistentKey");
100
+ });
101
+ });
@@ -0,0 +1,91 @@
1
+ import { Command } from "commander";
2
+ import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
+ import { initializeContractsCommands } from "../../src/commands/contracts";
4
+ import { CallAction } from "../../src/commands/contracts/call";
5
+
6
+ vi.mock("../../src/commands/contracts/call");
7
+
8
+ describe("call command", () => {
9
+ let program: Command;
10
+
11
+ beforeEach(() => {
12
+ program = new Command();
13
+ initializeContractsCommands(program);
14
+ vi.clearAllMocks();
15
+ });
16
+
17
+ afterEach(() => {
18
+ vi.restoreAllMocks();
19
+ });
20
+
21
+ test("CallAction.call is called with default options", async () => {
22
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
23
+ expect(CallAction).toHaveBeenCalledTimes(1);
24
+ expect(CallAction.prototype.call).toHaveBeenCalledWith({
25
+ contractAddress: "0xMockedContract",
26
+ method: "getData",
27
+ args: [],
28
+ type: "read",
29
+ });
30
+ });
31
+
32
+ test("CallAction.call is called with positional arguments", async () => {
33
+ program.parse([
34
+ "node",
35
+ "test",
36
+ "call",
37
+ "0xMockedContract",
38
+ "updateData",
39
+ "--args",
40
+ "1",
41
+ "2",
42
+ "Hello",
43
+ ]);
44
+ expect(CallAction).toHaveBeenCalledTimes(1);
45
+ expect(CallAction.prototype.call).toHaveBeenCalledWith({
46
+ contractAddress: "0xMockedContract",
47
+ method: "updateData",
48
+ args: ["1", "2", "Hello"],
49
+ type: "read",
50
+ });
51
+ });
52
+
53
+ test("CallAction.call is called with write type", async () => {
54
+ program.parse([
55
+ "node",
56
+ "test",
57
+ "call",
58
+ "0xMockedContract",
59
+ "updateData",
60
+ "--type",
61
+ "write",
62
+ ]);
63
+ expect(CallAction).toHaveBeenCalledTimes(1);
64
+ expect(CallAction.prototype.call).toHaveBeenCalledWith({
65
+ contractAddress: "0xMockedContract",
66
+ method: "updateData",
67
+ args: [],
68
+ type: "write",
69
+ });
70
+ });
71
+
72
+ test("CallAction is instantiated when the call command is executed", async () => {
73
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
74
+ expect(CallAction).toHaveBeenCalledTimes(1);
75
+ });
76
+
77
+ test("throws error for unrecognized options", async () => {
78
+ const callCommand = program.commands.find((cmd) => cmd.name() === "call");
79
+ callCommand?.exitOverride();
80
+ expect(() => program.parse(["node", "test", "call", "0xMockedContract", "getData", "--unknown"]))
81
+ .toThrowError("error: unknown option '--unknown'");
82
+ });
83
+
84
+ test("CallAction.call is called without throwing errors for valid options", async () => {
85
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"]);
86
+ vi.mocked(CallAction.prototype.call).mockResolvedValueOnce(undefined);
87
+ expect(() =>
88
+ program.parse(["node", "test", "call", "0xMockedContract", "getData"])
89
+ ).not.toThrow();
90
+ });
91
+ });
@@ -0,0 +1,54 @@
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
+ });
@@ -0,0 +1,69 @@
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
+
8
+ describe("deploy command", () => {
9
+ let program: Command;
10
+
11
+ beforeEach(() => {
12
+ program = new Command();
13
+ initializeContractsCommands(program);
14
+ vi.clearAllMocks();
15
+ });
16
+
17
+ afterEach(() => {
18
+ vi.restoreAllMocks();
19
+ });
20
+
21
+ test("DeployAction.deploy is called with default options", async () => {
22
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
23
+ expect(DeployAction).toHaveBeenCalledTimes(1);
24
+ expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
25
+ contract: "./path/to/contract",
26
+ args: [],
27
+ });
28
+ });
29
+
30
+ test("DeployAction.deploy is called with positional arguments", async () => {
31
+ program.parse([
32
+ "node",
33
+ "test",
34
+ "deploy",
35
+ "--contract",
36
+ "./path/to/contract",
37
+ "--args",
38
+ "1",
39
+ "2",
40
+ "3",
41
+ ]);
42
+ expect(DeployAction).toHaveBeenCalledTimes(1);
43
+ expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
44
+ contract: "./path/to/contract",
45
+ args: ["1", "2", "3"]
46
+ });
47
+ });
48
+
49
+ test("DeployAction is instantiated when the deploy command is executed", async () => {
50
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
51
+ expect(DeployAction).toHaveBeenCalledTimes(1);
52
+ });
53
+
54
+ test("throws error for unrecognized options", async () => {
55
+ const deployCommand = program.commands.find((cmd) => cmd.name() === "deploy");
56
+ deployCommand?.exitOverride();
57
+ expect(() => program.parse(["node", "test", "deploy", "--unknown"])).toThrowError(
58
+ "error: unknown option '--unknown'"
59
+ );
60
+ });
61
+
62
+ test("DeployAction.deploy is called without throwing errors for valid options", async () => {
63
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"]);
64
+ vi.mocked(DeployAction.prototype.deploy).mockResolvedValueOnce(undefined);
65
+ expect(() =>
66
+ program.parse(["node", "test", "deploy", "--contract", "./path/to/contract"])
67
+ ).not.toThrow();
68
+ });
69
+ });
@@ -17,6 +17,14 @@ vi.mock("../src/commands/keygen", () => ({
17
17
  initializeKeygenCommands: vi.fn(),
18
18
  }));
19
19
 
20
+ vi.mock("../src/commands/contracts", () => ({
21
+ initializeContractsCommands: vi.fn(),
22
+ }));
23
+
24
+ vi.mock("../src/commands/config", () => ({
25
+ initializeConfigCommands: vi.fn(),
26
+ }));
27
+
20
28
 
21
29
  describe("CLI", () => {
22
30
  it("should initialize CLI", () => {
@@ -0,0 +1,96 @@
1
+ import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
2
+ import fs from "fs";
3
+ import { getPrivateKey } from "../../src/lib/accounts/getPrivateKey";
4
+ import { ConfigFileManager } from "../../src/lib/config/ConfigFileManager";
5
+
6
+ vi.mock("fs");
7
+ vi.mock("../../src/lib/config/ConfigFileManager");
8
+
9
+ describe("getPrivateKey", () => {
10
+ new ConfigFileManager();
11
+
12
+ beforeEach(() => {
13
+ vi.clearAllMocks();
14
+ });
15
+
16
+ afterEach(() => {
17
+ vi.restoreAllMocks();
18
+ });
19
+
20
+ test("returns the private key if the file exists and is valid", () => {
21
+ const mockPath = "/mocked/path/keypair.json";
22
+ const mockPrivateKey = "0xMockedPrivateKey";
23
+ const mockKeypairData = { privateKey: mockPrivateKey };
24
+
25
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(mockPath);
26
+ vi.mocked(fs.existsSync).mockReturnValue(true);
27
+ vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockKeypairData));
28
+
29
+ const privateKey = getPrivateKey();
30
+
31
+ expect(ConfigFileManager.prototype.getConfigByKey).toHaveBeenCalledWith("keyPairPath");
32
+ expect(fs.existsSync).toHaveBeenCalledWith(mockPath);
33
+ expect(fs.readFileSync).toHaveBeenCalledWith(mockPath, "utf-8");
34
+ expect(privateKey).toBe(mockPrivateKey);
35
+ });
36
+
37
+ test("exits if the keypair path is missing in the config", () => {
38
+ const consoleErrorSpy = vi.spyOn(console, "error");
39
+ const processExitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
40
+ throw new Error("process.exit");
41
+ });
42
+
43
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(null);
44
+
45
+ expect(() => getPrivateKey()).toThrowError("process.exit");
46
+
47
+ expect(ConfigFileManager.prototype.getConfigByKey).toHaveBeenCalledWith("keyPairPath");
48
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
49
+ "Keypair file not found. Please generate or specify a valid keypair path."
50
+ );
51
+ expect(processExitSpy).toHaveBeenCalledWith(1);
52
+ });
53
+
54
+ test("exits if the keypair file does not exist", () => {
55
+ const consoleErrorSpy = vi.spyOn(console, "error");
56
+ const processExitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
57
+ throw new Error("process.exit");
58
+ });
59
+
60
+ const mockPath = "/mocked/path/keypair.json";
61
+
62
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(mockPath);
63
+ vi.mocked(fs.existsSync).mockReturnValue(false);
64
+
65
+ expect(() => getPrivateKey()).toThrowError("process.exit");
66
+
67
+ expect(ConfigFileManager.prototype.getConfigByKey).toHaveBeenCalledWith("keyPairPath");
68
+ expect(fs.existsSync).toHaveBeenCalledWith(mockPath);
69
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
70
+ "Keypair file not found. Please generate or specify a valid keypair path."
71
+ );
72
+ expect(processExitSpy).toHaveBeenCalledWith(1);
73
+ });
74
+
75
+ test("exits if the private key is missing in the keypair file", () => {
76
+ const consoleErrorSpy = vi.spyOn(console, "error");
77
+ const processExitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
78
+ throw new Error("process.exit");
79
+ });
80
+
81
+ const mockPath = "/mocked/path/keypair.json";
82
+ const mockKeypairData = { notPrivateKey: "SomeOtherData" }; // Invalid keypair data
83
+
84
+ vi.mocked(ConfigFileManager.prototype.getConfigByKey).mockReturnValue(mockPath);
85
+ vi.mocked(fs.existsSync).mockReturnValue(true);
86
+ vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockKeypairData));
87
+
88
+ expect(() => getPrivateKey()).toThrowError("process.exit");
89
+
90
+ expect(ConfigFileManager.prototype.getConfigByKey).toHaveBeenCalledWith("keyPairPath");
91
+ expect(fs.existsSync).toHaveBeenCalledWith(mockPath);
92
+ expect(fs.readFileSync).toHaveBeenCalledWith(mockPath, "utf-8");
93
+ expect(consoleErrorSpy).toHaveBeenCalledWith("Invalid keypair file. Private key is missing.");
94
+ expect(processExitSpy).toHaveBeenCalledWith(1);
95
+ });
96
+ });
package/tsconfig.json CHANGED
@@ -27,7 +27,7 @@
27
27
  /* Modules */
28
28
  "module": "ES2022" /* Specify what module code is generated. */,
29
29
  // "rootDir": /* Specify the root folder within your source files. */,
30
- "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
30
+ "moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
32
  "paths": {
33
33
  "@/*": ["./src/*"],