### Question:
EthCall extends AbstractBlockParameterMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return (JsonRpcResponse) findResultByParamType(requestContext); } EthCall(
      final BlockchainQueries blockchainQueries, final TransactionSimulator transactionSimulator); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void shouldThrowInvalidJsonRpcParametersExceptionWhenMissingToField() { final CallParameter callParameter = new JsonCallParameter("0x0", null, "0x0", "0x0", "0x0", ""); final JsonRpcRequestContext request = ethCallRequest(callParameter, "latest"); final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) .hasNoCause() .hasMessage("Missing \"to\" field in call arguments"); }
@Test public void shouldReturnNullWhenProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, null); when(transactionSimulator.process(any(), anyLong())).thenReturn(Optional.empty()); final JsonRpcResponse response = method.response(request); assertThat(response).isEqualToComparingFieldByField(expectedResponse); verify(transactionSimulator).process(any(), anyLong()); }
@Test public void shouldAcceptRequestWhenMissingOptionalFields() { final CallParameter callParameter = new JsonCallParameter(null, "0x0", null, null, null, null); final JsonRpcRequestContext request = ethCallRequest(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Bytes.of().toString()); mockTransactionProcessorSuccessResult(Bytes.of()); final JsonRpcResponse response = method.response(request); assertThat(response).isEqualToComparingFieldByFieldRecursively(expectedResponse); verify(transactionSimulator).process(eq(callParameter), anyLong()); }
@Test public void shouldReturnExecutionResultWhenExecutionIsSuccessful() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Bytes.of(1).toString()); mockTransactionProcessorSuccessResult(Bytes.of(1)); final JsonRpcResponse response = method.response(request); assertThat(response).isEqualToComparingFieldByFieldRecursively(expectedResponse); verify(transactionSimulator).process(eq(callParameter()), anyLong()); }
@Test public void shouldUseCorrectBlockNumberWhenLatest() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); when(blockchainQueries.headBlockNumber()).thenReturn(11L); when(transactionSimulator.process(any(), anyLong())).thenReturn(Optional.empty()); method.response(request); verify(transactionSimulator).process(any(), eq(11L)); }
@Test public void shouldUseCorrectBlockNumberWhenEarliest() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "earliest"); when(transactionSimulator.process(any(), anyLong())).thenReturn(Optional.empty()); method.response(request); verify(transactionSimulator).process(any(), eq(0L)); }
@Test public void shouldUseCorrectBlockNumberWhenSpecified() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), Quantity.create(13L)); when(transactionSimulator.process(any(), anyLong())).thenReturn(Optional.empty()); method.response(request); verify(transactionSimulator).process(any(), eq(13L)); }