Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

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

Merged
merged 20 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1ff064a
EthGetTransactionReceipt Acceptance test added
Shinabyss Nov 4, 2018
2146a6a
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Shinabyss Nov 4, 2018
ef0db70
GetTransactionReceipt Acceptance Test updated to conform to new dsl
Shinabyss Nov 4, 2018
85d70a3
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Shinabyss Nov 18, 2018
7c46e78
Update to new dsl
Shinabyss Nov 18, 2018
984dd7d
Update to new dsl
Shinabyss Nov 19, 2018
5f9135b
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Shinabyss Nov 19, 2018
a3ec974
Update to new dsl - spotless applied
Shinabyss Nov 19, 2018
4549355
Naming convention corrected
Shinabyss Nov 20, 2018
8f1193d
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Shinabyss Nov 20, 2018
90ffc61
Naming convention corrected
Shinabyss Nov 20, 2018
e404973
Naming convention corrected
Shinabyss Nov 20, 2018
4929caf
Merge remote-tracking branch 'origin/NC-1145' into NC-1145
Shinabyss Nov 20, 2018
1a581a4
Merge branch 'master' into NC-1145
Shinabyss Nov 20, 2018
41c6026
Naming convention corrected
Shinabyss Nov 20, 2018
b4c1054
Removed sender field to make test more efficient
Shinabyss Nov 20, 2018
e07ef34
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Shinabyss Nov 20, 2018
01f3339
Merge remote-tracking branch 'origin/NC-1145' into NC-1145
Shinabyss Nov 20, 2018
d0653fc
Removed sender field to make test more efficient
Shinabyss Nov 20, 2018
42beaf4
Merge branch 'master' into NC-1145
Shinabyss Nov 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 ExpectEthGetTransactionRecieptNull implements Condition {
Shinabyss marked this conversation as resolved.
Show resolved Hide resolved

private final EthGetTransactionReceiptTransaction transaction;

public ExpectEthGetTransactionRecieptNull(final EthGetTransactionReceiptTransaction transaction) {
this.transaction = transaction;
}

@Override
public void verify(final Node node) {
final Optional<TransactionReceipt> response = node.execute(transaction);
assertThat(response.isPresent()).isFalse();
}
}
Original file line number Diff line number Diff line change
@@ -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 SanityCheckEthGetTransactionReceiptValues implements Condition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't doing any sanity checking - just checking it's present so probably should just be ExpectEthGetTransactionReceiptPresent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed


private final EthGetTransactionReceiptTransaction transaction;

public SanityCheckEthGetTransactionReceiptValues(
final EthGetTransactionReceiptTransaction transaction) {
this.transaction = transaction;
}

@Override
public void verify(final Node node) {
final Optional<TransactionReceipt> response = node.execute(transaction);
assertThat(response.isPresent()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

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.ExpectEthGetTransactionRecieptNull;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthGetWorkException;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.SanityCheckEthGetTransactionReceiptValues;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.SanityCheckEthGetWorkValues;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;

Expand All @@ -37,4 +39,12 @@ public Condition getWorkExceptional(final String expectedMessage) {
public Condition accountsExceptional(final String expectedMessage) {
return new ExpectEthAccountsException(transactions.accounts(), expectedMessage);
}

public Condition getTransactionReceipt(final String param) {
return new SanityCheckEthGetTransactionReceiptValues(transactions.getTransactionReceipt(param));
}

public Condition getTransactionReceiptNull(final String param) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param should have a meaningful name - maybe transactionHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

return new ExpectEthGetTransactionRecieptNull(transactions.getTransactionReceipt(param));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public EthGetBalanceTransaction getBalance(final Account account) {
public EthAccountsTransaction accounts() {
return new EthAccountsTransaction();
}

public EthGetTransactionReceiptTransaction getTransactionReceipt(final String param) {
return new EthGetTransactionReceiptTransaction(param);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 sender;
private Account recipient;

@Before
public void setUp() throws Exception {
sender = accounts.createAccount("sender");
recipient = accounts.createAccount("recipient");
minerNode = pantheon.createMinerNode("node");
cluster.start(minerNode);
minerNode.execute(transactions.createTransfer(sender, 10));
cluster.verify(sender.balanceEquals(10));
}

@Test
public void mustCorrectlyQueryTransactionReceiptFromContractCreationTransaction() {
final Hash transactionHash = minerNode.execute(transactions.createTransfer(recipient, 5));
Shinabyss marked this conversation as resolved.
Show resolved Hide resolved
cluster.verify(recipient.balanceEquals(5));
minerNode.verify(eth.getTransactionReceipt(transactionHash.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming-wise this would probably be better as:
minerNode.verify(eth.transactionReceiptIsAvailable(transactionHash))

You shouldn't need to call toString() in the test - the DSL should accept the actual Hash and convert to a string itself if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed and moved toString() into DSL

}

@Test
public void mustCorrectlyQueryTransactionReceiptFromNormalTransaction() {
Shinabyss marked this conversation as resolved.
Show resolved Hide resolved
final Hash transactionHash =
minerNode.execute(transactions.createTransfer(sender, recipient, 5));
cluster.verify(recipient.balanceEquals(5));
minerNode.verify(eth.getTransactionReceipt(transactionHash.toString()));
}

@Test
public void mustReturnNullWhenTransactionDoesNotExist() {
Shinabyss marked this conversation as resolved.
Show resolved Hide resolved
minerNode.verify(
eth.getTransactionReceiptNull(
"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would be better as minerNode.verify(eth.transactionReceiptNotAvailable("...")). Using a string here is probably sensible since the test is simpler that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed test to be more succinct

}
}