|
|
|
@ -96,7 +96,7 @@ public class QbftControllerTest { |
|
|
|
|
private final ConsensusRoundIdentifier futureRoundIdentifier = new ConsensusRoundIdentifier(5, 0); |
|
|
|
|
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(4, 0); |
|
|
|
|
private final ConsensusRoundIdentifier pastRoundIdentifier = new ConsensusRoundIdentifier(3, 0); |
|
|
|
|
@Mock private QbftGossip ibftGossip; |
|
|
|
|
@Mock private QbftGossip qbftGossip; |
|
|
|
|
@Mock private FutureMessageBuffer futureMessageBuffer; |
|
|
|
|
private QbftController qbftController; |
|
|
|
|
|
|
|
|
@ -119,13 +119,13 @@ public class QbftControllerTest { |
|
|
|
|
when(messageTracker.hasSeenMessage(any())).thenReturn(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void constructIbftController() { |
|
|
|
|
private void constructQbftController() { |
|
|
|
|
qbftController = |
|
|
|
|
new QbftController( |
|
|
|
|
blockChain, |
|
|
|
|
bftFinalState, |
|
|
|
|
blockHeightManagerFactory, |
|
|
|
|
ibftGossip, |
|
|
|
|
qbftGossip, |
|
|
|
|
messageTracker, |
|
|
|
|
futureMessageBuffer, |
|
|
|
|
mock(EthSynchronizerUpdater.class), |
|
|
|
@ -134,7 +134,7 @@ public class QbftControllerTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void createsNewBlockHeightManagerWhenStarted() { |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
verify(blockHeightManagerFactory, never()).create(chainHeadBlockHeader); |
|
|
|
|
qbftController.start(); |
|
|
|
|
|
|
|
|
@ -155,7 +155,7 @@ public class QbftControllerTest { |
|
|
|
|
when(blockHeightManager.getChainHeight()).thenReturn(5L); |
|
|
|
|
when(futureMessageBuffer.retrieveMessagesForHeight(5L)).thenReturn(height2Msgs); |
|
|
|
|
|
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
|
|
|
|
|
verify(futureMessageBuffer).retrieveMessagesForHeight(5L); |
|
|
|
@ -164,11 +164,11 @@ public class QbftControllerTest { |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verify(blockHeightManager, never()).handleProposalPayload(proposal); |
|
|
|
|
verify(blockHeightManager).handlePreparePayload(prepare); |
|
|
|
|
verify(ibftGossip).send(prepareMessage); |
|
|
|
|
verify(qbftGossip).send(prepareMessage); |
|
|
|
|
verify(blockHeightManager).handleCommitPayload(commit); |
|
|
|
|
verify(ibftGossip).send(commitMessage); |
|
|
|
|
verify(qbftGossip).send(commitMessage); |
|
|
|
|
verify(blockHeightManager).handleRoundChangePayload(roundChange); |
|
|
|
|
verify(ibftGossip).send(roundChangeMessage); |
|
|
|
|
verify(qbftGossip).send(roundChangeMessage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -184,7 +184,7 @@ public class QbftControllerTest { |
|
|
|
|
.thenReturn(emptyList()); |
|
|
|
|
when(blockHeightManager.getChainHeight()).thenReturn(5L); |
|
|
|
|
|
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
final NewChainHead newChainHead = new NewChainHead(nextBlock); |
|
|
|
|
qbftController.handleNewBlockEvent(newChainHead); |
|
|
|
@ -193,18 +193,18 @@ public class QbftControllerTest { |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verify(futureMessageBuffer, times(2)).retrieveMessagesForHeight(5L); |
|
|
|
|
verify(blockHeightManager).handleProposalPayload(proposal); |
|
|
|
|
verify(ibftGossip).send(proposalMessage); |
|
|
|
|
verify(qbftGossip).send(proposalMessage); |
|
|
|
|
verify(blockHeightManager).handlePreparePayload(prepare); |
|
|
|
|
verify(ibftGossip).send(prepareMessage); |
|
|
|
|
verify(qbftGossip).send(prepareMessage); |
|
|
|
|
verify(blockHeightManager).handleCommitPayload(commit); |
|
|
|
|
verify(ibftGossip).send(commitMessage); |
|
|
|
|
verify(qbftGossip).send(commitMessage); |
|
|
|
|
verify(blockHeightManager).handleRoundChangePayload(roundChange); |
|
|
|
|
verify(ibftGossip).send(roundChangeMessage); |
|
|
|
|
verify(qbftGossip).send(roundChangeMessage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void newBlockForCurrentOrPreviousHeightTriggersNoChange() { |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
long chainHeadHeight = chainHeadBlockHeader.getNumber(); |
|
|
|
|
when(nextBlock.getNumber()).thenReturn(chainHeadHeight); |
|
|
|
@ -223,7 +223,7 @@ public class QbftControllerTest { |
|
|
|
|
public void handlesRoundExpiry() { |
|
|
|
|
final RoundExpiry roundExpiry = new RoundExpiry(roundIdentifier); |
|
|
|
|
|
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleRoundExpiry(roundExpiry); |
|
|
|
|
|
|
|
|
@ -234,7 +234,7 @@ public class QbftControllerTest { |
|
|
|
|
public void handlesBlockTimerExpiry() { |
|
|
|
|
final BlockTimerExpiry blockTimerExpiry = new BlockTimerExpiry(roundIdentifier); |
|
|
|
|
|
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleBlockTimerExpiry(blockTimerExpiry); |
|
|
|
|
|
|
|
|
@ -244,13 +244,13 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void proposalForCurrentHeightIsPassedToBlockHeightManager() { |
|
|
|
|
setupProposal(roundIdentifier, validator); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage)); |
|
|
|
|
|
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
|
verify(blockHeightManager).handleProposalPayload(proposal); |
|
|
|
|
verify(ibftGossip).send(proposalMessage); |
|
|
|
|
verify(qbftGossip).send(proposalMessage); |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verifyNoMoreInteractions(blockHeightManager); |
|
|
|
|
} |
|
|
|
@ -258,13 +258,13 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void prepareForCurrentHeightIsPassedToBlockHeightManager() { |
|
|
|
|
setupPrepare(roundIdentifier, validator); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(prepareMessage)); |
|
|
|
|
|
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
|
verify(blockHeightManager).handlePreparePayload(prepare); |
|
|
|
|
verify(ibftGossip).send(prepareMessage); |
|
|
|
|
verify(qbftGossip).send(prepareMessage); |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verifyNoMoreInteractions(blockHeightManager); |
|
|
|
|
} |
|
|
|
@ -272,13 +272,13 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void commitForCurrentHeightIsPassedToBlockHeightManager() { |
|
|
|
|
setupCommit(roundIdentifier, validator); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(commitMessage)); |
|
|
|
|
|
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
|
verify(blockHeightManager).handleCommitPayload(commit); |
|
|
|
|
verify(ibftGossip).send(commitMessage); |
|
|
|
|
verify(qbftGossip).send(commitMessage); |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verifyNoMoreInteractions(blockHeightManager); |
|
|
|
|
} |
|
|
|
@ -286,13 +286,13 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void roundChangeForCurrentHeightIsPassedToBlockHeightManager() { |
|
|
|
|
setupRoundChange(roundIdentifier, validator); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(roundChangeMessage)); |
|
|
|
|
|
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
|
verify(blockHeightManager).handleRoundChangePayload(roundChange); |
|
|
|
|
verify(ibftGossip).send(roundChangeMessage); |
|
|
|
|
verify(qbftGossip).send(roundChangeMessage); |
|
|
|
|
verify(blockHeightManager, atLeastOnce()).getChainHeight(); |
|
|
|
|
verifyNoMoreInteractions(blockHeightManager); |
|
|
|
|
} |
|
|
|
@ -324,7 +324,7 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void roundExpiryForPastHeightIsDiscarded() { |
|
|
|
|
final RoundExpiry roundExpiry = new RoundExpiry(pastRoundIdentifier); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleRoundExpiry(roundExpiry); |
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
@ -334,7 +334,7 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void blockTimerForPastHeightIsDiscarded() { |
|
|
|
|
final BlockTimerExpiry blockTimerExpiry = new BlockTimerExpiry(pastRoundIdentifier); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleBlockTimerExpiry(blockTimerExpiry); |
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
@ -401,7 +401,7 @@ public class QbftControllerTest { |
|
|
|
|
public void uniqueMessagesAreAddedAsSeen() { |
|
|
|
|
when(messageTracker.hasSeenMessage(proposalMessageData)).thenReturn(false); |
|
|
|
|
setupProposal(roundIdentifier, validator); |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage)); |
|
|
|
|
|
|
|
|
@ -411,7 +411,7 @@ public class QbftControllerTest { |
|
|
|
|
@Test |
|
|
|
|
public void messagesWhichAreAboveHeightManagerButBelowBlockChainLengthAreDiscarded() { |
|
|
|
|
// NOTE: for this to occur, the system would need to be synchronising - i.e. blockchain is
|
|
|
|
|
// moving up faster than ibft loop is handling NewBlock messages
|
|
|
|
|
// moving up faster than qbft loop is handling NewBlock messages
|
|
|
|
|
final long blockchainLength = 10L; |
|
|
|
|
final long blockHeightManagerTargettingBlock = 6L; |
|
|
|
|
final long messageHeight = 8L; |
|
|
|
@ -422,7 +422,7 @@ public class QbftControllerTest { |
|
|
|
|
when(blockHeightManagerFactory.create(any())).thenReturn(blockHeightManager); |
|
|
|
|
when(blockHeightManager.getChainHeight()).thenReturn(blockHeightManagerTargettingBlock); |
|
|
|
|
|
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(proposalMessage)); |
|
|
|
|
verify(futureMessageBuffer, never()).addMessage(anyLong(), any()); |
|
|
|
@ -430,7 +430,7 @@ public class QbftControllerTest { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void verifyNotHandledAndNoFutureMsgs(final BftReceivedMessageEvent msg) { |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(msg); |
|
|
|
|
|
|
|
|
@ -440,7 +440,7 @@ public class QbftControllerTest { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void verifyHasFutureMessages(final long msgHeight, final Message message) { |
|
|
|
|
constructIbftController(); |
|
|
|
|
constructQbftController(); |
|
|
|
|
qbftController.start(); |
|
|
|
|
qbftController.handleMessageEvent(new BftReceivedMessageEvent(message)); |
|
|
|
|
|
|
|
|
|