diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/RequestType.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/RequestType.java index b1cddb44040..628baa6d5f7 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/RequestType.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/RequestType.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.datatypes; -import java.util.Arrays; - /** Enum representing different types of requests with associated serialized type values. */ public enum RequestType { /** DEPOSITS */ @@ -47,12 +45,12 @@ public byte getSerializedType() { * RequestType}. */ public static RequestType of(final int serializedTypeValue) { - return Arrays.stream(RequestType.values()) - .filter(requestType -> requestType.typeValue == serializedTypeValue) - .findFirst() - .orElseThrow( - () -> - new IllegalArgumentException( - String.format("Unsupported request type: 0x%02X", serializedTypeValue))); + return switch (serializedTypeValue) { + case 0x00 -> DEPOSIT; + case 0x01 -> WITHDRAWAL; + default -> + throw new IllegalArgumentException( + String.format("Unsupported request type: 0x%02X", serializedTypeValue)); + }; } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/RequestValidatorProvider.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/RequestValidatorProvider.java index a86f4ca5eac..505d3695186 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/RequestValidatorProvider.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/RequestValidatorProvider.java @@ -66,6 +66,6 @@ private static RequestsValidatorCoordinator getRequestValidatorCoordinator( final ProtocolSpec protocolSchedule) { return Optional.ofNullable(protocolSchedule) .map(ProtocolSpec::getRequestsValidatorCoordinator) - .orElseGet(() -> new RequestsValidatorCoordinator.Builder().build()); + .orElseGet(RequestsValidatorCoordinator::empty); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java index 15b3a9c2c21..aff5713afc6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java @@ -14,6 +14,9 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; +import static org.hyperledger.besu.ethereum.mainnet.requests.RequestUtil.getDepositRequests; +import static org.hyperledger.besu.ethereum.mainnet.requests.RequestUtil.getWithdrawalRequests; + import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineGetPayloadBodiesResultV1.PayloadBody; @@ -24,12 +27,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockValueCalculator; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.core.Deposit; -import org.hyperledger.besu.ethereum.core.Request; -import org.hyperledger.besu.ethereum.core.WithdrawalRequest; import org.hyperledger.besu.ethereum.core.encoding.EncodingContext; import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder; -import org.hyperledger.besu.ethereum.mainnet.requests.RequestUtil; import java.util.ArrayList; import java.util.List; @@ -176,23 +175,12 @@ public EngineGetPayloadResultV4 payloadTransactionCompleteV4( blockWithReceipts.getHeader(), txs, blockWithReceipts.getBlock().getBody().getWithdrawals(), - getDepositRequest(blockWithReceipts.getBlock().getBody().getRequests()), - getWithdrawalRequest(blockWithReceipts.getBlock().getBody().getRequests()), + getDepositRequests(blockWithReceipts.getBlock().getBody().getRequests()), + getWithdrawalRequests(blockWithReceipts.getBlock().getBody().getRequests()), Quantity.create(blockValue), blobsBundleV1); } - private Optional> getDepositRequest(final Optional> requests) { - return requests.map( - requestList -> RequestUtil.filterRequestsOfType(requestList, Deposit.class)); - } - - private Optional> getWithdrawalRequest( - final Optional> requests) { - return requests.map( - requestList -> RequestUtil.filterRequestsOfType(requestList, WithdrawalRequest.class)); - } - public BlockResult transactionHash(final BlockWithMetadata blockWithMetadata) { return transactionHash(blockWithMetadata, false); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java index dc40b164a4a..dba31f7f0d6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java @@ -521,7 +521,7 @@ protected void assertValidResponse(final BlockHeader mockHeader, final JsonRpcRe } private void mockProhibitedRequestsValidator() { - var validator = new RequestsValidatorCoordinator.Builder().build(); + var validator = RequestsValidatorCoordinator.empty(); when(protocolSpec.getRequestsValidatorCoordinator()).thenReturn(validator); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java index 679a274cbc5..276eaf6b611 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java @@ -158,7 +158,7 @@ public void shouldReturnInvalidIfDepositsIsNotNull_WhenDepositsProhibited() { final List deposits = List.of(); lenient() .when(protocolSpec.getRequestsValidatorCoordinator()) - .thenReturn(new RequestsValidatorCoordinator.Builder().build()); + .thenReturn(RequestsValidatorCoordinator.empty()); var resp = resp( @@ -311,7 +311,7 @@ protected JsonRpcResponse resp(final EnginePayloadParameter payload) { } private void mockProhibitedRequestsValidator() { - var validator = new RequestsValidatorCoordinator.Builder().build(); + var validator = RequestsValidatorCoordinator.empty(); when(protocolSpec.getRequestsValidatorCoordinator()).thenReturn(validator); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index 00576d493f8..103b8fdb667 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -134,7 +134,7 @@ void findDepositsFromReceipts() { UInt64.valueOf(539967)); final List expectedDeposits = List.of(expectedDeposit); - final Optional> depositsFromReceipts = + var depositsFromReceipts = new DepositRequestProcessor(DEFAULT_DEPOSIT_CONTRACT_ADDRESS).process(null, receipts); assertThat(depositsFromReceipts.get()).isEqualTo(expectedDeposits); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java index 86392b86d6b..15e8c3c804f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java @@ -89,7 +89,7 @@ public static Hash withdrawalsRoot(final List withdrawals) { } /** - * Generates the request root for a list of requests + * Generates the requests root for a list of requests * * @param requests list of request * @return the requests root diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index 61fba7b1fdc..f79c6a874bb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -78,7 +78,7 @@ public class ProtocolSpecBuilder { new WithdrawalsValidator.ProhibitedWithdrawals(); private WithdrawalsProcessor withdrawalsProcessor; private RequestsValidatorCoordinator requestsValidatorCoordinator = - new RequestsValidatorCoordinator.Builder().build(); + RequestsValidatorCoordinator.empty(); private RequestProcessorCoordinator requestProcessorCoordinator; protected BlockHashProcessor blockHashProcessor; private FeeMarket feeMarket = FeeMarket.legacy(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositRequestProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositRequestProcessor.java index 16109946dfd..766ce1f94e0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositRequestProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositRequestProcessor.java @@ -39,13 +39,13 @@ public DepositRequestProcessor(final Address depositContractAddress) { } @Override - public Optional> process( + public Optional> process( final MutableWorldState ignored, final List transactionReceipts) { if (depositContractAddress.isEmpty()) { return Optional.empty(); } List deposits = findDepositsFromReceipts(transactionReceipts); - return Optional.of(deposits.stream().map(r -> (Request) r).toList()); + return Optional.of(deposits); } @VisibleForTesting diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositsValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositsValidator.java index 1c6c3ca21c8..6a2d3bdc587 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositsValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/DepositsValidator.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.mainnet.requests; +import static org.hyperledger.besu.ethereum.mainnet.requests.RequestUtil.getDepositRequests; + import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Deposit; @@ -23,6 +25,7 @@ import org.hyperledger.besu.evm.log.Log; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -75,7 +78,7 @@ public boolean validateDeposits( @Override public boolean validate( final Block block, final List requests, final List receipts) { - var deposits = RequestUtil.filterRequestsOfType(requests, Deposit.class); + var deposits = getDepositRequests(Optional.of(requests)).orElse(Collections.emptyList()); return validateDeposits(block, deposits, receipts); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestProcessor.java index c365e0d754b..d09b3c47d18 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestProcessor.java @@ -22,7 +22,7 @@ import java.util.Optional; public interface RequestProcessor { - Optional> process( + Optional> process( final MutableWorldState mutableWorldState, final List transactionReceipts); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestUtil.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestUtil.java index 54478bfef85..3d85fc48f52 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestUtil.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestUtil.java @@ -14,7 +14,9 @@ */ package org.hyperledger.besu.ethereum.mainnet.requests; +import org.hyperledger.besu.ethereum.core.Deposit; import org.hyperledger.besu.ethereum.core.Request; +import org.hyperledger.besu.ethereum.core.WithdrawalRequest; import java.util.ArrayList; import java.util.Collections; @@ -40,6 +42,23 @@ public static List filterRequestsOfType( return requests.stream().filter(requestType::isInstance).map(requestType::cast).toList(); } + public static Optional> getDepositRequests(final Optional> requests) { + return requests.map(r -> filterRequestsOfType(r, Deposit.class)); + } + + public static Optional> getWithdrawalRequests( + final Optional> requests) { + return requests.map(r -> filterRequestsOfType(r, WithdrawalRequest.class)); + } + + /** + * Combines two optional lists of requests into a single optional list. + * + * @param maybeDeposits Optional list of deposit requests. + * @param maybeWithdrawalRequest Optional list of withdrawal requests. + * @return An Optional containing the combined list of requests, or an empty Optional if both + * inputs are empty. + */ public static Optional> combine( final Optional> maybeDeposits, final Optional> maybeWithdrawalRequest) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestsValidatorCoordinator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestsValidatorCoordinator.java index f6800f95c3b..7b8f5cf4973 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestsValidatorCoordinator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestsValidatorCoordinator.java @@ -41,6 +41,10 @@ public class RequestsValidatorCoordinator { private static final Logger LOG = LoggerFactory.getLogger(RequestsValidatorCoordinator.class); private final ImmutableSortedMap validators; + public static RequestsValidatorCoordinator empty() { + return new Builder().build(); + } + /** * Constructs a new RequestsDelegateValidator with a mapping of request types to their respective * validators. diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java index f9c029d5153..9803f23f3f9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java @@ -25,7 +25,7 @@ public class WithdrawalRequestProcessor implements RequestProcessor { @Override - public Optional> process( + public Optional> process( final MutableWorldState mutableWorldState, final List transactionReceipts) { @@ -33,6 +33,6 @@ public Optional> process( WithdrawalRequestContractHelper.popWithdrawalRequestsFromQueue(mutableWorldState).stream() .toList(); - return Optional.of(withdrawalRequests.stream().map(r -> (Request) r).toList()); + return Optional.of(withdrawalRequests); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestValidator.java index b1fc88196c9..d5f04e6ef74 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestValidator.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.mainnet.requests; +import static org.hyperledger.besu.ethereum.mainnet.requests.RequestUtil.getWithdrawalRequests; + import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Request; @@ -45,7 +47,7 @@ private boolean validateWithdrawalRequestsInBlock( block .getBody() .getRequests() - .map(requests -> RequestUtil.filterRequestsOfType(requests, WithdrawalRequest.class)) + .flatMap(requests -> getWithdrawalRequests(Optional.of(requests))) .orElse(Collections.emptyList()); // TODO Do we need to allow for customization? (e.g. if the value changes in the next fork) @@ -74,7 +76,8 @@ private boolean validateWithdrawalRequestsInBlock( @Override public boolean validate( final Block block, final List requests, final List receipts) { - var withdrawalRequests = RequestUtil.filterRequestsOfType(requests, WithdrawalRequest.class); + var withdrawalRequests = + getWithdrawalRequests(Optional.of(requests)).orElse(Collections.emptyList()); return validateWithdrawalRequestsInBlock(block, withdrawalRequests); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java index 6c84b29b478..d2d1fed8b73 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java @@ -114,7 +114,7 @@ public void setup() { when(protocolContext.getWorldStateArchive()).thenReturn(worldStateArchive); when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); when(protocolSpec.getRequestsValidatorCoordinator()) - .thenReturn(new RequestsValidatorCoordinator.Builder().build()); + .thenReturn(RequestsValidatorCoordinator.empty()); when(protocolSpec.getBlockHashProcessor()).thenReturn(new FrontierBlockHashProcessor()); mainnetBlockValidator = new MainnetBlockValidator( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/DepositEncoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/DepositEncoderTest.java index fc9027cdbab..7b4052cffb3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/DepositEncoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/DepositEncoderTest.java @@ -27,24 +27,35 @@ import org.junit.jupiter.api.Test; class DepositEncoderTest { + private final String expectedDepositEncodedBytes = + "f8bbb0b10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416ea00017a7fcf06faf493d30bbe2632ea7c2383cd86825e12797165de7aa35589483850773594000b860a889db8300194050a2636c92a95bc7160515867614b7971a9500cdb62f9c0890217d2901c3241f86fac029428fc106930606154bd9e406d7588934a5f15b837180b17194d6e44bd6de23e43b163dfe12e369dcc75a3852cd997963f158217eb501"; + + final Deposit deposit = + new Deposit( + BLSPublicKey.fromHexString( + "0xb10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e"), + Bytes32.fromHexString( + "0x0017a7fcf06faf493d30bbe2632ea7c2383cd86825e12797165de7aa35589483"), + GWei.of(32000000000L), + BLSSignature.fromHexString( + "0xa889db8300194050a2636c92a95bc7160515867614b7971a9500cdb62f9c0890217d2901c3241f86fac029428fc106930606154bd9e406d7588934a5f15b837180b17194d6e44bd6de23e43b163dfe12e369dcc75a3852cd997963f158217eb5"), + UInt64.ONE); + @Test void shouldEncodeDeposit() { - final Deposit deposit = - new Deposit( - BLSPublicKey.fromHexString( - "0xb10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e"), - Bytes32.fromHexString( - "0x0017a7fcf06faf493d30bbe2632ea7c2383cd86825e12797165de7aa35589483"), - GWei.of(32000000000L), - BLSSignature.fromHexString( - "0xa889db8300194050a2636c92a95bc7160515867614b7971a9500cdb62f9c0890217d2901c3241f86fac029428fc106930606154bd9e406d7588934a5f15b837180b17194d6e44bd6de23e43b163dfe12e369dcc75a3852cd997963f158217eb5"), - UInt64.ONE); - final Bytes encoded = DepositEncoder.encodeOpaqueBytes(deposit); + assertThat(encoded).isEqualTo(Bytes.fromHexString(expectedDepositEncodedBytes)); + } + @Test + void shouldEncodeDepositRequest() { + final Bytes encoded = RequestEncoder.encodeOpaqueBytes(deposit); + // Request encoding is Request = RequestType ++ RequestData assertThat(encoded) .isEqualTo( Bytes.fromHexString( - "0xf8bbb0b10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416ea00017a7fcf06faf493d30bbe2632ea7c2383cd86825e12797165de7aa35589483850773594000b860a889db8300194050a2636c92a95bc7160515867614b7971a9500cdb62f9c0890217d2901c3241f86fac029428fc106930606154bd9e406d7588934a5f15b837180b17194d6e44bd6de23e43b163dfe12e369dcc75a3852cd997963f158217eb501")); + String.format( + "0x%02X%s", + deposit.getType().getSerializedType(), expectedDepositEncodedBytes))); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/WithdrawalRequestEncoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/WithdrawalRequestEncoderTest.java index 3f9eb0e8668..14c9cfacef2 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/WithdrawalRequestEncoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/WithdrawalRequestEncoderTest.java @@ -25,20 +25,31 @@ import org.junit.jupiter.api.Test; class WithdrawalRequestEncoderTest { + + private final String expectedEncodedBytes = + "f84794763c396673f9c391dce3361a9a71c8e161388000b0b10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e05"; + + final WithdrawalRequest withdrawalRequest = + new WithdrawalRequest( + Address.fromHexString("0x763c396673F9c391DCe3361A9A71C8E161388000"), + BLSPublicKey.fromHexString( + "0xb10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e"), + GWei.of(5)); + @Test void shouldEncodeWithdrawalRequest() { - final WithdrawalRequest withdrawalRequest = - new WithdrawalRequest( - Address.fromHexString("0x763c396673F9c391DCe3361A9A71C8E161388000"), - BLSPublicKey.fromHexString( - "0xb10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e"), - GWei.of(5)); - final Bytes encoded = WithdrawalRequestEncoder.encodeOpaqueBytes(withdrawalRequest); + assertThat(encoded).isEqualTo(Bytes.fromHexString(expectedEncodedBytes)); + } + @Test + void shouldEncodeRequest() { + final Bytes encoded = RequestEncoder.encodeOpaqueBytes(withdrawalRequest); assertThat(encoded) .isEqualTo( Bytes.fromHexString( - "0xf84794763c396673f9c391dce3361a9a71c8e161388000b0b10a4a15bf67b328c9b101d09e5c6ee6672978fdad9ef0d9e2ceffaee99223555d8601f0cb3bcc4ce1af9864779a416e05")); + String.format( + "0x%02X%s", + withdrawalRequest.getType().getSerializedType(), expectedEncodedBytes))); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessorTest.java index 2db101ab659..2a66c6e1151 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessorTest.java @@ -70,7 +70,7 @@ void baseSetup() { lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); lenient() .when(protocolSpec.getRequestsValidatorCoordinator()) - .thenReturn(new RequestsValidatorCoordinator.Builder().build()); + .thenReturn(RequestsValidatorCoordinator.empty()); lenient() .when(protocolSpec.getBlockHashProcessor()) .thenReturn(new FrontierBlockHashProcessor()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessorTest.java index 9f2092ea81b..a06aece37bd 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessorTest.java @@ -51,7 +51,7 @@ public class MainnetBlockProcessorTest extends AbstractBlockProcessorTest { public void setup() { when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); when(protocolSpec.getRequestsValidatorCoordinator()) - .thenReturn(new RequestsValidatorCoordinator.Builder().build()); + .thenReturn(RequestsValidatorCoordinator.empty()); when(protocolSpec.getBlockHashProcessor()).thenReturn(new FrontierBlockHashProcessor()); }