Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@
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;

// 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);
Expand Down Expand Up @@ -77,14 +82,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 @@ -38,8 +38,8 @@ public BigInteger deserialize(final JsonParser jsonparser, final Deserialization
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;
}
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