private static <T extends Contract> T create( T contract, String binary, String encodedConstructor, BigInteger value) throws IOException, TransactionException { TransactionReceipt transactionReceipt = contract.executeTransaction(binary + encodedConstructor, value, FUNC_DEPLOY); String contractAddress = transactionReceipt.getContractAddress(); if (contractAddress == null) { throw new RuntimeException("Empty contract address returned"); } contract.setContractAddress(contractAddress); contract.setTransactionReceipt(transactionReceipt); return contract; }
@Override public int hashCode() { int result = getTransactionHash() != null ? getTransactionHash().hashCode() : 0; result = 31 * result + (transactionIndex != null ? transactionIndex.hashCode() : 0); result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); result = 31 * result + (blockNumber != null ? blockNumber.hashCode() : 0); result = 31 * result + (cumulativeGasUsed != null ? cumulativeGasUsed.hashCode() : 0); result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0); result = 31 * result + (getContractAddress() != null ? getContractAddress().hashCode() : 0); result = 31 * result + (getRoot() != null ? getRoot().hashCode() : 0); result = 31 * result + (getStatus() != null ? getStatus().hashCode() : 0); result = 31 * result + (getFrom() != null ? getFrom().hashCode() : 0); result = 31 * result + (getTo() != null ? getTo().hashCode() : 0); result = 31 * result + (getLogs() != null ? getLogs().hashCode() : 0); result = 31 * result + (getLogsBloom() != null ? getLogsBloom().hashCode() : 0); return result; }
return false; if (getContractAddress() != null ? !getContractAddress().equals(that.getContractAddress()) : that.getContractAddress() != null) { return false;
private String createContract( Credentials credentials, BigInteger initialSupply) throws Exception { String createTransactionHash = sendCreateContractTransaction(credentials, initialSupply); assertFalse(createTransactionHash.isEmpty()); TransactionReceipt createTransactionReceipt = waitForTransactionReceipt(createTransactionHash); assertThat(createTransactionReceipt.getTransactionHash(), is(createTransactionHash)); assertFalse("Contract execution ran out of gas", createTransactionReceipt.getGasUsed().equals(GAS_LIMIT)); String contractAddress = createTransactionReceipt.getContractAddress(); assertNotNull(contractAddress); return contractAddress; }
@Test public void testContractCreation() throws Exception { boolean accountUnlocked = unlockAccount(); assertTrue(accountUnlocked); String transactionHash = sendTransaction(); assertFalse(transactionHash.isEmpty()); TransactionReceipt transactionReceipt = waitForTransactionReceipt(transactionHash); assertThat(transactionReceipt.getTransactionHash(), is(transactionHash)); assertFalse("Contract execution ran out of gas", transactionReceipt.getGasUsed().equals(GAS_LIMIT)); String contractAddress = transactionReceipt.getContractAddress(); assertNotNull(contractAddress); Function function = createFibonacciFunction(); String responseValue = callSmartContractFunction(function, contractAddress); assertFalse(responseValue.isEmpty()); List<Type> uint = FunctionReturnDecoder.decode( responseValue, function.getOutputParameters()); assertThat(uint.size(), is(1)); assertThat(uint.get(0).getValue(), equalTo(BigInteger.valueOf(13))); }
@Test public void testGreeterContract() throws Exception { boolean accountUnlocked = unlockAccount(); assertTrue(accountUnlocked); // create our smart contract String createTransactionHash = sendCreateContractTransaction(); assertFalse(createTransactionHash.isEmpty()); TransactionReceipt createTransactionReceipt = waitForTransactionReceipt(createTransactionHash); assertThat(createTransactionReceipt.getTransactionHash(), is(createTransactionHash)); assertFalse("Contract execution ran out of gas", createTransactionReceipt.getGasUsed().equals(GAS_LIMIT)); String contractAddress = createTransactionReceipt.getContractAddress(); assertNotNull(contractAddress); // call our getter Function getFunction = createGreetFunction(); String responseValue = callSmartContractFunction(getFunction, contractAddress); assertFalse(responseValue.isEmpty()); List<Type> response = FunctionReturnDecoder.decode( responseValue, getFunction.getOutputParameters()); assertThat(response.size(), is(1)); assertThat(response.get(0).getValue(), is(VALUE)); }
); if (transReceipt != null) { return transReceipt.getContractAddress();
when(ethGetTransactionReceipt.getTransactionReceipt()).thenReturn(Optional.of(rawTransactionalRecept)); when(ethGetTransactionReceipt.getResult()).thenReturn(rawTransactionalRecept); when(rawTransactionalRecept.getContractAddress()).thenReturn("testContractAddress");
assertThat(transactionReceipt.getContractAddress()).isEqualTo(contractAddress);
private TransactionReceipt toReceipt(EthBlock.TransactionObject tx) { org.web3j.protocol.core.methods.response.TransactionReceipt receipt = web3JFacade.getReceipt(EthHash.of(tx.getHash())); boolean successful = !receipt.getGasUsed().equals(tx.getGas()); String error = ""; if(!successful) { error = "Error fromSeed RPC, all the gas was used"; } return new TransactionReceipt(EthHash.of(tx.getHash()), EthAddress.of(tx.getFrom()),EthAddress.of(tx.getTo()), EthAddress.of(receipt.getContractAddress()), error, EthData.empty(), successful); }