update referencetests to latest develop branch (#2335)

* update referencetests to latest develop branch
* update submodule reference
* get 1559 test cases passing
* fix transaction encoding of 2718 typed transactions

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/2339/head
garyschulte 3 years ago committed by GitHub
parent bc172b285b
commit 922bff4b9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java
  2. 2
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java
  3. 14
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java
  4. 2
      ethereum/referencetests/build.gradle
  5. 6
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/GeneralStateTestCaseSpec.java
  6. 20
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/StateTestVersionedTransaction.java
  7. 2
      ethereum/referencetests/src/test/resources

@ -485,10 +485,16 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
}
final BigInteger recId = BigInteger.valueOf(signature.getRecId());
if (chainId.isEmpty()) {
return recId.add(REPLAY_UNPROTECTED_V_BASE);
if (transactionType != null && transactionType != TransactionType.FRONTIER) {
// EIP-2718 typed transaction, return yParity:
return recId;
} else {
return recId.add(REPLAY_PROTECTED_V_BASE).add(TWO.multiply(chainId.get()));
if (chainId.isEmpty()) {
return recId.add(REPLAY_UNPROTECTED_V_BASE);
} else {
return recId.add(REPLAY_PROTECTED_V_BASE).add(TWO.multiply(chainId.get()));
}
}
}

@ -45,6 +45,7 @@ import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult.Status;
import org.hyperledger.besu.ethereum.vm.OperationTracer;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.plugin.data.TransactionType;
import java.math.BigInteger;
import java.util.Optional;
@ -290,6 +291,7 @@ public class TransactionSimulatorTest {
final Transaction expectedTransaction =
Transaction.builder()
.type(TransactionType.FRONTIER)
.nonce(1L)
.gasPrice(callParameter.getGasPrice())
.gasLimit(callParameter.getGasLimit())

@ -39,6 +39,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class GeneralStateReferenceTestTools {
private static final ReferenceTestProtocolSchedules REFERENCE_TEST_PROTOCOL_SCHEDULES =
@ -148,10 +149,15 @@ public class GeneralStateReferenceTestTools {
// Check the logs.
final Hash expectedLogsHash = spec.getExpectedLogsHash();
final List<Log> logs = result.getLogs();
assertThat(Hash.hash(RLP.encode(out -> out.writeList(logs, Log::writeTo))))
.withFailMessage("Unmatched logs hash. Generated logs: %s", logs)
.isEqualTo(expectedLogsHash);
Optional.ofNullable(expectedLogsHash)
.ifPresent(
expected -> {
final List<Log> logs = result.getLogs();
assertThat(Hash.hash(RLP.encode(out -> out.writeList(logs, Log::writeTo))))
.withFailMessage("Unmatched logs hash. Generated logs: %s", logs)
.isEqualTo(expected);
});
}
private static boolean shouldClearEmptyAccounts(final String eip) {

@ -41,7 +41,7 @@ task ('validateReferenceTestSubmodule') {
description = "Checks that the reference tests submodule is not accidentally changed"
doLast {
def result = new ByteArrayOutputStream()
def expectedHash = 'bb662629b6da3a4ebea3f7cebf02d6c4870c2871'
def expectedHash = '4d539de6788147a0376b70f2bc71a8f818872164'
def submodulePath = java.nio.file.Path.of("${rootProject.projectDir}", "ethereum/referencetests/src/test/resources").toAbsolutePath()
try {
exec {

@ -24,7 +24,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -121,7 +123,7 @@ public class GeneralStateTestCaseSpec {
public static class PostSection {
private final Hash rootHash;
private final Hash logsHash;
@Nullable private final Hash logsHash;
private final Indexes indexes;
@JsonCreator
@ -131,7 +133,7 @@ public class GeneralStateTestCaseSpec {
@JsonProperty("indexes") final Indexes indexes,
@JsonProperty("txbytes") final String txbytes) {
this.rootHash = Hash.fromHexString(hash);
this.logsHash = Hash.fromHexString(logs);
this.logsHash = Optional.ofNullable(logs).map(Hash::fromHexString).orElse(null);
this.indexes = indexes;
}
}

@ -60,7 +60,9 @@ import org.apache.tuweni.bytes.Bytes32;
public class StateTestVersionedTransaction {
private final long nonce;
private final Wei gasPrice;
@Nullable private final Wei maxFeePerGas;
@Nullable private final Wei maxPriorityFeePerGas;
@Nullable private final Wei gasPrice;
@Nullable private final Address to;
private final KeyPair keys;
@ -74,7 +76,9 @@ public class StateTestVersionedTransaction {
* Constructor for populating a mock transaction with json data.
*
* @param nonce Nonce of the mock transaction.
* @param gasPrice Gas price of the mock transaction.
* @param gasPrice Gas price of the mock transaction, if not 1559 transaction.
* @param maxFeePerGas Wei fee cap of the mock transaction, if a 1559 transaction.
* @param maxPriorityFeePerGas Wei tip cap of the mock transaction, if a 1559 transaction.
* @param gasLimit Gas Limit of the mock transaction.
* @param to Recipient account of the mock transaction.
* @param value Amount of ether transferred in the mock transaction.
@ -86,6 +90,8 @@ public class StateTestVersionedTransaction {
public StateTestVersionedTransaction(
@JsonProperty("nonce") final String nonce,
@JsonProperty("gasPrice") final String gasPrice,
@JsonProperty("maxFeePerGas") final String maxFeePerGas,
@JsonProperty("maxPriorityFeePerGas") final String maxPriorityFeePerGas,
@JsonProperty("gasLimit") final String[] gasLimit,
@JsonProperty("to") final String to,
@JsonProperty("value") final String[] value,
@ -95,7 +101,10 @@ public class StateTestVersionedTransaction {
final List<List<AccessListEntry>> maybeAccessLists) {
this.nonce = Long.decode(nonce);
this.gasPrice = Wei.fromHexString(gasPrice);
this.gasPrice = Optional.ofNullable(gasPrice).map(Wei::fromHexString).orElse(null);
this.maxFeePerGas = Optional.ofNullable(maxFeePerGas).map(Wei::fromHexString).orElse(null);
this.maxPriorityFeePerGas =
Optional.ofNullable(maxPriorityFeePerGas).map(Wei::fromHexString).orElse(null);
this.to = to.isEmpty() ? null : Address.fromHexString(to);
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
@ -118,14 +127,17 @@ public class StateTestVersionedTransaction {
}
public Transaction get(final GeneralStateTestCaseSpec.Indexes indexes) {
final Transaction.Builder transactionBuilder =
Transaction.builder()
.nonce(nonce)
.gasPrice(gasPrice)
.gasLimit(gasLimits.get(indexes.gas).asUInt256().toLong())
.to(to)
.value(values.get(indexes.value))
.payload(payloads.get(indexes.data));
Optional.ofNullable(gasPrice).ifPresent(transactionBuilder::gasPrice);
Optional.ofNullable(maxFeePerGas).ifPresent(transactionBuilder::maxFeePerGas);
Optional.ofNullable(maxPriorityFeePerGas).ifPresent(transactionBuilder::maxPriorityFeePerGas);
maybeAccessLists.ifPresent(
accessLists ->
transactionBuilder.accessList(accessLists.get(indexes.data)).chainId(BigInteger.ONE));

@ -1 +1 @@
Subproject commit bb662629b6da3a4ebea3f7cebf02d6c4870c2871
Subproject commit 4d539de6788147a0376b70f2bc71a8f818872164
Loading…
Cancel
Save