@ -49,14 +49,14 @@ import java.util.Optional;
import com.google.common.base.Supplier ;
import com.google.common.base.Suppliers ;
import org.assertj.core.util.Lists ;
import org.junit.Before ;
import org.junit.Test ;
import org.junit.runner.Run With ;
import org.junit.jupiter.api. BeforeEach ;
import org.junit.jupiter.api. Test ;
import org.junit.jupiter.api.extension.Extend With ;
import org.mockito.ArgumentCaptor ;
import org.mockito.Mock ;
import org.mockito.junit.MockitoJUnitRunner ;
import org.mockito.junit.jupiter.MockitoExtension ;
@RunWith ( MockitoJUnitRunner . class )
@ExtendWith ( MockitoExtension . class )
public class CliqueMiningCoordinatorTest {
private static final Supplier < SignatureAlgorithm > SIGNATURE_ALGORITHM =
@ -81,18 +81,13 @@ public class CliqueMiningCoordinatorTest {
@Mock private SyncState syncState ;
@Mock private ValidatorProvider validatorProvider ;
@Before
@BeforeEach
public void setup ( ) {
headerTestFixture . number ( 1 ) ;
Block genesisBlock = createEmptyBlock ( 0 , Hash . ZERO , proposerKeys ) ; // not normally signed but ok
blockChain = createInMemoryBlockchain ( genesisBlock ) ;
when ( validatorProvider . getValidatorsAfterBlock ( any ( ) ) ) . thenReturn ( validators ) ;
final CliqueContext cliqueContext = new CliqueContext ( validatorProvider , null , blockInterface ) ;
when ( protocolContext . getConsensusContext ( CliqueContext . class ) ) . thenReturn ( cliqueContext ) ;
when ( protocolContext . getBlockchain ( ) ) . thenReturn ( blockChain ) ;
when ( minerExecutor . startAsyncMining ( any ( ) , any ( ) , any ( ) ) ) . thenReturn ( Optional . of ( blockMiner ) ) ;
when ( syncState . isInSync ( ) ) . thenReturn ( true ) ;
@ -101,6 +96,8 @@ public class CliqueMiningCoordinatorTest {
@Test
public void outOfTurnBlockImportedDoesNotInterruptInTurnMiningOperation ( ) {
setupCliqueContextAndBlockchain ( ) ;
// As the head of the blockChain is 0 (which effectively doesn't have a signer, all validators
// are able to propose.
@ -159,6 +156,8 @@ public class CliqueMiningCoordinatorTest {
@Test
public void outOfTurnBlockImportedInterruptsOutOfTurnMiningOperation ( ) {
setupCliqueContextAndBlockchain ( ) ;
blockChain . appendBlock (
createEmptyBlock ( 1 , blockChain . getChainHeadHash ( ) , validatorKeys ) , Collections . emptyList ( ) ) ;
@ -190,6 +189,8 @@ public class CliqueMiningCoordinatorTest {
@Test
public void outOfTurnBlockImportedInterruptsNonRunningMiner ( ) {
setupCliqueContextAndBlockchain ( ) ;
blockChain . appendBlock (
createEmptyBlock ( 1 , blockChain . getChainHeadHash ( ) , proposerKeys ) , Collections . emptyList ( ) ) ;
@ -251,4 +252,13 @@ public class CliqueMiningCoordinatorTest {
TestHelpers . createCliqueSignedBlockHeader ( headerTestFixture , signer , validators ) ;
return new Block ( header , new BlockBody ( Collections . emptyList ( ) , Collections . emptyList ( ) ) ) ;
}
private void setupCliqueContextAndBlockchain ( ) {
when ( validatorProvider . getValidatorsAfterBlock ( any ( ) ) ) . thenReturn ( validators ) ;
final CliqueContext cliqueContext = new CliqueContext ( validatorProvider , null , blockInterface ) ;
when ( protocolContext . getConsensusContext ( CliqueContext . class ) ) . thenReturn ( cliqueContext ) ;
when ( protocolContext . getBlockchain ( ) ) . thenReturn ( blockChain ) ;
}
}