Skip to content

Commit

Permalink
test: add RESET_DATABASE environment variable to reset database
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Jun 1, 2019
1 parent 0690a2f commit 0836a05
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __tests__/integration/core-api/__support__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const setUp = async () => {
});

const databaseService = app.resolvePlugin<Database.IDatabaseService>("database");
await databaseService.connection.roundsRepository.truncate();
await databaseService.reset();
await databaseService.buildWallets();
await databaseService.saveRound(round);

Expand Down
10 changes: 4 additions & 6 deletions __tests__/integration/core-blockchain/__support__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { setUpContainer } from "../../../utils/helpers/container";

jest.setTimeout(60000);

export async function setUp() {
return setUpContainer({ exit: "@arkecosystem/core-blockchain" });
}
process.env.RESET_DATABASE = "1";

export async function tearDown(): Promise<void> {
await app.tearDown();
}
export const setUp = async () => setUpContainer({ exit: "@arkecosystem/core-blockchain" });

export const tearDown = async (): Promise<void> => app.tearDown();
2 changes: 0 additions & 2 deletions __tests__/integration/core-blockchain/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ describe("Blockchain", () => {
// Workaround: Add genesis transactions to the exceptions list, because they have a fee of 0
// and otherwise don't pass validation.
configManager.set("exceptions.transactions", genesisBlock.transactions.map(tx => tx.id));

await blockchain.database.reset();
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const setUp = async () => {
};

export const setUpFull = async () => {
process.env.RESET_DATABASE = "1";

try {
await setUpContainer({
exit: "@arkecosystem/core-transaction-pool",
Expand Down
4 changes: 4 additions & 0 deletions packages/core-database/src/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class DatabaseService implements Database.IDatabaseService {
}

public async init(): Promise<void> {
if (process.env.RESET_DATABASE) {
await this.reset();
}

await this.createGenesisBlock();

const lastBlock: Interfaces.IBlock = await this.getLastBlock();
Expand Down

0 comments on commit 0836a05

Please sign in to comment.