From 325308b31e5caa64c37c02543a7fcdfacac5694b Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Mon, 28 Jun 2021 14:31:58 +0200 Subject: [PATCH] add tests Signed-off-by: Karim TAAM --- .../ethereum/eth/sync/BlockPropagationManager.java | 1 + .../eth/sync/state/PendingBlocksManagerTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java index 7c7ee28eb30..c08346f400a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java @@ -263,6 +263,7 @@ private void handleNewBlockHashesFromNetwork(final EthMessage message) { @SuppressWarnings("unused") private CompletableFuture retrieveMissingAnnouncedBlock(final long blockNumber) { + LOG.info("retrieveMissingAnnouncedBlock " + blockNumber); final List peers = ethContext.getEthPeers().streamBestPeers().collect(Collectors.toList()); final GetBlockFromPeersTask getBlockTask = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/PendingBlocksManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/PendingBlocksManagerTest.java index 18e1315d56a..8c867c7d254 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/PendingBlocksManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/PendingBlocksManagerTest.java @@ -245,4 +245,18 @@ public void shouldReplaceLowestPriorityBlockWhenCacheIsFull() { } assertThat(pendingBlocksManager.contains(reorgBlock.getHash())).isTrue(); } + + @Test + public void shouldReturnLowestBlockByNumber() { + final BlockDataGenerator gen = new BlockDataGenerator(); + final Block parentBlock = gen.block(); + final Block childBlock = gen.nextBlock(parentBlock); + final Block childBlock2 = gen.nextBlock(parentBlock); + + pendingBlocksManager.registerPendingBlock(parentBlock, NODE_ID_1); + pendingBlocksManager.registerPendingBlock(childBlock, NODE_ID_1); + pendingBlocksManager.registerPendingBlock(childBlock2, NODE_ID_1); + + assertThat(pendingBlocksManager.lowestAnnouncedBlock()).contains(parentBlock.getHeader()); + } }