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

Commit

Permalink
Merge branch 'master' of https://github.com/PegaSysEng/pantheon into …
Browse files Browse the repository at this point in the history
…NC-1145
  • Loading branch information
Shinabyss committed Nov 18, 2018
2 parents ef0db70 + b942a66 commit 85d70a3
Show file tree
Hide file tree
Showing 187 changed files with 4,267 additions and 2,586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,27 @@
*/
package tech.pegasys.pantheon.tests.acceptance;

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.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;

import org.junit.Before;
import org.junit.Test;

public class PantheonClusterAcceptanceTest extends AcceptanceTestBase {
public class ClusterAcceptanceTest extends AcceptanceTestBase {

private PantheonNode minerNode;
private PantheonNode fullNode;
private Node minerNode;
private Node fullNode;

@Before
public void setUp() throws Exception {
minerNode = cluster.create(pantheonMinerNode("node1"));
fullNode = cluster.create(pantheonNode("node2"));
minerNode = pantheon.createMinerNode("node1");
fullNode = pantheon.createArchiveNode("node2");
cluster.start(minerNode, fullNode);
}

@Test
public void shouldConnectToOtherPeer() {
jsonRpc.waitForPeersConnected(minerNode, 1);
jsonRpc.waitForPeersConnected(fullNode, 1);
minerNode.verify(net.awaitPeerCount(1));
fullNode.verify(net.awaitPeerCount(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
package tech.pegasys.pantheon.tests.acceptance;

import static org.web3j.utils.Convert.Unit.ETHER;
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.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;

import org.junit.Before;
import org.junit.Ignore;
Expand All @@ -27,12 +25,12 @@
@Ignore
public class CreateAccountAcceptanceTest extends AcceptanceTestBase {

private PantheonNode minerNode;
private Node minerNode;

@Before
public void setUp() throws Exception {
minerNode = cluster.create(pantheonMinerNode("node1"));
cluster.start(minerNode, cluster.create(pantheonNode("node2")));
minerNode = pantheon.createMinerNode("node1");
cluster.start(minerNode, pantheon.createArchiveNode("node2"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
*/
package tech.pegasys.pantheon.tests.acceptance;

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;

import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
Expand All @@ -34,9 +30,9 @@ public class RpcApisTogglesAcceptanceTest extends AcceptanceTestBase {

@Before
public void before() throws Exception {
rpcEnabledNode = cluster.create(pantheonNode("rpc-enabled"));
rpcDisabledNode = cluster.create(pantheonRpcDisabledNode("rpc-disabled"));
ethApiDisabledNode = cluster.create(patheonNodeWithRpcApis("eth-api-disabled", RpcApis.NET));
rpcEnabledNode = pantheon.createArchiveNode("rpc-enabled");
rpcDisabledNode = pantheon.createArchiveNodeWithRpcDisabled("rpc-disabled");
ethApiDisabledNode = pantheon.createArchiveNodeWithRpcApis("eth-api-disabled", RpcApis.NET);
cluster.start(rpcEnabledNode, rpcDisabledNode, ethApiDisabledNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
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.node.PantheonNodeFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions;
Expand All @@ -31,22 +31,22 @@ public class AcceptanceTestBase {
protected final Accounts accounts;
protected final Blockchain blockchain;
protected final Cluster cluster;
protected final JsonRpc jsonRpc;
protected final Transactions transactions;
protected final Web3 web3;
protected final Eth eth;
protected final Net net;
protected final PantheonNodeFactory pantheon;

protected AcceptanceTestBase() {
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());
cluster = new Cluster(net);
transactions = new Transactions(accounts);
web3 = new Web3(new Web3Transactions());
pantheon = new PantheonNodeFactory();
}

@After
Expand Down
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.net;

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils;
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.NetPeerCountTransaction;

import java.math.BigInteger;

public class AwaitNetPeerCount implements Condition {

private final NetPeerCountTransaction transaction;
private final BigInteger expectedPeerCount;

public AwaitNetPeerCount(
final NetPeerCountTransaction transaction, final BigInteger expectedPeerCount) {
this.transaction = transaction;
this.expectedPeerCount = expectedPeerCount;
}

@Override
public void verify(final Node node) {
WaitUtils.waitFor(() -> assertThat(node.execute(transaction)).isEqualTo(expectedPeerCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
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.AwaitNetPeerCount;
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;

import java.math.BigInteger;

public class Net {

private final NetTransactions transactions;
Expand All @@ -30,6 +33,10 @@ public Condition netVersion() {
return new ExpectNetVersionIsNotBlank(transactions.netVersion());
}

public Condition awaitPeerCount(final int awaitPeerCount) {
return new AwaitNetPeerCount(transactions.peerCount(), BigInteger.valueOf(awaitPeerCount));
}

public Condition netVersionExceptional(final String expectedMessage) {
return new ExpectNetVersionConnectionException(transactions.netVersion(), expectedMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,71 @@

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Net;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Cluster implements AutoCloseable {

private final Map<String, PantheonNode> nodes = new HashMap<>();
private final Map<String, RunnableNode> nodes = new HashMap<>();
private final PantheonNodeRunner pantheonNodeRunner = PantheonNodeRunner.instance();
private final Net net;

public void start(final PantheonNode... nodes) {
public Cluster(final Net net) {
this.net = net;
}

public void start(final Node... nodes) {
start(
Arrays.stream(nodes)
.map(
n -> {
assertThat(n instanceof RunnableNode).isTrue();
return (RunnableNode) n;
})
.collect(Collectors.toList()));
}

public void start(final List<RunnableNode> nodes) {
this.nodes.clear();

final List<String> bootNodes = new ArrayList<>();

for (final PantheonNode node : nodes) {
for (final RunnableNode node : nodes) {
this.nodes.put(node.getName(), node);
bootNodes.add(node.enodeUrl());
bootNodes.add(node.getConfiguration().enodeUrl());
}

for (final PantheonNode node : nodes) {
node.bootnodes(bootNodes);
for (final RunnableNode node : nodes) {
node.getConfiguration().bootnodes(bootNodes);
node.start(pantheonNodeRunner);
}

for (final PantheonNode node : nodes) {
awaitPeerDiscovery(node, nodes.length);
for (final RunnableNode node : nodes) {
node.awaitPeerDiscovery(net.awaitPeerCount(nodes.size() - 1));
}
}

public void stop() {
for (final PantheonNode node : nodes.values()) {
for (final RunnableNode node : nodes.values()) {
node.stop();
}
pantheonNodeRunner.shutdown();
}

@Override
public void close() {
for (final PantheonNode node : nodes.values()) {
for (final RunnableNode node : nodes.values()) {
node.close();
}
pantheonNodeRunner.shutdown();
}

public PantheonNode create(final PantheonNodeConfig config) throws IOException {
config.initSocket();
final PantheonNode node =
new PantheonNode(
config.getName(),
config.getSocketPort(),
config.getMiningParameters(),
config.getJsonRpcConfiguration(),
config.getWebSocketConfiguration());
config.closeSocket();
return node;
}

private void awaitPeerDiscovery(final PantheonNode node, final int nodeCount) {
if (node.jsonRpcEnabled()) {
WaitUtils.waitFor(() -> assertThat(node.getPeerCount()).isEqualTo(nodeCount - 1));
}
}

public void verify(final Condition expected) {
for (final Node node : nodes.values()) {
expected.verify(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.node;

import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

public interface Node {

<T> T execute(Transaction<T> transaction);

void verify(final Condition expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
* 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 net.consensys.pantheon.consensus.common;
package tech.pegasys.pantheon.tests.acceptance.dsl.node;

import static org.assertj.core.api.Java6Assertions.assertThat;
import java.util.List;
import java.util.Optional;

import tech.pegasys.pantheon.consensus.common.VoteType;
public interface NodeConfiguration {

import org.junit.Test;
String enodeUrl();

public class VoteTypeTest {
@Test
public void testValidatorVoteMethodImplementation() {
assertThat(VoteType.ADD.isAddVote()).isTrue();
assertThat(VoteType.ADD.isDropVote()).isFalse();
void bootnodes(List<String> bootnodes);

assertThat(VoteType.DROP.isAddVote()).isFalse();
assertThat(VoteType.DROP.isDropVote()).isTrue();
}
void useWebSocketsForJsonRpc();

Optional<Integer> jsonRpcWebSocketPort();

String hostName();

boolean jsonRpcEnabled();
}
Loading

0 comments on commit 85d70a3

Please sign in to comment.