Acceptance test - refactor JsonRpc to use conditionals (#204)

CJ Hare 6 years ago committed by GitHub
parent 42d69d89ce
commit 697171d429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/CreateAccountAcceptanceTest.java
  2. 32
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java
  3. 24
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java
  4. 12
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Account.java
  5. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/account/Accounts.java
  6. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/blockchain/Blockchain.java
  7. 5
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/account/ExpectAccountBalance.java
  8. 5
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/blockchain/ExpectMinimumBlockNumber.java
  9. 41
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthAccountsException.java
  10. 41
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/ExpectEthGetWorkException.java
  11. 35
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eth/SanityCheckEthGetWorkValues.java
  12. 44
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/net/ExpectNetVersionConnectionException.java
  13. 38
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/net/ExpectNetVersionConnectionExceptionWithCause.java
  14. 33
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/net/ExpectNetVersionIsNotBlank.java
  15. 35
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/web3/ExpectWeb3Sha3Equals.java
  16. 40
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eth.java
  17. 3
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/JsonRpc.java
  18. 40
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Net.java
  19. 30
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Web3.java
  20. 91
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java
  21. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Transactions.java
  22. 3
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransaction.java
  23. 3
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionSet.java
  24. 27
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthAccountsTransaction.java
  25. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthBlockNumberTransaction.java
  26. 3
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBalanceTransaction.java
  27. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetWorkTransaction.java
  28. 6
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthTransactions.java
  29. 20
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetTransactions.java
  30. 39
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetVersionTransaction.java
  31. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Sha3Transaction.java
  32. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Transactions.java
  33. 11
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/EthGetWorkAcceptanceTest.java
  34. 12
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/Web3Sha3AcceptanceTest.java

@ -28,13 +28,11 @@ import org.junit.Test;
public class CreateAccountAcceptanceTest extends AcceptanceTestBase {
private PantheonNode minerNode;
private PantheonNode fullNode;
@Before
public void setUp() throws Exception {
minerNode = cluster.create(pantheonMinerNode("node1"));
fullNode = cluster.create(pantheonNode("node2"));
cluster.start(minerNode, fullNode);
cluster.start(minerNode, cluster.create(pantheonNode("node2")));
}
@Test

@ -12,8 +12,6 @@
*/
package tech.pegasys.pantheon.tests.acceptance;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonNode;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonRpcDisabledNode;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.patheonNodeWithRpcApis;
@ -22,11 +20,10 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import org.java_websocket.exceptions.WebsocketNotConnectedException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.exceptions.ClientConnectionException;
@Ignore
public class RpcApisTogglesAcceptanceTest extends AcceptanceTestBase {
@ -45,37 +42,40 @@ public class RpcApisTogglesAcceptanceTest extends AcceptanceTestBase {
@Test
public void shouldSucceedConnectingToNodeWithJsonRpcEnabled() {
rpcEnabledNode.verifyJsonRpcEnabled();
rpcEnabledNode.verify(net.netVersion());
}
@Test
public void shouldFailConnectingToNodeWithJsonRpcDisabled() {
rpcDisabledNode.verifyJsonRpcDisabled();
final String expectedMessage = "Failed to connect to /127.0.0.1:8545";
rpcDisabledNode.verify(net.netVersionExceptional(expectedMessage));
}
@Test
public void shouldSucceedConnectingToNodeWithWsRpcEnabled() {
rpcEnabledNode.verifyWsRpcEnabled();
rpcEnabledNode.useWebSocketsForJsonRpc();
// TODO previously this test was calling netVersion using the HTTP not WebSockets, now failing
rpcEnabledNode.verify(net.netVersion());
}
@Test
public void shouldFailConnectingToNodeWithWsRpcDisabled() {
rpcDisabledNode.verifyWsRpcDisabled();
rpcDisabledNode.useWebSocketsForJsonRpc();
rpcDisabledNode.verify(net.netVersionExceptional(WebsocketNotConnectedException.class));
}
@Test
public void shouldSucceedCallingMethodFromEnabledApiGroup() throws Exception {
final Web3j web3j = ethApiDisabledNode.web3j();
assertThat(web3j.netVersion().send().getError()).isNull();
public void shouldSucceedCallingMethodFromEnabledApiGroup() {
ethApiDisabledNode.verify(net.netVersion());
}
@Test
public void shouldFailCallingMethodFromDisabledApiGroup() {
final Web3j web3j = ethApiDisabledNode.web3j();
final String expectedMessage = "Invalid response received: 400";
assertThat(catchThrowable(() -> web3j.ethAccounts().send()))
.isInstanceOf(ClientConnectionException.class)
.hasMessageContaining("Invalid response received: 400");
ethApiDisabledNode.verify(eth.accountsExceptional(expectedMessage));
}
}

@ -14,10 +14,15 @@ 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.jsonrpc.Eth;
import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.JsonRpc;
import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Net;
import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Web3;
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 tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3.Web3Transactions;
import org.junit.After;
@ -26,19 +31,22 @@ public class AcceptanceTestBase {
protected final Accounts accounts;
protected final Blockchain blockchain;
protected final Cluster cluster;
protected final EthTransactions eth;
protected final JsonRpc jsonRpc;
protected final Transactions transactions;
protected final Web3Transactions web3;
protected final Web3 web3;
protected final Eth eth;
protected final Net net;
protected AcceptanceTestBase() {
eth = new EthTransactions();
accounts = new Accounts(eth);
blockchain = new Blockchain(eth);
final EthTransactions ethTransactions = new EthTransactions();
accounts = new Accounts(ethTransactions);
blockchain = new Blockchain(ethTransactions);
cluster = new Cluster();
eth = new Eth(ethTransactions);
jsonRpc = new JsonRpc(cluster);
net = new Net(new NetTransactions());
transactions = new Transactions(accounts);
web3 = new Web3Transactions();
web3 = new Web3(new Web3Transactions());
}
@After

@ -17,8 +17,8 @@ import tech.pegasys.pantheon.crypto.SECP256K1.PrivateKey;
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.tests.acceptance.dsl.condition.account.ExpectAccountBalance;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
import tech.pegasys.pantheon.util.bytes.Bytes32;
import java.math.BigInteger;
@ -62,14 +62,6 @@ public class Account {
return BigInteger.valueOf(nonce++);
}
public void setNextNonce(final long nonce) {
this.nonce = nonce;
}
public String getName() {
return name;
}
public Condition balanceEquals(final String expectedBalance, final Unit balanceUnit) {
return new ExpectAccountBalance(eth, this, expectedBalance, balanceUnit);
}

@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.account;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
public class Accounts {

@ -13,9 +13,9 @@
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.condition.blockchain.ExpectMinimumBlockNumber;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
public class Blockchain {

@ -10,15 +10,16 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.account;
import static org.assertj.core.api.Assertions.assertThat;
import static org.web3j.utils.Convert.toWei;
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.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
import org.web3j.utils.Convert.Unit;

@ -10,12 +10,13 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.blockchain;
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.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
import java.math.BigInteger;

@ -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.condition.eth;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
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.EthAccountsTransaction;
import org.web3j.protocol.exceptions.ClientConnectionException;
public class ExpectEthAccountsException implements Condition {
private final String expectedMessage;
private final EthAccountsTransaction transaction;
public ExpectEthAccountsException(
final EthAccountsTransaction transaction, final String expectedMessage) {
this.expectedMessage = expectedMessage;
this.transaction = transaction;
}
@Override
public void verify(final Node node) {
final Throwable thrown = catchThrowable(() -> node.execute(transaction));
assertThat(thrown).isInstanceOf(ClientConnectionException.class);
assertThat(thrown.getMessage()).contains(expectedMessage);
}
}

@ -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.condition.eth;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
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.EthGetWorkTransaction;
import org.web3j.protocol.exceptions.ClientConnectionException;
public class ExpectEthGetWorkException implements Condition {
private final EthGetWorkTransaction transaction;
private final String expectedMessage;
public ExpectEthGetWorkException(
final EthGetWorkTransaction transaction, final String expectedMessage) {
this.transaction = transaction;
this.expectedMessage = expectedMessage;
}
@Override
public void verify(final Node node) {
final Throwable thrown = catchThrowable(() -> node.execute(transaction));
assertThat(thrown).isInstanceOf(ClientConnectionException.class);
assertThat(thrown.getMessage()).contains(expectedMessage);
}
}

@ -0,0 +1,35 @@
/*
* 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.EthGetWorkTransaction;
public class SanityCheckEthGetWorkValues implements Condition {
private final EthGetWorkTransaction transaction;
public SanityCheckEthGetWorkValues(final EthGetWorkTransaction transaction) {
this.transaction = transaction;
}
@Override
public void verify(final Node node) {
final String[] response = node.execute(transaction);
assertThat(response).hasSize(3);
assertThat(response).doesNotContainNull();
}
}

@ -0,0 +1,44 @@
/*
* 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.net;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
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.net.NetVersionTransaction;
import java.net.ConnectException;
public class ExpectNetVersionConnectionException implements Condition {
private final NetVersionTransaction transaction;
private final String expectedMessage;
public ExpectNetVersionConnectionException(
final NetVersionTransaction transaction, final String expectedMessage) {
this.transaction = transaction;
this.expectedMessage = expectedMessage;
}
@Override
public void verify(final Node node) {
final Throwable thrown = catchThrowable(() -> node.execute(transaction));
assertThat(thrown).isInstanceOf(RuntimeException.class);
final Throwable cause = thrown.getCause();
assertThat(cause).isInstanceOf(ConnectException.class);
assertThat(cause.getMessage()).contains(expectedMessage);
}
}

@ -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.net;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
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.net.NetVersionTransaction;
public class ExpectNetVersionConnectionExceptionWithCause implements Condition {
private final NetVersionTransaction transaction;
private final Class<? extends Throwable> cause;
public ExpectNetVersionConnectionExceptionWithCause(
final NetVersionTransaction transaction, final Class<? extends Throwable> cause) {
this.transaction = transaction;
this.cause = cause;
}
@Override
public void verify(final Node node) {
final Throwable thrown = catchThrowable(() -> node.execute(transaction));
assertThat(thrown).isInstanceOf(cause);
}
}

@ -0,0 +1,33 @@
/*
* 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.net;
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.net.NetVersionTransaction;
public class ExpectNetVersionIsNotBlank implements Condition {
private final NetVersionTransaction transaction;
public ExpectNetVersionIsNotBlank(final NetVersionTransaction transaction) {
this.transaction = transaction;
}
@Override
public void verify(final Node node) {
assertThat(node.execute(transaction)).isNotBlank();
}
}

@ -0,0 +1,35 @@
/*
* 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.web3;
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.web3.Web3Sha3Transaction;
public class ExpectWeb3Sha3Equals implements Condition {
private final Web3Sha3Transaction input;
private final String hash;
public ExpectWeb3Sha3Equals(final Web3Sha3Transaction input, final String expectedHash) {
this.hash = expectedHash;
this.input = input;
}
@Override
public void verify(final Node node) {
assertThat(node.execute(input)).isEqualTo(hash);
}
}

@ -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.jsonrpc;
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.ExpectEthGetWorkException;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.SanityCheckEthGetWorkValues;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
public class Eth {
private final EthTransactions transactions;
public Eth(final EthTransactions transactions) {
this.transactions = transactions;
}
public Condition getWork() {
return new SanityCheckEthGetWorkValues(transactions.getWork());
}
public Condition getWorkExceptional(final String expectedMessage) {
return new ExpectEthGetWorkException(transactions.getWork(), expectedMessage);
}
public Condition accountsExceptional(final String expectedMessage) {
return new ExpectEthAccountsException(transactions.accounts(), expectedMessage);
}
}

@ -10,10 +10,11 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Cluster;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;

@ -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.jsonrpc;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionException;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionExceptionWithCause;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionIsNotBlank;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions;
public class Net {
private final NetTransactions transactions;
public Net(final NetTransactions transactions) {
this.transactions = transactions;
}
public Condition netVersion() {
return new ExpectNetVersionIsNotBlank(transactions.netVersion());
}
public Condition netVersionExceptional(final String expectedMessage) {
return new ExpectNetVersionConnectionException(transactions.netVersion(), expectedMessage);
}
public Condition netVersionExceptional(final Class<? extends Throwable> cause) {
return new ExpectNetVersionConnectionExceptionWithCause(transactions.netVersion(), cause);
}
}

@ -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.jsonrpc;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.web3.ExpectWeb3Sha3Equals;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3.Web3Transactions;
public class Web3 {
private final Web3Transactions transactions;
public Web3(final Web3Transactions transactions) {
this.transactions = transactions;
}
public Condition sha3(final String input, final String expectedHash) {
return new ExpectWeb3Sha3Equals(transactions.sha3(input), expectedHash);
}
}

@ -13,8 +13,6 @@
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 tech.pegasys.pantheon.controller.KeyPairUtil;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
@ -27,7 +25,6 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ConnectException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -40,7 +37,6 @@ import com.google.common.base.MoreObjects;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
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.http.HttpService;
@ -64,7 +60,6 @@ public class PantheonNode implements Node, AutoCloseable {
private final Properties portsProperties = new Properties();
private List<String> bootnodes = new ArrayList<>();
private Web3 web3;
private Web3j web3j;
public PantheonNode(
@ -86,7 +81,7 @@ public class PantheonNode implements Node, AutoCloseable {
LOG.info("Created PantheonNode {}", this.toString());
}
public String getName() {
String getName() {
return name;
}
@ -130,8 +125,7 @@ public class PantheonNode implements Node, AutoCloseable {
@Deprecated
public Web3j web3j() {
if (!jsonRpcBaseUrl().isPresent()) {
throw new IllegalStateException(
"Can't create a web3j instance for a node with RPC disabled.");
return web3j(new HttpService("http://" + LOCALHOST + ":8545"));
}
if (web3j == null) {
@ -141,7 +135,16 @@ public class PantheonNode implements Node, AutoCloseable {
return web3j;
}
private Web3j web3j(final Web3jService web3jService) {
public void setWeb3j(final Web3jService web3jService) {
if (web3j != null) {
web3j.shutdown();
}
web3j = Web3j.build(web3jService, 2000, Async.defaultExecutorService());
}
@Deprecated
public Web3j web3j(final Web3jService web3jService) {
if (web3j == null) {
web3j = Web3j.build(web3jService, 2000, Async.defaultExecutorService());
}
@ -149,6 +152,19 @@ public class PantheonNode implements Node, AutoCloseable {
return web3j;
}
/** All future JSON-RPC calls are made via a web sockets connection. */
public void useWebSocketsForJsonRpc() {
final String url = wsRpcBaseUrl().isPresent() ? wsRpcBaseUrl().get() : "ws://127.0.0.1:8546";
final WebSocketService webSocketService = new WebSocketService(url, true);
if (web3j != null) {
web3j.shutdown();
}
web3j = Web3j.build(webSocketService, 2000, Async.defaultExecutorService());
}
public int getPeerCount() {
try {
return web3j().netPeerCount().send().getQuantity().intValueExact();
@ -171,53 +187,6 @@ public class PantheonNode implements Node, AutoCloseable {
}
}
public void verifyJsonRpcEnabled() {
if (!jsonRpcBaseUrl().isPresent()) {
throw new RuntimeException("JSON-RPC is not enabled in node configuration");
}
try {
assertThat(web3j().netVersion().send().getError()).isNull();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
public void verifyJsonRpcDisabled() {
if (jsonRpcBaseUrl().isPresent()) {
throw new RuntimeException("JSON-RPC is enabled in node configuration");
}
final HttpService web3jService = new HttpService("http://" + LOCALHOST + ":8545");
assertThat(catchThrowable(() -> web3j(web3jService).netVersion().send()))
.isInstanceOf(ConnectException.class)
.hasMessage("Failed to connect to /127.0.0.1:8545");
}
public void verifyWsRpcEnabled() {
if (!wsRpcBaseUrl().isPresent()) {
throw new RuntimeException("WS-RPC is not enabled in node configuration");
}
try {
final WebSocketService webSocketService = new WebSocketService(wsRpcBaseUrl().get(), true);
assertThat(web3j(webSocketService).netVersion().send().getError()).isNull();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
public void verifyWsRpcDisabled() {
if (wsRpcBaseUrl().isPresent()) {
throw new RuntimeException("WS-RPC is enabled in node configuration");
}
final WebSocketService webSocketService =
new WebSocketService("ws://" + LOCALHOST + ":8546", true);
assertThat(catchThrowable(() -> web3j(webSocketService).netVersion().send()))
.isInstanceOf(WebsocketNotConnectedException.class);
}
Path homeDirectory() {
return homeDirectory;
}
@ -288,8 +257,6 @@ public class PantheonNode implements Node, AutoCloseable {
web3j.shutdown();
web3j = null;
}
web3 = null;
}
@Override
@ -302,14 +269,6 @@ public class PantheonNode implements Node, AutoCloseable {
}
}
public Web3 web3() {
if (web3 == null) {
web3 = new Web3(web3j());
}
return web3;
}
@Override
public <T> T execute(final Transaction<T> transaction) {
return transaction.execute(web3j());

@ -14,6 +14,8 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.transaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Accounts;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account.TransferTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account.TransferTransactionSet;
import java.util.ArrayList;
import java.util.List;

@ -10,12 +10,13 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account;
import static org.web3j.utils.Numeric.toHexString;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import java.math.BigInteger;

@ -10,9 +10,10 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.util.ArrayList;
import java.util.List;

@ -10,27 +10,30 @@
* 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;
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.List;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.Web3Sha3;
public class Web3 {
import org.web3j.protocol.core.methods.response.EthAccounts;
private final Web3j web3j;
public class EthAccountsTransaction implements Transaction<List<String>> {
public Web3(final Web3j web3) {
this.web3j = web3;
}
EthAccountsTransaction() {}
public String web3Sha3(final String input) throws IOException {
final Web3Sha3 result = web3j.web3Sha3(input).send();
@Override
public List<String> execute(final Web3j node) {
try {
final EthAccounts result = node.ethAccounts().send();
assertThat(result).isNotNull();
assertThat(result.hasError()).isFalse();
return result.getResult();
return result.getAccounts();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}

@ -10,10 +10,12 @@
* 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;
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.math.BigInteger;

@ -10,12 +10,13 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth;
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 tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import java.math.BigInteger;

@ -10,10 +10,12 @@
* 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;
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 org.web3j.protocol.Web3j;

@ -10,7 +10,7 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
@ -27,4 +27,8 @@ public class EthTransactions {
public EthGetBalanceTransaction getBalance(final Account account) {
return new EthGetBalanceTransaction(account);
}
public EthAccountsTransaction accounts() {
return new EthAccountsTransaction();
}
}

@ -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.net;
public class NetTransactions {
public NetVersionTransaction netVersion() {
return new NetVersionTransaction();
}
}

@ -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.transaction.net;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.NetVersion;
public class NetVersionTransaction implements Transaction<String> {
NetVersionTransaction() {}
@Override
public String execute(final Web3j node) {
try {
final NetVersion result = node.netVersion().send();
assertThat(result).isNotNull();
assertThat(result.hasError()).isFalse();
return result.getNetVersion();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}

@ -10,10 +10,12 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import org.web3j.protocol.Web3j;

@ -10,7 +10,7 @@
* 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;
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3;
public class Web3Transactions {

@ -12,8 +12,6 @@
*/
package tech.pegasys.pantheon.tests.acceptance.jsonrpc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonMinerNode;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonNode;
@ -22,7 +20,6 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import org.junit.Before;
import org.junit.Test;
import org.web3j.protocol.exceptions.ClientConnectionException;
public class EthGetWorkAcceptanceTest extends AcceptanceTestBase {
@ -38,15 +35,11 @@ public class EthGetWorkAcceptanceTest extends AcceptanceTestBase {
@Test
public void shouldReturnSuccessResponseWhenMining() {
final String[] response = minerNode.execute(eth.getWork());
assertThat(response).hasSize(3);
assertThat(response).doesNotContainNull();
minerNode.verify(eth.getWork());
}
@Test
public void shouldReturnErrorResponseWhenNotMining() {
final Throwable thrown = catchThrowable(() -> fullNode.execute(eth.getWork()));
assertThat(thrown).isInstanceOf(ClientConnectionException.class);
assertThat(thrown.getMessage()).contains("No mining work available yet");
fullNode.verify(eth.getWorkExceptional("No mining work available yet"));
}
}

@ -12,14 +12,11 @@
*/
package tech.pegasys.pantheon.tests.acceptance.jsonrpc;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
@ -34,12 +31,11 @@ public class Web3Sha3AcceptanceTest extends AcceptanceTestBase {
}
@Test
public void shouldReturnCorrectSha3() throws IOException {
public void shouldReturnCorrectSha3() {
final String input = "0x68656c6c6f20776f726c64";
final String sha3 = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad";
final String response = node.execute(web3.sha3(input));
final String expectedHash =
"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad";
assertThat(response).isEqualTo(sha3);
node.verify(web3.sha3(input, expectedHash));
}
}

Loading…
Cancel
Save