|
40 | 40 | import org.hyperledger.besu.ethereum.core.BlockHeader; |
41 | 41 | import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; |
42 | 42 | import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
| 43 | +import org.hyperledger.besu.ethereum.core.CodeDelegation; |
43 | 44 | import org.hyperledger.besu.ethereum.core.Difficulty; |
44 | 45 | import org.hyperledger.besu.ethereum.core.MiningConfiguration; |
45 | 46 | import org.hyperledger.besu.ethereum.core.MutableWorldState; |
|
59 | 60 | import org.hyperledger.besu.evm.account.Account; |
60 | 61 | import org.hyperledger.besu.evm.account.MutableAccount; |
61 | 62 | import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; |
| 63 | +import org.hyperledger.besu.evm.tracing.OperationTracer; |
62 | 64 | import org.hyperledger.besu.evm.worldstate.WorldUpdater; |
63 | 65 |
|
64 | 66 | import java.math.BigInteger; |
| 67 | +import java.util.List; |
65 | 68 | import java.util.Map; |
66 | 69 | import java.util.Optional; |
67 | 70 | import java.util.OptionalLong; |
@@ -923,6 +926,47 @@ public void shouldSimulateLegacyTransactionWhenBaseFeeNotZero() { |
923 | 926 | assertThat(result.get().isSuccessful()).isTrue(); |
924 | 927 | } |
925 | 928 |
|
| 929 | + @Test |
| 930 | + public void shouldGuessDelegateCodeTransactionTypeWhenAuthorizationsPresent() { |
| 931 | + final CodeDelegation delegation = |
| 932 | + new CodeDelegation(BigInteger.ONE, Address.fromHexString("0x1"), 42L, FAKE_SIGNATURE); |
| 933 | + |
| 934 | + final CallParameter callParameter = |
| 935 | + legacyTransactionCallParameterBuilder() |
| 936 | + .codeDelegationAuthorizations(List.of(delegation)) |
| 937 | + .build(); |
| 938 | + |
| 939 | + final BlockHeader blockHeader = mockBlockchainAndWorldState(callParameter); |
| 940 | + |
| 941 | + mockProtocolSpecForProcessWithWorldUpdater(); |
| 942 | + |
| 943 | + final Transaction expectedTx = |
| 944 | + Transaction.builder() |
| 945 | + .chainId(BigInteger.ONE) |
| 946 | + .nonce(1L) |
| 947 | + .gasLimit(blockHeader.getGasLimit()) |
| 948 | + .sender(callParameter.getSender().orElseThrow()) |
| 949 | + .to(callParameter.getTo().orElseThrow()) |
| 950 | + .value(callParameter.getValue().orElseThrow()) |
| 951 | + .payload(callParameter.getPayload().orElseThrow()) |
| 952 | + .signature(FAKE_SIGNATURE) |
| 953 | + .codeDelegations(List.of(delegation)) |
| 954 | + .guessType() |
| 955 | + .build(); |
| 956 | + |
| 957 | + mockProcessorStatusForTransaction(expectedTx, Status.SUCCESSFUL); |
| 958 | + |
| 959 | + final Optional<TransactionSimulatorResult> result = |
| 960 | + uncappedTransactionSimulator.process( |
| 961 | + callParameter, |
| 962 | + TransactionValidationParams.transactionSimulator(), |
| 963 | + OperationTracer.NO_TRACING, |
| 964 | + blockHeader); |
| 965 | + |
| 966 | + assertThat(result).isPresent(); |
| 967 | + assertThat(result.get().transaction().getType()).isEqualTo(TransactionType.DELEGATE_CODE); |
| 968 | + } |
| 969 | + |
926 | 970 | private BlockHeader mockBlockchainAndWorldState(final CallParameter callParameter) { |
927 | 971 | final BlockHeader blockHeader = |
928 | 972 | mockBlockHeader(Hash.ZERO, 1L, Wei.ONE, DEFAULT_BLOCK_GAS_LIMIT); |
|
0 commit comments