diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java index 8ebbb1aa70..b2c47dadaa 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java @@ -13,23 +13,32 @@ package tech.pegasys.pantheon.tests.acceptance.dsl; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Accounts; +import tech.pegasys.pantheon.tests.acceptance.dsl.blockchain.Blockchain; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Cluster; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Web3Transactions; import org.junit.After; public class AcceptanceTestBase { protected final Accounts accounts; + protected final Blockchain blockchain; protected final Cluster cluster; - protected final Transactions transactions; + protected final EthTransactions eth; protected final JsonRpc jsonRpc; + protected final Transactions transactions; + protected final Web3Transactions web3; protected AcceptanceTestBase() { - accounts = new Accounts(); + eth = new EthTransactions(); + accounts = new Accounts(eth); + blockchain = new Blockchain(eth); cluster = new Cluster(); - transactions = new Transactions(accounts); jsonRpc = new JsonRpc(cluster); + transactions = new Transactions(accounts); + web3 = new Web3Transactions(); } @After diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Account.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Account.java index 0b3433f5ab..31496f5fc4 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Account.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Account.java @@ -18,6 +18,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ExpectAccountBalance; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; import tech.pegasys.pantheon.util.bytes.Bytes32; import java.math.BigInteger; @@ -27,21 +28,25 @@ import org.web3j.utils.Convert.Unit; public class Account { + private final EthTransactions eth; private final String name; private final KeyPair keyPair; private long nonce = 0; - private Account(final String name, final KeyPair keyPair) { + private Account(final EthTransactions eth, final String name, final KeyPair keyPair) { this.name = name; this.keyPair = keyPair; + this.eth = eth; } - public static Account create(final String name) { - return new Account(name, KeyPair.generate()); + public static Account create(final EthTransactions eth, final String name) { + return new Account(eth, name, KeyPair.generate()); } - public static Account fromPrivateKey(final String name, final String privateKey) { - return new Account(name, KeyPair.create(PrivateKey.create(Bytes32.fromHexString(privateKey)))); + static Account fromPrivateKey( + final EthTransactions eth, final String name, final String privateKey) { + return new Account( + eth, name, KeyPair.create(PrivateKey.create(Bytes32.fromHexString(privateKey)))); } public Credentials web3jCredentials() { @@ -66,7 +71,7 @@ public class Account { } public Condition balanceEquals(final String expectedBalance, final Unit balanceUnit) { - return new ExpectAccountBalance(this, expectedBalance, balanceUnit); + return new ExpectAccountBalance(eth, this, expectedBalance, balanceUnit); } public Condition balanceEquals(final int expectedBalance) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Accounts.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Accounts.java index a002c02c64..ddb28abf07 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Accounts.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Accounts.java @@ -12,18 +12,24 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.account; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; + public class Accounts { + private final EthTransactions eth; private final Account richBenefactorOne; private final Account richBenefactorTwo; - public Accounts() { + public Accounts(final EthTransactions eth) { + this.eth = eth; richBenefactorOne = Account.fromPrivateKey( + eth, "Rich Benefactor One", "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"); richBenefactorTwo = Account.fromPrivateKey( + eth, "Rich Benefactor Two", "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"); } @@ -37,6 +43,6 @@ public class Accounts { } public Account createAccount(final String accountName) { - return Account.create(accountName); + return Account.create(eth, accountName); } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/blockchain/Blockchain.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/blockchain/Blockchain.java new file mode 100644 index 0000000000..7c0d7bbd08 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/blockchain/Blockchain.java @@ -0,0 +1,31 @@ +/* + * 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.blockchain; + +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ExpectMinimumBlockNumber; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; + +public class Blockchain { + + private final EthTransactions eth; + + public Blockchain(final EthTransactions eth) { + this.eth = eth; + } + + public Condition blockNumberMustBeLatest(final Node node) { + return new ExpectMinimumBlockNumber(eth, node.execute(eth.blockNumber())); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectAccountBalance.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectAccountBalance.java index b92246df8e..38a3072e7c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectAccountBalance.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectAccountBalance.java @@ -18,27 +18,33 @@ import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; import org.web3j.utils.Convert.Unit; public class ExpectAccountBalance implements Condition { + private final EthTransactions eth; private final Account account; private final String expectedBalance; private final Unit balanceUnit; public ExpectAccountBalance( - final Account account, final String expectedBalance, final Unit balanceUnit) { + final EthTransactions eth, + final Account account, + final String expectedBalance, + final Unit balanceUnit) { this.expectedBalance = expectedBalance; this.balanceUnit = balanceUnit; this.account = account; + this.eth = eth; } @Override public void verify(final Node node) { waitFor( () -> - assertThat(node.getAccountBalance(account)) + assertThat(node.execute(eth.getBalance((account)))) .isEqualTo(toWei(expectedBalance, balanceUnit).toBigIntegerExact())); } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectMinimumBlockNumber.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectMinimumBlockNumber.java new file mode 100644 index 0000000000..79580c8b8b --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ExpectMinimumBlockNumber.java @@ -0,0 +1,36 @@ +/* + * 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; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; + +import java.math.BigInteger; + +public class ExpectMinimumBlockNumber implements Condition { + + private final EthTransactions eth; + private final BigInteger blockNumber; + + public ExpectMinimumBlockNumber(final EthTransactions eth, final BigInteger blockNumber) { + this.blockNumber = blockNumber; + this.eth = eth; + } + + @Override + public void verify(final Node node) { + assertThat(node.execute(eth.blockNumber())).isGreaterThanOrEqualTo(blockNumber); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Eth.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Eth.java deleted file mode 100644 index 057034d90b..0000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Eth.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.node; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.math.BigInteger; - -import org.web3j.protocol.Web3j; -import org.web3j.protocol.core.methods.response.EthBlockNumber; -import org.web3j.protocol.core.methods.response.EthGetWork; - -public class Eth { - - private final Web3j web3j; - - public Eth(final Web3j web3) { - this.web3j = web3; - } - - public BigInteger blockNumber() throws IOException { - final EthBlockNumber result = web3j.ethBlockNumber().send(); - assertThat(result).isNotNull(); - assertThat(result.hasError()).isFalse(); - return result.getBlockNumber(); - } - - public String[] getWork() throws IOException { - final EthGetWork result = web3j.ethGetWork().send(); - assertThat(result).isNotNull(); - return new String[] { - result.getCurrentBlockHeaderPowHash(), - result.getSeedHashForDag(), - result.getBoundaryCondition() - }; - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Node.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Node.java index bbccde6966..a029506ff9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Node.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/Node.java @@ -12,14 +12,9 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.node; -import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; -import java.math.BigInteger; - public interface Node { T execute(Transaction transaction); - - BigInteger getAccountBalance(Account account); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index cca53949ea..ca946401b5 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -15,20 +15,18 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.node; import static org.apache.logging.log4j.LogManager.getLogger; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; -import static org.web3j.protocol.core.DefaultBlockParameterName.LATEST; import tech.pegasys.pantheon.controller.KeyPairUtil; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.math.BigInteger; import java.net.ConnectException; import java.nio.file.Files; import java.nio.file.Path; @@ -45,7 +43,6 @@ import org.apache.logging.log4j.Logger; import org.java_websocket.exceptions.WebsocketNotConnectedException; import org.web3j.protocol.Web3j; import org.web3j.protocol.Web3jService; -import org.web3j.protocol.core.methods.response.EthGetBalance; import org.web3j.protocol.http.HttpService; import org.web3j.protocol.websocket.WebSocketService; import org.web3j.utils.Async; @@ -67,7 +64,6 @@ public class PantheonNode implements Node, AutoCloseable { private final Properties portsProperties = new Properties(); private List bootnodes = new ArrayList<>(); - private Eth eth; private Web3 web3; private Web3j web3j; @@ -145,8 +141,7 @@ public class PantheonNode implements Node, AutoCloseable { return web3j; } - @Deprecated - public Web3j web3j(final Web3jService web3jService) { + private Web3j web3j(final Web3jService web3jService) { if (web3j == null) { web3j = Web3j.build(web3jService, 2000, Async.defaultExecutorService()); } @@ -154,17 +149,6 @@ public class PantheonNode implements Node, AutoCloseable { return web3j; } - @Override - public BigInteger getAccountBalance(final Account account) { - try { - final EthGetBalance balanceResponse = - web3j().ethGetBalance(account.getAddress(), LATEST).send(); - return balanceResponse.getBalance(); - } catch (final IOException e) { - throw new RuntimeException(e); - } - } - public int getPeerCount() { try { return web3j().netPeerCount().send().getQuantity().intValueExact(); @@ -305,7 +289,6 @@ public class PantheonNode implements Node, AutoCloseable { web3j = null; } - eth = null; web3 = null; } @@ -327,16 +310,12 @@ public class PantheonNode implements Node, AutoCloseable { return web3; } - public Eth eth() { - if (eth == null) { - eth = new Eth(web3j()); - } - - return eth; - } - @Override public T execute(final Transaction transaction) { return transaction.execute(web3j()); } + + public void verify(final Condition expected) { + expected.verify(this); + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthBlockNumberTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthBlockNumberTransaction.java new file mode 100644 index 0000000000..fee3bf8a74 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthBlockNumberTransaction.java @@ -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.transaction; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.math.BigInteger; + +import org.web3j.protocol.Web3j; + +public class EthBlockNumberTransaction implements Transaction { + + EthBlockNumberTransaction() {} + + @Override + public BigInteger execute(final Web3j node) { + try { + final org.web3j.protocol.core.methods.response.EthBlockNumber result = + node.ethBlockNumber().send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getBlockNumber(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetBalanceTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetBalanceTransaction.java new file mode 100644 index 0000000000..b65e992ff9 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetBalanceTransaction.java @@ -0,0 +1,47 @@ +/* + * 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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.web3j.protocol.core.DefaultBlockParameterName.LATEST; + +import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; + +import java.io.IOException; +import java.math.BigInteger; + +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.methods.response.EthGetBalance; + +public class EthGetBalanceTransaction implements Transaction { + + private final Account account; + + EthGetBalanceTransaction(final Account account) { + this.account = account; + } + + @Override + public BigInteger execute(final Web3j node) { + try { + final EthGetBalance result = node.ethGetBalance(account.getAddress(), LATEST).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + + return result.getBalance(); + + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetWorkTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetWorkTransaction.java new file mode 100644 index 0000000000..4cb97a4454 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthGetWorkTransaction.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.transaction; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; + +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.methods.response.EthGetWork; + +public class EthGetWorkTransaction implements Transaction { + + EthGetWorkTransaction() {} + + @Override + public String[] execute(final Web3j node) { + try { + final EthGetWork result = node.ethGetWork().send(); + assertThat(result).isNotNull(); + return new String[] { + result.getCurrentBlockHeaderPowHash(), + result.getSeedHashForDag(), + result.getBoundaryCondition() + }; + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthTransactions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthTransactions.java new file mode 100644 index 0000000000..d0087c8cdc --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/EthTransactions.java @@ -0,0 +1,30 @@ +/* + * 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; + +import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; + +public class EthTransactions { + + public EthGetWorkTransaction getWork() { + return new EthGetWorkTransaction(); + } + + public EthBlockNumberTransaction blockNumber() { + return new EthBlockNumberTransaction(); + } + + public EthGetBalanceTransaction getBalance(final Account account) { + return new EthGetBalanceTransaction(account); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Sha3Transaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Sha3Transaction.java new file mode 100644 index 0000000000..c1fedd80f3 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Sha3Transaction.java @@ -0,0 +1,41 @@ +/* + * 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; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; + +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.methods.response.Web3Sha3; + +public class Web3Sha3Transaction implements Transaction { + + private final String input; + + Web3Sha3Transaction(final String input) { + this.input = input; + } + + @Override + public String execute(final Web3j node) { + try { + final Web3Sha3 result = node.web3Sha3(input).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Transactions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Transactions.java new file mode 100644 index 0000000000..7c333e9a80 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Web3Transactions.java @@ -0,0 +1,20 @@ +/* + * 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; + +public class Web3Transactions { + + public Web3Sha3Transaction sha3(final String input) { + return new Web3Sha3Transaction(input); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetWorkAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetWorkAcceptanceTest.java index 58db8fabd1..cdba399fbc 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetWorkAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetWorkAcceptanceTest.java @@ -37,15 +37,15 @@ public class EthGetWorkAcceptanceTest extends AcceptanceTestBase { } @Test - public void shouldReturnSuccessResponseWhenMining() throws Exception { - final String[] response = minerNode.eth().getWork(); + public void shouldReturnSuccessResponseWhenMining() { + final String[] response = minerNode.execute(eth.getWork()); assertThat(response).hasSize(3); assertThat(response).doesNotContainNull(); } @Test public void shouldReturnErrorResponseWhenNotMining() { - final Throwable thrown = catchThrowable(() -> fullNode.eth().getWork()); + final Throwable thrown = catchThrowable(() -> fullNode.execute(eth.getWork())); assertThat(thrown).isInstanceOf(ClientConnectionException.class); assertThat(thrown.getMessage()).contains("No mining work available yet"); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/Web3Sha3AcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/Web3Sha3AcceptanceTest.java index 459c8c78e7..a4fb059d0f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/Web3Sha3AcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/Web3Sha3AcceptanceTest.java @@ -38,7 +38,7 @@ public class Web3Sha3AcceptanceTest extends AcceptanceTestBase { final String input = "0x68656c6c6f20776f726c64"; final String sha3 = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"; - final String response = node.web3().web3Sha3(input); + final String response = node.execute(web3.sha3(input)); assertThat(response).isEqualTo(sha3); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java index d676d8f0f1..42572a969b 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java @@ -12,19 +12,17 @@ */ package tech.pegasys.pantheon.tests.acceptance.pubsub; -import static org.assertj.core.api.Assertions.assertThat; import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonMinerNode; import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonNode; 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.condition.Condition; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; import tech.pegasys.pantheon.tests.acceptance.dsl.pubsub.Subscription; import tech.pegasys.pantheon.tests.acceptance.dsl.pubsub.WebSocket; -import java.math.BigInteger; - import io.vertx.core.Vertx; import org.junit.After; import org.junit.Before; @@ -69,7 +67,7 @@ public class NewPendingTransactionAcceptanceTest extends AcceptanceTestBase { minerWebSocket.verifyTotalEventsReceived(1); lightForkSubscription.verifyEventReceived(lightForkEvent); - final BigInteger lighterForkBlockNumber = minerNode.eth().blockNumber(); + final Condition atLeastLighterForkBlockNumber = blockchain.blockNumberMustBeLatest(minerNode); cluster.stop(); @@ -100,7 +98,8 @@ public class NewPendingTransactionAcceptanceTest extends AcceptanceTestBase { heavyForkSubscription.verifyEventReceived(heavyForkEventTwo); heavyForkSubscription.verifyEventReceived(heavyForkEventThree); - final BigInteger heavierForkBlockNumber = minerNodeTwo.eth().blockNumber(); + final Condition atLeastHeavierForkBlockNumber = + blockchain.blockNumberMustBeLatest(minerNodeTwo); cluster.stop(); @@ -115,9 +114,9 @@ public class NewPendingTransactionAcceptanceTest extends AcceptanceTestBase { final Subscription archiveMergedForksSubscription = archiveMergedForksWebSocket.subscribe(); // Check that all node have loaded their respective forks, i.e. not begin new chains - assertThat(minerNode.eth().blockNumber()).isGreaterThanOrEqualTo(lighterForkBlockNumber); - assertThat(archiveNode.eth().blockNumber()).isGreaterThanOrEqualTo(lighterForkBlockNumber); - assertThat(minerNodeTwo.eth().blockNumber()).isGreaterThanOrEqualTo(heavierForkBlockNumber); + minerNode.verify(atLeastLighterForkBlockNumber); + archiveNode.verify(atLeastLighterForkBlockNumber); + minerNodeTwo.verify(atLeastHeavierForkBlockNumber); // This publish give time needed for heavy fork to be chosen final Hash mergedForksEventOne =