Skip to content

Commit

Permalink
Support authorizationList parsing in reference tests for execution-sp…
Browse files Browse the repository at this point in the history
…ec-tests

Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Jan 14, 2025
1 parent b797f2e commit 770b7a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
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;
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;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CodeDelegation implements org.hyperledger.besu.datatypes.CodeDelegation {
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
Expand Down Expand Up @@ -77,14 +81,23 @@ public CodeDelegation(
*/
@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -103,7 +106,9 @@ public 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);
Expand All @@ -124,6 +129,7 @@ public 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) {
Expand Down Expand Up @@ -170,6 +176,7 @@ public Transaction get(final GeneralStateTestCaseSpec.Indexes indexes) {
// 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()) {
Expand Down

0 comments on commit 770b7a9

Please sign in to comment.