diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthGetTransactionReceiptIsAbsent.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthGetTransactionReceiptIsAbsent.java new file mode 100644 index 0000000000..6ea5ffca35 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthGetTransactionReceiptIsAbsent.java @@ -0,0 +1,39 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthGetTransactionReceiptTransaction; + +import java.util.Optional; + +import org.web3j.protocol.core.methods.response.TransactionReceipt; + +public class ExpectEthGetTransactionReceiptIsAbsent implements Condition { + + private final EthGetTransactionReceiptTransaction transaction; + + public ExpectEthGetTransactionReceiptIsAbsent( + final EthGetTransactionReceiptTransaction transaction) { + this.transaction = transaction; + } + + @Override + public void verify(final Node node) { + final Optional response = node.execute(transaction); + assertThat(response.isPresent()).isFalse(); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceipt.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceipt.java new file mode 100644 index 0000000000..de435048a5 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceipt.java @@ -0,0 +1,40 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthGetTransactionReceiptTransaction; + +import java.util.Optional; + +import org.web3j.protocol.core.methods.response.TransactionReceipt; + +public class ExpectSuccessfulEthGetTransactionReceipt implements Condition { + + private final EthGetTransactionReceiptTransaction transaction; + + public ExpectSuccessfulEthGetTransactionReceipt( + final EthGetTransactionReceiptTransaction transaction) { + this.transaction = transaction; + } + + @Override + public void verify(final Node node) { + final Optional response = node.execute(transaction); + assertThat(response.isPresent()).isTrue(); + assertThat(response.get().getStatus()).isEqualToIgnoringCase("0x1"); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java index 82a24a26aa..10ee67b239 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java @@ -12,9 +12,12 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc; +import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthAccountsException; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthGetTransactionReceiptIsAbsent; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthGetWorkException; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectSuccessfulEthGetTransactionReceipt; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.SanityCheckEthGetWorkValues; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; @@ -37,4 +40,14 @@ public Condition getWorkExceptional(final String expectedMessage) { public Condition accountsExceptional(final String expectedMessage) { return new ExpectEthAccountsException(transactions.accounts(), expectedMessage); } + + public Condition expectSuccessfulTransactionReceipt(final Hash transactionHash) { + return new ExpectSuccessfulEthGetTransactionReceipt( + transactions.getTransactionReceipt(transactionHash.toString())); + } + + public Condition expectNoTransactionReceipt(final String transactionHash) { + return new ExpectEthGetTransactionReceiptIsAbsent( + transactions.getTransactionReceipt(transactionHash)); + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java new file mode 100644 index 0000000000..085f02ba93 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java @@ -0,0 +1,45 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; +import java.util.Optional; + +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt; +import org.web3j.protocol.core.methods.response.TransactionReceipt; + +public class EthGetTransactionReceiptTransaction + implements Transaction> { + + private final String input; + + EthGetTransactionReceiptTransaction(final String input) { + this.input = input; + } + + @Override + public Optional execute(final Web3j node) { + try { + final EthGetTransactionReceipt result = node.ethGetTransactionReceipt(input).send(); + assertThat(result.hasError()).isFalse(); + return result.getTransactionReceipt(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java index 80dec048c0..9cf73a95e1 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java @@ -31,4 +31,8 @@ public EthGetBalanceTransaction getBalance(final Account account) { public EthAccountsTransaction accounts() { return new EthAccountsTransaction(); } + + public EthGetTransactionReceiptTransaction getTransactionReceipt(final String transactionHash) { + return new EthGetTransactionReceiptTransaction(transactionHash); + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetTransactionReceiptAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetTransactionReceiptAcceptanceTest.java new file mode 100644 index 0000000000..638c57db94 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetTransactionReceiptAcceptanceTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.acceptance.jsonrpc; + +import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; + +import org.junit.Before; +import org.junit.Test; + +public class EthGetTransactionReceiptAcceptanceTest extends AcceptanceTestBase { + + private PantheonNode minerNode; + private Account recipient; + + @Before + public void setUp() throws Exception { + recipient = accounts.createAccount("recipient"); + minerNode = pantheon.createMinerNode("node"); + cluster.start(minerNode); + } + + @Test + public void transactionMustHaveReceipt() { + final Hash transactionHash = minerNode.execute(transactions.createTransfer(recipient, 5)); + cluster.verify(recipient.balanceEquals(5)); + minerNode.verify(eth.expectSuccessfulTransactionReceipt(transactionHash)); + } + + @Test + public void imaginaryTransactionMustHaveNoReceipt() { + minerNode.verify( + eth.expectNoTransactionReceipt( + "0x0000000000000000000000000000000000000000000000000000000000000000")); + } +}