genlayer 0.18.0 → 0.18.2-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.
- package/CHANGELOG.md +9 -0
- package/dist/index.js +25711 -12445
- package/package.json +2 -2
- package/src/commands/contracts/call.ts +7 -49
- package/src/commands/contracts/deploy.ts +17 -13
- package/src/commands/contracts/index.ts +36 -11
- package/src/commands/contracts/write.ts +49 -0
- package/src/commands/general/init.ts +15 -20
- package/src/commands/general/start.ts +14 -10
- package/src/commands/keygen/create.ts +2 -2
- package/src/commands/network/index.ts +14 -0
- package/src/commands/network/setNetwork.ts +60 -0
- package/src/index.ts +9 -7
- package/src/lib/actions/BaseAction.ts +20 -18
- package/tests/actions/call.test.ts +22 -86
- package/tests/actions/create.test.ts +8 -8
- package/tests/actions/deploy.test.ts +72 -60
- package/tests/actions/init.test.ts +173 -102
- package/tests/actions/setNetwork.test.ts +199 -0
- package/tests/actions/start.test.ts +48 -24
- package/tests/actions/write.test.ts +102 -0
- package/tests/commands/network.test.ts +60 -0
- package/tests/commands/write.test.ts +76 -0
- package/tests/index.test.ts +5 -2
- package/tests/libs/baseAction.test.ts +37 -26
- package/tests/services/simulator.test.ts +98 -102
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
|
+
import {createClient, createAccount} from "genlayer-js";
|
|
3
|
+
import {CallAction} from "../../src/commands/contracts/call";
|
|
4
4
|
|
|
5
5
|
vi.mock("genlayer-js");
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ describe("CallAction", () => {
|
|
|
11
11
|
writeContract: vi.fn(),
|
|
12
12
|
waitForTransactionReceipt: vi.fn(),
|
|
13
13
|
getContractSchema: vi.fn(),
|
|
14
|
-
initializeConsensusSmartContract: vi.fn()
|
|
14
|
+
initializeConsensusSmartContract: vi.fn(),
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
const mockPrivateKey = "mocked_private_key";
|
|
@@ -19,7 +19,7 @@ describe("CallAction", () => {
|
|
|
19
19
|
beforeEach(() => {
|
|
20
20
|
vi.clearAllMocks();
|
|
21
21
|
vi.mocked(createClient).mockReturnValue(mockClient as any);
|
|
22
|
-
vi.mocked(createAccount).mockReturnValue({
|
|
22
|
+
vi.mocked(createAccount).mockReturnValue({privateKey: mockPrivateKey} as any);
|
|
23
23
|
callActions = new CallAction();
|
|
24
24
|
vi.spyOn(callActions as any, "getPrivateKey").mockResolvedValue(mockPrivateKey);
|
|
25
25
|
|
|
@@ -34,10 +34,9 @@ describe("CallAction", () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test("calls readContract successfully", async () => {
|
|
37
|
-
const options = {
|
|
37
|
+
const options = {args: [1, 2, "Hello"]};
|
|
38
38
|
const mockResult = "mocked_result";
|
|
39
39
|
|
|
40
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { getData: { readonly: true } } });
|
|
41
40
|
vi.mocked(mockClient.readContract).mockResolvedValue(mockResult);
|
|
42
41
|
|
|
43
42
|
await callActions.call({
|
|
@@ -51,65 +50,24 @@ describe("CallAction", () => {
|
|
|
51
50
|
functionName: "getData",
|
|
52
51
|
args: [1, 2, "Hello"],
|
|
53
52
|
});
|
|
54
|
-
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const options = { args: [42, "Update"] };
|
|
59
|
-
const mockHash = "0xMockedTransactionHash";
|
|
60
|
-
const mockReceipt = { status: "success" };
|
|
61
|
-
|
|
62
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { updateData: { readonly: false } } });
|
|
63
|
-
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
|
|
64
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
|
|
65
|
-
|
|
66
|
-
await callActions.call({
|
|
67
|
-
contractAddress: "0xMockedContract",
|
|
68
|
-
method: "updateData",
|
|
69
|
-
...options,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(mockClient.writeContract).toHaveBeenCalledWith({
|
|
73
|
-
address: "0xMockedContract",
|
|
74
|
-
functionName: "updateData",
|
|
75
|
-
args: [42, "Update"],
|
|
76
|
-
value: 0n,
|
|
77
|
-
});
|
|
78
|
-
expect(callActions["log"]).toHaveBeenCalledWith("Write transaction hash:", mockHash);
|
|
79
|
-
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith("Write operation successfully executed", mockReceipt);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("fails when method is not found", async () => {
|
|
83
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { updateData: { readonly: false } } });
|
|
84
|
-
|
|
85
|
-
await callActions.call({ contractAddress: "0xMockedContract", method: "getData", args: [] });
|
|
86
|
-
|
|
87
|
-
expect(callActions["failSpinner"]).toHaveBeenCalledWith("method getData not found.");
|
|
53
|
+
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith(
|
|
54
|
+
"Read operation successfully executed",
|
|
55
|
+
"mocked_result",
|
|
56
|
+
);
|
|
88
57
|
});
|
|
89
58
|
|
|
90
59
|
test("handles readContract errors", async () => {
|
|
91
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { getData: { readonly: true } } });
|
|
92
60
|
vi.mocked(mockClient.readContract).mockRejectedValue(new Error("Mocked read error"));
|
|
93
61
|
|
|
94
|
-
await callActions.call({
|
|
62
|
+
await callActions.call({contractAddress: "0xMockedContract", method: "getData", args: [1]});
|
|
95
63
|
|
|
96
64
|
expect(callActions["failSpinner"]).toHaveBeenCalledWith("Error during read operation", expect.any(Error));
|
|
97
65
|
});
|
|
98
66
|
|
|
99
|
-
test("handles writeContract errors", async () => {
|
|
100
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { updateData: { readonly: false } } });
|
|
101
|
-
vi.mocked(mockClient.writeContract).mockRejectedValue(new Error("Mocked write error"));
|
|
102
|
-
|
|
103
|
-
await callActions.call({ contractAddress: "0xMockedContract", method: "updateData", args: [1] });
|
|
104
|
-
|
|
105
|
-
expect(callActions["failSpinner"]).toHaveBeenCalledWith("Error during write operation", expect.any(Error));
|
|
106
|
-
});
|
|
107
|
-
|
|
108
67
|
test("uses custom RPC URL when provided", async () => {
|
|
109
|
-
const options = {
|
|
68
|
+
const options = {args: [1, 2, "Hello"], rpc: "https://custom-rpc-url.com"};
|
|
110
69
|
const mockResult = "mocked_result";
|
|
111
70
|
|
|
112
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { getData: { readonly: true } } });
|
|
113
71
|
vi.mocked(mockClient.readContract).mockResolvedValue(mockResult);
|
|
114
72
|
|
|
115
73
|
await callActions.call({
|
|
@@ -118,41 +76,19 @@ describe("CallAction", () => {
|
|
|
118
76
|
...options,
|
|
119
77
|
});
|
|
120
78
|
|
|
121
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
122
|
-
|
|
123
|
-
|
|
79
|
+
expect(createClient).toHaveBeenCalledWith(
|
|
80
|
+
expect.objectContaining({
|
|
81
|
+
endpoint: "https://custom-rpc-url.com",
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
124
84
|
expect(mockClient.readContract).toHaveBeenCalledWith({
|
|
125
85
|
address: "0xMockedContract",
|
|
126
86
|
functionName: "getData",
|
|
127
87
|
args: [1, 2, "Hello"],
|
|
128
88
|
});
|
|
129
|
-
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const options = { args: [42, "Update"], rpc: "https://custom-rpc-url.com" };
|
|
134
|
-
const mockHash = "0xMockedTransactionHash";
|
|
135
|
-
const mockReceipt = { status: "success" };
|
|
136
|
-
|
|
137
|
-
vi.mocked(mockClient.getContractSchema).mockResolvedValue({ methods: { updateData: { readonly: false } } });
|
|
138
|
-
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
|
|
139
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
|
|
140
|
-
|
|
141
|
-
await callActions.call({
|
|
142
|
-
contractAddress: "0xMockedContract",
|
|
143
|
-
method: "updateData",
|
|
144
|
-
...options,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(createClient).toHaveBeenCalledWith(expect.objectContaining({
|
|
148
|
-
endpoint: "https://custom-rpc-url.com"
|
|
149
|
-
}));
|
|
150
|
-
expect(mockClient.writeContract).toHaveBeenCalledWith({
|
|
151
|
-
address: "0xMockedContract",
|
|
152
|
-
functionName: "updateData",
|
|
153
|
-
args: [42, "Update"],
|
|
154
|
-
value: 0n,
|
|
155
|
-
});
|
|
156
|
-
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith("Write operation successfully executed", mockReceipt);
|
|
89
|
+
expect(callActions["succeedSpinner"]).toHaveBeenCalledWith(
|
|
90
|
+
"Read operation successfully executed",
|
|
91
|
+
"mocked_result",
|
|
92
|
+
);
|
|
157
93
|
});
|
|
158
|
-
});
|
|
94
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
|
+
import {KeypairCreator} from "../../src/commands/keygen/create";
|
|
3
|
+
import {writeFileSync, existsSync} from "fs";
|
|
4
|
+
import {ethers} from "ethers";
|
|
5
5
|
|
|
6
6
|
vi.mock("fs");
|
|
7
7
|
|
|
@@ -33,7 +33,7 @@ describe("KeypairCreator", () => {
|
|
|
33
33
|
vi.spyOn(keypairCreator as any, "succeedSpinner").mockImplementation(() => {});
|
|
34
34
|
vi.spyOn(keypairCreator as any, "failSpinner").mockImplementation(() => {});
|
|
35
35
|
vi.spyOn(keypairCreator as any, "writeConfig").mockImplementation(() => {});
|
|
36
|
-
vi.spyOn(keypairCreator as any, "getFilePath").mockImplementation(
|
|
36
|
+
vi.spyOn(keypairCreator as any, "getFilePath").mockImplementation(fileName => `/mocked/path/${fileName}`);
|
|
37
37
|
vi.mocked(ethers.Wallet.createRandom).mockReturnValue(mockWallet);
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -43,14 +43,14 @@ describe("KeypairCreator", () => {
|
|
|
43
43
|
|
|
44
44
|
test("successfully creates and saves a keypair", () => {
|
|
45
45
|
vi.mocked(existsSync).mockReturnValue(false);
|
|
46
|
-
const options = {
|
|
46
|
+
const options = {output: "keypair.json", overwrite: false};
|
|
47
47
|
|
|
48
48
|
keypairCreator.createKeypairAction(options);
|
|
49
49
|
|
|
50
50
|
expect(keypairCreator["startSpinner"]).toHaveBeenCalledWith("Creating keypair...");
|
|
51
51
|
expect(mockKeypairManager.createKeypair).toHaveBeenCalledWith(options.output, options.overwrite);
|
|
52
52
|
expect(keypairCreator["succeedSpinner"]).toHaveBeenCalledWith(
|
|
53
|
-
"Keypair successfully created and saved to: keypair.json"
|
|
53
|
+
"Keypair successfully created and saved to: keypair.json",
|
|
54
54
|
);
|
|
55
55
|
});
|
|
56
56
|
|
|
@@ -60,7 +60,7 @@ describe("KeypairCreator", () => {
|
|
|
60
60
|
throw mockError;
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
keypairCreator.createKeypairAction({
|
|
63
|
+
keypairCreator.createKeypairAction({output: "keypair.json", overwrite: true});
|
|
64
64
|
|
|
65
65
|
expect(keypairCreator["failSpinner"]).toHaveBeenCalledWith("Failed to generate keypair", mockError);
|
|
66
66
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {describe, test, vi, beforeEach, afterEach, expect} from "vitest";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import {createClient, createAccount} from "genlayer-js";
|
|
4
|
+
import {DeployAction, DeployOptions} from "../../src/commands/contracts/deploy";
|
|
5
|
+
import {buildSync} from "esbuild";
|
|
6
|
+
import {pathToFileURL} from "url";
|
|
7
7
|
|
|
8
8
|
vi.mock("fs");
|
|
9
9
|
vi.mock("genlayer-js");
|
|
@@ -24,9 +24,10 @@ describe("DeployAction", () => {
|
|
|
24
24
|
beforeEach(() => {
|
|
25
25
|
vi.clearAllMocks();
|
|
26
26
|
vi.mocked(createClient).mockReturnValue(mockClient as any);
|
|
27
|
-
vi.mocked(createAccount).mockReturnValue({
|
|
27
|
+
vi.mocked(createAccount).mockReturnValue({privateKey: mockPrivateKey} as any);
|
|
28
28
|
deployer = new DeployAction();
|
|
29
29
|
vi.spyOn(deployer as any, "getPrivateKey").mockResolvedValue(mockPrivateKey);
|
|
30
|
+
vi.spyOn(deployer as any, "getConfig").mockReturnValue({});
|
|
30
31
|
|
|
31
32
|
vi.spyOn(deployer as any, "startSpinner").mockImplementation(() => {});
|
|
32
33
|
vi.spyOn(deployer as any, "succeedSpinner").mockImplementation(() => {});
|
|
@@ -57,7 +58,7 @@ describe("DeployAction", () => {
|
|
|
57
58
|
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
58
59
|
|
|
59
60
|
expect(() => deployer["readContractCode"](contractPath)).toThrowError(
|
|
60
|
-
`Contract file not found: ${contractPath}
|
|
61
|
+
`Contract file not found: ${contractPath}`,
|
|
61
62
|
);
|
|
62
63
|
expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
|
|
63
64
|
});
|
|
@@ -73,7 +74,7 @@ describe("DeployAction", () => {
|
|
|
73
74
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
74
75
|
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
|
|
75
76
|
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
|
|
76
|
-
data: {
|
|
77
|
+
data: {contract_address: "0xdasdsadasdasdada"},
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
await deployer.deploy(options);
|
|
@@ -105,9 +106,7 @@ describe("DeployAction", () => {
|
|
|
105
106
|
|
|
106
107
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
107
108
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
108
|
-
vi.mocked(mockClient.deployContract).mockRejectedValue(
|
|
109
|
-
new Error("Mocked deployment error")
|
|
110
|
-
);
|
|
109
|
+
vi.mocked(mockClient.deployContract).mockRejectedValue(new Error("Mocked deployment error"));
|
|
111
110
|
|
|
112
111
|
await deployer.deploy(options);
|
|
113
112
|
|
|
@@ -131,11 +130,7 @@ describe("DeployAction", () => {
|
|
|
131
130
|
|
|
132
131
|
test("deployScripts executes scripts in order", async () => {
|
|
133
132
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
134
|
-
vi.mocked(fs.readdirSync).mockReturnValue([
|
|
135
|
-
"1_first.ts",
|
|
136
|
-
"2_second.js",
|
|
137
|
-
"10_last.ts",
|
|
138
|
-
] as any);
|
|
133
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js", "10_last.ts"] as any);
|
|
139
134
|
|
|
140
135
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
141
136
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
@@ -144,7 +139,11 @@ describe("DeployAction", () => {
|
|
|
144
139
|
|
|
145
140
|
expect(deployer["setSpinnerText"]).toHaveBeenCalledWith("Found 3 deploy scripts. Executing...");
|
|
146
141
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), undefined);
|
|
147
|
-
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
142
|
+
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
143
|
+
expect.stringMatching(/2_second.js/),
|
|
144
|
+
undefined,
|
|
145
|
+
undefined,
|
|
146
|
+
);
|
|
148
147
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/10_last.ts/), undefined);
|
|
149
148
|
});
|
|
150
149
|
|
|
@@ -182,20 +181,26 @@ describe("DeployAction", () => {
|
|
|
182
181
|
|
|
183
182
|
test("deployScripts sorts and executes scripts correctly", async () => {
|
|
184
183
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
185
|
-
vi.mocked(fs.readdirSync).mockReturnValue([
|
|
186
|
-
"10_last.ts",
|
|
187
|
-
"2_second.js",
|
|
188
|
-
"1_first.ts"
|
|
189
|
-
] as any);
|
|
184
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["10_last.ts", "2_second.js", "1_first.ts"] as any);
|
|
190
185
|
|
|
191
186
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
192
187
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
193
188
|
|
|
194
189
|
await deployer.deployScripts();
|
|
195
190
|
|
|
196
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
192
|
+
expect.stringContaining("1_first.ts"),
|
|
193
|
+
undefined,
|
|
194
|
+
);
|
|
195
|
+
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
196
|
+
expect.stringContaining("2_second.js"),
|
|
197
|
+
undefined,
|
|
198
|
+
undefined,
|
|
199
|
+
);
|
|
200
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
201
|
+
expect.stringContaining("10_last.ts"),
|
|
202
|
+
undefined,
|
|
203
|
+
);
|
|
199
204
|
});
|
|
200
205
|
|
|
201
206
|
test("deployScripts fails when no scripts are found", async () => {
|
|
@@ -216,7 +221,7 @@ describe("DeployAction", () => {
|
|
|
216
221
|
|
|
217
222
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
218
223
|
expect.stringContaining("Error executing script:"),
|
|
219
|
-
expect.any(Error)
|
|
224
|
+
expect.any(Error),
|
|
220
225
|
);
|
|
221
226
|
});
|
|
222
227
|
|
|
@@ -227,12 +232,12 @@ describe("DeployAction", () => {
|
|
|
227
232
|
|
|
228
233
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
229
234
|
expect.stringContaining("Error executing:"),
|
|
230
|
-
expect.any(Error)
|
|
235
|
+
expect.any(Error),
|
|
231
236
|
);
|
|
232
237
|
});
|
|
233
238
|
|
|
234
239
|
test("deploy fails when contract code is empty", async () => {
|
|
235
|
-
const options: DeployOptions = {
|
|
240
|
+
const options: DeployOptions = {contract: "/mocked/contract/path"};
|
|
236
241
|
|
|
237
242
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
238
243
|
vi.mocked(fs.readFileSync).mockReturnValue("");
|
|
@@ -249,7 +254,7 @@ describe("DeployAction", () => {
|
|
|
249
254
|
"2alpha_script.ts",
|
|
250
255
|
"3alpha_script.ts",
|
|
251
256
|
"blpha_script.ts",
|
|
252
|
-
"clpha_script.ts"
|
|
257
|
+
"clpha_script.ts",
|
|
253
258
|
] as any);
|
|
254
259
|
|
|
255
260
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
@@ -258,21 +263,33 @@ describe("DeployAction", () => {
|
|
|
258
263
|
await deployer.deployScripts();
|
|
259
264
|
|
|
260
265
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringContaining("script.ts"), undefined);
|
|
261
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
267
|
+
expect.stringContaining("2alpha_script.ts"),
|
|
268
|
+
undefined,
|
|
269
|
+
);
|
|
270
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
271
|
+
expect.stringContaining("3alpha_script.ts"),
|
|
272
|
+
undefined,
|
|
273
|
+
);
|
|
274
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
275
|
+
expect.stringContaining("blpha_script.ts"),
|
|
276
|
+
undefined,
|
|
277
|
+
);
|
|
278
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
279
|
+
expect.stringContaining("clpha_script.ts"),
|
|
280
|
+
undefined,
|
|
281
|
+
);
|
|
265
282
|
});
|
|
266
283
|
|
|
267
284
|
test("executeJsScript fails if module has no default export", async () => {
|
|
268
285
|
const filePath = "/mocked/script.js";
|
|
269
286
|
|
|
270
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
287
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: "Not a function"}));
|
|
271
288
|
|
|
272
289
|
await deployer["executeJsScript"](filePath);
|
|
273
290
|
|
|
274
291
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
275
|
-
expect.stringContaining(
|
|
292
|
+
expect.stringContaining('No "default" function found in:'),
|
|
276
293
|
);
|
|
277
294
|
});
|
|
278
295
|
|
|
@@ -280,7 +297,7 @@ describe("DeployAction", () => {
|
|
|
280
297
|
const filePath = "/mocked/script.js";
|
|
281
298
|
const mockFn = vi.fn(); // This mock function simulates the script execution
|
|
282
299
|
|
|
283
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
300
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
|
|
284
301
|
|
|
285
302
|
await deployer["executeJsScript"](filePath);
|
|
286
303
|
|
|
@@ -299,17 +316,14 @@ describe("DeployAction", () => {
|
|
|
299
316
|
|
|
300
317
|
await deployer["executeTsScript"](filePath);
|
|
301
318
|
|
|
302
|
-
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
303
|
-
`Error executing: ${filePath}`,
|
|
304
|
-
error
|
|
305
|
-
);
|
|
319
|
+
expect(deployer["failSpinner"]).toHaveBeenCalledWith(`Error executing: ${filePath}`, error);
|
|
306
320
|
});
|
|
307
321
|
|
|
308
322
|
test("deploys contract with rpc option", async () => {
|
|
309
323
|
const options: DeployOptions = {
|
|
310
324
|
contract: "/mocked/contract/path",
|
|
311
325
|
args: [1, 2, 3],
|
|
312
|
-
rpc: "https://custom-rpc-url.com"
|
|
326
|
+
rpc: "https://custom-rpc-url.com",
|
|
313
327
|
};
|
|
314
328
|
const contractContent = "contract code";
|
|
315
329
|
|
|
@@ -317,14 +331,16 @@ describe("DeployAction", () => {
|
|
|
317
331
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
318
332
|
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
|
|
319
333
|
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
|
|
320
|
-
data: {
|
|
334
|
+
data: {contract_address: "0xdasdsadasdasdada"},
|
|
321
335
|
});
|
|
322
336
|
|
|
323
337
|
await deployer.deploy(options);
|
|
324
338
|
|
|
325
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
326
|
-
|
|
327
|
-
|
|
339
|
+
expect(createClient).toHaveBeenCalledWith(
|
|
340
|
+
expect.objectContaining({
|
|
341
|
+
endpoint: "https://custom-rpc-url.com",
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
328
344
|
expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
|
|
329
345
|
expect(mockClient.deployContract).toHaveBeenCalledWith({
|
|
330
346
|
code: contractContent,
|
|
@@ -338,13 +354,15 @@ describe("DeployAction", () => {
|
|
|
338
354
|
const rpcUrl = "https://custom-rpc-url.com";
|
|
339
355
|
const mockFn = vi.fn();
|
|
340
356
|
|
|
341
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
357
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
|
|
342
358
|
|
|
343
359
|
await deployer["executeJsScript"](filePath, undefined, rpcUrl);
|
|
344
360
|
|
|
345
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
346
|
-
|
|
347
|
-
|
|
361
|
+
expect(createClient).toHaveBeenCalledWith(
|
|
362
|
+
expect.objectContaining({
|
|
363
|
+
endpoint: rpcUrl,
|
|
364
|
+
}),
|
|
365
|
+
);
|
|
348
366
|
expect(mockFn).toHaveBeenCalledWith(mockClient);
|
|
349
367
|
expect(deployer["succeedSpinner"]).toHaveBeenCalledWith(`Successfully executed: ${filePath}`);
|
|
350
368
|
});
|
|
@@ -376,26 +394,20 @@ describe("DeployAction", () => {
|
|
|
376
394
|
|
|
377
395
|
test("deployScripts passes rpc url to script execution methods", async () => {
|
|
378
396
|
const rpcUrl = "https://custom-rpc-url.com";
|
|
379
|
-
|
|
397
|
+
|
|
380
398
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
381
|
-
vi.mocked(fs.readdirSync).mockReturnValue([
|
|
382
|
-
"1_first.ts",
|
|
383
|
-
"2_second.js",
|
|
384
|
-
] as any);
|
|
399
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js"] as any);
|
|
385
400
|
|
|
386
401
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
387
402
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
388
403
|
|
|
389
|
-
await deployer.deployScripts({
|
|
404
|
+
await deployer.deployScripts({rpc: rpcUrl});
|
|
390
405
|
|
|
391
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
392
|
-
expect.stringMatching(/1_first.ts/),
|
|
393
|
-
rpcUrl
|
|
394
|
-
);
|
|
406
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), rpcUrl);
|
|
395
407
|
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
396
408
|
expect.stringMatching(/2_second.js/),
|
|
397
409
|
undefined,
|
|
398
|
-
rpcUrl
|
|
410
|
+
rpcUrl,
|
|
399
411
|
);
|
|
400
412
|
});
|
|
401
413
|
});
|