Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startTmpBeaconDb util #4281

Merged
merged 1 commit into from
Jul 12, 2022
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {expect} from "chai";
import {config} from "@lodestar/config/default";
import {LevelDbController} from "@lodestar/db";
import {fromHexString} from "@chainsafe/ssz";
import {allForks, phase0, ssz} from "@lodestar/types";
import {BeaconDb} from "../../../../../../src/db/index.js";
import {generateSignedBlock} from "../../../../../utils/block.js";
import {testLogger} from "../../../../../utils/logger.js";
import {BlockArchiveBatchPutBinaryItem} from "../../../../../../src/db/repositories/index.js";
import {startTmpBeaconDb} from "../../../../../utils/db.js";

describe("BlockArchiveRepository", function () {
let db: BeaconDb;
Expand Down Expand Up @@ -35,11 +35,7 @@ describe("BlockArchiveRepository", function () {
});

before(async () => {
db = new BeaconDb({
config,
controller: new LevelDbController({name: ".tmpdb"}, {logger}),
});
await db.start();
db = await startTmpBeaconDb(config, logger);
});

after(async () => {
Expand Down
8 changes: 2 additions & 6 deletions packages/beacon-node/test/e2e/interop/genesisState.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import {expect} from "chai";
import {toHexString} from "@chainsafe/ssz";
import {LevelDbController} from "@lodestar/db";
import {config} from "@lodestar/config/default";
import {ssz} from "@lodestar/types";
import {BeaconDb} from "../../../src/index.js";
import {initDevState} from "../../../src/node/utils/state.js";
import {testLogger} from "../../utils/logger.js";
import {interopDeposits} from "../../../src/node/utils/interop/deposits.js";
import {startTmpBeaconDb} from "../../utils/db.js";

describe("interop / initDevState", () => {
let db: BeaconDb;
const logger = testLogger();

before(async () => {
db = new BeaconDb({
config,
controller: new LevelDbController({name: ".tmpdb"}, {logger}),
});
await db.start();
db = await startTmpBeaconDb(config, logger);
});

after(async () => {
Expand Down
21 changes: 20 additions & 1 deletion packages/beacon-node/test/utils/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import {IFilterOptions} from "@lodestar/db";
import child_process from "node:child_process";
import {IFilterOptions, LevelDbController} from "@lodestar/db";
import {IChainForkConfig} from "@lodestar/config";
import {ILogger} from "@lodestar/utils";
import {BeaconDb} from "../../src/index.js";

export const TEMP_DB_LOCATION = ".tmpdb";

export async function startTmpBeaconDb(config: IChainForkConfig, logger: ILogger): Promise<BeaconDb> {
// Clean-up db first
child_process.execSync(`rm -rf ${TEMP_DB_LOCATION}`);

const db = new BeaconDb({
config,
controller: new LevelDbController({name: TEMP_DB_LOCATION}, {logger}),
});
await db.start();

return db;
}

/**
* Helper to filter an array with DB IFilterOptions options
Expand Down