genlayer 0.8.1-beta.0 → 0.9.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/.env.example +0 -1
- package/CHANGELOG.md +3 -3
- package/dist/index.js +3 -74
- package/docker-compose.yml +6 -6
- package/package.json +1 -1
- package/src/commands/contracts/deploy.ts +2 -5
- package/src/commands/contracts/index.ts +3 -12
- package/tests/actions/deploy.test.ts +0 -2
- package/src/commands/contracts/call.ts +0 -83
- package/tests/actions/call.test.ts +0 -144
- package/tests/commands/call.test.ts +0 -91
package/.env.example
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.9.0 (2024-12-13)
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
###
|
|
6
|
+
### Features
|
|
7
7
|
|
|
8
|
-
*
|
|
8
|
+
* Add Deploy Command and Update Configurations for Compatibility ([#153](https://github.com/yeagerai/genlayer-cli/issues/153)) ([8744b2d](https://github.com/yeagerai/genlayer-cli/commit/8744b2d3ef2b4d7fd4d3ac71ac6e8eef69ed1555))
|
|
9
9
|
|
|
10
10
|
## 0.8.0 (2024-12-11)
|
|
11
11
|
|
package/dist/index.js
CHANGED
|
@@ -58904,7 +58904,7 @@ var {
|
|
|
58904
58904
|
} = import_index.default;
|
|
58905
58905
|
|
|
58906
58906
|
// package.json
|
|
58907
|
-
var version = "0.
|
|
58907
|
+
var version = "0.9.0";
|
|
58908
58908
|
var package_default = {
|
|
58909
58909
|
name: "genlayer",
|
|
58910
58910
|
version,
|
|
@@ -91367,11 +91367,9 @@ var DeployAction = class {
|
|
|
91367
91367
|
console.log("Starting contract deployment...");
|
|
91368
91368
|
console.log("Deployment Parameters:", deployParams);
|
|
91369
91369
|
try {
|
|
91370
|
-
const
|
|
91371
|
-
const result = await this.genlayerClient.waitForTransactionReceipt({ hash: hash3, retries: 15, interval: 2e3 });
|
|
91370
|
+
const result = await this.genlayerClient.deployContract(deployParams);
|
|
91372
91371
|
console.log("Contract deployed successfully.");
|
|
91373
|
-
console.log("Transaction Hash:",
|
|
91374
|
-
console.log("Contract Address:", result.data?.contract_address);
|
|
91372
|
+
console.log("Transaction Hash:", result);
|
|
91375
91373
|
} catch (error) {
|
|
91376
91374
|
console.error("Error deploying contract:", error);
|
|
91377
91375
|
throw new Error("Contract deployment failed.");
|
|
@@ -91379,81 +91377,12 @@ var DeployAction = class {
|
|
|
91379
91377
|
}
|
|
91380
91378
|
};
|
|
91381
91379
|
|
|
91382
|
-
// src/commands/contracts/call.ts
|
|
91383
|
-
var CallAction = class {
|
|
91384
|
-
constructor() {
|
|
91385
|
-
__publicField(this, "genlayerClient");
|
|
91386
|
-
this.genlayerClient = createClient2({
|
|
91387
|
-
chain: simulator,
|
|
91388
|
-
endpoint: process.env.VITE_JSON_RPC_SERVER_URL,
|
|
91389
|
-
account: createAccount(getPrivateKey())
|
|
91390
|
-
});
|
|
91391
|
-
}
|
|
91392
|
-
async call({
|
|
91393
|
-
contractAddress,
|
|
91394
|
-
method,
|
|
91395
|
-
args,
|
|
91396
|
-
type
|
|
91397
|
-
}) {
|
|
91398
|
-
console.log(`Calling ${type} method ${method} on contract at ${contractAddress}...`);
|
|
91399
|
-
try {
|
|
91400
|
-
if (type === "read") {
|
|
91401
|
-
await this.executeRead(contractAddress, method, args);
|
|
91402
|
-
} else if (type === "write") {
|
|
91403
|
-
await this.executeWrite(contractAddress, method, args);
|
|
91404
|
-
} else {
|
|
91405
|
-
throw new Error(`Invalid call type: ${type}. Use "read" or "write".`);
|
|
91406
|
-
}
|
|
91407
|
-
} catch (error) {
|
|
91408
|
-
console.error("Error calling contract method:", error);
|
|
91409
|
-
throw error;
|
|
91410
|
-
}
|
|
91411
|
-
}
|
|
91412
|
-
async executeRead(contractAddress, method, args) {
|
|
91413
|
-
try {
|
|
91414
|
-
const result = await this.genlayerClient.readContract({
|
|
91415
|
-
address: contractAddress,
|
|
91416
|
-
functionName: method,
|
|
91417
|
-
args
|
|
91418
|
-
});
|
|
91419
|
-
console.log("Read result:", result);
|
|
91420
|
-
} catch (error) {
|
|
91421
|
-
console.error("Error during read operation:", error);
|
|
91422
|
-
throw error;
|
|
91423
|
-
}
|
|
91424
|
-
}
|
|
91425
|
-
async executeWrite(contractAddress, method, args) {
|
|
91426
|
-
try {
|
|
91427
|
-
const hash3 = await this.genlayerClient.writeContract({
|
|
91428
|
-
address: contractAddress,
|
|
91429
|
-
functionName: method,
|
|
91430
|
-
args,
|
|
91431
|
-
value: 0n
|
|
91432
|
-
});
|
|
91433
|
-
const result = await this.genlayerClient.waitForTransactionReceipt({
|
|
91434
|
-
hash: hash3,
|
|
91435
|
-
retries: 15,
|
|
91436
|
-
interval: 2e3
|
|
91437
|
-
});
|
|
91438
|
-
console.log("Write transaction hash:", hash3);
|
|
91439
|
-
console.log("Result:", result);
|
|
91440
|
-
} catch (error) {
|
|
91441
|
-
console.error("Error during write operation:", error);
|
|
91442
|
-
throw error;
|
|
91443
|
-
}
|
|
91444
|
-
}
|
|
91445
|
-
};
|
|
91446
|
-
|
|
91447
91380
|
// src/commands/contracts/index.ts
|
|
91448
91381
|
function initializeContractsCommands(program2) {
|
|
91449
91382
|
program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--args <args...>", "Positional arguments for the contract (space-separated, use quotes for multi-word arguments)", []).action(async (options) => {
|
|
91450
91383
|
const deployer = new DeployAction();
|
|
91451
91384
|
await deployer.deploy(options);
|
|
91452
91385
|
});
|
|
91453
|
-
program2.command("call <contractAddress> <method>").description("Call a contract method").option("--args <args...>", "Positional arguments for the method (space-separated, use quotes for multi-word arguments)", []).option("--type <type>", "Type of call: read or write (default is read)", "read").action(async (contractAddress, method, options) => {
|
|
91454
|
-
const caller = new CallAction();
|
|
91455
|
-
await caller.call({ contractAddress, method, ...options });
|
|
91456
|
-
});
|
|
91457
91386
|
return program2;
|
|
91458
91387
|
}
|
|
91459
91388
|
|
package/docker-compose.yml
CHANGED
|
@@ -7,8 +7,8 @@ services:
|
|
|
7
7
|
- "${FRONTEND_PORT:-8080}:8080"
|
|
8
8
|
environment:
|
|
9
9
|
- VITE_*
|
|
10
|
-
|
|
11
|
-
- ./.env
|
|
10
|
+
volumes:
|
|
11
|
+
- ./.env:/app/.env
|
|
12
12
|
depends_on:
|
|
13
13
|
jsonrpc:
|
|
14
14
|
condition: service_healthy
|
|
@@ -36,8 +36,8 @@ services:
|
|
|
36
36
|
ports:
|
|
37
37
|
- "${RPCPORT:-5000}:${RPCPORT:-5000}"
|
|
38
38
|
- "${RPCDEBUGPORT:-5001}:${RPCDEBUGPORT:-5001}"
|
|
39
|
-
|
|
40
|
-
- ./.env
|
|
39
|
+
volumes:
|
|
40
|
+
- ./.env:/app/.env
|
|
41
41
|
healthcheck:
|
|
42
42
|
test: [ "CMD", "python", "backend/healthcheck.py", "--port", "${RPCPORT}" ]
|
|
43
43
|
interval: 30s
|
|
@@ -75,8 +75,8 @@ services:
|
|
|
75
75
|
expose:
|
|
76
76
|
- "${WEBREQUESTPORT:-5002}:${WEBREQUESTPORT:-5002}"
|
|
77
77
|
- "${WEBREQUESTSELENIUMPORT:-4444}:${WEBREQUESTSELENIUMPORT:-4444}"
|
|
78
|
-
|
|
79
|
-
- ./.env
|
|
78
|
+
volumes:
|
|
79
|
+
- ./.env:/app/webrequest/.env
|
|
80
80
|
depends_on:
|
|
81
81
|
ollama:
|
|
82
82
|
condition: service_started
|
package/package.json
CHANGED
|
@@ -57,13 +57,10 @@ export class DeployAction {
|
|
|
57
57
|
console.log("Deployment Parameters:", deployParams);
|
|
58
58
|
|
|
59
59
|
try {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const result = await this.genlayerClient.waitForTransactionReceipt({hash, retries: 15, interval: 2000})
|
|
60
|
+
const result = await this.genlayerClient.deployContract(deployParams);
|
|
63
61
|
|
|
64
62
|
console.log("Contract deployed successfully.");
|
|
65
|
-
console.log("Transaction Hash:",
|
|
66
|
-
console.log("Contract Address:", result.data?.contract_address);
|
|
63
|
+
console.log("Transaction Hash:", result);
|
|
67
64
|
} catch (error) {
|
|
68
65
|
console.error("Error deploying contract:", error);
|
|
69
66
|
throw new Error("Contract deployment failed.");
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { DeployAction, DeployOptions } from "
|
|
3
|
-
import { CallAction, CallOptions } from "./call";
|
|
2
|
+
import { DeployAction, DeployOptions } from "../contracts/deploy";
|
|
4
3
|
|
|
5
4
|
export function initializeContractsCommands(program: Command) {
|
|
5
|
+
|
|
6
6
|
program
|
|
7
7
|
.command("deploy")
|
|
8
8
|
.description("Deploy intelligent contracts")
|
|
9
9
|
.option("--contract <contractPath>", "Path to the smart contract to deploy")
|
|
10
|
+
// .option("--network <networkName>", "Specify the network (e.g., testnet)", "localnet")
|
|
10
11
|
.option("--args <args...>", "Positional arguments for the contract (space-separated, use quotes for multi-word arguments)", [])
|
|
11
12
|
.action(async (options: DeployOptions) => {
|
|
12
13
|
const deployer = new DeployAction();
|
|
13
14
|
await deployer.deploy(options);
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
program
|
|
17
|
-
.command("call <contractAddress> <method>")
|
|
18
|
-
.description("Call a contract method")
|
|
19
|
-
.option("--args <args...>", "Positional arguments for the method (space-separated, use quotes for multi-word arguments)", [])
|
|
20
|
-
.option("--type <type>", "Type of call: read or write (default is read)", "read")
|
|
21
|
-
.action(async (contractAddress: string, method: string, options: CallOptions) => {
|
|
22
|
-
const caller = new CallAction();
|
|
23
|
-
await caller.call({ contractAddress, method, ...options });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
17
|
return program;
|
|
27
18
|
}
|
|
@@ -12,7 +12,6 @@ describe("Deploy Action", () => {
|
|
|
12
12
|
let deployer: DeployAction;
|
|
13
13
|
const mockClient = {
|
|
14
14
|
deployContract: vi.fn(),
|
|
15
|
-
waitForTransactionReceipt: vi.fn()
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
const mockPrivateKey = "mocked_private_key";
|
|
@@ -63,7 +62,6 @@ describe("Deploy Action", () => {
|
|
|
63
62
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
64
63
|
vi.mocked(fs.readFileSync).mockReturnValue(contractContent);
|
|
65
64
|
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
|
|
66
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({data: {contractAddress: '0xdasdsadasdasdada'}});
|
|
67
65
|
|
|
68
66
|
await deployer.deploy(options);
|
|
69
67
|
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { createClient, createAccount } from "genlayer-js";
|
|
2
|
-
import { simulator } from "genlayer-js/chains";
|
|
3
|
-
import type { GenLayerClient } from "genlayer-js/types";
|
|
4
|
-
import { getPrivateKey } from "../../lib/accounts/getPrivateKey";
|
|
5
|
-
|
|
6
|
-
export interface CallOptions {
|
|
7
|
-
args: any[];
|
|
8
|
-
type: "read" | "write";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class CallAction {
|
|
12
|
-
private genlayerClient: GenLayerClient<typeof simulator>;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.genlayerClient = createClient({
|
|
16
|
-
chain: simulator,
|
|
17
|
-
endpoint: process.env.VITE_JSON_RPC_SERVER_URL,
|
|
18
|
-
account: createAccount(getPrivateKey() as any),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async call({
|
|
23
|
-
contractAddress,
|
|
24
|
-
method,
|
|
25
|
-
args,
|
|
26
|
-
type,
|
|
27
|
-
}: {
|
|
28
|
-
contractAddress: string;
|
|
29
|
-
method: string;
|
|
30
|
-
args: any[];
|
|
31
|
-
type: "read" | "write";
|
|
32
|
-
}): Promise<void> {
|
|
33
|
-
console.log(`Calling ${type} method ${method} on contract at ${contractAddress}...`);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
if (type === "read") {
|
|
37
|
-
await this.executeRead(contractAddress, method, args);
|
|
38
|
-
} else if (type === "write") {
|
|
39
|
-
await this.executeWrite(contractAddress, method, args);
|
|
40
|
-
} else {
|
|
41
|
-
throw new Error(`Invalid call type: ${type}. Use "read" or "write".`);
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error("Error calling contract method:", error);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private async executeRead(contractAddress: string, method: string, args: any[]): Promise<void> {
|
|
50
|
-
try {
|
|
51
|
-
const result = await this.genlayerClient.readContract({
|
|
52
|
-
address: contractAddress as any,
|
|
53
|
-
functionName: method,
|
|
54
|
-
args,
|
|
55
|
-
});
|
|
56
|
-
console.log("Read result:", result);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error("Error during read operation:", error);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private async executeWrite(contractAddress: string, method: string, args: any[]): Promise<void> {
|
|
64
|
-
try {
|
|
65
|
-
const hash = await this.genlayerClient.writeContract({
|
|
66
|
-
address: contractAddress as any,
|
|
67
|
-
functionName: method,
|
|
68
|
-
args,
|
|
69
|
-
value: 0n,
|
|
70
|
-
});
|
|
71
|
-
const result = await this.genlayerClient.waitForTransactionReceipt({
|
|
72
|
-
hash,
|
|
73
|
-
retries: 15,
|
|
74
|
-
interval: 2000,
|
|
75
|
-
});
|
|
76
|
-
console.log("Write transaction hash:", hash);
|
|
77
|
-
console.log("Result:", result);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error("Error during write operation:", error);
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { describe, test, vi, beforeEach, afterEach, expect } from "vitest";
|
|
2
|
-
import { createClient, createAccount } from "genlayer-js";
|
|
3
|
-
import { CallAction, CallOptions } from "../../src/commands/contracts/call";
|
|
4
|
-
import { getPrivateKey } from "../../src/lib/accounts/getPrivateKey";
|
|
5
|
-
|
|
6
|
-
vi.mock("genlayer-js");
|
|
7
|
-
vi.mock("../../src/lib/accounts/getPrivateKey");
|
|
8
|
-
|
|
9
|
-
describe("Call Action", () => {
|
|
10
|
-
let caller: CallAction;
|
|
11
|
-
const mockClient = {
|
|
12
|
-
readContract: vi.fn(),
|
|
13
|
-
writeContract: vi.fn(),
|
|
14
|
-
waitForTransactionReceipt: vi.fn(),
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const mockPrivateKey = "mocked_private_key";
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
vi.clearAllMocks();
|
|
21
|
-
vi.mocked(createClient).mockReturnValue(mockClient as any);
|
|
22
|
-
vi.mocked(createAccount).mockReturnValue({ privateKey: mockPrivateKey } as any);
|
|
23
|
-
vi.mocked(getPrivateKey).mockReturnValue(mockPrivateKey);
|
|
24
|
-
caller = new CallAction();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
vi.restoreAllMocks();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("calls readContract successfully", async () => {
|
|
32
|
-
const options: CallOptions = {
|
|
33
|
-
args: [1, 2, "Hello"],
|
|
34
|
-
type: "read",
|
|
35
|
-
};
|
|
36
|
-
const mockResult = "mocked_result";
|
|
37
|
-
|
|
38
|
-
vi.mocked(mockClient.readContract).mockResolvedValue(mockResult);
|
|
39
|
-
|
|
40
|
-
await caller.call({
|
|
41
|
-
contractAddress: "0xMockedContract",
|
|
42
|
-
method: "getData",
|
|
43
|
-
...options,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
expect(mockClient.readContract).toHaveBeenCalledWith({
|
|
47
|
-
address: "0xMockedContract",
|
|
48
|
-
functionName: "getData",
|
|
49
|
-
args: [1, 2, "Hello"],
|
|
50
|
-
});
|
|
51
|
-
expect(mockClient.readContract).toHaveResolvedWith(mockResult);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("calls writeContract successfully", async () => {
|
|
55
|
-
const options: CallOptions = {
|
|
56
|
-
args: [42, "Update"],
|
|
57
|
-
type: "write",
|
|
58
|
-
};
|
|
59
|
-
const mockHash = "0xMockedTransactionHash";
|
|
60
|
-
const mockReceipt = { status: "success" };
|
|
61
|
-
|
|
62
|
-
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
|
|
63
|
-
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);
|
|
64
|
-
|
|
65
|
-
await caller.call({
|
|
66
|
-
contractAddress: "0xMockedContract",
|
|
67
|
-
method: "updateData",
|
|
68
|
-
...options,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(mockClient.writeContract).toHaveBeenCalledWith({
|
|
72
|
-
address: "0xMockedContract",
|
|
73
|
-
functionName: "updateData",
|
|
74
|
-
args: [42, "Update"],
|
|
75
|
-
value: 0n,
|
|
76
|
-
});
|
|
77
|
-
expect(mockClient.waitForTransactionReceipt).toHaveBeenCalledWith({
|
|
78
|
-
hash: mockHash,
|
|
79
|
-
retries: 15,
|
|
80
|
-
interval: 2000,
|
|
81
|
-
});
|
|
82
|
-
expect(mockClient.writeContract).toHaveResolvedWith(mockHash);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("throws error for invalid call type", async () => {
|
|
86
|
-
const options: CallOptions = {
|
|
87
|
-
args: [],
|
|
88
|
-
type: "invalid" as any,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
await expect(
|
|
92
|
-
caller.call({
|
|
93
|
-
contractAddress: "0xMockedContract",
|
|
94
|
-
method: "getData",
|
|
95
|
-
...options,
|
|
96
|
-
})
|
|
97
|
-
).rejects.toThrowError("Invalid call type: invalid. Use \"read\" or \"write\".");
|
|
98
|
-
|
|
99
|
-
expect(mockClient.readContract).not.toHaveBeenCalled();
|
|
100
|
-
expect(mockClient.writeContract).not.toHaveBeenCalled();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("handles errors during readContract", async () => {
|
|
104
|
-
const options: CallOptions = {
|
|
105
|
-
args: [1],
|
|
106
|
-
type: "read",
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
vi.mocked(mockClient.readContract).mockRejectedValue(
|
|
110
|
-
new Error("Mocked read error")
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
await expect(
|
|
114
|
-
caller.call({
|
|
115
|
-
contractAddress: "0xMockedContract",
|
|
116
|
-
method: "getData",
|
|
117
|
-
...options,
|
|
118
|
-
})
|
|
119
|
-
).rejects.toThrowError("Mocked read error");
|
|
120
|
-
|
|
121
|
-
expect(mockClient.readContract).toHaveBeenCalled();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test("handles errors during writeContract", async () => {
|
|
125
|
-
const options: CallOptions = {
|
|
126
|
-
args: [1],
|
|
127
|
-
type: "write",
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
vi.mocked(mockClient.writeContract).mockRejectedValue(
|
|
131
|
-
new Error("Mocked write error")
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
await expect(
|
|
135
|
-
caller.call({
|
|
136
|
-
contractAddress: "0xMockedContract",
|
|
137
|
-
method: "updateData",
|
|
138
|
-
...options,
|
|
139
|
-
})
|
|
140
|
-
).rejects.toThrowError("Mocked write error");
|
|
141
|
-
|
|
142
|
-
expect(mockClient.writeContract).toHaveBeenCalled();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,91 +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 { 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
|
-
});
|