mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-08 15:13:58 -05:00
Support authorizationList parsing in reference test txs (#8116)
Support authorizationList parsing in reference tests for execution-spec-tests Allow zero chainId Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
This commit is contained in:
@@ -21,6 +21,7 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.encoding.CodeDelegationTransactionEncoder;
|
||||
import org.hyperledger.besu.ethereum.core.json.ChainIdDeserializer;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -28,10 +29,14 @@ import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.google.common.base.Suppliers;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
// ignore `signer` field used in execution-spec-tests
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CodeDelegation implements org.hyperledger.besu.datatypes.CodeDelegation {
|
||||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
|
||||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
|
||||
@@ -77,14 +82,23 @@ public class CodeDelegation implements org.hyperledger.besu.datatypes.CodeDelega
|
||||
*/
|
||||
@JsonCreator
|
||||
public static org.hyperledger.besu.datatypes.CodeDelegation createCodeDelegation(
|
||||
@JsonProperty("chainId") final BigInteger chainId,
|
||||
@JsonProperty("chainId") @JsonDeserialize(using = ChainIdDeserializer.class)
|
||||
final BigInteger chainId,
|
||||
@JsonProperty("address") final Address address,
|
||||
@JsonProperty("nonce") final long nonce,
|
||||
@JsonProperty("v") final byte v,
|
||||
@JsonProperty("r") final BigInteger r,
|
||||
@JsonProperty("s") final BigInteger s) {
|
||||
@JsonProperty("nonce") final String nonce,
|
||||
@JsonProperty("v") final String v,
|
||||
@JsonProperty("r") final String r,
|
||||
@JsonProperty("s") final String s) {
|
||||
return new CodeDelegation(
|
||||
chainId, address, nonce, SIGNATURE_ALGORITHM.get().createSignature(r, s, v));
|
||||
chainId,
|
||||
address,
|
||||
Bytes.fromHexStringLenient(nonce).toLong(),
|
||||
SIGNATURE_ALGORITHM
|
||||
.get()
|
||||
.createSignature(
|
||||
Bytes.fromHexStringLenient(r).toUnsignedBigInteger(),
|
||||
Bytes.fromHexStringLenient(s).toUnsignedBigInteger(),
|
||||
Bytes.fromHexStringLenient(v).get(0)));
|
||||
}
|
||||
|
||||
@JsonProperty("chainId")
|
||||
|
||||
@@ -38,8 +38,8 @@ public class ChainIdDeserializer extends StdDeserializer<BigInteger> {
|
||||
final var chainId =
|
||||
UInt256.fromHexString(jsonparser.getCodec().readValue(jsonparser, String.class))
|
||||
.toBigInteger();
|
||||
if (chainId.signum() <= 0) {
|
||||
throw new IllegalArgumentException("Non positive chain id: " + chainId);
|
||||
if (chainId.signum() < 0) {
|
||||
throw new IllegalArgumentException("Negative chain id: " + chainId);
|
||||
}
|
||||
return chainId;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public class StateTestVersionedTransaction {
|
||||
// String instead of VersionedHash because reference tests intentionally use bad hashes.
|
||||
private final List<String> blobVersionedHashes;
|
||||
|
||||
@JsonDeserialize(contentAs = org.hyperledger.besu.ethereum.core.CodeDelegation.class)
|
||||
private final List<org.hyperledger.besu.datatypes.CodeDelegation> authorizationList;
|
||||
|
||||
/**
|
||||
* Constructor for populating a mock transaction with json data.
|
||||
*
|
||||
@@ -103,7 +106,9 @@ public class StateTestVersionedTransaction {
|
||||
@JsonDeserialize(using = StateTestAccessListDeserializer.class) @JsonProperty("accessLists")
|
||||
final List<List<AccessListEntry>> maybeAccessLists,
|
||||
@JsonProperty("maxFeePerBlobGas") final String maxFeePerBlobGas,
|
||||
@JsonProperty("blobVersionedHashes") final List<String> blobVersionedHashes) {
|
||||
@JsonProperty("blobVersionedHashes") final List<String> blobVersionedHashes,
|
||||
@JsonProperty("authorizationList")
|
||||
final List<org.hyperledger.besu.datatypes.CodeDelegation> authorizationList) {
|
||||
|
||||
this.nonce = Bytes.fromHexStringLenient(nonce).toLong();
|
||||
this.gasPrice = Optional.ofNullable(gasPrice).map(Wei::fromHexString).orElse(null);
|
||||
@@ -124,6 +129,7 @@ public class StateTestVersionedTransaction {
|
||||
this.maxFeePerBlobGas =
|
||||
Optional.ofNullable(maxFeePerBlobGas).map(Wei::fromHexString).orElse(null);
|
||||
this.blobVersionedHashes = blobVersionedHashes;
|
||||
this.authorizationList = authorizationList;
|
||||
}
|
||||
|
||||
private static <T> List<T> parseArray(final String[] array, final Function<String, T> parseFct) {
|
||||
@@ -170,6 +176,7 @@ public class StateTestVersionedTransaction {
|
||||
// versioned hash string was bad, so this is an invalid transaction
|
||||
return null;
|
||||
}
|
||||
Optional.ofNullable(authorizationList).ifPresent(transactionBuilder::codeDelegations);
|
||||
|
||||
transactionBuilder.guessType();
|
||||
if (transactionBuilder.getTransactionType().requiresChainId()) {
|
||||
|
||||
Reference in New Issue
Block a user