diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index ff4c15c034a..fb9a7d4e632 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -84,8 +84,10 @@ private JsonCallParameter overrideGasLimitAndPrice( private Function gasEstimateResponse( final JsonRpcRequestContext request) { return result -> - new JsonRpcSuccessResponse( - request.getRequest().getId(), Quantity.create(result.getGasEstimate())); + result.isSuccessful() + ? new JsonRpcSuccessResponse( + request.getRequest().getId(), Quantity.create(result.getGasEstimate())) + : null; } private JsonRpcErrorResponse errorResponse(final JsonRpcRequestContext request) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 37c7eb94504..c1669723977 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -83,9 +83,9 @@ public void shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty() { } @Test - public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResult() { + public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResultSuccess() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); - mockTransientProcessorResultGasEstimate(1L); + mockTransientProcessorResultGasEstimate(1L, true); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Quantity.create(1L)); @@ -93,11 +93,25 @@ public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResul .isEqualToComparingFieldByField(expectedResponse); } - private void mockTransientProcessorResultGasEstimate(final long gasEstimate) { + @Test + public void shouldReturnGasEstimateErrorWhenTransientTransactionProcessorReturnsResultFailure() { + final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); + mockTransientProcessorResultGasEstimate(1L, false); + + final JsonRpcResponse expectedResponse = + new JsonRpcErrorResponse(null, JsonRpcError.INTERNAL_ERROR); + + Assertions.assertThat(method.response(request)) + .isEqualToComparingFieldByField(expectedResponse); + } + + private void mockTransientProcessorResultGasEstimate( + final long gasEstimate, final boolean isSuccessful) { final TransactionSimulatorResult result = mock(TransactionSimulatorResult.class); when(result.getGasEstimate()).thenReturn(gasEstimate); when(transactionSimulator.process(eq(modifiedCallParameter()), eq(1L))) .thenReturn(Optional.of(result)); + when(result.isSuccessful()).thenReturn(isSuccessful); } private JsonCallParameter callParameter() {