Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BESU-146 - return better gas estimate service error message if possible #436

Merged
merged 5 commits into from
Mar 5, 2020

Conversation

anthonybuckle
Copy link
Contributor

@anthonybuckle anthonybuckle commented Feb 29, 2020

Signed-off-by: Anthony Buckle anthonybuckle@gmail.com

PR description

Here is a suggestion to improve gas estimate service error messages concerning jira ticket BESU-146.

Fixed Issue(s)

Fixes: https://jira.hyperledger.org/browse/BESU-146

Signed-off-by: Anthony Buckle <anthonybuckle@gmail.com>
Signed-off-by: Anthony Buckle <anthonybuckle@gmail.com>
@CjHare
Copy link
Contributor

CjHare commented Mar 2, 2020

It would be good to see an addition test in EthEstimateGasTest that covers the flow you've changed i.e an error is encountered by the function returned by gasEstimateResponse().

@anthonybuckle
Copy link
Contributor Author

Hi CjHare, Thanks for the feedback and no problem. Are you referring to the case where gasEstimateResponse(requestContext) fails and returns a null value. That would lead line 68 orElse(errorResponse(requestContext, JsonRpcError.INTERNAL_ERROR)) returning an error response. It would need a test case. Do you know any good ways to make gasEstimateResponse(requestContext) fail in the test cases using when().thenReturn(). Those methods are private in the class.

@CjHare
Copy link
Contributor

CjHare commented Mar 3, 2020

Ah, actually I was thinking a test for the flow that goes through line 93 (the replacement of null for errorResponse(request, result.getValidationResult());, where the result is unsuccessful and the validation result would be something other than INTERNAL_ERROR.

The case you raise is a also good one, let me ponder over it 🤔

@CjHare
Copy link
Contributor

CjHare commented Mar 3, 2020

@anthonybuckle, I suspect the case you mention (the orElse() on line 68) may already be covered by shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty()

@CjHare
Copy link
Contributor

CjHare commented Mar 3, 2020

This test would cover the additional flow incorporating the simulation validation result 🙂

  @Test
  public void shouldReturnErrorWhenTransactionProcessorReturnsUnsuccessfulSimulation() {
    final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter());
    setupUnsuccessfulSimulation(UPFRONT_COST_EXCEEDS_BALANCE);

    final JsonRpcResponse expectedResponse =
        new JsonRpcErrorResponse(null, JsonRpcError.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);

    Assertions.assertThat(method.response(request))
        .isEqualToComparingFieldByField(expectedResponse);
  }

  private void setupUnsuccessfulSimulation(final TransactionValidator.TransactionInvalidReason reason){
    final  TransactionSimulatorResult simulation = mock(TransactionSimulatorResult.class);
    when(simulation.isSuccessful()).thenReturn(false);
    when(simulation.getValidationResult()).thenReturn( ValidationResult.invalid(reason));
    when(transactionSimulator.process(eq(modifiedCallParameter()), eq(1L)))
        .thenReturn(Optional.of( simulation ));
  }

Signed-off-by: Anthony Buckle <anthonybuckle@gmail.com>
Signed-off-by: Anthony Buckle <anthonybuckle@gmail.com>
@anthonybuckle
Copy link
Contributor Author

Hi @CjHare, I confirmed that test case shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty does handle the orElse() case. I also added the exceeds balance test case as you suggested. Thanks for your help. Cheers.

@CjHare CjHare merged commit 7bc8bb4 into hyperledger:master Mar 5, 2020
@timbeiko
Copy link
Contributor

@anthonybuckle if you'd like this change included in the release notes, please add a line about it to the changelog. Thanks!

@anthonybuckle
Copy link
Contributor Author

@anthonybuckle if you'd like this change included in the release notes, please add a line about it to the changelog. Thanks!

@timbeiko Sure no problem. A PR for the updated changelog is here: #451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants