From 0d63d144304760b8db4ed7b0142f6282c8d75a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com> Date: Sun, 10 Jun 2018 18:04:51 +0200 Subject: [PATCH] [enh] allow to define the number of blocks to resolve --- app/lib/other_constants.ts | 2 +- app/service/BlockchainService.ts | 6 ++++-- test/integration/tools/toolbox.ts | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/lib/other_constants.ts b/app/lib/other_constants.ts index e7b7b364b..2e46465ee 100644 --- a/app/lib/other_constants.ts +++ b/app/lib/other_constants.ts @@ -13,7 +13,7 @@ export const OtherConstants = { - MUTE_LOGS_DURING_UNIT_TESTS: false, + MUTE_LOGS_DURING_UNIT_TESTS: true, SQL_TRACES: false, BC_EVENT: { diff --git a/app/service/BlockchainService.ts b/app/service/BlockchainService.ts index 5ec97e4e2..bc34133c3 100644 --- a/app/service/BlockchainService.ts +++ b/app/service/BlockchainService.ts @@ -223,9 +223,10 @@ export class BlockchainService extends FIFOService { }) } - async blockResolution(): Promise<BlockDTO|null> { + async blockResolution(max = 0): Promise<BlockDTO|null> { let lastAdded:BlockDTO|null = null let added:BlockDTO|null + let nbAdded = 0 do { const current = await this.current() let potentials = [] @@ -238,7 +239,7 @@ export class BlockchainService extends FIFOService { } added = null let i = 0 - while (!added && i < potentials.length) { + while (!added && i < potentials.length && (!max || nbAdded < max)) { const dto = BlockDTO.fromJSONObject(potentials[i]) try { if (dto.issuer === this.conf.pair.pub) { @@ -251,6 +252,7 @@ export class BlockchainService extends FIFOService { bcEvent: OtherConstants.BC_EVENT.HEAD_CHANGED, block: added }) + nbAdded++ // Clear invalid forks' cache this.invalidForks.splice(0, this.invalidForks.length) } catch (e) { diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index d79b97f8a..a975ad95a 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -489,6 +489,16 @@ export class TestingServer { if (!blocksResolved) { throw Error(DataErrors[DataErrors.BLOCK_WASNT_COMMITTED]) } + console.log(blocksResolved.getRawSigned()) + return blocksResolved + } + + async resolveExistingBlock(max = 0) { + const blocksResolved = await this.server.BlockchainService.blockResolution(max) + if (!blocksResolved) { + throw Error(DataErrors[DataErrors.BLOCK_WASNT_COMMITTED]) + } + console.log(blocksResolved.getRawSigned()) return blocksResolved } -- GitLab