Nc 1145 Acceptance test for getTransactionReceipt JSON-RPC method (#278)

* EthGetTransactionReceipt Acceptance test added

* GetTransactionReceipt Acceptance Test updated to conform to new dsl

* Update to new dsl

* Update to new dsl

* Update to new dsl - spotless applied

* Naming convention corrected

* Naming convention corrected
Deleted obsolete test cases
added assertion for status code

* Naming convention corrected
Deleted obsolete test cases
added assertion for status code

* Naming convention corrected

* Removed sender field to make test more efficient

* Removed sender field to make test more efficient
Michael Connor 6 years ago committed by GitHub
parent 33ac7e1ec9
commit c555993648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthGetTransactionReceiptIsAbsent.java
  2. 40
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectSuccessfulEthGetTransactionReceipt.java
  3. 13
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java
  4. 45
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java
  5. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java
  6. 48
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetTransactionReceiptAcceptanceTest.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<TransactionReceipt> response = node.execute(transaction);
assertThat(response.isPresent()).isFalse();
}
}

@ -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<TransactionReceipt> response = node.execute(transaction);
assertThat(response.isPresent()).isTrue();
assertThat(response.get().getStatus()).isEqualToIgnoringCase("0x1");
}
}

@ -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 class Eth {
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));
}
}

@ -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<Optional<TransactionReceipt>> {
private final String input;
EthGetTransactionReceiptTransaction(final String input) {
this.input = input;
}
@Override
public Optional<TransactionReceipt> 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);
}
}
}

@ -31,4 +31,8 @@ public class EthTransactions {
public EthAccountsTransaction accounts() {
return new EthAccountsTransaction();
}
public EthGetTransactionReceiptTransaction getTransactionReceipt(final String transactionHash) {
return new EthGetTransactionReceiptTransaction(transactionHash);
}
}

@ -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"));
}
}
Loading…
Cancel
Save