genlayer 0.18.0-beta.0 → 0.18.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.
@@ -1,76 +0,0 @@
1
- import {Command} from "commander";
2
- import {WriteAction} from "../../src/commands/contracts/write";
3
- import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
4
- import {initializeContractsCommands} from "../../src/commands/contracts";
5
-
6
- vi.mock("../../src/commands/contracts/write");
7
- vi.mock("esbuild", () => ({
8
- buildSync: vi.fn(),
9
- }));
10
-
11
- describe("write 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("WriteAction.write is called with default options", async () => {
25
- program.parse(["node", "test", "write", "0xMockedContract", "setData"]);
26
- expect(WriteAction).toHaveBeenCalledTimes(1);
27
- expect(WriteAction.prototype.write).toHaveBeenCalledWith({
28
- contractAddress: "0xMockedContract",
29
- method: "setData",
30
- args: [],
31
- });
32
- });
33
-
34
- test("WriteAction.write is called with positional arguments and options", async () => {
35
- program.parse([
36
- "node",
37
- "test",
38
- "write",
39
- "0xMockedContract",
40
- "updateCounter",
41
- "--args",
42
- "100",
43
- "someString",
44
- "true",
45
- "--rpc",
46
- "https://custom-rpc-url-for-write.com",
47
- ]);
48
- expect(WriteAction).toHaveBeenCalledTimes(1);
49
- expect(WriteAction.prototype.write).toHaveBeenCalledWith({
50
- contractAddress: "0xMockedContract",
51
- method: "updateCounter",
52
- args: [100, "someString", true],
53
- rpc: "https://custom-rpc-url-for-write.com",
54
- });
55
- });
56
-
57
- test("WriteAction is instantiated when the write command is executed", async () => {
58
- program.parse(["node", "test", "write", "0xMockedContract", "anotherMethod"]);
59
- expect(WriteAction).toHaveBeenCalledTimes(1);
60
- });
61
-
62
- test("throws error for unrecognized options", async () => {
63
- const writeCommand = program.commands.find(cmd => cmd.name() === "write");
64
- writeCommand?.exitOverride();
65
- expect(() =>
66
- program.parse(["node", "test", "write", "0xMockedContract", "someMethod", "--invalid-option"]),
67
- ).toThrowError("error: unknown option '--invalid-option'");
68
- });
69
-
70
- test("WriteAction.write is called without throwing errors for valid options", async () => {
71
- program.parse(["node", "test", "write", "0xMockedContract", "validMethod"]);
72
- vi.mocked(WriteAction.prototype.write).mockResolvedValueOnce(undefined);
73
- // Need to parse again inside expect to ensure the mockResolvedValueOnce is used for the assertion context
74
- expect(() => program.parse(["node", "test", "write", "0xMockedContract", "validMethod"])).not.toThrow();
75
- });
76
- });