diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java index d36a0b6a87d..b2dd41bbfa5 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator; +import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; import org.hyperledger.besu.evm.gascalculator.GasCalculator; @@ -33,6 +34,7 @@ import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; import org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator; +import org.hyperledger.besu.evm.gascalculator.ShanghaiGasCalculator; import org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator; import org.hyperledger.besu.evm.gascalculator.TangerineWhistleGasCalculator; import org.hyperledger.besu.testutil.JsonTestParameters; @@ -54,7 +56,8 @@ private static TransactionValidator transactionValidator(final String name) { return REFERENCE_TEST_PROTOCOL_SCHEDULES .getByName(name) .getByBlockHeader(BlockHeaderBuilder.createDefault().buildBlockHeader()) - .getTransactionValidatorFactory().get(); + .getTransactionValidatorFactory() + .get(); } private static final String TEST_CONFIG_FILE_DIR_PATH = "TransactionTests/"; @@ -62,7 +65,9 @@ private static TransactionValidator transactionValidator(final String name) { public static Stream getTestParametersForConfig() { return JsonTestParameters.create(TransactionTestCaseSpec.class) .generator((name, fullPath, spec, collector) -> collector.add(name, fullPath, spec, true)) - .generate(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> Arguments.of(params[0], params[1])); + .generate(TEST_CONFIG_FILE_DIR_PATH) + .stream() + .map(params -> Arguments.of(params[0], params[1])); } @ParameterizedTest(name = "Name: {0}") @@ -125,8 +130,30 @@ public void london(final String name, final TransactionTestCaseSpec spec) { milestone(spec, name, "London", new LondonGasCalculator(), Optional.of(Wei.of(0))); } + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void merge(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Merge", new LondonGasCalculator(), Optional.of(Wei.of(0))); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void shanghai(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Shanghai", new ShanghaiGasCalculator(), Optional.of(Wei.of(0))); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void cancun(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Cancun", new CancunGasCalculator(), Optional.of(Wei.of(0))); + } + public void milestone( - final TransactionTestCaseSpec spec, final String name, final String milestone, final GasCalculator gasCalculator, final Optional baseFee) { + final TransactionTestCaseSpec spec, + final String name, + final String milestone, + final GasCalculator gasCalculator, + final Optional baseFee) { final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone); diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java index 7f9c3cb7c63..7ce7384e1ab 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Assumptions; /** A Transaction test case specification. */ @JsonIgnoreProperties({"_info"}) @@ -109,9 +110,7 @@ public Bytes getRlp() { public Expectation expectation(final String milestone) { final Expectation expectation = expectations.get(milestone); - if (expectation == null) { - throw new IllegalStateException("Expectation for milestone " + milestone + " not found"); - } + Assumptions.assumeFalse(expectation == null, () -> "No expectation for milestone " + milestone); return expectation; } diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java index a4eff43c98d..b6d01dae83f 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java @@ -16,12 +16,13 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; -import org.assertj.core.api.Assertions; import org.hyperledger.besu.ethereum.rlp.util.RLPTestUtil; import org.hyperledger.besu.testutil.JsonTestParameters; import java.util.stream.Stream; +import org.apache.tuweni.bytes.Bytes; +import org.assertj.core.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -29,23 +30,45 @@ /** The Ethereum reference RLP tests. */ public class RLPRefTest { - private static final String TEST_CONFIG_FILES = "RLPTests/rlptest.json"; + private static final String[] TEST_CONFIG_FILES = { + "RLPTests/rlptest.json", "RLPTests/invalidRLPTest.json" + }; + + private static final Bytes INVALID = Bytes.fromHexString("0x494e56414c4944"); public static Stream getTestParametersForConfig() { - return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream().map(params -> Arguments.of(params[0], params[1], params[2])); + return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream() + .map(params -> Arguments.of(params[0], params[1], params[2])); } @ParameterizedTest(name = "Name: {0}") @MethodSource("getTestParametersForConfig") public void encode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { assumeTrue(runTest, "Test was blacklisted"); - Assertions.assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); + if (!spec.getIn().equals(INVALID)) { + Assertions.assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); + } } @ParameterizedTest(name = "Name: {0}") @MethodSource("getTestParametersForConfig") public void decode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { assumeTrue(runTest, "Test was blacklisted"); - Assertions.assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); + if (spec.getIn().equals(INVALID)) { + Assertions.assertThatThrownBy(() -> RLPTestUtil.decode(spec.getOut())) + .isInstanceOf(RLPException.class); + Assertions.assertThatThrownBy(() -> decode2(RLP.input(spec.getOut()))) + .isInstanceOf(RLPException.class); + } else { + Assertions.assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); + } + } + + private static Object decode2(final RLPInput in) { + if (in.nextIsList()) { + return in.readList(RLPRefTest::decode2); + } else { + return in.readBytes(); + } } }