diff --git a/app/lib/other_constants.ts b/app/lib/other_constants.ts index e7b7b364bf47b06f56e5363574cbc56a3ae02c96..2e46465eeb0ab92a57ba4e596446365141b2439f 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 5ec97e4e2026f5bdb0a18d307c748719dc47fa77..bc34133c3846ec9579a8d7fe39bf98ed11b9a2fe 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 d79b97f8a20110253e0e29f5050c37b5b59fcc0a..a975ad95a1f39a8c6d6bf0259c4cf63cf04841fc 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 }