Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@
"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1",
"winston-transport": "^4.5.0",
"yargs": "^16.1.0"
"yargs": "^17.7.1"
},
"devDependencies": {
"@types/expand-tilde": "^2.0.0",
"@types/got": "^9.6.12",
"@types/inquirer": "^9.0.3",
"@types/lodash": "^4.14.192",
"@types/yargs": "^15.0.9"
"@types/yargs": "^17.0.24"
}
}
1 change: 0 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
import yargs from "yargs";
// @ts-expect-error no type
import {hideBin} from "yargs/helpers";
import {cmds} from "./cmds/index.js";
import {globalOptions, rcConfigOption} from "./options/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "source-map-support/register.js";

const lodestar = getLodestarCli();

lodestar
void lodestar
.fail((msg, err) => {
if (msg) {
// Show command help message when no command is provided
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
/* eslint-disable no-console */
import fs from "node:fs";
import path from "node:path";
import rimraf from "rimraf";
import {rimraf} from "rimraf";
import {expect} from "chai";
import sinon from "sinon";
import {Keystore} from "@chainsafe/bls-keystore";
import {fromHex} from "@lodestar/utils";
import {ReturnType as ValidatorListReturnType} from "../../src/cmds/validator/list.js";
import {testFilesDir} from "../utils.js";
import {getCliInMemoryRunner} from "../utils/inMemoryRunner.js";

/* eslint-disable no-console */

type ConsoleKeys = "log" | "warn" | "error";
const consoleKeys: ConsoleKeys[] = ["log", "warn", "error"];

describe("cmds / validator", function () {
const lodestar = getCliInMemoryRunner();

const dataDir = testFilesDir;

const consoleData: {[P in ConsoleKeys]: string} = {
log: "",
warn: "",
error: "",
};
const consoleCache: {[P in ConsoleKeys]: typeof console.log} = {
log: console.log,
warn: console.warn,
error: console.error,
};

beforeEach("Hijack console", () => {
for (const key of consoleKeys) {
consoleData[key] = "";
console[key] = (...args: any[]) => {
consoleData.log += args.map(String).join(" ");
};
}
beforeEach(() => {
sinon.spy(console, "info");
sinon.spy(console, "log");
});

afterEach("Release console", () => {
for (const key of consoleKeys) {
console[key] = consoleCache[key];
}
afterEach(() => {
sinon.restore();
});

before("Clean dataDir", () => {
Expand All @@ -62,28 +41,23 @@ describe("cmds / validator", function () {
fs.writeFileSync(passphraseFilepath, passphrase);
fs.writeFileSync(keystoreFilepath, keystore.stringify());

const res = await lodestar<ValidatorListReturnType>([
// ⏎
await lodestar([
"validator import",
`--dataDir ${dataDir}`,
`--keystore ${keystoreFilepath}`,
`--passphraseFile ${passphraseFilepath}`,
]);

console.log(res);
expect(console.log).be.calledWith(`Imported keystore ${pkHex} ${keystoreFilepath}`);
});

it("should list validators", async function () {
fs.mkdirSync(path.join(dataDir, "keystores"), {recursive: true});
fs.mkdirSync(path.join(dataDir, "secrets"), {recursive: true});

const validatorPubKeys = await lodestar<ValidatorListReturnType>([
// ⏎
"validator list",
`--dataDir ${dataDir}`,
]);
await lodestar(["validator list", `--dataDir ${dataDir}`]);

// No keys are imported before this test. TODO: Import some
expect(validatorPubKeys.sort()).to.deep.equal([pkHex], "Wrong validator pubkeys");
expect(console.info).calledWith("1 local keystores");
expect(console.info).calledWith(pkHex);
});
});
17 changes: 10 additions & 7 deletions packages/cli/test/utils/inMemoryRunner.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import yargs from "yargs";
import {getLodestarCli} from "../../src/cli.js";

export function getCliInMemoryRunner() {
return async <T = any>(arg: string | readonly string[], context?: Record<string, unknown>): Promise<T> => {
return async (arg: string | readonly string[], context?: Record<string, unknown>): Promise<void> => {
return new Promise((resolve, reject) => {
const lodestar = getLodestarCli();
const lodestar = getLodestarCli() as yargs.Argv<any>;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
lodestar
// Called after the completion of any command. handler is invoked with the result returned by the command:
.onFinishCommand((result) => {
resolve(result);
})
// Method to execute when a failure occurs, rather than printing the failure message.
.fail((msg, err) => {
if (err !== undefined) reject(err);
Expand All @@ -17,7 +15,12 @@ export function getCliInMemoryRunner() {
})
.help(false)
.exitProcess(false)
.parse(Array.isArray(arg) ? arg.join(" ") : arg, context);
.parse(Array.isArray(arg) ? arg.join(" ") : arg, context)
// Called after the completion of any command. handler is invoked with the result returned by the command:
.then((result: any) => {
resolve(result);
})
.catch((e: unknown) => reject(e));
});
};
}
4 changes: 2 additions & 2 deletions packages/flare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
"@lodestar/state-transition": "^1.7.2",
"@lodestar/types": "^1.7.2",
"source-map-support": "^0.5.21",
"yargs": "^16.1.0"
"yargs": "^17.7.1"
},
"devDependencies": {
"@types/yargs": "^15.0.9"
"@types/yargs": "^17.0.24"
}
}
1 change: 0 additions & 1 deletion packages/flare/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
import yargs from "yargs";
// @ts-expect-error no type
import {hideBin} from "yargs/helpers";
import {cmds} from "./cmds/index.js";
import {registerCommandToYargs} from "./util/command.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/flare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "source-map-support/register.js";

const flare = getCli();

flare
void flare
.fail((msg, err) => {
if (msg) {
// Show command help message when no command is provided
Expand Down
4 changes: 2 additions & 2 deletions packages/prover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
"source-map-support": "^0.5.21",
"winston": "^3.8.2",
"winston-transport": "^4.5.0",
"yargs": "^16.1.0"
"yargs": "^17.7.1"
},
"devDependencies": {
"@types/http-proxy": "^1.17.10",
"@types/yargs": "^15.0.9",
"@types/yargs": "^17.0.24",
"ethers": "^6.2.3",
"web3": "^1.9.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/prover/src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
import yargs from "yargs";
// @ts-expect-error no type
import {hideBin} from "yargs/helpers";
import {registerCommandToYargs} from "../utils/command.js";
import {getVersionData} from "../utils/version.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/prover/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "source-map-support/register.js";

const prover = getLodestarProverCli();

prover
void prover
.fail((msg, err) => {
if (msg) {
// Show command help message when no command is provided
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4178,10 +4178,10 @@
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.0.tgz"
integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==

"@types/yargs@^15.0.9":
version "15.0.13"
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.13.tgz"
integrity sha512-kQ5JNTrbDv3Rp5X2n/iUu37IJBDU2gsZ5R/g1/KHOOEc5IKfUFjXT6DENPGduh08I/pamwtEq4oul7gUqKTQDQ==
"@types/yargs@^17.0.24":
version "17.0.24"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.24.tgz#b3ef8d50ad4aa6aecf6ddc97c580a00f5aa11902"
integrity sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -15727,7 +15727,7 @@ yargs-parser@21.0.1:

yargs-parser@^18.1.2:
version "18.1.3"
resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"
integrity sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==
dependencies:
camelcase "^5.0.0"
Expand All @@ -15753,9 +15753,9 @@ yargs-unparser@2.0.0:
flat "^5.0.2"
is-plain-obj "^2.1.0"

yargs@16.2.0, yargs@^16.1.0, yargs@^16.1.1, yargs@^16.2.0:
yargs@16.2.0, yargs@^16.1.1, yargs@^16.2.0:
version "16.2.0"
resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
dependencies:
cliui "^7.0.2"
Expand All @@ -15768,7 +15768,7 @@ yargs@16.2.0, yargs@^16.1.0, yargs@^16.1.1, yargs@^16.2.0:

yargs@^15.0.2:
version "15.4.1"
resolved "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
dependencies:
cliui "^6.0.0"
Expand All @@ -15784,17 +15784,17 @@ yargs@^15.0.2:
yargs-parser "^18.1.2"

yargs@^17.1.1:
version "17.1.1"
resolved "https://registry.npmjs.org/yargs/-/yargs-17.1.1.tgz"
integrity sha512-c2k48R0PwKIqKhPMWjeiF6y2xY/gPMUlro0sgxqXpbOIohWiLNXWslsootttv7E1e73QPAMQSg5FeySbVcpsPQ==
version "17.6.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.6.2.tgz#2e23f2944e976339a1ee00f18c77fedee8332541"
integrity sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==
dependencies:
cliui "^7.0.2"
cliui "^8.0.1"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.0"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^20.2.2"
yargs-parser "^21.1.1"

yargs@^17.4.0:
version "17.5.1"
Expand All @@ -15809,7 +15809,7 @@ yargs@^17.4.0:
y18n "^5.0.5"
yargs-parser "^21.0.0"

yargs@^17.5.1:
yargs@^17.5.1, yargs@^17.7.1:
version "17.7.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.1.tgz#34a77645201d1a8fc5213ace787c220eabbd0967"
integrity sha512-cwiTb08Xuv5fqF4AovYacTFNxk62th7LKJ6BL9IGUpTJrWoU7/7WdQGTP2SjKf1dUNBGzDd28p/Yfs/GI6JrLw==
Expand Down