Skip to content

Commit

Permalink
Simplify Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
  • Loading branch information
Gabriel-Trintinalia committed Aug 25, 2023
1 parent fc4933e commit 02b420f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,12 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited(
@Test
public void shouldValidateBlobGasUsedCorrectly() {
// V2 should return error if non-null blobGasUsed
final List<WithdrawalParameter> withdrawals = List.of();
lenient()
.when(protocolSpec.getWithdrawalsValidator())
.thenReturn(new WithdrawalsValidator.ProhibitedWithdrawals());

BlockHeader blockHeader =
createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty())
.blobGasUsed(100L)
.buildHeader();

var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), withdrawals, null));

var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null));
final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
assertThat(jsonRpcError.getData()).isEqualTo("non-nil BlobGasUsed pre-cancun");
Expand All @@ -152,17 +146,12 @@ public void shouldValidateBlobGasUsedCorrectly() {
@Test
public void shouldValidateExcessBlobGasCorrectly() {
// V2 should return error if non-null ExcessBlobGas
final List<WithdrawalParameter> withdrawals = List.of();
lenient()
.when(protocolSpec.getWithdrawalsValidator())
.thenReturn(new WithdrawalsValidator.ProhibitedWithdrawals());

BlockHeader blockHeader =
createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty())
.excessBlobGas(BlobGas.MAX_BLOB_GAS)
.buildHeader();

var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), withdrawals, null));
var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null));

final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
Expand All @@ -42,7 +41,6 @@
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.mainnet.BodyValidation;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.mainnet.WithdrawalsValidator;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;

import java.util.Collections;
Expand Down Expand Up @@ -165,18 +163,13 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() {
@Override
public void shouldValidateBlobGasUsedCorrectly() {
// V3 must return error if null blobGasUsed
final List<WithdrawalParameter> withdrawals = List.of();
lenient()
.when(protocolSpec.getWithdrawalsValidator())
.thenReturn(new WithdrawalsValidator.ProhibitedWithdrawals());

BlockHeader blockHeader =
createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty())
.excessBlobGas(BlobGas.MAX_BLOB_GAS)
.blobGasUsed(null)
.buildHeader();

var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), withdrawals, null));
var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null));

final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
Expand All @@ -188,18 +181,13 @@ public void shouldValidateBlobGasUsedCorrectly() {
@Override
public void shouldValidateExcessBlobGasCorrectly() {
// V3 must return error if null excessBlobGas
final List<WithdrawalParameter> withdrawals = List.of();
lenient()
.when(protocolSpec.getWithdrawalsValidator())
.thenReturn(new WithdrawalsValidator.ProhibitedWithdrawals());

BlockHeader blockHeader =
createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty())
.excessBlobGas(null)
.blobGasUsed(100L)
.buildHeader();

var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), withdrawals, null));
var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null));

final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
Expand Down

0 comments on commit 02b420f

Please sign in to comment.