|
|
|
@ -79,7 +79,8 @@ public class TransactionSimulatorTest { |
|
|
|
|
|
|
|
|
|
private static final Address DEFAULT_FROM = |
|
|
|
|
Address.fromHexString("0x0000000000000000000000000000000000000000"); |
|
|
|
|
private static final long GASCAP = 500L; |
|
|
|
|
private static final long GAS_CAP = 500000L; |
|
|
|
|
private static final long TRANSFER_GAS_LIMIT = 21000L; |
|
|
|
|
private TransactionSimulator transactionSimulator; |
|
|
|
|
private TransactionSimulator cappedTransactionSimulator; |
|
|
|
|
|
|
|
|
@ -96,7 +97,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
this.transactionSimulator = |
|
|
|
|
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, 0); |
|
|
|
|
this.cappedTransactionSimulator = |
|
|
|
|
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, GASCAP); |
|
|
|
|
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, GAS_CAP); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -124,7 +125,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(callParameter.getGasPrice()) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -155,7 +156,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(Wei.ZERO) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -175,7 +176,8 @@ public class TransactionSimulatorTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldSetFeePerGasToZeroWhenExceedingBalanceAllowed() { |
|
|
|
|
final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ONE, Wei.ONE); |
|
|
|
|
final CallParameter callParameter = |
|
|
|
|
eip1559TransactionCallParameter(Wei.ONE, Wei.ONE, TRANSFER_GAS_LIMIT); |
|
|
|
|
|
|
|
|
|
final BlockHeader blockHeader = mockBlockHeader(Hash.ZERO, 1L, Wei.ONE); |
|
|
|
|
|
|
|
|
@ -187,7 +189,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(TRANSFER_GAS_LIMIT) |
|
|
|
|
.maxFeePerGas(Wei.ZERO) |
|
|
|
|
.maxPriorityFeePerGas(Wei.ZERO) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
@ -223,7 +225,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(callParameter.getGasPrice()) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -244,7 +246,8 @@ public class TransactionSimulatorTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldNotSetFeePerGasToZeroWhenExceedingBalanceIsNotAllowed() { |
|
|
|
|
final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ONE, Wei.ONE); |
|
|
|
|
final CallParameter callParameter = |
|
|
|
|
eip1559TransactionCallParameter(Wei.ONE, Wei.ONE, TRANSFER_GAS_LIMIT); |
|
|
|
|
|
|
|
|
|
final BlockHeader blockHeader = mockBlockHeader(Hash.ZERO, 1L, Wei.ONE); |
|
|
|
|
|
|
|
|
@ -256,7 +259,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(TRANSFER_GAS_LIMIT) |
|
|
|
|
.maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow()) |
|
|
|
|
.maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
@ -349,7 +352,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(callParameter.getGasPrice()) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -390,7 +393,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(callParameter.getGasPrice()) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -479,7 +482,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.FRONTIER) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasPrice(callParameter.getGasPrice()) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
@ -509,7 +512,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasLimit(callParameter.getGasLimit()) |
|
|
|
|
.gasLimit(blockHeader.getGasLimit()) |
|
|
|
|
.maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow()) |
|
|
|
|
.maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
@ -530,7 +533,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
@Test |
|
|
|
|
public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() { |
|
|
|
|
final CallParameter callParameter = |
|
|
|
|
eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, GASCAP + 1); |
|
|
|
|
eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, GAS_CAP + 1); |
|
|
|
|
|
|
|
|
|
final BlockHeader blockHeader = mockBlockHeader(Hash.ZERO, 1L, Wei.ONE); |
|
|
|
|
|
|
|
|
@ -542,7 +545,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasLimit(GASCAP) |
|
|
|
|
.gasLimit(GAS_CAP) |
|
|
|
|
.maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow()) |
|
|
|
|
.maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
@ -566,11 +569,48 @@ public class TransactionSimulatorTest { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldUseRpcGasCapWhenCapIsHigherThanGasLimit() { |
|
|
|
|
// generate a transaction with a gas limit that is lower than the gas cap,
|
|
|
|
|
// expect the gas cap to override parameter gas limit
|
|
|
|
|
public void shouldUseProvidedGasLimitWhenBelowRpcCapGas() { |
|
|
|
|
final CallParameter callParameter = |
|
|
|
|
eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, GASCAP - 1); |
|
|
|
|
eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, GAS_CAP / 2); |
|
|
|
|
|
|
|
|
|
final BlockHeader blockHeader = mockBlockHeader(Hash.ZERO, 1L, Wei.ONE); |
|
|
|
|
|
|
|
|
|
mockBlockchainForBlockHeader(blockHeader); |
|
|
|
|
mockWorldStateForAccount(blockHeader, callParameter.getFrom(), 1L); |
|
|
|
|
|
|
|
|
|
final Transaction expectedTransaction = |
|
|
|
|
Transaction.builder() |
|
|
|
|
.type(TransactionType.EIP1559) |
|
|
|
|
.chainId(BigInteger.ONE) |
|
|
|
|
.nonce(1L) |
|
|
|
|
.gasLimit(GAS_CAP / 2) |
|
|
|
|
.maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow()) |
|
|
|
|
.maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow()) |
|
|
|
|
.to(callParameter.getTo()) |
|
|
|
|
.sender(callParameter.getFrom()) |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
|
.payload(callParameter.getPayload()) |
|
|
|
|
.signature(FAKE_SIGNATURE) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
mockProtocolSpecForProcessWithWorldUpdater(); |
|
|
|
|
|
|
|
|
|
// call process with original transaction
|
|
|
|
|
cappedTransactionSimulator.process( |
|
|
|
|
callParameter, |
|
|
|
|
TransactionValidationParams.transactionSimulator(), |
|
|
|
|
OperationTracer.NO_TRACING, |
|
|
|
|
1L); |
|
|
|
|
|
|
|
|
|
// expect overwritten transaction to be processed
|
|
|
|
|
verifyTransactionWasProcessed(expectedTransaction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldUseRpcGasCapWhenGasLimitNoPresent() { |
|
|
|
|
// generate call parameters that do not specify a gas limit,
|
|
|
|
|
// expect the rpc gas cap to be used for simulation
|
|
|
|
|
final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, -1); |
|
|
|
|
|
|
|
|
|
final BlockHeader blockHeader = mockBlockHeader(Hash.ZERO, 1L, Wei.ONE); |
|
|
|
|
|
|
|
|
@ -591,7 +631,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
.value(callParameter.getValue()) |
|
|
|
|
.payload(callParameter.getPayload()) |
|
|
|
|
.signature(FAKE_SIGNATURE) |
|
|
|
|
.gasLimit(GASCAP) |
|
|
|
|
.gasLimit(GAS_CAP) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
// call process with original transaction
|
|
|
|
@ -781,7 +821,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
return new CallParameter( |
|
|
|
|
Address.fromHexString("0x0"), |
|
|
|
|
Address.fromHexString("0x0"), |
|
|
|
|
0, |
|
|
|
|
-1, |
|
|
|
|
gasPrice, |
|
|
|
|
Wei.of(0), |
|
|
|
|
Bytes.EMPTY); |
|
|
|
@ -793,7 +833,7 @@ public class TransactionSimulatorTest { |
|
|
|
|
|
|
|
|
|
private CallParameter eip1559TransactionCallParameter( |
|
|
|
|
final Wei maxFeePerGas, final Wei maxPriorityFeePerGas) { |
|
|
|
|
return eip1559TransactionCallParameter(maxFeePerGas, maxPriorityFeePerGas, 0L); |
|
|
|
|
return eip1559TransactionCallParameter(maxFeePerGas, maxPriorityFeePerGas, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private CallParameter eip1559TransactionCallParameter( |
|
|
|
|