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

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed May 13, 2019
1 parent a9361bb commit a064a67
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,50 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc;

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

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.node.RunnableNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;
import java.net.URI;

import org.web3j.protocol.core.Response;

public class Admin {

public Condition addPeer(final Node node) {

System.out.println("999");

return new Condition() {
@Override
public void verify(Node x) {

System.out.println("888");

final Boolean result =
node.execute(
new Transaction<Boolean>() {
@Override
public Boolean execute(JsonRequestFactories requestFactories) {

System.out.println("777");

Response<Boolean> resp = null;
try {
URI enodeUrl = ((RunnableNode) x).enodeUrl();
resp = requestFactories.admin().adminAddPeer(enodeUrl).send();
assertThat(resp).isNotNull();
assertThat(resp.hasError()).isFalse();
} catch (final Exception ignored) {
}
return resp.getResult();
}
});
assertThat(result).isTrue();
}
};
}
public Condition addPeer(final Node node) {

System.out.println("999");

return new Condition() {
@Override
public void verify(Node x) {

System.out.println("888");

final Boolean result =
node.execute(
new Transaction<Boolean>() {
@Override
public Boolean execute(JsonRequestFactories requestFactories) {

System.out.println("777");

Response<Boolean> resp = null;
try {
URI enodeUrl = ((RunnableNode) x).enodeUrl();
resp = requestFactories.admin().adminAddPeer(enodeUrl).send();
assertThat(resp).isNotNull();
assertThat(resp.hasError()).isFalse();
} catch (final Exception ignored) {
}
return resp.getResult();
}
});
assertThat(result).isTrue();
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,48 @@
/*
* 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.dsl.jsonrpc;

import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.NetVersion;
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.node.RunnableNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NetServicesJsonRpcRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

import java.net.URI;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import org.web3j.protocol.core.Request;

public class NetServices {

public Condition addPeer(final Node node) {

System.out.println("999");

return new Condition() {
@Override
public void verify(Node x) {

System.out.println("888");

final Map<String, Map<String, String>> result =
node.execute(
new Transaction<Map<String, Map<String, String>>>() {
@Override
public Map<String, Map<String, String>> execute(JsonRequestFactories requestFactories) {

System.out.println("777");

NetServicesJsonRpcRequestFactory.NetServicesResponse c = null;
try {

//System.out.println("netVersion: " + requestFactories.net().netVersion().send().getNetVersion());

//System.out.println("netVersion: " + requestFactories.net().netListening().send().isListening());

URI enodeUrl = ((RunnableNode) x).enodeUrl();

System.out.println("xxx");

NetServicesJsonRpcRequestFactory s = requestFactories.netServices();

System.out.println("yyy");

Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> t = s.netServices(enodeUrl);

System.out.println("zzz");

c = t.send();

//System.out.println("--> " + c.getResult());

System.out.println("aaa");

//resp = requestFactories.admin().adminAddPeer(enodeUrl).send();
//assertThat(resp).isNotNull();
//assertThat(resp.hasError()).isFalse();
} catch (final Exception ignored) {
}
return c.getResult();
}
});
//assertThat(result).isTrue();
System.out.println("--> " + result);
}
};
}
public Map<String, Map<String, String>> addPeer(final Node node) {

final Map<String, Map<String, String>> result =
node.execute(
new Transaction<Map<String, Map<String, String>>>() {
@Override
public Map<String, Map<String, String>> execute(
JsonRequestFactories requestFactories) {
NetServicesJsonRpcRequestFactory.NetServicesResponse c = null;
try {
NetServicesJsonRpcRequestFactory s = requestFactories.netServices();
Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> t =
s.netServices();
c = t.send();
} catch (final Exception ignored) {
}
return c.getResult();
}
});

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private JsonRequestFactories jsonRequestFactories() {
new PermissioningJsonRpcRequestFactory(web3jService),
new AdminJsonRpcRequestFactory(web3jService),
new EeaJsonRpcRequestFactory(web3jService),
new NetServicesJsonRpcRequestFactory(web3jService),
new NetServicesJsonRpcRequestFactory(web3jService),
websocketService);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
/*
* 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.dsl.transaction;

import java.util.Collections;
import java.util.Map;

import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;

import java.net.URI;
import java.util.Collections;
import java.util.Map;

public class NetServicesJsonRpcRequestFactory {

//public static class ProposalsResponse extends Response<Map<Address, Boolean>> {}
public static class NetServicesResponse extends Response<Map<String, Map<String, String>>> {

}
// public static class ProposalsResponse extends Response<Map<Address, Boolean>> {}
public static class NetServicesResponse extends Response<Map<String, Map<String, String>>> {}

private final Web3jService web3jService;
private final Web3jService web3jService;

public NetServicesJsonRpcRequestFactory(final Web3jService web3jService) {
this.web3jService = web3jService;
}
public NetServicesJsonRpcRequestFactory(final Web3jService web3jService) {
this.web3jService = web3jService;
}

public Request<?, NetServicesResponse> netServices(final URI enodeAddress) {
public Request<?, NetServicesResponse> netServices() {

Request request = new Request<>(
"net_services",
Collections.EMPTY_LIST,
web3jService,
NetServicesResponse.class);
Request request =
new Request<>(
"net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class);

return request;
}
return request;
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
/*
* 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;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;

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

public class NetServicesAcceptanceTest extends AcceptanceTestBase {

private Cluster noDiscoveryCluster;
import java.util.HashMap;
import java.util.Map;

private Node nodeA;
private Node nodeB;
import org.junit.Before;
import org.junit.Test;

@Before
public void setUp() throws Exception {
final ClusterConfiguration clusterConfiguration =
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build();
noDiscoveryCluster = new Cluster(clusterConfiguration, net);
nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA");
nodeB = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeB");
noDiscoveryCluster.start(nodeA, nodeB);
}
public class NetServicesAcceptanceTest extends AcceptanceTestBase {

@Test
public void adminAddPeerForcesConnection() {
private Cluster noDiscoveryCluster;

System.out.println("AAA");
private Node nodeA;
private Node nodeB;

nodeA.verify(netServices.addPeer(nodeA));
@Before
public void setUp() throws Exception {
final ClusterConfiguration clusterConfiguration =
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build();
noDiscoveryCluster = new Cluster(clusterConfiguration, net);
nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA");
nodeB = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeB");
noDiscoveryCluster.start(nodeA, nodeB);
}

System.out.println("ZZZ");
}
@Test
public void adminAddPeerForcesConnection() {
Map<String, Map<String, String>> result = netServices.addPeer(nodeA);
Map<String, Map<String, String>> expectation = new HashMap<>();
Map<String, String> constituentMap =
new HashMap() {
{
put("host", "127.0.0.1");
put("port", "0");
}
};
expectation.put("jsonrpc", constituentMap);
expectation.put("ws", constituentMap);
expectation.put("p2p", constituentMap);
assertThat(expectation.get("jsonrpc").get("host")).isEqualTo(result.get("jsonrpc").get("host"));
assertThat(expectation.get("jsonrpc").get("port")).isEqualTo(result.get("jsonrpc").get("port"));
assertThat(expectation.get("ws").get("host")).isEqualTo(result.get("ws").get("host"));
assertThat(expectation.get("ws").get("port")).isEqualTo(result.get("ws").get("port"));
assertThat(expectation.get("p2p").get("host")).isEqualTo(result.get("p2p").get("host"));
}
}
Loading

0 comments on commit a064a67

Please sign in to comment.