genlayer 0.3.0 → 0.4.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 +7 -0
- package/dist/index.js +48 -10
- package/package.json +1 -1
- package/renovate.json +1 -2
- package/src/commands/general/index.ts +2 -0
- package/src/commands/general/init.ts +5 -0
- package/src/commands/general/start.ts +6 -1
- package/src/index.ts +8 -6
- package/src/lib/clients/system.ts +6 -3
- package/src/lib/interfaces/ISimulatorService.ts +1 -0
- package/src/lib/services/simulator.ts +11 -0
- package/tests/actions/init.test.ts +7 -3
- package/tests/actions/start.test.ts +4 -2
- package/tests/commands/init.test.ts +9 -2
- package/tests/commands/up.test.ts +12 -8
- package/tests/index.test.ts +21 -0
- package/tests/libs/system.test.ts +1 -1
- package/tests/services/simulator.test.ts +6 -0
- package/vitest.config.ts +1 -1
- package/src/lib/errors/jsonRpcClientError.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.4.0 (2024-11-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* new reset db option ([#139](https://github.com/yeagerai/genlayer-cli/issues/139)) ([e3fed64](https://github.com/yeagerai/genlayer-cli/commit/e3fed6437e7313002685258aeced710a6fd63f4f))
|
|
9
|
+
|
|
3
10
|
## 0.3.0 (2024-11-15)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
31
31
|
var __commonJS = (cb, mod) => function __require() {
|
|
32
32
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
33
33
|
};
|
|
34
|
+
var __export = (target, all) => {
|
|
35
|
+
for (var name in all)
|
|
36
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
37
|
+
};
|
|
34
38
|
var __copyProps = (to, from3, except, desc) => {
|
|
35
39
|
if (from3 && typeof from3 === "object" || typeof from3 === "function") {
|
|
36
40
|
for (let key of __getOwnPropNames(from3))
|
|
@@ -47,6 +51,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
47
51
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
48
52
|
mod
|
|
49
53
|
));
|
|
54
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
55
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
51
56
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
52
57
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
@@ -46391,6 +46396,13 @@ var require_set = __commonJS({
|
|
|
46391
46396
|
}
|
|
46392
46397
|
});
|
|
46393
46398
|
|
|
46399
|
+
// src/index.ts
|
|
46400
|
+
var src_exports = {};
|
|
46401
|
+
__export(src_exports, {
|
|
46402
|
+
initializeCLI: () => initializeCLI
|
|
46403
|
+
});
|
|
46404
|
+
module.exports = __toCommonJS(src_exports);
|
|
46405
|
+
|
|
46394
46406
|
// node_modules/commander/esm.mjs
|
|
46395
46407
|
var import_index = __toESM(require_commander(), 1);
|
|
46396
46408
|
var {
|
|
@@ -46409,7 +46421,7 @@ var {
|
|
|
46409
46421
|
} = import_index.default;
|
|
46410
46422
|
|
|
46411
46423
|
// package.json
|
|
46412
|
-
var version = "0.
|
|
46424
|
+
var version = "0.4.0";
|
|
46413
46425
|
|
|
46414
46426
|
// src/lib/config/text.ts
|
|
46415
46427
|
var CLI_DESCRIPTION = "GenLayer CLI is a development environment for the GenLayer ecosystem. It allows developers to interact with the protocol by creating accounts, sending transactions, and working with Intelligent Contracts by testing, debugging, and deploying them.";
|
|
@@ -47010,9 +47022,12 @@ var MissingRequirementError = class extends Error {
|
|
|
47010
47022
|
// src/lib/clients/system.ts
|
|
47011
47023
|
function checkCommand(command, toolName) {
|
|
47012
47024
|
return __async(this, null, function* () {
|
|
47013
|
-
|
|
47014
|
-
|
|
47015
|
-
|
|
47025
|
+
try {
|
|
47026
|
+
yield import_node_util5.default.promisify(import_child_process.exec)(command);
|
|
47027
|
+
} catch (error) {
|
|
47028
|
+
if (error.stderr) {
|
|
47029
|
+
throw new MissingRequirementError(toolName);
|
|
47030
|
+
}
|
|
47016
47031
|
}
|
|
47017
47032
|
});
|
|
47018
47033
|
}
|
|
@@ -47319,6 +47334,16 @@ var SimulatorService = class {
|
|
|
47319
47334
|
return true;
|
|
47320
47335
|
});
|
|
47321
47336
|
}
|
|
47337
|
+
cleanDatabase() {
|
|
47338
|
+
return __async(this, null, function* () {
|
|
47339
|
+
try {
|
|
47340
|
+
yield rpcClient.request({ method: "sim_clearDbTables", params: [["current_state", "transactions"]] });
|
|
47341
|
+
} catch (error) {
|
|
47342
|
+
console.error(error);
|
|
47343
|
+
}
|
|
47344
|
+
return true;
|
|
47345
|
+
});
|
|
47346
|
+
}
|
|
47322
47347
|
};
|
|
47323
47348
|
var simulator_default = new SimulatorService();
|
|
47324
47349
|
|
|
@@ -50085,6 +50110,9 @@ function initAction(options, simulatorService) {
|
|
|
50085
50110
|
console.error(error);
|
|
50086
50111
|
return;
|
|
50087
50112
|
}
|
|
50113
|
+
if (options.resetDb) {
|
|
50114
|
+
yield simulatorService.cleanDatabase();
|
|
50115
|
+
}
|
|
50088
50116
|
let successMessage = "GenLayer simulator initialized successfully! ";
|
|
50089
50117
|
successMessage += options.headless ? "" : `Go to ${simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
50090
50118
|
console.log(successMessage);
|
|
@@ -50101,7 +50129,7 @@ function initAction(options, simulatorService) {
|
|
|
50101
50129
|
// src/commands/general/start.ts
|
|
50102
50130
|
function startAction(options, simulatorService) {
|
|
50103
50131
|
return __async(this, null, function* () {
|
|
50104
|
-
const { resetValidators, numValidators, branch, location, headless } = options;
|
|
50132
|
+
const { resetValidators, numValidators, branch, location, headless, resetDb } = options;
|
|
50105
50133
|
simulatorService.setComposeOptions(headless);
|
|
50106
50134
|
simulatorService.setSimulatorLocation(location);
|
|
50107
50135
|
const restartValidatorsHintText = resetValidators ? `creating new ${numValidators} random validators` : "keeping the existing validators";
|
|
@@ -50138,6 +50166,9 @@ function startAction(options, simulatorService) {
|
|
|
50138
50166
|
console.error(error);
|
|
50139
50167
|
return;
|
|
50140
50168
|
}
|
|
50169
|
+
if (resetDb) {
|
|
50170
|
+
yield simulatorService.cleanDatabase();
|
|
50171
|
+
}
|
|
50141
50172
|
if (resetValidators) {
|
|
50142
50173
|
console.log("Initializing validators...");
|
|
50143
50174
|
try {
|
|
@@ -50183,15 +50214,22 @@ function startAction(options, simulatorService) {
|
|
|
50183
50214
|
|
|
50184
50215
|
// src/commands/general/index.ts
|
|
50185
50216
|
function initializeGeneralCommands(program2) {
|
|
50186
|
-
program2.command("init").description("Initialize the GenLayer Environment").option("--numValidators <numValidators>", "Number of validators", "5").option("--branch <branch>", "Branch", "main").option("--location <folder>", "Location where it will be installed", process.cwd()).option("--headless", "Headless mode", false).action((options) => initAction(options, simulator_default));
|
|
50187
|
-
program2.command("up").description("Starts GenLayer's simulator").option("--reset-validators", "Remove all current validators and create new random ones", false).option("--numValidators <numValidators>", "Number of validators", "5").option("--branch <branch>", "Branch", "main").option("--location <folder>", "Location where it will be installed", process.cwd()).option("--headless", "Headless mode", false).action((options) => startAction(options, simulator_default));
|
|
50217
|
+
program2.command("init").description("Initialize the GenLayer Environment").option("--numValidators <numValidators>", "Number of validators", "5").option("--branch <branch>", "Branch", "main").option("--location <folder>", "Location where it will be installed", process.cwd()).option("--headless", "Headless mode", false).option("--reset-db", "Reset Database", false).action((options) => initAction(options, simulator_default));
|
|
50218
|
+
program2.command("up").description("Starts GenLayer's simulator").option("--reset-validators", "Remove all current validators and create new random ones", false).option("--numValidators <numValidators>", "Number of validators", "5").option("--branch <branch>", "Branch", "main").option("--location <folder>", "Location where it will be installed", process.cwd()).option("--headless", "Headless mode", false).option("--reset-db", "Reset Database", false).action((options) => startAction(options, simulator_default));
|
|
50188
50219
|
return program2;
|
|
50189
50220
|
}
|
|
50190
50221
|
|
|
50191
50222
|
// src/index.ts
|
|
50192
|
-
|
|
50193
|
-
|
|
50194
|
-
program
|
|
50223
|
+
function initializeCLI() {
|
|
50224
|
+
program.version(version).description(CLI_DESCRIPTION);
|
|
50225
|
+
initializeGeneralCommands(program);
|
|
50226
|
+
program.parse(process.argv);
|
|
50227
|
+
}
|
|
50228
|
+
initializeCLI();
|
|
50229
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50230
|
+
0 && (module.exports = {
|
|
50231
|
+
initializeCLI
|
|
50232
|
+
});
|
|
50195
50233
|
/*! Bundled license information:
|
|
50196
50234
|
|
|
50197
50235
|
safe-buffer/index.js:
|
package/package.json
CHANGED
package/renovate.json
CHANGED
|
@@ -13,6 +13,7 @@ export function initializeGeneralCommands(program: Command) {
|
|
|
13
13
|
.option("--branch <branch>", "Branch", "main")
|
|
14
14
|
.option("--location <folder>", "Location where it will be installed", process.cwd())
|
|
15
15
|
.option("--headless", "Headless mode", false)
|
|
16
|
+
.option("--reset-db", "Reset Database", false)
|
|
16
17
|
.action((options: InitActionOptions) => initAction(options, simulatorService));
|
|
17
18
|
|
|
18
19
|
program
|
|
@@ -23,6 +24,7 @@ export function initializeGeneralCommands(program: Command) {
|
|
|
23
24
|
.option("--branch <branch>", "Branch", "main")
|
|
24
25
|
.option("--location <folder>", "Location where it will be installed", process.cwd())
|
|
25
26
|
.option("--headless", "Headless mode", false)
|
|
27
|
+
.option("--reset-db", "Reset Database", false)
|
|
26
28
|
.action((options: StartActionOptions) => startAction(options, simulatorService));
|
|
27
29
|
|
|
28
30
|
return program;
|
|
@@ -7,6 +7,7 @@ export interface InitActionOptions {
|
|
|
7
7
|
branch: string;
|
|
8
8
|
location: string;
|
|
9
9
|
headless: boolean;
|
|
10
|
+
resetDb: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
function getRequirementsErrorMessage({git, docker}: Record<string, boolean>): string {
|
|
@@ -225,6 +226,10 @@ export async function initAction(options: InitActionOptions, simulatorService: I
|
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
if(options.resetDb){
|
|
230
|
+
await simulatorService.cleanDatabase()
|
|
231
|
+
}
|
|
232
|
+
|
|
228
233
|
// Simulator ready
|
|
229
234
|
let successMessage = "GenLayer simulator initialized successfully! "
|
|
230
235
|
successMessage += options.headless ? '' : `Go to ${simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
@@ -8,10 +8,11 @@ export interface StartActionOptions {
|
|
|
8
8
|
branch: string;
|
|
9
9
|
location: string;
|
|
10
10
|
headless: boolean;
|
|
11
|
+
resetDb: boolean
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export async function startAction(options: StartActionOptions, simulatorService: ISimulatorService) {
|
|
14
|
-
const {resetValidators, numValidators, branch, location, headless} = options;
|
|
15
|
+
const {resetValidators, numValidators, branch, location, headless, resetDb} = options;
|
|
15
16
|
// Update simulator location with user input
|
|
16
17
|
simulatorService.setComposeOptions(headless);
|
|
17
18
|
simulatorService.setSimulatorLocation(location);
|
|
@@ -60,6 +61,10 @@ export async function startAction(options: StartActionOptions, simulatorService:
|
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
if(resetDb){
|
|
65
|
+
await simulatorService.cleanDatabase()
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
if (resetValidators) {
|
|
64
69
|
// Initializing validators
|
|
65
70
|
console.log("Initializing validators...");
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {program} from "commander";
|
|
3
3
|
import {version} from "../package.json";
|
|
4
|
-
import {CLI_DESCRIPTION} from "
|
|
5
|
-
import {initializeGeneralCommands} from "
|
|
4
|
+
import {CLI_DESCRIPTION} from "../src/lib/config/text";
|
|
5
|
+
import {initializeGeneralCommands} from "../src/commands/general";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export function initializeCLI() {
|
|
8
|
+
program.version(version).description(CLI_DESCRIPTION);
|
|
9
|
+
initializeGeneralCommands(program);
|
|
10
|
+
program.parse(process.argv);
|
|
11
|
+
}
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
program.parse(process.argv);
|
|
13
|
+
initializeCLI();
|
|
@@ -6,9 +6,12 @@ import {RunningPlatform, AVAILABLE_PLATFORMS} from "../config/simulator";
|
|
|
6
6
|
import {MissingRequirementError} from "../errors/missingRequirement";
|
|
7
7
|
|
|
8
8
|
export async function checkCommand(command: string, toolName: string): Promise<void> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
try {
|
|
10
|
+
await util.promisify(exec)(command);
|
|
11
|
+
}catch (error:any) {
|
|
12
|
+
if (error.stderr) {
|
|
13
|
+
throw new MissingRequirementError(toolName);
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -317,6 +317,17 @@ export class SimulatorService implements ISimulatorService {
|
|
|
317
317
|
|
|
318
318
|
return true;
|
|
319
319
|
}
|
|
320
|
+
|
|
321
|
+
public async cleanDatabase(): Promise<boolean> {
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
await rpcClient.request({method: "sim_clearDbTables", params: [['current_state', 'transactions']]});
|
|
325
|
+
}catch (error) {
|
|
326
|
+
console.error(error);
|
|
327
|
+
}
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
|
|
320
331
|
}
|
|
321
332
|
|
|
322
333
|
export default new SimulatorService();
|
|
@@ -7,7 +7,7 @@ import {mkdtempSync} from "fs";
|
|
|
7
7
|
import {join} from "path";
|
|
8
8
|
|
|
9
9
|
const tempDir = mkdtempSync(join(tmpdir(), "test-initAction-"));
|
|
10
|
-
const defaultActionOptions = { numValidators: 5, branch: "main", location: tempDir, headless: false };
|
|
10
|
+
const defaultActionOptions = { numValidators: 5, branch: "main", location: tempDir, headless: false, resetDb: false };
|
|
11
11
|
|
|
12
12
|
describe("init action", () => {
|
|
13
13
|
let error: ReturnType<any>;
|
|
@@ -188,7 +188,7 @@ describe("init action", () => {
|
|
|
188
188
|
);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
|
-
test("should open the frontend if everything went well (
|
|
191
|
+
test("should open the frontend if everything went well (custom options)", async () => {
|
|
192
192
|
inquirerPrompt.mockResolvedValue({
|
|
193
193
|
confirmReset: true,
|
|
194
194
|
confirmDownload: true,
|
|
@@ -211,7 +211,7 @@ describe("init action", () => {
|
|
|
211
211
|
simServResetDockerContainers.mockResolvedValue(true);
|
|
212
212
|
simServResetDockerImages.mockResolvedValue(true);
|
|
213
213
|
|
|
214
|
-
await initAction({...defaultActionOptions, headless: true}, simulatorService);
|
|
214
|
+
await initAction({...defaultActionOptions, headless: true, resetDb: true}, simulatorService);
|
|
215
215
|
|
|
216
216
|
expect(log).toHaveBeenCalledWith(
|
|
217
217
|
`GenLayer simulator initialized successfully! `
|
|
@@ -235,8 +235,12 @@ describe("init action", () => {
|
|
|
235
235
|
simServWaitForSimulator.mockResolvedValue({ initialized: true });
|
|
236
236
|
simServPullOllamaModel.mockResolvedValue(true);
|
|
237
237
|
simServDeleteAllValidators.mockResolvedValue(true);
|
|
238
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
239
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
238
240
|
simServCreateRandomValidators.mockRejectedValue();
|
|
239
241
|
simServOpenFrontend.mockResolvedValue(true);
|
|
242
|
+
simServResetDockerContainers.mockResolvedValue(true);
|
|
243
|
+
simServResetDockerImages.mockResolvedValue(true);
|
|
240
244
|
|
|
241
245
|
await initAction({...defaultActionOptions, headless: true}, simulatorService);
|
|
242
246
|
|
|
@@ -15,6 +15,7 @@ describe("startAction - Additional Tests", () => {
|
|
|
15
15
|
branch: "main",
|
|
16
16
|
location: '',
|
|
17
17
|
headless: false,
|
|
18
|
+
resetDb: false
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
beforeEach(() => {
|
|
@@ -36,6 +37,7 @@ describe("startAction - Additional Tests", () => {
|
|
|
36
37
|
{ name: "Provider B", value: "providerB" },
|
|
37
38
|
]),
|
|
38
39
|
getFrontendUrl: vi.fn(() => "http://localhost:8080"),
|
|
40
|
+
cleanDatabase: vi.fn().mockResolvedValue(undefined),
|
|
39
41
|
} as unknown as ISimulatorService;
|
|
40
42
|
});
|
|
41
43
|
|
|
@@ -59,8 +61,8 @@ describe("startAction - Additional Tests", () => {
|
|
|
59
61
|
expect(simulatorService.openFrontend).toHaveBeenCalled();
|
|
60
62
|
});
|
|
61
63
|
|
|
62
|
-
test("runs successfully with
|
|
63
|
-
await startAction({...defaultOptions, headless: true}, simulatorService);
|
|
64
|
+
test("runs successfully with custom options and keeps existing validators", async () => {
|
|
65
|
+
await startAction({...defaultOptions, headless: true, resetDb: true}, simulatorService);
|
|
64
66
|
|
|
65
67
|
expect(simulatorService.updateSimulator).toHaveBeenCalledWith("main");
|
|
66
68
|
expect(simulatorService.runSimulator).toHaveBeenCalled();
|
|
@@ -5,6 +5,13 @@ import { getCommand, getCommandOption } from "../utils";
|
|
|
5
5
|
import simulatorService from '../../src/lib/services/simulator'
|
|
6
6
|
|
|
7
7
|
const openFrontendSpy = vi.spyOn(simulatorService, "openFrontend");
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
numValidators: "5",
|
|
10
|
+
branch: "main",
|
|
11
|
+
location: process.cwd(),
|
|
12
|
+
headless: false,
|
|
13
|
+
resetDb: false
|
|
14
|
+
}
|
|
8
15
|
|
|
9
16
|
vi.mock("inquirer", () => ({
|
|
10
17
|
prompt: vi.fn(() => {}),
|
|
@@ -74,13 +81,13 @@ describe("init command", () => {
|
|
|
74
81
|
test("action is called", async () => {
|
|
75
82
|
program.parse(["node", "test", "init"]);
|
|
76
83
|
expect(action).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(action).toHaveBeenCalledWith(
|
|
84
|
+
expect(action).toHaveBeenCalledWith(defaultOptions);
|
|
78
85
|
});
|
|
79
86
|
|
|
80
87
|
test("option --headless is accepted", async () => {
|
|
81
88
|
program.parse(["node", "test", "init", "--headless"]);
|
|
82
89
|
expect(action).toHaveBeenCalledTimes(1);
|
|
83
|
-
expect(action).toHaveBeenCalledWith({
|
|
90
|
+
expect(action).toHaveBeenCalledWith({...defaultOptions, headless: true});
|
|
84
91
|
expect(openFrontendSpy).not.toHaveBeenCalled();
|
|
85
92
|
});
|
|
86
93
|
});
|
|
@@ -7,6 +7,14 @@ import simulatorService from '../../src/lib/services/simulator'
|
|
|
7
7
|
const openFrontendSpy = vi.spyOn(simulatorService, "openFrontend");
|
|
8
8
|
|
|
9
9
|
const action = vi.fn();
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
resetValidators: false,
|
|
12
|
+
numValidators: "5",
|
|
13
|
+
branch: "main",
|
|
14
|
+
location: process.cwd(),
|
|
15
|
+
headless: false ,
|
|
16
|
+
resetDb: false
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
describe("up command", () => {
|
|
12
20
|
let upCommand: Command;
|
|
@@ -72,7 +80,7 @@ describe("up command", () => {
|
|
|
72
80
|
test("action is called with default options", async () => {
|
|
73
81
|
program.parse(["node", "test", "up"]);
|
|
74
82
|
expect(action).toHaveBeenCalledTimes(1);
|
|
75
|
-
expect(action).toHaveBeenCalledWith(
|
|
83
|
+
expect(action).toHaveBeenCalledWith(defaultOptions);
|
|
76
84
|
});
|
|
77
85
|
|
|
78
86
|
test("action is called with custom options", async () => {
|
|
@@ -86,16 +94,12 @@ describe("up command", () => {
|
|
|
86
94
|
"--branch",
|
|
87
95
|
"development",
|
|
88
96
|
"--headless",
|
|
97
|
+
"true",
|
|
98
|
+
"--reset-db",
|
|
89
99
|
"true"
|
|
90
100
|
]);
|
|
91
101
|
expect(action).toHaveBeenCalledTimes(1);
|
|
92
|
-
expect(action).toHaveBeenCalledWith({
|
|
93
|
-
resetValidators: true,
|
|
94
|
-
numValidators: "10",
|
|
95
|
-
branch: "development",
|
|
96
|
-
location: process.cwd(),
|
|
97
|
-
headless: true,
|
|
98
|
-
});
|
|
102
|
+
expect(action).toHaveBeenCalledWith({...defaultOptions, headless: true, branch: 'development', numValidators: '10', resetValidators: true, resetDb: true});
|
|
99
103
|
expect(openFrontendSpy).not.toHaveBeenCalled();
|
|
100
104
|
});
|
|
101
105
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, it, vi, expect } from "vitest";
|
|
2
|
+
import { initializeCLI } from "../src/index";
|
|
3
|
+
|
|
4
|
+
vi.mock("commander", () => ({
|
|
5
|
+
program: {
|
|
6
|
+
version: vi.fn().mockReturnThis(),
|
|
7
|
+
description: vi.fn().mockReturnThis(),
|
|
8
|
+
parse: vi.fn(),
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock("../src/commands/general", () => ({
|
|
13
|
+
initializeGeneralCommands: vi.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
describe("CLI", () => {
|
|
18
|
+
it("should initialize CLI", () => {
|
|
19
|
+
expect(initializeCLI).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -88,7 +88,7 @@ describe("System Functions - Error Paths", () => {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
test("checkCommand returns false if the command does not exist", async () => {
|
|
91
|
-
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.
|
|
91
|
+
vi.mocked(util.promisify).mockReturnValueOnce(() => Promise.reject({
|
|
92
92
|
stdout: "",
|
|
93
93
|
stderr: "command not found"
|
|
94
94
|
}));
|
|
@@ -281,6 +281,12 @@ describe("SimulatorService - Basic Tests", () => {
|
|
|
281
281
|
expect(simulatorService.getAiProvidersOptions(false)).toEqual(expect.any(Array));
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
+
test("clean simulator should success", async () => {
|
|
285
|
+
vi.mocked(rpcClient.request).mockResolvedValueOnce('Success');
|
|
286
|
+
await expect(simulatorService.cleanDatabase).not.toThrow();
|
|
287
|
+
expect(rpcClient.request).toHaveBeenCalledWith({ method: "sim_clearDbTables", params: [['current_state', 'transactions']] });
|
|
288
|
+
});
|
|
289
|
+
|
|
284
290
|
});
|
|
285
291
|
describe("SimulatorService - Docker Tests", () => {
|
|
286
292
|
let mockExec: Mock;
|
package/vitest.config.ts
CHANGED
|
@@ -5,7 +5,7 @@ export default defineConfig({
|
|
|
5
5
|
globals: true,
|
|
6
6
|
environment: 'jsdom',
|
|
7
7
|
coverage: {
|
|
8
|
-
exclude: [...configDefaults.exclude, '*.js', '
|
|
8
|
+
exclude: [...configDefaults.exclude, '*.js', 'tests/**/*.ts', 'src/types'],
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export class MissingRequirementError extends Error {
|
|
2
|
-
requirement: string;
|
|
3
|
-
|
|
4
|
-
constructor(requirement: string) {
|
|
5
|
-
super(`${requirement} is not installed. Please install ${requirement}.`);
|
|
6
|
-
this.name = "MissingRequirement";
|
|
7
|
-
this.requirement = requirement;
|
|
8
|
-
}
|
|
9
|
-
}
|