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

fix(blockchain): use resolveOptions("blockchain") to get databaseRollback options #2572

Merged
merged 4 commits into from May 13, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/unit/core-blockchain/mocks/container.ts
Expand Up @@ -58,7 +58,7 @@ export const container = {

return undefined;
},
resolveOptions: () => ({}),
resolveOptions: plugin => ({}),
has: () => true,
forceExit: () => undefined,
},
Expand Down
29 changes: 15 additions & 14 deletions __tests__/unit/core-blockchain/state-machine.test.ts
Expand Up @@ -388,24 +388,31 @@ describe("State Machine", () => {
await expect(() => actionMap.startForkRecovery()).toDispatch(blockchain, "SUCCESS");

expect(loggerInfo).toHaveBeenCalledWith("Starting fork recovery");
methodsCalled.forEach(method => {
for (const method of methodsCalled) {
expect(method).toHaveBeenCalled();
});
}
});
});

describe("rollbackDatabase", () => {
afterEach(() => jest.restoreAllMocks());

beforeEach(() => {
jest.spyOn(container.app, "resolveOptions").mockImplementation(plugin =>
plugin === "blockchain"
? {
databaseRollback: {
maxBlockRewind: 14,
steps: 3,
},
}
: {},
);
});

it("should try to remove X blocks based on databaseRollback config until database.verifyBlockchain() passes - and dispatch SUCCESS", async () => {
const loggerInfo = jest.spyOn(logger, "info");

jest.spyOn(container.app, "resolveOptions").mockReturnValue({
databaseRollback: {
maxBlockRewind: 14,
steps: 3,
},
});
// @ts-ignore
const removeTopBlocks = jest.spyOn(blockchain, "removeTopBlocks").mockReturnValue(true);
jest.spyOn(blockchain.database, "verifyBlockchain")
Expand All @@ -428,12 +435,6 @@ describe("State Machine", () => {

it(`should try to remove X blocks based on databaseRollback config until database.verifyBlockchain() passes
and dispatch FAILURE as verifyBlockchain never passed`, async () => {
jest.spyOn(container.app, "resolveOptions").mockReturnValue({
databaseRollback: {
maxBlockRewind: 14,
steps: 3,
},
});
// @ts-ignore
const removeTopBlocks = jest.spyOn(blockchain, "removeTopBlocks").mockReturnValue(true);
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/core-blockchain/src/state-machine.ts
Expand Up @@ -291,7 +291,7 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({
async rollbackDatabase() {
logger.info("Trying to restore database integrity");

const { maxBlockRewind, steps } = app.resolveOptions("p2p").databaseRollback;
const { maxBlockRewind, steps } = app.resolveOptions("blockchain").databaseRollback;

for (let i = maxBlockRewind; i >= 0; i -= steps) {
await blockchain.removeTopBlocks(steps);
Expand Down