From 4d1ee886bbc4644c9ded3aef16cd243e41c3fe6e Mon Sep 17 00:00:00 2001 From: Anthony Buckle Date: Thu, 20 Feb 2020 23:15:50 -0330 Subject: [PATCH 1/5] BESU-146 - check if success and return errorResponse otherwise Signed-off-by: Anthony Buckle --- .../ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..0e3e68256ed 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,8 @@ 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) { From 931aab876ca96d02e4c36af57f09ee741c5d6aad Mon Sep 17 00:00:00 2001 From: Anthony Buckle Date: Thu, 20 Feb 2020 23:49:40 -0330 Subject: [PATCH 2/5] BESU-146 - applied spotless Signed-off-by: Anthony Buckle --- .../api/jsonrpc/internal/methods/EthEstimateGas.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 0e3e68256ed..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 -> - result.isSuccessful() ? new JsonRpcSuccessResponse( - request.getRequest().getId(), Quantity.create(result.getGasEstimate())) : null; + result.isSuccessful() + ? new JsonRpcSuccessResponse( + request.getRequest().getId(), Quantity.create(result.getGasEstimate())) + : null; } private JsonRpcErrorResponse errorResponse(final JsonRpcRequestContext request) { From 11c33570a77ec936acb39e3dfec3d5f56afa129b Mon Sep 17 00:00:00 2001 From: Anthony Buckle Date: Fri, 21 Feb 2020 06:25:32 -0330 Subject: [PATCH 3/5] BESU-146 - corrected gas estimate test case Signed-off-by: Anthony Buckle --- .../api/jsonrpc/internal/methods/EthEstimateGasTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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..c9cd960fbe2 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 @@ -85,7 +85,7 @@ public void shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty() { @Test public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResult() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); - mockTransientProcessorResultGasEstimate(1L); + mockTransientProcessorResultGasEstimate(1L, true); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Quantity.create(1L)); @@ -93,11 +93,12 @@ public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResul .isEqualToComparingFieldByField(expectedResponse); } - private void mockTransientProcessorResultGasEstimate(final long gasEstimate) { + 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() { From 47ba91e17a25c763fa363344de15e6977302b10e Mon Sep 17 00:00:00 2001 From: Anthony Buckle Date: Fri, 21 Feb 2020 06:31:46 -0330 Subject: [PATCH 4/5] BESU-146 - applied spotless Signed-off-by: Anthony Buckle --- .../api/jsonrpc/internal/methods/EthEstimateGasTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 c9cd960fbe2..4246c8d8c80 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 @@ -93,7 +93,8 @@ public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResul .isEqualToComparingFieldByField(expectedResponse); } - private void mockTransientProcessorResultGasEstimate(final long gasEstimate, final boolean isSuccessful) { + 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))) From a2136f549a1084c86f22ce18cb03642eb3db7d73 Mon Sep 17 00:00:00 2001 From: Anthony Buckle Date: Fri, 21 Feb 2020 20:29:09 -0330 Subject: [PATCH 5/5] BESU-146 - added failure test case for gas estimate Signed-off-by: Anthony Buckle --- .../internal/methods/EthEstimateGasTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 4246c8d8c80..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,7 +83,7 @@ public void shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty() { } @Test - public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResult() { + public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResultSuccess() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); mockTransientProcessorResultGasEstimate(1L, true); @@ -93,6 +93,18 @@ public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResul .isEqualToComparingFieldByField(expectedResponse); } + @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);