Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 8d2eb69

Browse files
Gabriel-Trintinaliagaryschulte
authored andcommitted
Fix guess type for delegate code transactions (#8090)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
1 parent 506fa71 commit 8d2eb69

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,14 @@ public Builder versionedHashes(final List<VersionedHash> versionedHashes) {
13001300
}
13011301

13021302
public Builder guessType() {
1303-
if (versionedHashes != null && !versionedHashes.isEmpty()) {
1303+
if (codeDelegationAuthorizations.isPresent()) {
1304+
transactionType = TransactionType.DELEGATE_CODE;
1305+
} else if (versionedHashes != null && !versionedHashes.isEmpty()) {
13041306
transactionType = TransactionType.BLOB;
13051307
} else if (maxPriorityFeePerGas != null || maxFeePerGas != null) {
13061308
transactionType = TransactionType.EIP1559;
13071309
} else if (accessList.isPresent()) {
13081310
transactionType = TransactionType.ACCESS_LIST;
1309-
} else if (codeDelegationAuthorizations.isPresent()) {
1310-
transactionType = TransactionType.DELEGATE_CODE;
13111311
} else {
13121312
transactionType = TransactionType.FRONTIER;
13131313
}

ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.core;
1616

17-
import static java.util.stream.Collectors.toUnmodifiableSet;
1817
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.hyperledger.besu.datatypes.VersionedHash.DEFAULT_VERSIONED_HASH;
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.fail;
2121

2222
import org.hyperledger.besu.crypto.KeyPair;
23+
import org.hyperledger.besu.crypto.SECPSignature;
2324
import org.hyperledger.besu.crypto.SignatureAlgorithm;
2425
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
2526
import org.hyperledger.besu.datatypes.AccessListEntry;
27+
import org.hyperledger.besu.datatypes.Address;
2628
import org.hyperledger.besu.datatypes.TransactionType;
2729
import org.hyperledger.besu.datatypes.Wei;
2830
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
2931

3032
import java.math.BigInteger;
3133
import java.util.List;
3234
import java.util.Optional;
33-
import java.util.Set;
3435
import java.util.function.Supplier;
3536
import java.util.stream.Stream;
3637

@@ -45,20 +46,51 @@ class TransactionBuilderTest {
4546
@Test
4647
void guessTypeCanGuessAllTypes() {
4748
final BlockDataGenerator gen = new BlockDataGenerator();
49+
final List<AccessListEntry> accessList =
50+
List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32())));
51+
4852
final Transaction.Builder frontierBuilder = Transaction.builder();
49-
final Transaction.Builder eip1559Builder = Transaction.builder().maxFeePerGas(Wei.of(5));
50-
final Transaction.Builder accessListBuilder =
53+
final Transaction.Builder accessListBuilder = Transaction.builder().accessList(accessList);
54+
55+
final Transaction.Builder eip1559Builder =
56+
Transaction.builder().accessList(accessList).maxFeePerGas(Wei.of(5));
57+
58+
final Transaction.Builder blobBuilder =
59+
Transaction.builder()
60+
.accessList(accessList)
61+
.maxFeePerGas(Wei.of(5))
62+
.versionedHashes(List.of(DEFAULT_VERSIONED_HASH));
63+
64+
final CodeDelegation codeDelegation =
65+
new CodeDelegation(
66+
BigInteger.ZERO,
67+
Address.ZERO,
68+
0,
69+
new SECPSignature(BigInteger.ZERO, BigInteger.ZERO, (byte) 0));
70+
71+
final Transaction.Builder delegateCodeBuilder =
5172
Transaction.builder()
52-
.accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32()))));
73+
.accessList(accessList)
74+
.maxFeePerGas(Wei.of(5))
75+
.codeDelegations(List.of(codeDelegation));
5376

54-
final Set<TransactionType> guessedTypes =
55-
Stream.of(frontierBuilder, eip1559Builder, accessListBuilder)
77+
final List<TransactionType> guessedTypes =
78+
Stream.of(
79+
frontierBuilder,
80+
accessListBuilder,
81+
eip1559Builder,
82+
blobBuilder,
83+
delegateCodeBuilder)
5684
.map(transactionBuilder -> transactionBuilder.guessType().getTransactionType())
57-
.collect(toUnmodifiableSet());
85+
.toList();
5886

5987
assertThat(guessedTypes)
60-
.containsExactlyInAnyOrder(
61-
TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559);
88+
.containsExactly(
89+
TransactionType.FRONTIER,
90+
TransactionType.ACCESS_LIST,
91+
TransactionType.EIP1559,
92+
TransactionType.BLOB,
93+
TransactionType.DELEGATE_CODE);
6294
}
6395

6496
@Test

0 commit comments

Comments
 (0)