mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 21:17:54 -05:00
consensus/merge junit5 (#5632)
* junit5 Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
This commit is contained in:
@@ -57,11 +57,9 @@ dependencies {
|
||||
testImplementation project(path: ':metrics:core', configuration: 'testSupportArtifacts')
|
||||
testImplementation project(':testutil')
|
||||
|
||||
testImplementation 'junit:junit'
|
||||
testImplementation 'org.assertj:assertj-core'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.mockito:mockito-core'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
testImplementation project(':ethereum:core')
|
||||
|
||||
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.hyperledger.besu.evm.operation.Push0Operation;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MergeProtocolScheduleTest {
|
||||
|
||||
|
||||
@@ -37,13 +37,13 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PostMergeContextTest {
|
||||
|
||||
@Mock private SyncState mockSyncState;
|
||||
@@ -52,7 +52,7 @@ public class PostMergeContextTest {
|
||||
|
||||
private MergeStateChangeCollector mergeStateChangeCollector;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
mergeStateChangeCollector = new MergeStateChangeCollector();
|
||||
postMergeContext = new PostMergeContext();
|
||||
@@ -178,12 +178,6 @@ public class PostMergeContextTest {
|
||||
|
||||
@Test
|
||||
public void tryingToRetrieveABlockPutButEvictedReturnsEmpty() {
|
||||
for (long i = 0; i < PostMergeContext.MAX_BLOCKS_IN_PROGRESS + 1; i++) {
|
||||
PayloadIdentifier payloadId = new PayloadIdentifier(i);
|
||||
BlockWithReceipts mockBlockWithReceipts = createBlockWithReceipts((int) i + 1, 11, 1);
|
||||
postMergeContext.putPayloadById(payloadId, mockBlockWithReceipts);
|
||||
}
|
||||
|
||||
PayloadIdentifier evictedPayloadId = new PayloadIdentifier(0L);
|
||||
|
||||
assertThat(postMergeContext.retrieveBlockById(evictedPayloadId)).isEmpty();
|
||||
@@ -222,10 +216,10 @@ public class PostMergeContextTest {
|
||||
lenient()
|
||||
.when(mockBlock.toLogString())
|
||||
.thenReturn(number + " (" + Hash.wrap(Bytes32.random()) + ")");
|
||||
when(mockBlock.getHeader().getGasUsed()).thenReturn(gasUsed);
|
||||
when(mockBlock.getBody().getTransactions().size()).thenReturn(txCount);
|
||||
lenient().when(mockBlock.getHeader().getGasUsed()).thenReturn(gasUsed);
|
||||
lenient().when(mockBlock.getBody().getTransactions().size()).thenReturn(txCount);
|
||||
BlockWithReceipts mockBlockWithReceipts = mock(BlockWithReceipts.class);
|
||||
when(mockBlockWithReceipts.getBlock()).thenReturn(mockBlock);
|
||||
lenient().when(mockBlockWithReceipts.getBlock()).thenReturn(mockBlock);
|
||||
return mockBlockWithReceipts;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TransitionBestPeerComparatorTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -30,13 +30,13 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TransitionProtocolScheduleTest {
|
||||
|
||||
@Mock ProtocolContext protocolContext;
|
||||
@@ -49,11 +49,8 @@ public class TransitionProtocolScheduleTest {
|
||||
private static final long BLOCK_NUMBER = 29L;
|
||||
private TransitionProtocolSchedule transitionProtocolSchedule;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext);
|
||||
when(mergeContext.getTerminalTotalDifficulty()).thenReturn(TTD);
|
||||
|
||||
transitionProtocolSchedule =
|
||||
new TransitionProtocolSchedule(
|
||||
@@ -83,6 +80,9 @@ public class TransitionProtocolScheduleTest {
|
||||
@Test
|
||||
public void returnPreMergeIfTerminalPoWBlock() {
|
||||
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext);
|
||||
when(mergeContext.getTerminalTotalDifficulty()).thenReturn(TTD);
|
||||
when(mergeContext.getFinalized()).thenReturn(Optional.empty());
|
||||
when(mergeContext.isPostMerge()).thenReturn(true);
|
||||
|
||||
@@ -100,6 +100,8 @@ public class TransitionProtocolScheduleTest {
|
||||
|
||||
@Test
|
||||
public void returnPreMergeIfAfterMergeButReorgPreTTD() {
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
when(mergeContext.getTerminalTotalDifficulty()).thenReturn(TTD);
|
||||
|
||||
when(mergeContext.getFinalized()).thenReturn(Optional.empty());
|
||||
when(mergeContext.isPostMerge()).thenReturn(true);
|
||||
@@ -119,6 +121,9 @@ public class TransitionProtocolScheduleTest {
|
||||
@Test
|
||||
public void returnPostMergeIfAfterMergeButReorgPostTTD() {
|
||||
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext);
|
||||
when(mergeContext.getTerminalTotalDifficulty()).thenReturn(TTD);
|
||||
when(mergeContext.getFinalized()).thenReturn(Optional.empty());
|
||||
when(mergeContext.isPostMerge()).thenReturn(true);
|
||||
|
||||
|
||||
@@ -88,17 +88,20 @@ import com.google.common.base.Suppliers;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
private static final com.google.common.base.Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
|
||||
@@ -163,7 +166,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
private final BadBlockManager badBlockManager = spy(new BadBlockManager());
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(mergeContext.as(MergeContext.class)).thenReturn(mergeContext);
|
||||
when(mergeContext.getTerminalTotalDifficulty())
|
||||
@@ -816,7 +819,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
prevParent, genesisState.getBlock().getHash(), genesisState.getBlock().getHash());
|
||||
Hash expectedCommonAncestor = blockchain.getBlockHeader(2).get().getBlockHash();
|
||||
|
||||
// generate from 3' down to some other head. Remeber those.
|
||||
// generate from 3' down to some other head. Remember those.
|
||||
BlockHeader forkPoint = blockchain.getBlockHeader(2).get();
|
||||
prevParent = forkPoint;
|
||||
for (int i = 3; i <= 5; i++) {
|
||||
|
||||
@@ -48,13 +48,16 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
public class MergeReorgTest implements MergeGenesisConfigHelper {
|
||||
|
||||
@Mock PendingTransactions mockPendingTransactions;
|
||||
@@ -77,7 +80,7 @@ public class MergeReorgTest implements MergeGenesisConfigHelper {
|
||||
private final BaseFeeMarket feeMarket =
|
||||
new LondonFeeMarket(0, genesisState.getBlock().getHeader().getBaseFee());
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
var mutable = worldStateArchive.getMutable();
|
||||
genesisState.writeStateTo(mutable);
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.UInt64;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PayloadIdentifierTest {
|
||||
|
||||
|
||||
@@ -29,20 +29,20 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ConstantOmmersHashValidationTest {
|
||||
|
||||
@Mock private ProtocolContext protocolContext;
|
||||
@Mock private MutableBlockchain blockchain;
|
||||
@Mock private MergeContext mergeContext;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(blockchain.getTotalDifficultyByHash(any())).thenReturn(Optional.of(Difficulty.ONE));
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
|
||||
@@ -28,20 +28,20 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class IncrementalTimestampValidationTest {
|
||||
|
||||
@Mock private ProtocolContext protocolContext;
|
||||
@Mock private MutableBlockchain blockchain;
|
||||
@Mock private MergeContext mergeContext;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(blockchain.getTotalDifficultyByHash(any())).thenReturn(Optional.of(Difficulty.ONE));
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
|
||||
@@ -28,20 +28,20 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class NoDifficultyValidationTest {
|
||||
|
||||
@Mock private ProtocolContext protocolContext;
|
||||
@Mock private MutableBlockchain blockchain;
|
||||
@Mock private MergeContext mergeContext;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(blockchain.getTotalDifficultyByHash(any())).thenReturn(Optional.of(Difficulty.ONE));
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
|
||||
@@ -28,20 +28,20 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class NoNonceValidationTest {
|
||||
|
||||
@Mock private ProtocolContext protocolContext;
|
||||
@Mock private MutableBlockchain blockchain;
|
||||
@Mock private MergeContext mergeContext;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(blockchain.getTotalDifficultyByHash(any())).thenReturn(Optional.of(Difficulty.ONE));
|
||||
when(protocolContext.getBlockchain()).thenReturn(blockchain);
|
||||
|
||||
@@ -69,8 +69,6 @@ dependencies {
|
||||
testImplementation 'org.mockito:mockito-core'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
|
||||
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
|
||||
|
||||
integrationTestImplementation project(':crypto:algorithms')
|
||||
integrationTestImplementation project(path: ':crypto:services', configuration: 'testSupportArtifacts')
|
||||
integrationTestImplementation project(path: ':consensus:common', configuration: 'testSupportArtifacts')
|
||||
|
||||
Reference in New Issue
Block a user