genlayer 0.16.0 → 0.18.0-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 +12 -0
- package/dist/index.js +17137 -12060
- 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 +21 -23
- package/src/commands/general/start.ts +22 -10
- package/src/commands/keygen/create.ts +2 -2
- package/src/lib/actions/BaseAction.ts +18 -18
- package/src/lib/config/simulator.ts +6 -0
- package/src/lib/interfaces/ISimulatorService.ts +1 -0
- package/src/lib/services/simulator.ts +13 -1
- package/tests/actions/call.test.ts +22 -86
- package/tests/actions/create.test.ts +8 -8
- package/tests/actions/deploy.test.ts +71 -60
- package/tests/actions/init.test.ts +190 -86
- package/tests/actions/start.test.ts +66 -19
- package/tests/actions/write.test.ts +102 -0
- package/tests/commands/write.test.ts +76 -0
- package/tests/libs/baseAction.test.ts +37 -26
- package/tests/services/simulator.test.ts +117 -92
|
@@ -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,7 +24,7 @@ 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
30
|
|
|
@@ -57,7 +57,7 @@ describe("DeployAction", () => {
|
|
|
57
57
|
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
58
58
|
|
|
59
59
|
expect(() => deployer["readContractCode"](contractPath)).toThrowError(
|
|
60
|
-
`Contract file not found: ${contractPath}
|
|
60
|
+
`Contract file not found: ${contractPath}`,
|
|
61
61
|
);
|
|
62
62
|
expect(fs.existsSync).toHaveBeenCalledWith(contractPath);
|
|
63
63
|
});
|
|
@@ -73,7 +73,7 @@ describe("DeployAction", () => {
|
|
|
73
73
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
74
74
|
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
|
|
75
75
|
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
|
|
76
|
-
data: {
|
|
76
|
+
data: {contract_address: "0xdasdsadasdasdada"},
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
await deployer.deploy(options);
|
|
@@ -105,9 +105,7 @@ describe("DeployAction", () => {
|
|
|
105
105
|
|
|
106
106
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
107
107
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
108
|
-
vi.mocked(mockClient.deployContract).mockRejectedValue(
|
|
109
|
-
new Error("Mocked deployment error")
|
|
110
|
-
);
|
|
108
|
+
vi.mocked(mockClient.deployContract).mockRejectedValue(new Error("Mocked deployment error"));
|
|
111
109
|
|
|
112
110
|
await deployer.deploy(options);
|
|
113
111
|
|
|
@@ -131,11 +129,7 @@ describe("DeployAction", () => {
|
|
|
131
129
|
|
|
132
130
|
test("deployScripts executes scripts in order", async () => {
|
|
133
131
|
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);
|
|
132
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js", "10_last.ts"] as any);
|
|
139
133
|
|
|
140
134
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
141
135
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
@@ -144,7 +138,11 @@ describe("DeployAction", () => {
|
|
|
144
138
|
|
|
145
139
|
expect(deployer["setSpinnerText"]).toHaveBeenCalledWith("Found 3 deploy scripts. Executing...");
|
|
146
140
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), undefined);
|
|
147
|
-
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
141
|
+
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
142
|
+
expect.stringMatching(/2_second.js/),
|
|
143
|
+
undefined,
|
|
144
|
+
undefined,
|
|
145
|
+
);
|
|
148
146
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/10_last.ts/), undefined);
|
|
149
147
|
});
|
|
150
148
|
|
|
@@ -182,20 +180,26 @@ describe("DeployAction", () => {
|
|
|
182
180
|
|
|
183
181
|
test("deployScripts sorts and executes scripts correctly", async () => {
|
|
184
182
|
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);
|
|
183
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["10_last.ts", "2_second.js", "1_first.ts"] as any);
|
|
190
184
|
|
|
191
185
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
192
186
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
193
187
|
|
|
194
188
|
await deployer.deployScripts();
|
|
195
189
|
|
|
196
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
197
|
-
|
|
198
|
-
|
|
190
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
191
|
+
expect.stringContaining("1_first.ts"),
|
|
192
|
+
undefined,
|
|
193
|
+
);
|
|
194
|
+
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
195
|
+
expect.stringContaining("2_second.js"),
|
|
196
|
+
undefined,
|
|
197
|
+
undefined,
|
|
198
|
+
);
|
|
199
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
200
|
+
expect.stringContaining("10_last.ts"),
|
|
201
|
+
undefined,
|
|
202
|
+
);
|
|
199
203
|
});
|
|
200
204
|
|
|
201
205
|
test("deployScripts fails when no scripts are found", async () => {
|
|
@@ -216,7 +220,7 @@ describe("DeployAction", () => {
|
|
|
216
220
|
|
|
217
221
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
218
222
|
expect.stringContaining("Error executing script:"),
|
|
219
|
-
expect.any(Error)
|
|
223
|
+
expect.any(Error),
|
|
220
224
|
);
|
|
221
225
|
});
|
|
222
226
|
|
|
@@ -227,12 +231,12 @@ describe("DeployAction", () => {
|
|
|
227
231
|
|
|
228
232
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
229
233
|
expect.stringContaining("Error executing:"),
|
|
230
|
-
expect.any(Error)
|
|
234
|
+
expect.any(Error),
|
|
231
235
|
);
|
|
232
236
|
});
|
|
233
237
|
|
|
234
238
|
test("deploy fails when contract code is empty", async () => {
|
|
235
|
-
const options: DeployOptions = {
|
|
239
|
+
const options: DeployOptions = {contract: "/mocked/contract/path"};
|
|
236
240
|
|
|
237
241
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
238
242
|
vi.mocked(fs.readFileSync).mockReturnValue("");
|
|
@@ -249,7 +253,7 @@ describe("DeployAction", () => {
|
|
|
249
253
|
"2alpha_script.ts",
|
|
250
254
|
"3alpha_script.ts",
|
|
251
255
|
"blpha_script.ts",
|
|
252
|
-
"clpha_script.ts"
|
|
256
|
+
"clpha_script.ts",
|
|
253
257
|
] as any);
|
|
254
258
|
|
|
255
259
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
@@ -258,21 +262,33 @@ describe("DeployAction", () => {
|
|
|
258
262
|
await deployer.deployScripts();
|
|
259
263
|
|
|
260
264
|
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringContaining("script.ts"), undefined);
|
|
261
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
266
|
+
expect.stringContaining("2alpha_script.ts"),
|
|
267
|
+
undefined,
|
|
268
|
+
);
|
|
269
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
270
|
+
expect.stringContaining("3alpha_script.ts"),
|
|
271
|
+
undefined,
|
|
272
|
+
);
|
|
273
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
274
|
+
expect.stringContaining("blpha_script.ts"),
|
|
275
|
+
undefined,
|
|
276
|
+
);
|
|
277
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
278
|
+
expect.stringContaining("clpha_script.ts"),
|
|
279
|
+
undefined,
|
|
280
|
+
);
|
|
265
281
|
});
|
|
266
282
|
|
|
267
283
|
test("executeJsScript fails if module has no default export", async () => {
|
|
268
284
|
const filePath = "/mocked/script.js";
|
|
269
285
|
|
|
270
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
286
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: "Not a function"}));
|
|
271
287
|
|
|
272
288
|
await deployer["executeJsScript"](filePath);
|
|
273
289
|
|
|
274
290
|
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
275
|
-
expect.stringContaining(
|
|
291
|
+
expect.stringContaining('No "default" function found in:'),
|
|
276
292
|
);
|
|
277
293
|
});
|
|
278
294
|
|
|
@@ -280,7 +296,7 @@ describe("DeployAction", () => {
|
|
|
280
296
|
const filePath = "/mocked/script.js";
|
|
281
297
|
const mockFn = vi.fn(); // This mock function simulates the script execution
|
|
282
298
|
|
|
283
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
299
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
|
|
284
300
|
|
|
285
301
|
await deployer["executeJsScript"](filePath);
|
|
286
302
|
|
|
@@ -299,17 +315,14 @@ describe("DeployAction", () => {
|
|
|
299
315
|
|
|
300
316
|
await deployer["executeTsScript"](filePath);
|
|
301
317
|
|
|
302
|
-
expect(deployer["failSpinner"]).toHaveBeenCalledWith(
|
|
303
|
-
`Error executing: ${filePath}`,
|
|
304
|
-
error
|
|
305
|
-
);
|
|
318
|
+
expect(deployer["failSpinner"]).toHaveBeenCalledWith(`Error executing: ${filePath}`, error);
|
|
306
319
|
});
|
|
307
320
|
|
|
308
321
|
test("deploys contract with rpc option", async () => {
|
|
309
322
|
const options: DeployOptions = {
|
|
310
323
|
contract: "/mocked/contract/path",
|
|
311
324
|
args: [1, 2, 3],
|
|
312
|
-
rpc: "https://custom-rpc-url.com"
|
|
325
|
+
rpc: "https://custom-rpc-url.com",
|
|
313
326
|
};
|
|
314
327
|
const contractContent = "contract code";
|
|
315
328
|
|
|
@@ -317,14 +330,16 @@ describe("DeployAction", () => {
|
|
|
317
330
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
318
331
|
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
|
|
319
332
|
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
|
|
320
|
-
data: {
|
|
333
|
+
data: {contract_address: "0xdasdsadasdasdada"},
|
|
321
334
|
});
|
|
322
335
|
|
|
323
336
|
await deployer.deploy(options);
|
|
324
337
|
|
|
325
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
326
|
-
|
|
327
|
-
|
|
338
|
+
expect(createClient).toHaveBeenCalledWith(
|
|
339
|
+
expect.objectContaining({
|
|
340
|
+
endpoint: "https://custom-rpc-url.com",
|
|
341
|
+
}),
|
|
342
|
+
);
|
|
328
343
|
expect(fs.readFileSync).toHaveBeenCalledWith(options.contract, "utf-8");
|
|
329
344
|
expect(mockClient.deployContract).toHaveBeenCalledWith({
|
|
330
345
|
code: contractContent,
|
|
@@ -338,13 +353,15 @@ describe("DeployAction", () => {
|
|
|
338
353
|
const rpcUrl = "https://custom-rpc-url.com";
|
|
339
354
|
const mockFn = vi.fn();
|
|
340
355
|
|
|
341
|
-
vi.doMock(pathToFileURL(filePath).href, () => ({
|
|
356
|
+
vi.doMock(pathToFileURL(filePath).href, () => ({default: mockFn}));
|
|
342
357
|
|
|
343
358
|
await deployer["executeJsScript"](filePath, undefined, rpcUrl);
|
|
344
359
|
|
|
345
|
-
expect(createClient).toHaveBeenCalledWith(
|
|
346
|
-
|
|
347
|
-
|
|
360
|
+
expect(createClient).toHaveBeenCalledWith(
|
|
361
|
+
expect.objectContaining({
|
|
362
|
+
endpoint: rpcUrl,
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
348
365
|
expect(mockFn).toHaveBeenCalledWith(mockClient);
|
|
349
366
|
expect(deployer["succeedSpinner"]).toHaveBeenCalledWith(`Successfully executed: ${filePath}`);
|
|
350
367
|
});
|
|
@@ -376,26 +393,20 @@ describe("DeployAction", () => {
|
|
|
376
393
|
|
|
377
394
|
test("deployScripts passes rpc url to script execution methods", async () => {
|
|
378
395
|
const rpcUrl = "https://custom-rpc-url.com";
|
|
379
|
-
|
|
396
|
+
|
|
380
397
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
381
|
-
vi.mocked(fs.readdirSync).mockReturnValue([
|
|
382
|
-
"1_first.ts",
|
|
383
|
-
"2_second.js",
|
|
384
|
-
] as any);
|
|
398
|
+
vi.mocked(fs.readdirSync).mockReturnValue(["1_first.ts", "2_second.js"] as any);
|
|
385
399
|
|
|
386
400
|
vi.spyOn(deployer as any, "executeTsScript").mockResolvedValue(undefined);
|
|
387
401
|
vi.spyOn(deployer as any, "executeJsScript").mockResolvedValue(undefined);
|
|
388
402
|
|
|
389
|
-
await deployer.deployScripts({
|
|
403
|
+
await deployer.deployScripts({rpc: rpcUrl});
|
|
390
404
|
|
|
391
|
-
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(
|
|
392
|
-
expect.stringMatching(/1_first.ts/),
|
|
393
|
-
rpcUrl
|
|
394
|
-
);
|
|
405
|
+
expect(deployer["executeTsScript"]).toHaveBeenCalledWith(expect.stringMatching(/1_first.ts/), rpcUrl);
|
|
395
406
|
expect(deployer["executeJsScript"]).toHaveBeenCalledWith(
|
|
396
407
|
expect.stringMatching(/2_second.js/),
|
|
397
408
|
undefined,
|
|
398
|
-
rpcUrl
|
|
409
|
+
rpcUrl,
|
|
399
410
|
);
|
|
400
411
|
});
|
|
401
412
|
});
|