/** * Perform request asynchronously with a future. * * @return a future containing our function */ public CompletableFuture<T> sendAsync() { return Async.run(this::send); }
@Override public <T extends Response> CompletableFuture<T> sendAsync( Request jsonRpc20Request, Class<T> responseType) { return Async.run(() -> send(jsonRpc20Request, responseType)); }
@Test(expected = ExecutionException.class) public void testRunException() throws Exception { Async.run(() -> { throw new RuntimeException(""); }).get(); } }
@Test public void testRun() throws Exception { assertThat(Async.run(() -> "").get(), is("")); }
@Test(expected = RuntimeException.class) @SuppressWarnings("unchecked") public void testInvalidTransactionResponse() throws Throwable { prepareNonceRequest(); EthSendTransaction ethSendTransaction = new EthSendTransaction(); ethSendTransaction.setError(new Response.Error(1, "Invalid transaction")); Request<?, EthSendTransaction> rawTransactionRequest = mock(Request.class); when(rawTransactionRequest.sendAsync()).thenReturn(Async.run(() -> ethSendTransaction)); when(web3j.ethSendRawTransaction(any(String.class))) .thenReturn((Request) rawTransactionRequest); testErrorScenario(); }
@Test(expected = RuntimeException.class) @SuppressWarnings("unchecked") public void testInvalidTransactionReceipt() throws Throwable { prepareNonceRequest(); prepareTransactionRequest(); EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(); ethGetTransactionReceipt.setError(new Response.Error(1, "Invalid transaction receipt")); Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class); when(getTransactionReceiptRequest.sendAsync()) .thenReturn(Async.run(() -> ethGetTransactionReceipt)); when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH)) .thenReturn((Request) getTransactionReceiptRequest); testErrorScenario(); }