Skip to content

Commit

Permalink
be more lenient with accepted filename when reading voting keys. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo authored May 4, 2022
1 parent 4295abb commit 5758cbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/util/recursivelyFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function isVotingKeystore(filename: string): boolean {
// Key derivation path reference:
//
// https://eips.ethereum.org/EIPS/eip-2334
/keystore-m_12381_3600_[0-9]+_0_0-[0-9]+.json/.test(filename))
/keystore[\w-]*.json/.test(filename))
);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/cli/test/unit/validator/keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import {expect} from "chai";
import sinon from "sinon";
import fs, {Dirent, Stats} from "node:fs";
import {resolveKeystorePaths} from "../../../src/cmds/validator/keys";
import {isVotingKeystore} from "../../../src/util";

describe("validator / keys / resolveKeystorePaths", () => {
beforeEach(() => {
sinon.stub(fs, "lstatSync").returns({isDirectory: () => true} as Stats);
});

it("should filter out deposite data files", function () {
it("should filter out deposit data files", function () {
const keystoreFilename = "keystore-m_12381_3600_0_0_0-1642090404.json";
const depositData = "deposit_data-1642090404.json";

Expand All @@ -21,6 +22,16 @@ describe("validator / keys / resolveKeystorePaths", () => {
expect(result[0]).to.equal(`dir/${keystoreFilename}`);
});

it("should read key voting files with accepted file names", function () {
const keystoreFilenames = ["keystore-m_12381_3600_0_0_0-1642090404.json", "keystore-0.json", "keystore.json"];

sinon.stub(fs, "readdirSync").callsFake(() => {
return ([keystoreFilenames] as unknown) as Dirent[];
});

expect(keystoreFilenames.every(isVotingKeystore)).to.equal(true, "should read voting keystore file");
});

afterEach(() => {
sinon.restore();
});
Expand Down

0 comments on commit 5758cbe

Please sign in to comment.