Skip to content

Commit

Permalink
Update existed tests
Browse files Browse the repository at this point in the history
Signed-off-by: Navie Chan <[email protected]>
  • Loading branch information
ensi321 committed Feb 20, 2023
1 parent 2e68cca commit 91a851f
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void setSyncTarget() {
mock(EthPeer.class),
new org.hyperledger.besu.ethereum.core.BlockHeader(
null, null, null, null, null, null, null, null, 1, 1, 1, 1, null, null, null, 1, null,
null, null));
null, null, null));
}

private void clearSyncTarget() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.Transaction;
Expand Down Expand Up @@ -115,6 +116,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
private static final KeyPair KEYS1 =
new KeyPair(PRIVATE_KEY1, SIGNATURE_ALGORITHM.get().createPublicKey(PRIVATE_KEY1));
private static final Optional<List<Withdrawal>> EMPTY_WITHDRAWALS = Optional.empty();
private static final Optional<List<Deposit>> EMPTY_DEPOSITS = Optional.empty();

private static final long REPETITION_MIN_DURATION = 100;
@Mock MergeContext mergeContext;
Expand Down Expand Up @@ -225,7 +227,8 @@ public void coinbaseShouldMatchSuggestedFeeRecipient() {
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
EMPTY_WITHDRAWALS);
EMPTY_WITHDRAWALS,
EMPTY_DEPOSITS);

ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
ArgumentCaptor.forClass(BlockWithReceipts.class);
Expand Down Expand Up @@ -263,7 +266,8 @@ public void exceptionDuringBuildingBlockShouldNotBeInvalid()
.doThrow(new MerkleTrieException("missing leaf"))
.doCallRealMethod()
.when(beingSpiedOn)
.createBlock(any(), any(Bytes32.class), anyLong(), eq(Optional.empty()));
.createBlock(
any(), any(Bytes32.class), anyLong(), eq(Optional.empty()), eq(Optional.empty()));
return beingSpiedOn;
};

Expand Down Expand Up @@ -299,6 +303,7 @@ public void exceptionDuringBuildingBlockShouldNotBeInvalid()
System.currentTimeMillis() / 1000,
Bytes32.random(),
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

verify(willThrow, never()).addBadBlock(any(), any());
Expand Down Expand Up @@ -343,6 +348,7 @@ public void shouldContinueBuildingBlocksUntilFinalizeIsCalled()
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

blockCreationTask.get();
Expand Down Expand Up @@ -394,6 +400,7 @@ public void blockCreationRepetitionShouldTakeNotLessThanRepetitionMinDuration()
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

blockCreationTask.get();
Expand Down Expand Up @@ -439,6 +446,7 @@ public void shouldRetryBlockCreationOnRecoverableError()
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

blockCreationTask.get();
Expand Down Expand Up @@ -473,6 +481,7 @@ public void shouldStopRetryBlockCreationIfTimeExpired() throws InterruptedExcept
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

try {
Expand Down Expand Up @@ -515,6 +524,7 @@ public void shouldStopInProgressBlockCreationIfFinalizedIsCalled()
System.currentTimeMillis() / 1000,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

waitForBlockCreationInProgress.await();
Expand Down Expand Up @@ -561,6 +571,7 @@ public void shouldNotStartAnotherBlockCreationJobIfCalledAgainWithTheSamePayload
timestamp,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

final CompletableFuture<Void> task1 = blockCreationTask;
Expand All @@ -571,6 +582,7 @@ public void shouldNotStartAnotherBlockCreationJobIfCalledAgainWithTheSamePayload
timestamp,
Bytes32.ZERO,
suggestedFeeRecipient,
Optional.empty(),
Optional.empty());

assertThat(payloadId1).isEqualTo(payloadId2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private Object createFakeBlock(final Long height) {
0,
null,
null,
null,
null),
new BlockBody(
List.of(
Expand Down Expand Up @@ -202,6 +203,7 @@ private Object createEmptyBlock(final Long height) {
0,
null,
null,
null,
null),
new BlockBody(List.of(), List.of())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class EthGetTransactionReceiptTest {
Optional.of(PoWHasher.ETHASH_LIGHT),
null,
Optional.empty(),
null,
Optional.empty(),
true);
private final ProtocolSpec statusTransactionTypeSpec =
new ProtocolSpec(
Expand Down Expand Up @@ -142,6 +144,8 @@ public class EthGetTransactionReceiptTest {
Optional.of(PoWHasher.ETHASH_LIGHT),
null,
Optional.empty(),
null,
Optional.empty(),
true);

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public void shouldReturnValidWithoutFinalizedWithPayload() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
Address.ECREC,
Optional.empty(),
Optional.empty()))
.thenReturn(mockPayloadId);

Expand Down Expand Up @@ -441,7 +442,7 @@ public void shouldIgnoreUpdateToOldHeadAndNotPreparePayload() {

var forkchoiceRes = (EngineUpdateForkchoiceResult) resp.getResult();

verify(mergeCoordinator, never()).preparePayload(any(), any(), any(), any(), any());
verify(mergeCoordinator, never()).preparePayload(any(), any(), any(), any(), any(), any());

assertThat(forkchoiceRes.getPayloadStatus().getStatus()).isEqualTo(VALID);
assertThat(forkchoiceRes.getPayloadStatus().getError()).isNull();
Expand Down Expand Up @@ -528,6 +529,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
Address.ECREC,
Optional.empty(),
Optional.empty()))
.thenReturn(mockPayloadId);

Expand Down Expand Up @@ -606,7 +608,8 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() {
Optional.of(
withdrawals.stream()
.map(WithdrawalParameter::toWithdrawal)
.collect(Collectors.toList()))))
.collect(Collectors.toList())),
Optional.empty()))
.thenReturn(mockPayloadId);

assertSuccessWithPayloadForForkchoiceResult(
Expand Down Expand Up @@ -645,6 +648,7 @@ public void shouldReturnValidIfTimestampScheduleIsEmpty() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
Address.ECREC,
Optional.empty(),
Optional.empty()))
.thenReturn(mockPayloadId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public AbstractEngineGetPayloadTest(final MethodFactory methodFactory) {
new BlockBody(
Collections.emptyList(),
Collections.emptyList(),
Optional.of(Collections.emptyList())));
Optional.of(Collections.emptyList()),
Optional.empty()));
protected static final BlockWithReceipts mockBlockWithReceiptsAndWithdrawals =
new BlockWithReceipts(mockBlockWithWithdrawals, Collections.emptyList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private BlockHeader createBlockHeader(final Hash blockHash, final long blockNumb
0,
null,
null,
null,
new BlockHeaderFunctions() {
@Override
public Hash hash(final BlockHeader header) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void shouldReturnWithdrawalNullWhenBlockIsPreShanghai() {
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.empty(),
Optional.empty());
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(preShanghaiBlockBody));
when(blockchain.getBlockBody(blockHash2)).thenReturn(Optional.of(preShanghaiBlockBody2));
Expand Down Expand Up @@ -207,13 +208,15 @@ public void shouldReturnWithdrawalsWhenBlockIsPostShanghai() {
new TransactionTestFixture().createTransaction(sig.generateKeyPair()),
new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());

final BlockBody shanghaiBlockBody2 =
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal2)));
Optional.of(List.of(withdrawal2)),
Optional.empty());
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(shanghaiBlockBody));
when(blockchain.getBlockBody(blockHash2)).thenReturn(Optional.of(shanghaiBlockBody2));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void shouldReturnNullForWithdrawalsWhenBlockIsPreShanghai() {
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.empty(),
Optional.empty());
when(blockchain.getChainHeadBlockNumber()).thenReturn(Long.valueOf(130));
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(preShanghaiBlockBody));
Expand Down Expand Up @@ -210,13 +211,15 @@ public void shouldReturnWithdrawalsWhenBlockIsPostShanghai() {
new TransactionTestFixture().createTransaction(sig.generateKeyPair()),
new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());

final BlockBody shanghaiBlockBody2 =
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal2)));
Optional.of(List.of(withdrawal2)),
Optional.empty());
when(blockchain.getChainHeadBlockNumber()).thenReturn(Long.valueOf(130));
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(shanghaiBlockBody));
when(blockchain.getBlockBody(blockHash2)).thenReturn(Optional.of(shanghaiBlockBody2));
Expand Down Expand Up @@ -246,7 +249,8 @@ public void shouldNotContainTrailingNullForBlocksPastTheCurrentHead() {
new TransactionTestFixture().createTransaction(sig.generateKeyPair()),
new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());
when(blockchain.getChainHeadBlockNumber()).thenReturn(Long.valueOf(123));
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(shanghaiBlockBody));
when(blockchain.getBlockHashByNumber(123)).thenReturn(Optional.of(blockHash1));
Expand All @@ -269,17 +273,20 @@ public void shouldReturnUpUntilHeadWhenStartBlockPlusCountEqualsHeadNumber() {
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());
final BlockBody shanghaiBlockBody2 =
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());
final BlockBody shanghaiBlockBody3 =
new BlockBody(
List.of(new TransactionTestFixture().createTransaction(sig.generateKeyPair())),
Collections.emptyList(),
Optional.of(List.of(withdrawal)));
Optional.of(List.of(withdrawal)),
Optional.empty());
when(blockchain.getChainHeadBlockNumber()).thenReturn(Long.valueOf(125));
when(blockchain.getBlockBody(blockHash1)).thenReturn(Optional.of(shanghaiBlockBody));
when(blockchain.getBlockBody(blockHash2)).thenReturn(Optional.of(shanghaiBlockBody2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void setup() {
0,
null,
null,
null,
new MainnetBlockHeaderFunctions());
testHash = fakeHeader.getHash();
final BlockBody fakeBody = new BlockBody(Collections.emptyList(), Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void setup() {
0,
null,
null,
null,
new MainnetBlockHeaderFunctions(),
Optional.of(testLogsBloomFilter));
testHash = fakeHeader.getHash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private BlockHeader createBlock(final long number) {
0,
null,
null,
null,
new MainnetBlockHeaderFunctions(),
Optional.of(testLogsBloomFilter));
return fakeHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void setup() throws IOException {
0,
null,
null,
null,
new MainnetBlockHeaderFunctions());
testHash = fakeHeader.getHash();
when(blockchain.getBlockHeader(anyLong())).thenReturn(Optional.of(fakeHeader));
Expand Down Expand Up @@ -268,6 +269,7 @@ private BlockHeader createBlock(final long number, final Optional<String> messag
0,
null,
null,
null,
new MainnetBlockHeaderFunctions());
testHash = fakeHeader.getHash();
when(blockchain.getBlockHeader(number)).thenReturn(Optional.of(fakeHeader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ void withProcessorAndEmptyWithdrawals_NoWithdrawalsAreProcessed() {
final AbstractBlockCreator blockCreator = blockCreatorWithWithdrawalsProcessor();
final BlockCreationResult blockCreationResult =
blockCreator.createBlock(
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1L, false);
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
1L,
false);
verify(withdrawalsProcessor, never()).processWithdrawals(any(), any());
assertThat(blockCreationResult.getBlock().getHeader().getWithdrawalsRoot()).isEmpty();
assertThat(blockCreationResult.getBlock().getBody().getWithdrawals()).isEmpty();
Expand All @@ -81,7 +87,13 @@ void withNoProcessorAndEmptyWithdrawals_NoWithdrawalsAreNotProcessed() {
final AbstractBlockCreator blockCreator = blockCreatorWithoutWithdrawalsProcessor();
final BlockCreationResult blockCreationResult =
blockCreator.createBlock(
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1L, false);
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
1L,
false);
verify(withdrawalsProcessor, never()).processWithdrawals(any(), any());
assertThat(blockCreationResult.getBlock().getHeader().getWithdrawalsRoot()).isEmpty();
assertThat(blockCreationResult.getBlock().getBody().getWithdrawals()).isEmpty();
Expand All @@ -98,6 +110,7 @@ void withProcessorAndWithdrawals_WithdrawalsAreProcessed() {
Optional.empty(),
Optional.of(withdrawals),
Optional.empty(),
Optional.empty(),
1L,
false);

Expand All @@ -119,6 +132,7 @@ void withNoProcessorAndWithdrawals_WithdrawalsAreNotProcessed() {
Optional.empty(),
Optional.of(withdrawals),
Optional.empty(),
Optional.empty(),
1L,
false);
verify(withdrawalsProcessor, never()).processWithdrawals(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void assertBodyIdentifierUsesWithdrawalsToGenerateBodyIdentifiers() {
final BlockBody emptyBodyBlock = BlockBody.empty();
// Block with no tx, no ommers, 1 withdrawal
final BlockBody bodyBlockWithWithdrawal =
new BlockBody(emptyList(), emptyList(), Optional.of(List.of(withdrawal)));
new BlockBody(emptyList(), emptyList(), Optional.of(List.of(withdrawal)), Optional.empty());

assertThat(
new GetBodiesFromPeerTask.BodyIdentifier(emptyBodyBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public TestBlockHeader(
Bytes.fromHexStringLenient(nonce).toLong(),
null,
null,
null,
new MainnetBlockHeaderFunctions());
}
}
Expand Down
Loading

0 comments on commit 91a851f

Please sign in to comment.