@ -44,6 +44,8 @@ import org.hyperledger.besu.ethereum.transaction.CallParameter;
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason ;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator ;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult ;
import org.hyperledger.besu.ethereum.util.AccountOverride ;
import org.hyperledger.besu.ethereum.util.AccountOverrideMap ;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive ;
import org.hyperledger.besu.evm.tracing.OperationTracer ;
@ -99,12 +101,44 @@ public class EthEstimateGasTest {
assertThat ( method . getName ( ) ) . isEqualTo ( "eth_estimateGas" ) ;
}
@Test
public void noAccountOverrides ( ) {
final Wei gasPrice = Wei . of ( 1000 ) ;
final JsonRpcRequestContext request =
ethEstimateGasRequest ( defaultLegacyTransactionCallParameter ( gasPrice ) , "latest" ) ;
Optional < AccountOverrideMap > overrideMap = method . getAddressAccountOverrideMap ( request ) ;
assertThat ( overrideMap . isPresent ( ) ) . isFalse ( ) ;
}
@Test
public void someAccountOverrides ( ) {
AccountOverrideMap expectedOverrides = new AccountOverrideMap ( ) ;
AccountOverride override = new AccountOverride . Builder ( ) . withNonce ( 88L ) . build ( ) ;
final Address address = Address . fromHexString ( "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3" ) ;
expectedOverrides . put ( address , override ) ;
final Wei gasPrice = Wei . of ( 1000 ) ;
final JsonRpcRequestContext request =
ethEstimateGasRequestWithStateOverrides (
defaultLegacyTransactionCallParameter ( gasPrice ) , "latest" , expectedOverrides ) ;
Optional < AccountOverrideMap > maybeOverrideMap = method . getAddressAccountOverrideMap ( request ) ;
assertThat ( maybeOverrideMap . isPresent ( ) ) . isTrue ( ) ;
AccountOverrideMap overrideMap = maybeOverrideMap . get ( ) ;
assertThat ( overrideMap . keySet ( ) ) . hasSize ( 1 ) ;
assertThat ( overrideMap . values ( ) ) . hasSize ( 1 ) ;
assertThat ( overrideMap ) . containsKey ( address ) ;
assertThat ( overrideMap ) . containsValue ( override ) ;
}
@Test
public void shouldReturnErrorWhenTransientLegacyTransactionProcessorReturnsEmpty ( ) {
final JsonRpcRequestContext request =
ethEstimateGasRequest ( defaultLegacyTransactionCallParameter ( Wei . ZERO ) ) ;
when ( transactionSimulator . process (
eq ( modifiedLegacyTransactionCallParameter ( Wei . ZERO ) ) ,
eq ( Optional . empty ( ) ) , // no account overrides
any ( TransactionValidationParams . class ) ,
any ( OperationTracer . class ) ,
eq ( latestBlockHeader ) ) )
@ -341,6 +375,7 @@ public class EthEstimateGasTest {
verify ( transactionSimulator )
. process (
eq ( modifiedLegacyTransactionCallParameter ( Wei . ZERO ) ) ,
eq ( Optional . empty ( ) ) , // no account overrides
eq (
ImmutableTransactionValidationParams . builder ( )
. from ( TransactionValidationParams . transactionSimulator ( ) )
@ -361,6 +396,7 @@ public class EthEstimateGasTest {
verify ( transactionSimulator )
. process (
eq ( modifiedLegacyTransactionCallParameter ( Wei . ZERO ) ) ,
eq ( Optional . empty ( ) ) , // no account overrides
eq (
ImmutableTransactionValidationParams . builder ( )
. from ( TransactionValidationParams . transactionSimulator ( ) )
@ -461,12 +497,14 @@ public class EthEstimateGasTest {
final TransactionSimulatorResult mockTxSimResult = mock ( TransactionSimulatorResult . class ) ;
when ( transactionSimulator . process (
eq ( modifiedLegacyTransactionCallParameter ( gasPrice ) ) ,
eq ( Optional . empty ( ) ) , // no account overrides
any ( TransactionValidationParams . class ) ,
any ( OperationTracer . class ) ,
eq ( blockHeader ) ) )
. thenReturn ( Optional . of ( mockTxSimResult ) ) ;
when ( transactionSimulator . process (
eq ( modifiedEip1559TransactionCallParameter ( ) ) ,
eq ( Optional . empty ( ) ) , // no account overrides
any ( TransactionValidationParams . class ) ,
any ( OperationTracer . class ) ,
eq ( blockHeader ) ) )
@ -551,4 +589,13 @@ public class EthEstimateGasTest {
return new JsonRpcRequestContext (
new JsonRpcRequest ( "2.0" , "eth_estimateGas" , new Object [ ] { callParameter , blockParam } ) ) ;
}
private JsonRpcRequestContext ethEstimateGasRequestWithStateOverrides (
final CallParameter callParameter ,
final String blockParam ,
final AccountOverrideMap overrides ) {
return new JsonRpcRequestContext (
new JsonRpcRequest (
"2.0" , "eth_estimateGas" , new Object [ ] { callParameter , blockParam , overrides } ) ) ;
}
}