Skip to content

Commit

Permalink
fix pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Karim TAAM <[email protected]>
  • Loading branch information
matkt committed Jun 17, 2021
1 parent 89fc16b commit 796217c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class EthCallIntegrationTest {
public static void setUpOnce() throws Exception {
final String genesisJson =
Resources.toString(BlockTestUtil.getTestGenesisUrl(), Charsets.UTF_8);

BLOCKCHAIN =
new JsonRpcTestMethodsFactory(
new BlockchainImporter(BlockTestUtil.getTestBlockchainUrl(), genesisJson));
Expand All @@ -65,7 +66,6 @@ public void setUp() {

@Test
public void shouldReturnExpectedResultForCallAtLatestBlock() {

final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class EthCallIntegrationTest {
public static void setUpOnce() throws Exception {
final String genesisJson =
Resources.toString(BlockTestUtil.getTestLondonGenesisUrl(), Charsets.UTF_8);

BLOCKCHAIN =
new JsonRpcTestMethodsFactory(
new BlockchainImporter(BlockTestUtil.getTestLondonBlockchainUrl(), genesisJson));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext r
if (callParams.getTo() == null) {
throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments");
}
if (callParams.getGasPrice() != null
&& (callParams.getMaxFeePerGas().isPresent()
|| callParams.getMaxPriorityFeePerGas().isPresent())) {
throw new InvalidJsonRpcParameters(
"gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
}
return callParams;
}

Expand All @@ -141,7 +147,8 @@ private TransactionValidationParams buildTransactionValidationParams(

// if it is not set explicitly whether we want a strict check of the balance or not. this will
// be decided according to the provided parameters
if (callParams.isStrict().isEmpty()) {

if (callParams.isMaybeStrict().isEmpty()) {

boolean isZeroGasPrice =
callParams.getGasPrice() == null || Wei.ZERO.equals(callParams.getGasPrice());
Expand Down Expand Up @@ -170,7 +177,7 @@ private TransactionValidationParams buildTransactionValidationParams(
});
} else {
transactionValidationParams.isAllowExceedingBalance(
!callParams.isStrict().orElse(Boolean.FALSE));
!callParams.isMaybeStrict().orElse(Boolean.FALSE));
}
return transactionValidationParams.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
modifiedCallParams,
ImmutableTransactionValidationParams.builder()
.from(TransactionValidationParams.transactionSimulator())
.isAllowExceedingBalance(!callParams.isStrict().orElse(Boolean.FALSE))
.isAllowExceedingBalance(!callParams.isMaybeStrict().orElse(Boolean.FALSE))
.build(),
operationTracer,
blockHeader.getNumber())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public JsonCallParameter(
this.strict = Optional.ofNullable(strict);
}

public Optional<Boolean> isStrict() {
public Optional<Boolean> isMaybeStrict() {
return strict;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gasPrice": "0x10000000000000"
"gasPrice": "0x10000000000000",
"strict": false
},
"0x8"
]
Expand All @@ -17,6 +18,19 @@
"id": 4,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gasPrice": "0x10000000000000"
},
"0x8"
]
},
{
"id": 5,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
Expand All @@ -41,6 +55,14 @@
"code": -32004,
"message": "Upfront cost exceeds account balance"
}
},
{
"jsonrpc": "2.0",
"id": 5,
"error": {
"code": -32004,
"message": "Upfront cost exceeds account balance"
}
}
],
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,13 @@ public Optional<TransactionSimulatorResult> process(

if (header.getBaseFee().isEmpty()) {
transactionBuilder.gasPrice(gasPrice);
} else {
if (protocolSchedule.getChainId().isEmpty()) {
return Optional.empty();
}
} else if (protocolSchedule.getChainId().isPresent()) {
transactionBuilder
.chainId(protocolSchedule.getChainId().orElseThrow())
.maxFeePerGas(callParams.getMaxFeePerGas().orElse(gasPrice))
.maxPriorityFeePerGas(callParams.getMaxPriorityFeePerGas().orElse(gasPrice));
} else {
return Optional.empty();
}

transactionBuilder.guessType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,14 @@ public void shouldReturnFailureResultWhenProcessingFailsByHash() {
public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSuccessful() {
final CallParameter callParameter = eip1559TransactionCallParameter();

mockBlockchainForBlockHeader(Hash.ZERO, 1L);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, Hash.ZERO, 1L);
mockWorldStateForAccount(Hash.ZERO, callParameter.getFrom(), 1L);

final Transaction expectedTransaction =
Transaction.builder()
.nonce(1L)
.gasPrice(callParameter.getGasPrice())
.chainId(BigInteger.ONE)
.type(TransactionType.EIP1559)
.gasLimit(callParameter.getGasLimit())
.maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow())
.maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow())
Expand Down Expand Up @@ -451,12 +452,24 @@ private void mockBlockchainForBlockHeader(
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getStateRoot()).thenReturn(stateRoot);
when(blockHeader.getNumber()).thenReturn(blockNumber);
when(blockHeader.getBaseFee()).thenReturn(Optional.of(0L));
when(blockchain.getBlockHeader(blockNumber)).thenReturn(Optional.of(blockHeader));
when(blockchain.getBlockHeader(headerHash)).thenReturn(Optional.of(blockHeader));
}

private void mockBlockchainForBlockHeader(
final Hash stateRoot, final long blockNumber, final Hash headerHash, final long baseFee) {
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getStateRoot()).thenReturn(stateRoot);
when(blockHeader.getNumber()).thenReturn(blockNumber);
when(blockHeader.getBaseFee()).thenReturn(Optional.of(baseFee));
when(blockchain.getBlockHeader(blockNumber)).thenReturn(Optional.of(blockHeader));
when(blockchain.getBlockHeader(headerHash)).thenReturn(Optional.of(blockHeader));
}

private void mockProcessorStatusForTransaction(
final long blockNumber, final Transaction transaction, final Status status) {
when(protocolSchedule.getChainId()).thenReturn(Optional.of(BigInteger.ONE));
when(protocolSchedule.getByBlockNumber(eq(blockNumber))).thenReturn(protocolSpec);
when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(BlockHeader::getCoinbase);
Expand Down

0 comments on commit 796217c

Please sign in to comment.