@Override public void setTransactionHash(String transactionHash) { super.setTransactionHash(transactionHash); }
@SuppressWarnings("unchecked") protected TransactionReceipt prepareTransfer() throws IOException { TransactionReceipt transactionReceipt = new TransactionReceipt(); transactionReceipt.setTransactionHash(TRANSACTION_HASH); transactionReceipt.setStatus("0x1"); prepareTransaction(transactionReceipt); EthGasPrice ethGasPrice = new EthGasPrice(); ethGasPrice.setResult("0x1"); Request<?, EthGasPrice> gasPriceRequest = mock(Request.class); when(gasPriceRequest.send()).thenReturn(ethGasPrice); when(web3j.ethGasPrice()).thenReturn((Request) gasPriceRequest); return transactionReceipt; } }
private TransactionReceipt createTransactionReceiptWithStatus(String status) { TransactionReceipt transactionReceipt = new TransactionReceipt(); transactionReceipt.setTransactionHash(TRANSACTION_HASH); transactionReceipt.setContractAddress(ADDRESS); transactionReceipt.setStatus(status); transactionReceipt.setGasUsed("0x1"); return transactionReceipt; }
@Test(expected = RuntimeException.class) public void testDeployInvalidContractAddress() throws Throwable { TransactionReceipt transactionReceipt = new TransactionReceipt(); transactionReceipt.setTransactionHash(TRANSACTION_HASH); prepareTransaction(transactionReceipt); String encodedConstructor = FunctionEncoder.encodeConstructor( Arrays.<Type>asList(new Uint256(BigInteger.TEN))); try { TestContract.deployRemoteCall( TestContract.class, web3j, SampleKeys.CREDENTIALS, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT, "0xcafed00d", encodedConstructor, BigInteger.ZERO).send(); } catch (InterruptedException e) { throw e; } catch (ExecutionException e) { throw e.getCause(); } }
@Test public void testTransaction() throws Exception { TransactionReceipt transactionReceipt = new TransactionReceipt(); transactionReceipt.setTransactionHash(TRANSACTION_HASH); transactionReceipt.setStatus("0x1"); prepareTransaction(transactionReceipt); assertThat(contract.performTransaction( new Address(BigInteger.TEN), new Uint256(BigInteger.ONE)).send(), is(transactionReceipt)); }
@Test public void testTransactionFailed() throws Exception { thrown.expect(TransactionException.class); thrown.expectMessage( "Transaction has failed with status: 0x0. Gas used: 1. (not-enough gas?)"); TransactionReceipt transactionReceipt = new TransactionReceipt(); transactionReceipt.setTransactionHash(TRANSACTION_HASH); transactionReceipt.setStatus("0x0"); transactionReceipt.setGasUsed("0x1"); prepareTransaction(transactionReceipt); contract.performTransaction( new Address(BigInteger.TEN), new Uint256(BigInteger.ONE)).send(); }