### Question:
EthEstimateGas implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final JsonCallParameter callParams = requestContext.getRequiredParameter(0, JsonCallParameter.class); final BlockHeader blockHeader = blockHeader(); if (blockHeader == null) { return errorResponse(requestContext, JsonRpcError.INTERNAL_ERROR); } final JsonCallParameter modifiedCallParams = overrideGasLimitAndPrice(callParams, blockHeader.getGasLimit()); final EstimateGasOperationTracer operationTracer = new EstimateGasOperationTracer(); return transactionSimulator .process(modifiedCallParams, operationTracer, blockHeader.getNumber()) .map(gasEstimateResponse(requestContext, operationTracer)) .orElse(errorResponse(requestContext, JsonRpcError.INTERNAL_ERROR)); } EthEstimateGas(
      final BlockchainQueries blockchainQueries, final TransactionSimulator transactionSimulator); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void shouldReturnErrorWhenTransientTransactionProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); when(transactionSimulator.process( eq(modifiedCallParameter()), any(OperationTracer.class), eq(1L))) .thenReturn(Optional.empty()); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, JsonRpcError.INTERNAL_ERROR); Assertions.assertThat(method.response(request)) .isEqualToComparingFieldByField(expectedResponse); }
@Test public void shouldReturnGasEstimateWhenTransientTransactionProcessorReturnsResultSuccess() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); mockTransientProcessorResultGasEstimate(1L, true); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Quantity.create(1L)); Assertions.assertThat(method.response(request)) .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); }
@Test public void shouldReturnErrorWhenTransactionProcessorReturnsTxInvalidReason() { final JsonRpcRequestContext request = ethEstimateGasRequest(callParameter()); mockTransientProcessorResultTxInvalidReason( TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, JsonRpcError.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); Assertions.assertThat(method.response(request)) .isEqualToComparingFieldByField(expectedResponse); }