genlayer 0.6.0 → 0.7.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 +1 -0
- package/CHANGELOG.md +7 -0
- package/dist/index.js +19 -2
- package/docker-compose.yml +4 -4
- package/package.json +1 -1
- package/src/commands/general/index.ts +1 -0
- package/src/commands/general/init.ts +7 -0
- package/src/lib/interfaces/ISimulatorService.ts +1 -0
- package/src/lib/services/simulator.ts +17 -0
- package/tests/actions/init.test.ts +3 -2
- package/tests/commands/init.test.ts +9 -1
- package/tests/services/simulator.test.ts +34 -0
package/.env.example
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (2024-12-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* adding localnet version option on init ([#151](https://github.com/yeagerai/genlayer-cli/issues/151)) ([a7bf419](https://github.com/yeagerai/genlayer-cli/commit/a7bf41986e89e8db95003df290d381e77dad127f))
|
|
9
|
+
|
|
3
10
|
## 0.6.0 (2024-12-03)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.js
CHANGED
|
@@ -50858,7 +50858,7 @@ var {
|
|
|
50858
50858
|
} = import_index.default;
|
|
50859
50859
|
|
|
50860
50860
|
// package.json
|
|
50861
|
-
var version = "0.
|
|
50861
|
+
var version = "0.7.0";
|
|
50862
50862
|
var package_default = {
|
|
50863
50863
|
name: "genlayer",
|
|
50864
50864
|
version,
|
|
@@ -51817,6 +51817,18 @@ Run npm install -g genlayer to update
|
|
|
51817
51817
|
return true;
|
|
51818
51818
|
});
|
|
51819
51819
|
}
|
|
51820
|
+
normalizeLocalnetVersion(version3) {
|
|
51821
|
+
if (!version3.startsWith("v")) {
|
|
51822
|
+
version3 = "v" + version3;
|
|
51823
|
+
}
|
|
51824
|
+
const versionRegex = /^v(\d+)\.(\d+)\.(\d+)(-.+)?$/;
|
|
51825
|
+
const match = version3.match(versionRegex);
|
|
51826
|
+
if (!match) {
|
|
51827
|
+
console.error("Invalid version format. Expected format: v0.0.0 or v0.0.0-suffix");
|
|
51828
|
+
process.exit(1);
|
|
51829
|
+
}
|
|
51830
|
+
return version3;
|
|
51831
|
+
}
|
|
51820
51832
|
};
|
|
51821
51833
|
var simulator_default = new SimulatorService();
|
|
51822
51834
|
|
|
@@ -54427,6 +54439,10 @@ function getVersionErrorMessage({ docker, node }) {
|
|
|
54427
54439
|
function initAction(options, simulatorService) {
|
|
54428
54440
|
return __async(this, null, function* () {
|
|
54429
54441
|
simulatorService.setComposeOptions(options.headless);
|
|
54442
|
+
let localnetVersion = options.localnetVersion;
|
|
54443
|
+
if (localnetVersion !== "latest") {
|
|
54444
|
+
localnetVersion = simulatorService.normalizeLocalnetVersion(localnetVersion);
|
|
54445
|
+
}
|
|
54430
54446
|
yield simulatorService.checkCliVersion();
|
|
54431
54447
|
try {
|
|
54432
54448
|
const requirementsInstalled = yield simulatorService.checkInstallRequirements();
|
|
@@ -54512,6 +54528,7 @@ function initAction(options, simulatorService) {
|
|
|
54512
54528
|
}
|
|
54513
54529
|
console.log("Configuring GenLayer Simulator environment...");
|
|
54514
54530
|
simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
54531
|
+
simulatorService.addConfigToEnvFile({ LOCALNETVERSION: localnetVersion });
|
|
54515
54532
|
console.log("Running the GenLayer Simulator...");
|
|
54516
54533
|
try {
|
|
54517
54534
|
yield simulatorService.runSimulator();
|
|
@@ -54646,7 +54663,7 @@ function startAction(options, simulatorService) {
|
|
|
54646
54663
|
|
|
54647
54664
|
// src/commands/general/index.ts
|
|
54648
54665
|
function initializeGeneralCommands(program2) {
|
|
54649
|
-
program2.command("init").description("Initialize the GenLayer Environment").option("--numValidators <numValidators>", "Number of validators", "5").option("--headless", "Headless mode", false).option("--reset-db", "Reset Database", false).action((options) => initAction(options, simulator_default));
|
|
54666
|
+
program2.command("init").description("Initialize the GenLayer Environment").option("--numValidators <numValidators>", "Number of validators", "5").option("--headless", "Headless mode", false).option("--reset-db", "Reset Database", false).option("--localnet-version <localnetVersion>", "Select a specific localnet version", "latest").action((options) => initAction(options, simulator_default));
|
|
54650
54667
|
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("--headless", "Headless mode", false).option("--reset-db", "Reset Database", false).action((options) => startAction(options, simulator_default));
|
|
54651
54668
|
return program2;
|
|
54652
54669
|
}
|
package/docker-compose.yml
CHANGED
|
@@ -2,7 +2,7 @@ version: "3.8"
|
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
4
|
frontend:
|
|
5
|
-
image: yeagerai/simulator-frontend
|
|
5
|
+
image: yeagerai/simulator-frontend:${LOCALNETVERSION:-latest}
|
|
6
6
|
ports:
|
|
7
7
|
- "${FRONTEND_PORT:-8080}:8080"
|
|
8
8
|
environment:
|
|
@@ -25,7 +25,7 @@ services:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
jsonrpc:
|
|
28
|
-
image: yeagerai/simulator-jsonrpc
|
|
28
|
+
image: yeagerai/simulator-jsonrpc:${LOCALNETVERSION:-latest}
|
|
29
29
|
environment:
|
|
30
30
|
- FLASK_SERVER_PORT=${RPCPORT:-5000}
|
|
31
31
|
- PYTHONUNBUFFERED=1
|
|
@@ -63,7 +63,7 @@ services:
|
|
|
63
63
|
replicas: ${JSONRPC_REPLICAS:-1}
|
|
64
64
|
|
|
65
65
|
webrequest:
|
|
66
|
-
image: yeagerai/simulator-webrequest
|
|
66
|
+
image: yeagerai/simulator-webrequest:${LOCALNETVERSION:-latest}
|
|
67
67
|
shm_size: 2gb
|
|
68
68
|
environment:
|
|
69
69
|
- FLASK_SERVER_PORT=${WEBREQUESTPORT:-5002}
|
|
@@ -131,7 +131,7 @@ services:
|
|
|
131
131
|
# - "./data/postgres:/var/lib/postgresql/data"
|
|
132
132
|
|
|
133
133
|
database-migration:
|
|
134
|
-
image: yeagerai/simulator-database-migration
|
|
134
|
+
image: yeagerai/simulator-database-migration:${LOCALNETVERSION:-latest}
|
|
135
135
|
environment:
|
|
136
136
|
- DB_URL=postgresql://${DBUSER:-postgres}:${DBPASSWORD:-postgres}@postgres/${DBNAME:-simulator_db}
|
|
137
137
|
- WEBREQUESTPORT=${WEBREQUESTPORT:-5002}
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ export function initializeGeneralCommands(program: Command) {
|
|
|
11
11
|
.option("--numValidators <numValidators>", "Number of validators", "5")
|
|
12
12
|
.option("--headless", "Headless mode", false)
|
|
13
13
|
.option("--reset-db", "Reset Database", false)
|
|
14
|
+
.option("--localnet-version <localnetVersion>", "Select a specific localnet version", 'latest')
|
|
14
15
|
.action((options: InitActionOptions) => initAction(options, simulatorService));
|
|
15
16
|
|
|
16
17
|
program
|
|
@@ -6,6 +6,7 @@ export interface InitActionOptions {
|
|
|
6
6
|
numValidators: number;
|
|
7
7
|
headless: boolean;
|
|
8
8
|
resetDb: boolean;
|
|
9
|
+
localnetVersion: string;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
function getRequirementsErrorMessage({docker}: Record<string, boolean>): string {
|
|
@@ -34,6 +35,11 @@ function getVersionErrorMessage({docker, node}: Record<string, string>): string
|
|
|
34
35
|
export async function initAction(options: InitActionOptions, simulatorService: ISimulatorService) {
|
|
35
36
|
simulatorService.setComposeOptions(options.headless);
|
|
36
37
|
|
|
38
|
+
let localnetVersion = options.localnetVersion;
|
|
39
|
+
|
|
40
|
+
if(localnetVersion !== 'latest'){
|
|
41
|
+
localnetVersion = simulatorService.normalizeLocalnetVersion(localnetVersion);
|
|
42
|
+
}
|
|
37
43
|
await simulatorService.checkCliVersion();
|
|
38
44
|
|
|
39
45
|
// Check if requirements are installed
|
|
@@ -139,6 +145,7 @@ export async function initAction(options: InitActionOptions, simulatorService: I
|
|
|
139
145
|
|
|
140
146
|
console.log("Configuring GenLayer Simulator environment...");
|
|
141
147
|
simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
148
|
+
simulatorService.addConfigToEnvFile({LOCALNETVERSION: localnetVersion});
|
|
142
149
|
|
|
143
150
|
|
|
144
151
|
// Run the GenLayer Simulator
|
|
@@ -295,6 +295,23 @@ export class SimulatorService implements ISimulatorService {
|
|
|
295
295
|
return true;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
public normalizeLocalnetVersion(version: string) {
|
|
299
|
+
|
|
300
|
+
if (!version.startsWith('v')) {
|
|
301
|
+
version = 'v' + version;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const versionRegex = /^v(\d+)\.(\d+)\.(\d+)(-.+)?$/;
|
|
305
|
+
const match = version.match(versionRegex);
|
|
306
|
+
|
|
307
|
+
if (!match) {
|
|
308
|
+
console.error('Invalid version format. Expected format: v0.0.0 or v0.0.0-suffix');
|
|
309
|
+
process.exit(1);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return version
|
|
313
|
+
}
|
|
314
|
+
|
|
298
315
|
}
|
|
299
316
|
|
|
300
317
|
export default new SimulatorService();
|
|
@@ -14,7 +14,7 @@ vi.mock("dotenv");
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
const tempDir = mkdtempSync(join(tmpdir(), "test-initAction-"));
|
|
17
|
-
const defaultActionOptions = { numValidators: 5, branch: "main", location: tempDir, headless: false, resetDb: false };
|
|
17
|
+
const defaultActionOptions = { numValidators: 5, branch: "main", location: tempDir, headless: false, resetDb: false, localnetVersion: 'latest' };
|
|
18
18
|
|
|
19
19
|
describe("init action", () => {
|
|
20
20
|
let error: ReturnType<any>;
|
|
@@ -201,7 +201,7 @@ describe("init action", () => {
|
|
|
201
201
|
simServResetDockerContainers.mockResolvedValue(true);
|
|
202
202
|
simServResetDockerImages.mockResolvedValue(true);
|
|
203
203
|
|
|
204
|
-
await initAction({...defaultActionOptions, headless: true, resetDb: true}, simulatorService);
|
|
204
|
+
await initAction({...defaultActionOptions, headless: true, resetDb: true, localnetVersion: "v1.0.0"}, simulatorService);
|
|
205
205
|
|
|
206
206
|
expect(log).toHaveBeenCalledWith(
|
|
207
207
|
`GenLayer simulator initialized successfully! `
|
|
@@ -441,4 +441,5 @@ describe("init action", () => {
|
|
|
441
441
|
|
|
442
442
|
expect(error).toHaveBeenCalledWith(errorMsg);
|
|
443
443
|
});
|
|
444
|
+
|
|
444
445
|
});
|
|
@@ -8,7 +8,8 @@ const openFrontendSpy = vi.spyOn(simulatorService, "openFrontend");
|
|
|
8
8
|
const defaultOptions = {
|
|
9
9
|
numValidators: "5",
|
|
10
10
|
headless: false,
|
|
11
|
-
resetDb: false
|
|
11
|
+
resetDb: false,
|
|
12
|
+
localnetVersion: 'latest'
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
vi.mock("inquirer", () => ({
|
|
@@ -73,4 +74,11 @@ describe("init command", () => {
|
|
|
73
74
|
expect(action).toHaveBeenCalledWith({...defaultOptions, headless: true});
|
|
74
75
|
expect(openFrontendSpy).not.toHaveBeenCalled();
|
|
75
76
|
});
|
|
77
|
+
|
|
78
|
+
test("option --localnet-version is accepted", async () => {
|
|
79
|
+
program.parse(["node", "test", "init", "--localnet-version", "v1.0.0"]);
|
|
80
|
+
expect(action).toHaveBeenCalledTimes(1);
|
|
81
|
+
expect(action).toHaveBeenCalledWith({...defaultOptions, localnetVersion: "v1.0.0"});
|
|
82
|
+
expect(openFrontendSpy).not.toHaveBeenCalled();
|
|
83
|
+
});
|
|
76
84
|
});
|
|
@@ -505,3 +505,37 @@ describe("SimulatorService - Docker Tests", () => {
|
|
|
505
505
|
consoleWarnSpy.mockRestore();
|
|
506
506
|
});
|
|
507
507
|
});
|
|
508
|
+
|
|
509
|
+
describe('normalizeLocalnetVersion', () => {
|
|
510
|
+
test('should add "v" if not present', () => {
|
|
511
|
+
expect(simulatorService.normalizeLocalnetVersion("0.26.0")).toBe("v0.26.0");
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
test('should preserve "v" if already present', () => {
|
|
515
|
+
expect(simulatorService.normalizeLocalnetVersion("v0.26.0")).toBe("v0.26.0");
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test('should retain suffixes like "-test000"', () => {
|
|
519
|
+
expect(simulatorService.normalizeLocalnetVersion("0.25.0-test000")).toBe("v0.25.0-test000");
|
|
520
|
+
expect(simulatorService.normalizeLocalnetVersion("v1.0.0-alpha")).toBe("v1.0.0-alpha");
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
test('should handle versions with numbers only', () => {
|
|
524
|
+
expect(simulatorService.normalizeLocalnetVersion("1.0.0")).toBe("v1.0.0");
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test('should throw an error and exit for invalid versions', () => {
|
|
528
|
+
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { return undefined as never});
|
|
529
|
+
const mockConsoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
530
|
+
|
|
531
|
+
simulatorService.normalizeLocalnetVersion("invalid-version");
|
|
532
|
+
|
|
533
|
+
expect(mockConsoleError).toHaveBeenCalledWith(
|
|
534
|
+
'Invalid version format. Expected format: v0.0.0 or v0.0.0-suffix'
|
|
535
|
+
);
|
|
536
|
+
expect(mockExit).toHaveBeenCalledWith(1);
|
|
537
|
+
|
|
538
|
+
mockExit.mockRestore();
|
|
539
|
+
mockConsoleError.mockRestore();
|
|
540
|
+
});
|
|
541
|
+
});
|