genlayer 0.33.1 → 0.34.1

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.
Files changed (128) hide show
  1. package/dist/index.js +68 -31
  2. package/package.json +11 -2
  3. package/.eslintignore +0 -2
  4. package/.github/workflows/cli-docs.yml +0 -121
  5. package/.github/workflows/publish-beta.yml +0 -41
  6. package/.github/workflows/publish.yml +0 -43
  7. package/.github/workflows/validate-code.yml +0 -47
  8. package/.prettierignore +0 -19
  9. package/.prettierrc +0 -12
  10. package/.release-it.json +0 -64
  11. package/CHANGELOG.md +0 -419
  12. package/CLAUDE.md +0 -55
  13. package/CONTRIBUTING.md +0 -117
  14. package/docker-compose.yml +0 -154
  15. package/docs/delegator-guide.md +0 -203
  16. package/docs/validator-guide.md +0 -329
  17. package/esbuild.config.dev.js +0 -17
  18. package/esbuild.config.js +0 -22
  19. package/esbuild.config.prod.js +0 -17
  20. package/eslint.config.js +0 -60
  21. package/renovate.json +0 -22
  22. package/src/commands/account/create.ts +0 -29
  23. package/src/commands/account/export.ts +0 -106
  24. package/src/commands/account/import.ts +0 -135
  25. package/src/commands/account/index.ts +0 -126
  26. package/src/commands/account/list.ts +0 -34
  27. package/src/commands/account/lock.ts +0 -39
  28. package/src/commands/account/remove.ts +0 -30
  29. package/src/commands/account/send.ts +0 -156
  30. package/src/commands/account/show.ts +0 -74
  31. package/src/commands/account/unlock.ts +0 -51
  32. package/src/commands/account/use.ts +0 -21
  33. package/src/commands/config/getSetReset.ts +0 -51
  34. package/src/commands/config/index.ts +0 -30
  35. package/src/commands/contracts/call.ts +0 -39
  36. package/src/commands/contracts/code.ts +0 -33
  37. package/src/commands/contracts/deploy.ts +0 -157
  38. package/src/commands/contracts/index.ts +0 -86
  39. package/src/commands/contracts/schema.ts +0 -31
  40. package/src/commands/contracts/write.ts +0 -49
  41. package/src/commands/general/index.ts +0 -45
  42. package/src/commands/general/init.ts +0 -179
  43. package/src/commands/general/start.ts +0 -116
  44. package/src/commands/general/stop.ts +0 -26
  45. package/src/commands/localnet/index.ts +0 -100
  46. package/src/commands/localnet/validators.ts +0 -269
  47. package/src/commands/network/index.ts +0 -29
  48. package/src/commands/network/setNetwork.ts +0 -77
  49. package/src/commands/scaffold/index.ts +0 -16
  50. package/src/commands/scaffold/new.ts +0 -34
  51. package/src/commands/staking/StakingAction.ts +0 -267
  52. package/src/commands/staking/delegatorClaim.ts +0 -41
  53. package/src/commands/staking/delegatorExit.ts +0 -56
  54. package/src/commands/staking/delegatorJoin.ts +0 -44
  55. package/src/commands/staking/index.ts +0 -346
  56. package/src/commands/staking/setIdentity.ts +0 -78
  57. package/src/commands/staking/setOperator.ts +0 -46
  58. package/src/commands/staking/stakingInfo.ts +0 -584
  59. package/src/commands/staking/validatorClaim.ts +0 -43
  60. package/src/commands/staking/validatorDeposit.ts +0 -48
  61. package/src/commands/staking/validatorExit.ts +0 -63
  62. package/src/commands/staking/validatorHistory.ts +0 -298
  63. package/src/commands/staking/validatorJoin.ts +0 -47
  64. package/src/commands/staking/validatorPrime.ts +0 -73
  65. package/src/commands/staking/wizard.ts +0 -809
  66. package/src/commands/transactions/appeal.ts +0 -39
  67. package/src/commands/transactions/index.ts +0 -39
  68. package/src/commands/transactions/receipt.ts +0 -90
  69. package/src/commands/update/index.ts +0 -25
  70. package/src/commands/update/ollama.ts +0 -103
  71. package/src/lib/actions/BaseAction.ts +0 -295
  72. package/src/lib/clients/jsonRpcClient.ts +0 -41
  73. package/src/lib/clients/system.ts +0 -73
  74. package/src/lib/config/ConfigFileManager.ts +0 -194
  75. package/src/lib/config/KeychainManager.ts +0 -89
  76. package/src/lib/config/simulator.ts +0 -68
  77. package/src/lib/config/text.ts +0 -2
  78. package/src/lib/errors/missingRequirement.ts +0 -9
  79. package/src/lib/errors/versionRequired.ts +0 -9
  80. package/src/lib/interfaces/ISimulatorService.ts +0 -37
  81. package/src/lib/services/simulator.ts +0 -351
  82. package/src/types/node-fetch.d.ts +0 -1
  83. package/tests/actions/appeal.test.ts +0 -99
  84. package/tests/actions/call.test.ts +0 -94
  85. package/tests/actions/code.test.ts +0 -87
  86. package/tests/actions/create.test.ts +0 -65
  87. package/tests/actions/deploy.test.ts +0 -420
  88. package/tests/actions/getSetReset.test.ts +0 -88
  89. package/tests/actions/init.test.ts +0 -467
  90. package/tests/actions/lock.test.ts +0 -86
  91. package/tests/actions/new.test.ts +0 -80
  92. package/tests/actions/ollama.test.ts +0 -193
  93. package/tests/actions/receipt.test.ts +0 -261
  94. package/tests/actions/schema.test.ts +0 -94
  95. package/tests/actions/setNetwork.test.ts +0 -160
  96. package/tests/actions/staking.test.ts +0 -279
  97. package/tests/actions/start.test.ts +0 -235
  98. package/tests/actions/stop.test.ts +0 -77
  99. package/tests/actions/unlock.test.ts +0 -139
  100. package/tests/actions/validators.test.ts +0 -750
  101. package/tests/actions/write.test.ts +0 -102
  102. package/tests/commands/account.test.ts +0 -146
  103. package/tests/commands/appeal.test.ts +0 -58
  104. package/tests/commands/call.test.ts +0 -78
  105. package/tests/commands/code.test.ts +0 -69
  106. package/tests/commands/config.test.ts +0 -54
  107. package/tests/commands/deploy.test.ts +0 -83
  108. package/tests/commands/init.test.ts +0 -101
  109. package/tests/commands/localnet.test.ts +0 -131
  110. package/tests/commands/network.test.ts +0 -60
  111. package/tests/commands/new.test.ts +0 -68
  112. package/tests/commands/receipt.test.ts +0 -142
  113. package/tests/commands/schema.test.ts +0 -67
  114. package/tests/commands/staking.test.ts +0 -329
  115. package/tests/commands/stop.test.ts +0 -27
  116. package/tests/commands/up.test.ts +0 -105
  117. package/tests/commands/update.test.ts +0 -45
  118. package/tests/commands/write.test.ts +0 -76
  119. package/tests/index.test.ts +0 -56
  120. package/tests/libs/baseAction.test.ts +0 -516
  121. package/tests/libs/configFileManager.test.ts +0 -117
  122. package/tests/libs/jsonRpcClient.test.ts +0 -59
  123. package/tests/libs/keychainManager.test.ts +0 -156
  124. package/tests/libs/system.test.ts +0 -148
  125. package/tests/services/simulator.test.ts +0 -705
  126. package/tests/utils.ts +0 -13
  127. package/tsconfig.json +0 -120
  128. package/vitest.config.ts +0 -12
@@ -1,101 +0,0 @@
1
- import { Command } from "commander";
2
- import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
- import { initializeGeneralCommands } from "../../src/commands/general";
4
- import { getCommand, getCommandOption } from "../utils";
5
- import simulatorService from '../../src/lib/services/simulator'
6
- import {localnetCompatibleVersion} from "../../src/lib/config/simulator";
7
- import { InitAction } from "../../src/commands/general/init";
8
-
9
-
10
- vi.mock("../../src/commands/general/init");
11
-
12
-
13
- const openFrontendSpy = vi.spyOn(simulatorService, "openFrontend");
14
- const defaultOptions = {
15
- numValidators: "5",
16
- headless: false,
17
- resetDb: false,
18
- localnetVersion: localnetCompatibleVersion,
19
- ollama: false,
20
- }
21
-
22
- vi.mock("inquirer", () => ({
23
- prompt: vi.fn(() => {}),
24
- }));
25
-
26
- describe("init command", () => {
27
- let initCommand: Command;
28
- let program: Command;
29
-
30
- beforeEach(() => {
31
- program = new Command();
32
- initializeGeneralCommands(program);
33
-
34
- initCommand = getCommand(program, "init");
35
- vi.clearAllMocks();
36
- });
37
-
38
- afterEach(() => {
39
- vi.restoreAllMocks();
40
- });
41
-
42
- test("doesn't have required arguments nor options", async () => {
43
- expect(() => program.parse(["node", "test", "init"])).not.toThrow();
44
- });
45
-
46
- test("option --numValidators is accepted", async () => {
47
- expect(() => program.parse(["node", "test", "init", "--numValidators", "10"])).not.toThrow();
48
- });
49
-
50
- test("option --numValidators default value is 5", async () => {
51
- const numValidatorsOption = getCommandOption(initCommand, "--numValidators");
52
- expect(numValidatorsOption?.defaultValue).toBe("5");
53
- });
54
-
55
-
56
- test("random option is not accepted", async () => {
57
- initCommand?.exitOverride();
58
- expect(() => program.parse(["node", "test", "init", "-random"])).toThrowError(
59
- "error: unknown option '-random'"
60
- );
61
- expect(() => program.parse(["node", "test", "init", "--randomOption"])).toThrowError(
62
- "error: unknown option '--randomOption'"
63
- );
64
- });
65
-
66
- test("action is called", async () => {
67
- program.parse(["node", "test", "init"]);
68
- expect(InitAction).toHaveBeenCalledTimes(1);
69
- expect(InitAction.prototype.execute).toHaveBeenCalledWith(defaultOptions);
70
- });
71
-
72
- test("option --headless is accepted", async () => {
73
- program.parse(["node", "test", "init", "--headless"]);
74
- expect(InitAction).toHaveBeenCalledTimes(1);
75
- expect(InitAction.prototype.execute).toHaveBeenCalledWith({...defaultOptions, headless: true});
76
- expect(openFrontendSpy).not.toHaveBeenCalled();
77
- });
78
-
79
- test("option --localnet-version is accepted", async () => {
80
- program.parse(["node", "test", "init", "--localnet-version", "v1.0.0"]);
81
- expect(InitAction).toHaveBeenCalledTimes(1);
82
- expect(InitAction.prototype.execute).toHaveBeenCalledWith({...defaultOptions, localnetVersion: "v1.0.0"});
83
- expect(openFrontendSpy).not.toHaveBeenCalled();
84
- });
85
-
86
- test("option --localnet-version description includes minimum version", async () => {
87
- const localnetVersionOption = getCommandOption(initCommand, "--localnet-version");
88
- expect(localnetVersionOption?.description).toBe(`Select a specific localnet version (minimum: ${localnetCompatibleVersion})`);
89
- });
90
-
91
- test("option --localnet-version default value is compatible version", async () => {
92
- const localnetVersionOption = getCommandOption(initCommand, "--localnet-version");
93
- expect(localnetVersionOption?.defaultValue).toBe(localnetCompatibleVersion);
94
- });
95
-
96
- test("option --ollama is accepted", async () => {
97
- program.parse(["node", "test", "init", "--ollama"]);
98
- expect(InitAction).toHaveBeenCalledTimes(1);
99
- expect(InitAction.prototype.execute).toHaveBeenCalledWith({...defaultOptions, ollama: true});
100
- });
101
- });
@@ -1,131 +0,0 @@
1
- import { Command } from "commander";
2
- import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
- import { initializeValidatorCommands } from "../../src/commands/localnet";
4
- import { ValidatorsAction } from "../../src/commands/localnet/validators";
5
-
6
- vi.mock("../../src/commands/localnet/validators");
7
-
8
- describe("localnet validator command", () => {
9
- let program: Command;
10
-
11
- beforeEach(() => {
12
- program = new Command();
13
- initializeValidatorCommands(program);
14
- });
15
-
16
- afterEach(() => {
17
- vi.restoreAllMocks();
18
- });
19
-
20
- test("ValidatorsAction.getValidator is called with address option", async () => {
21
- program.parse(["node", "test", "localnet", "validators", "get", "--address", "mocked_address"]);
22
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
23
- expect(ValidatorsAction.prototype.getValidator).toHaveBeenCalledWith({
24
- address: "mocked_address",
25
- });
26
- });
27
-
28
- test("ValidatorsAction.getValidator is called without address option", async () => {
29
- program.parse(["node", "test", "localnet", "validators", "get"]);
30
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
31
- expect(ValidatorsAction.prototype.getValidator).toHaveBeenCalledWith({});
32
- });
33
-
34
- test("ValidatorsAction.deleteValidator is called with address option", async () => {
35
- program.parse(["node", "test", "localnet", "validators", "delete", "--address", "mocked_address"]);
36
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
37
- expect(ValidatorsAction.prototype.deleteValidator).toHaveBeenCalledWith({
38
- address: "mocked_address",
39
- });
40
- });
41
-
42
- test("ValidatorsAction.deleteValidator is called without address option", async () => {
43
- program.parse(["node", "test", "localnet", "validators", "delete"]);
44
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
45
- expect(ValidatorsAction.prototype.deleteValidator).toHaveBeenCalledWith({});
46
- });
47
-
48
- test("ValidatorsAction.countValidators is called", async () => {
49
- program.parse(["node", "test", "localnet", "validators", "count"]);
50
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
51
- expect(ValidatorsAction.prototype.countValidators).toHaveBeenCalled();
52
- });
53
-
54
- test("ValidatorsAction.updateValidator is called with all options", async () => {
55
- program.parse([
56
- "node",
57
- "test",
58
- "localnet",
59
- "validators",
60
- "update",
61
- "mocked_address",
62
- "--stake",
63
- "10",
64
- "--provider",
65
- "mocked_provider",
66
- "--model",
67
- "mocked_model",
68
- '--config',
69
- '{"max_tokens":500}',
70
- ]);
71
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
72
- expect(ValidatorsAction.prototype.updateValidator).toHaveBeenCalledWith({
73
- address: "mocked_address",
74
- stake: "10",
75
- provider: "mocked_provider",
76
- model: "mocked_model",
77
- config: '{"max_tokens":500}',
78
- });
79
- });
80
-
81
- test("ValidatorsAction.createRandomValidators is called with count and providers", async () => {
82
- program.parse([
83
- "node",
84
- "test",
85
- "localnet",
86
- "validators",
87
- "create-random",
88
- "--count",
89
- "3",
90
- "--providers",
91
- "provider1",
92
- "provider2",
93
- ]);
94
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
95
- expect(ValidatorsAction.prototype.createRandomValidators).toHaveBeenCalledWith({
96
- count: "3",
97
- providers: ["provider1", "provider2"],
98
- models: []
99
- });
100
- });
101
-
102
- test("ValidatorsAction.createValidator is called with default stake", async () => {
103
- program.parse(["node", "test", "localnet", "validators", "create"]);
104
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
105
- expect(ValidatorsAction.prototype.createValidator).toHaveBeenCalledWith({
106
- stake: "1",
107
- config: undefined,
108
- });
109
- });
110
-
111
- test("ValidatorsAction.createValidator is called with stake and config", async () => {
112
- program.parse([
113
- "node",
114
- "test",
115
- "localnet",
116
- "validators",
117
- "create",
118
- "--stake",
119
- "5",
120
- '--config',
121
- '{"temperature":0.8}',
122
- ]);
123
- expect(ValidatorsAction).toHaveBeenCalledTimes(1);
124
- expect(ValidatorsAction.prototype.createValidator).toHaveBeenCalledWith({
125
- stake: "5",
126
- config: '{"temperature":0.8}',
127
- });
128
- });
129
- });
130
-
131
-
@@ -1,60 +0,0 @@
1
- import {Command} from "commander";
2
- import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
3
- import {initializeNetworkCommands} from "../../src/commands/network";
4
- import {NetworkActions} from "../../src/commands/network/setNetwork";
5
-
6
- vi.mock("../../src/commands/network/setNetwork");
7
-
8
- describe("network commands", () => {
9
- let program: Command;
10
-
11
- beforeEach(() => {
12
- program = new Command();
13
- initializeNetworkCommands(program);
14
- });
15
-
16
- afterEach(() => {
17
- vi.restoreAllMocks();
18
- });
19
-
20
- test("NetworkActions.setNetwork is called with the correct network name", async () => {
21
- program.parse(["node", "test", "network", "set", "localnet"]);
22
- expect(NetworkActions).toHaveBeenCalledTimes(1);
23
- expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("localnet");
24
- });
25
-
26
- test("NetworkActions.setNetwork is called with testnet-asimov", async () => {
27
- program.parse(["node", "test", "network", "set", "testnet-asimov"]);
28
- expect(NetworkActions).toHaveBeenCalledTimes(1);
29
- expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("testnet-asimov");
30
- });
31
-
32
- test("NetworkActions.setNetwork is called with studionet", async () => {
33
- program.parse(["node", "test", "network", "set", "studionet"]);
34
- expect(NetworkActions).toHaveBeenCalledTimes(1);
35
- expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith("studionet");
36
- });
37
-
38
- test("NetworkActions.setNetwork is called without a network name", async () => {
39
- program.parse(["node", "test", "network", "set"]);
40
- expect(NetworkActions).toHaveBeenCalledTimes(1);
41
- expect(NetworkActions.prototype.setNetwork).toHaveBeenCalledWith(undefined);
42
- });
43
-
44
- test("NetworkActions is instantiated when the command is executed", async () => {
45
- program.parse(["node", "test", "network", "set", "localnet"]);
46
- expect(NetworkActions).toHaveBeenCalledTimes(1);
47
- });
48
-
49
- test("NetworkActions.setNetwork is called without throwing errors for valid network", async () => {
50
- program.parse(["node", "test", "network", "set", "localnet"]);
51
- vi.mocked(NetworkActions.prototype.setNetwork).mockResolvedValue();
52
- expect(() => program.parse(["node", "test", "network", "set", "localnet"])).not.toThrow();
53
- });
54
-
55
- test("NetworkActions.showInfo is called for network info", async () => {
56
- program.parse(["node", "test", "network", "info"]);
57
- expect(NetworkActions).toHaveBeenCalledTimes(1);
58
- expect(NetworkActions.prototype.showInfo).toHaveBeenCalled();
59
- });
60
- });
@@ -1,68 +0,0 @@
1
- import { Command } from "commander";
2
- import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
3
- import { initializeScaffoldCommands } from "../../src/commands/scaffold";
4
- import { NewAction } from "../../src/commands/scaffold/new";
5
-
6
- vi.mock("../../src/commands/scaffold/new");
7
-
8
- describe("new command", () => {
9
- let program: Command;
10
-
11
- beforeEach(() => {
12
- program = new Command();
13
- initializeScaffoldCommands(program);
14
- vi.clearAllMocks();
15
- });
16
-
17
- afterEach(() => {
18
- vi.restoreAllMocks();
19
- });
20
-
21
- test("NewAction.createProject is called with default options", async () => {
22
- program.parse(["node", "test", "new", "myProject"]);
23
- expect(NewAction).toHaveBeenCalledTimes(1);
24
- expect(NewAction.prototype.createProject).toHaveBeenCalledWith("myProject", {
25
- path: ".",
26
- overwrite: false,
27
- });
28
- });
29
-
30
- test("NewAction.createProject is called with custom path", async () => {
31
- program.parse(["node", "test", "new", "myProject", "--path", "./customDir"]);
32
- expect(NewAction).toHaveBeenCalledTimes(1);
33
- expect(NewAction.prototype.createProject).toHaveBeenCalledWith("myProject", {
34
- path: "./customDir",
35
- overwrite: false,
36
- });
37
- });
38
-
39
- test("NewAction.createProject is called with overwrite flag", async () => {
40
- program.parse(["node", "test", "new", "myProject", "--overwrite"]);
41
- expect(NewAction).toHaveBeenCalledTimes(1);
42
- expect(NewAction.prototype.createProject).toHaveBeenCalledWith("myProject", {
43
- path: ".",
44
- overwrite: true,
45
- });
46
- });
47
-
48
- test("NewAction is instantiated when the new command is executed", async () => {
49
- program.parse(["node", "test", "new", "myProject"]);
50
- expect(NewAction).toHaveBeenCalledTimes(1);
51
- });
52
-
53
- test("throws error for unrecognized options", async () => {
54
- const newCommand = program.commands.find((cmd) => cmd.name() === "new");
55
- newCommand?.exitOverride();
56
- expect(() => program.parse(["node", "test", "new", "myProject", "--unknown"])).toThrowError(
57
- "error: unknown option '--unknown'"
58
- );
59
- });
60
-
61
- test("NewAction.createProject is called without throwing errors for valid options", async () => {
62
- program.parse(["node", "test", "new", "myProject"]);
63
- vi.mocked(NewAction.prototype.createProject).mockResolvedValueOnce(undefined);
64
- expect(() =>
65
- program.parse(["node", "test", "new", "myProject"])
66
- ).not.toThrow();
67
- });
68
- });
@@ -1,142 +0,0 @@
1
- import {Command} from "commander";
2
- import {ReceiptAction} from "../../src/commands/transactions/receipt";
3
- import {vi, describe, beforeEach, afterEach, test, expect} from "vitest";
4
- import {initializeTransactionsCommands} from "../../src/commands/transactions";
5
-
6
- vi.mock("../../src/commands/transactions/receipt");
7
-
8
- describe("receipt command", () => {
9
- let program: Command;
10
- const mockTxId = "0x1234567890123456789012345678901234567890123456789012345678901234";
11
-
12
- beforeEach(() => {
13
- program = new Command();
14
- initializeTransactionsCommands(program);
15
- vi.clearAllMocks();
16
- });
17
-
18
- afterEach(() => {
19
- vi.restoreAllMocks();
20
- });
21
-
22
- test("ReceiptAction.receipt is called with default options", async () => {
23
- program.parse(["node", "test", "receipt", mockTxId]);
24
- expect(ReceiptAction).toHaveBeenCalledTimes(1);
25
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
26
- txId: mockTxId,
27
- status: "FINALIZED",
28
- retries: 100,
29
- interval: 5000,
30
- });
31
- });
32
-
33
- test("ReceiptAction.receipt is called with custom options", async () => {
34
- program.parse([
35
- "node",
36
- "test",
37
- "receipt",
38
- mockTxId,
39
- "--status",
40
- "ACCEPTED",
41
- "--retries",
42
- "50",
43
- "--interval",
44
- "3000",
45
- "--rpc",
46
- "https://custom-rpc-url-for-receipt.com",
47
- ]);
48
- expect(ReceiptAction).toHaveBeenCalledTimes(1);
49
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
50
- txId: mockTxId,
51
- status: "ACCEPTED",
52
- retries: 50,
53
- interval: 3000,
54
- rpc: "https://custom-rpc-url-for-receipt.com",
55
- });
56
- });
57
-
58
- test("ReceiptAction is instantiated when the receipt command is executed", async () => {
59
- program.parse(["node", "test", "receipt", mockTxId]);
60
- expect(ReceiptAction).toHaveBeenCalledTimes(1);
61
- });
62
-
63
- test("throws error for unrecognized options", async () => {
64
- const receiptCommand = program.commands.find(cmd => cmd.name() === "receipt");
65
- receiptCommand?.exitOverride();
66
- expect(() =>
67
- program.parse(["node", "test", "receipt", mockTxId, "--invalid-option"]),
68
- ).toThrowError("error: unknown option '--invalid-option'");
69
- });
70
-
71
- test("parses numeric options correctly", async () => {
72
- program.parse([
73
- "node",
74
- "test",
75
- "receipt",
76
- mockTxId,
77
- "--retries",
78
- "25",
79
- "--interval",
80
- "1000",
81
- ]);
82
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
83
- txId: mockTxId,
84
- status: "FINALIZED",
85
- retries: 25,
86
- interval: 1000,
87
- });
88
- });
89
-
90
- test("uses fallback value for invalid numeric options", async () => {
91
- program.parse([
92
- "node",
93
- "test",
94
- "receipt",
95
- mockTxId,
96
- "--retries",
97
- "invalid",
98
- "--interval",
99
- "notanumber",
100
- ]);
101
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
102
- txId: mockTxId,
103
- status: "FINALIZED",
104
- retries: 100,
105
- interval: 5000,
106
- });
107
- });
108
-
109
- test("parses --stdout flag", async () => {
110
- program.parse(["node", "test", "receipt", mockTxId, "--stdout"]);
111
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
112
- txId: mockTxId,
113
- status: "FINALIZED",
114
- retries: 100,
115
- interval: 5000,
116
- stdout: true,
117
- });
118
- });
119
-
120
- test("parses --stderr flag", async () => {
121
- program.parse(["node", "test", "receipt", mockTxId, "--stderr"]);
122
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
123
- txId: mockTxId,
124
- status: "FINALIZED",
125
- retries: 100,
126
- interval: 5000,
127
- stderr: true,
128
- });
129
- });
130
-
131
- test("parses both --stdout and --stderr flags", async () => {
132
- program.parse(["node", "test", "receipt", mockTxId, "--stdout", "--stderr"]);
133
- expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
134
- txId: mockTxId,
135
- status: "FINALIZED",
136
- retries: 100,
137
- interval: 5000,
138
- stdout: true,
139
- stderr: true,
140
- });
141
- });
142
- });
@@ -1,67 +0,0 @@
1
- import { Command } from "commander";
2
- import { SchemaAction } from "../../src/commands/contracts/schema";
3
- import { vi, describe, beforeEach, afterEach, test, expect } from "vitest";
4
- import { initializeContractsCommands } from "../../src/commands/contracts";
5
-
6
- vi.mock("../../src/commands/contracts/schema");
7
- vi.mock("esbuild", () => ({
8
- buildSync: vi.fn(),
9
- }));
10
-
11
- describe("schema 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("SchemaAction.schema is called with default options", async () => {
25
- program.parse(["node", "test", "schema", "0xMockedContract"]);
26
- expect(SchemaAction).toHaveBeenCalledTimes(1);
27
- expect(SchemaAction.prototype.schema).toHaveBeenCalledWith({
28
- contractAddress: "0xMockedContract",
29
- });
30
- });
31
-
32
- test("SchemaAction.schema is called with custom RPC URL", async () => {
33
- program.parse([
34
- "node",
35
- "test",
36
- "schema",
37
- "0xMockedContract",
38
- "--rpc",
39
- "https://custom-rpc-url.com"
40
- ]);
41
- expect(SchemaAction).toHaveBeenCalledTimes(1);
42
- expect(SchemaAction.prototype.schema).toHaveBeenCalledWith({
43
- contractAddress: "0xMockedContract",
44
- rpc: "https://custom-rpc-url.com"
45
- });
46
- });
47
-
48
- test("SchemaAction is instantiated when the schema command is executed", async () => {
49
- program.parse(["node", "test", "schema", "0xMockedContract"]);
50
- expect(SchemaAction).toHaveBeenCalledTimes(1);
51
- });
52
-
53
- test("throws error for unrecognized options", async () => {
54
- const schemaCommand = program.commands.find((cmd) => cmd.name() === "schema");
55
- schemaCommand?.exitOverride();
56
- expect(() => program.parse(["node", "test", "schema", "0xMockedContract", "--unknown"]))
57
- .toThrowError("error: unknown option '--unknown'");
58
- });
59
-
60
- test("SchemaAction.schema is called without throwing errors for valid options", async () => {
61
- program.parse(["node", "test", "schema", "0xMockedContract"]);
62
- vi.mocked(SchemaAction.prototype.schema).mockResolvedValueOnce(undefined);
63
- expect(() =>
64
- program.parse(["node", "test", "schema", "0xMockedContract"])
65
- ).not.toThrow();
66
- });
67
- });