Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix guess type for delegate code transactions #8090

Merged
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 @@ -1300,14 +1300,14 @@ public Builder versionedHashes(final List<VersionedHash> versionedHashes) {
}

public Builder guessType() {
if (versionedHashes != null && !versionedHashes.isEmpty()) {
if (codeDelegationAuthorizations.isPresent()) {
transactionType = TransactionType.DELEGATE_CODE;
} else if (versionedHashes != null && !versionedHashes.isEmpty()) {
transactionType = TransactionType.BLOB;
} else if (maxPriorityFeePerGas != null || maxFeePerGas != null) {
transactionType = TransactionType.EIP1559;
} else if (accessList.isPresent()) {
transactionType = TransactionType.ACCESS_LIST;
} else if (codeDelegationAuthorizations.isPresent()) {
transactionType = TransactionType.DELEGATE_CODE;
} else {
transactionType = TransactionType.FRONTIER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
*/
package org.hyperledger.besu.ethereum.core;

import static java.util.stream.Collectors.toUnmodifiableSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.datatypes.VersionedHash.DEFAULT_VERSIONED_HASH;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream;

Expand All @@ -45,20 +46,51 @@ class TransactionBuilderTest {
@Test
void guessTypeCanGuessAllTypes() {
final BlockDataGenerator gen = new BlockDataGenerator();
final List<AccessListEntry> accessList =
List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32())));

final Transaction.Builder frontierBuilder = Transaction.builder();
final Transaction.Builder eip1559Builder = Transaction.builder().maxFeePerGas(Wei.of(5));
final Transaction.Builder accessListBuilder =
final Transaction.Builder accessListBuilder = Transaction.builder().accessList(accessList);

final Transaction.Builder eip1559Builder =
Transaction.builder().accessList(accessList).maxFeePerGas(Wei.of(5));

final Transaction.Builder blobBuilder =
Transaction.builder()
.accessList(accessList)
.maxFeePerGas(Wei.of(5))
.versionedHashes(List.of(DEFAULT_VERSIONED_HASH));

final CodeDelegation codeDelegation =
new CodeDelegation(
BigInteger.ZERO,
Address.ZERO,
0,
new SECPSignature(BigInteger.ZERO, BigInteger.ZERO, (byte) 0));

final Transaction.Builder delegateCodeBuilder =
Transaction.builder()
.accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32()))));
.accessList(accessList)
.maxFeePerGas(Wei.of(5))
.codeDelegations(List.of(codeDelegation));

final Set<TransactionType> guessedTypes =
Stream.of(frontierBuilder, eip1559Builder, accessListBuilder)
final List<TransactionType> guessedTypes =
Stream.of(
frontierBuilder,
accessListBuilder,
eip1559Builder,
blobBuilder,
delegateCodeBuilder)
.map(transactionBuilder -> transactionBuilder.guessType().getTransactionType())
.collect(toUnmodifiableSet());
.toList();

assertThat(guessedTypes)
.containsExactlyInAnyOrder(
TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559);
.containsExactly(
TransactionType.FRONTIER,
TransactionType.ACCESS_LIST,
TransactionType.EIP1559,
TransactionType.BLOB,
TransactionType.DELEGATE_CODE);
}

@Test
Expand Down
Loading