[MINOR] added acceptance test for admin_addPeer with P2P disabled (#703)

* added acceptance test for calling admin_addPeer on a node that has P2P disabled

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Sally MacFarlane 6 years ago committed by GitHub
parent b9a21f6e06
commit 7c835db064
  1. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/P2pDisabledAcceptanceTest.java
  2. 21
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java
  3. 67
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/admin/AdminAddPeerWithP2PDisabledAcceptanceTest.java

@ -31,7 +31,7 @@ public class P2pDisabledAcceptanceTest extends AcceptanceTestBase {
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build();
p2pDisabledCluster = new Cluster(clusterConfiguration, net);
node = pantheon.createArchiveNodeWithP2pDisabled("node1");
node = pantheon.createNodeWithP2pDisabled("node1");
p2pDisabledCluster.start(node);
}

@ -36,6 +36,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@ -110,13 +111,21 @@ public class PantheonNodeFactory {
.build());
}
public PantheonNode createArchiveNodeWithP2pDisabled(final String name) throws IOException {
public PantheonNode createNodeWithP2pDisabled(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
.setP2pEnabled(false)
.setJsonRpcConfiguration(jsonRpcConfigWithPermissioning())
.webSocketEnabled()
.build());
}
public PantheonNode createNodeWithP2pDisabledAndAdmin(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
.setP2pEnabled(false)
.setJsonRpcConfiguration(jsonRpcConfigWithPermissioningAndAdmin())
.build());
}
@ -339,10 +348,14 @@ public class PantheonNodeFactory {
return createJsonRpcConfigWithRpcApiEnabled(RpcApis.ADMIN);
}
private JsonRpcConfiguration createJsonRpcConfigWithRpcApiEnabled(final RpcApi rpcApi) {
private JsonRpcConfiguration jsonRpcConfigWithPermissioningAndAdmin() {
return createJsonRpcConfigWithRpcApiEnabled(RpcApis.PERM, RpcApis.ADMIN);
}
private JsonRpcConfiguration createJsonRpcConfigWithRpcApiEnabled(final RpcApi... rpcApi) {
final JsonRpcConfiguration jsonRpcConfig = createJsonRpcEnabledConfig();
final List<RpcApi> rpcApis = new ArrayList<>(jsonRpcConfig.getRpcApis());
rpcApis.add(rpcApi);
rpcApis.addAll(Arrays.asList(rpcApi));
jsonRpcConfig.setRpcApis(rpcApis);
return jsonRpcConfig;
}

@ -0,0 +1,67 @@
/*
* Copyright 2019 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.admin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
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.cluster.Cluster;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.web3j.protocol.exceptions.ClientConnectionException;
public class AdminAddPeerWithP2PDisabledAcceptanceTest extends AcceptanceTestBase {
private PantheonNode nodeA;
private PantheonNode nodeB;
private Cluster p2pDisabledCluster;
@Before
public void setUp() throws Exception {
final ClusterConfiguration clusterConfiguration =
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build();
p2pDisabledCluster = new Cluster(clusterConfiguration, net);
nodeA = pantheon.createNodeWithP2pDisabledAndAdmin("nodeA");
nodeB = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeB");
p2pDisabledCluster.start(nodeA, nodeB);
}
@After
public void tearDown() {
p2pDisabledCluster.stop();
}
@Test
public void adminAddPeerFailsWhenP2PDisabled() {
final String nodeBEnode = nodeB.enodeUrl();
try {
nodeA.verify(admin.addPeer(nodeBEnode));
fail("expected exception because P2P is disabled");
} catch (ClientConnectionException e) {
assertThat(e.getMessage().contains("P2P has been disabled")).isTrue();
}
nodeB.verify(net.awaitPeerCount(0));
}
@Test
public void adminAddPeerFailsWhenP2PDisabled2() {
final String nodeAEnode = nodeA.enodeUrl();
nodeB.verify(admin.addPeer(nodeAEnode));
nodeB.verify(net.awaitPeerCount(0));
}
}
Loading…
Cancel
Save