Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #130 from LiskHQ/fix_detached_fork_func
Browse files Browse the repository at this point in the history
Fix detached function not to throw - Closes #129
  • Loading branch information
shuse2 authored Sep 12, 2019
2 parents cefffa7 + 609cdf9 commit baf2745
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion framework/src/modules/chain/rounds/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ class Delegates {
cause,
};

await this.storage.entities.Account.insertFork(fork);
try {
await this.storage.entities.Account.insertFork(fork);
} catch (err) {
this.logger.warn(err, 'Failed to insert fork info');
}
this.channel.publish('chain:delegates:fork', fork);
}

Expand Down
20 changes: 20 additions & 0 deletions framework/test/mocha/unit/modules/chain/submodules/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('delegates', () => {
const mockLogger = {
debug: sinonSandbox.stub(),
info: sinonSandbox.stub(),
warn: sinonSandbox.stub(),
error: sinonSandbox.stub(),
};
const mockStorage = {
Expand Down Expand Up @@ -112,6 +113,25 @@ describe('delegates', () => {
fork,
);
});

it('should not throw an error when the database fails', async () => {
const fork = {
delegatePublicKey: dummyBlock.generatorPublicKey,
blockTimestamp: dummyBlock.timestamp,
blockId: dummyBlock.id,
blockHeight: dummyBlock.height,
previousBlockId: dummyBlock.previousBlock,
cause,
};
mockStorage.entities.Account.insertFork.rejects(
new Error('invalid DB state'),
);
await delegatesModule.fork(dummyBlock, cause);
expect(mockChannel.publish).to.be.calledWithExactly(
'chain:delegates:fork',
fork,
);
});
});

describe('#generateDelegateList', () => {
Expand Down

0 comments on commit baf2745

Please sign in to comment.