From 0e3b652e07dcff856740496345e2306ec2d88fc9 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 20 Sep 2023 16:51:55 +0800 Subject: [PATCH] add unit test --- .../forkchoice/ForkChoiceTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java index f7657bb5814..9e6cf578640 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java @@ -417,8 +417,6 @@ void onBlock_shouldUpdateVotesBasedOnAttestationsInBlocks() { @Test void onBlock_shouldUpdateVotesBasedOnAttesterSlashingEquivocationsInBlocks() { - final SignedBlockAndState commonBlock = chainBuilder.generateNextBlock(); - importBlock(commonBlock); final ChainBuilder forkChain = chainBuilder.fork(); final SignedBlockAndState forkBlock = forkChain.generateNextBlock( @@ -717,6 +715,27 @@ void onBlock_shouldNotifyOptimisticSyncChangeOnlyWhenImportingOnCanonicalHead() verifyNoMoreInteractions(optimisticSyncStateTracker); } + @Test + void onBlock_shouldApplyProposerBoostToFirstBlock() { + final ChainBuilder forkChain = chainBuilder.fork(); + + final SignedBlockAndState block = chainBuilder.generateNextBlock(); + final SignedBlockAndState forkBlock = forkChain.generateNextBlock(); + + final BlockOptions forkBlockOptions = BlockOptions.create(); + final List forkAttestations = + forkChain.streamValidAttestationsWithTargetBlock(forkBlock).limit(2).toList(); + forkAttestations.forEach(forkBlockOptions::addAttestation); + final SignedBlockAndState forkBlock1 = forkChain.generateNextBlock(forkBlockOptions); + + importBlock(block); + importBlock(forkBlock); + importBlock(forkBlock1); + + // proposer boost is given to the first block despite the fork chain having bigger weight + assertThat(recentChainData.getStore().getProposerBoostRoot()).hasValue(block.getRoot()); + } + @Test void applyHead_shouldSendForkChoiceUpdatedNotification() { final SignedBlockAndState blockAndState = storageSystem.chainUpdater().advanceChainUntil(1);