This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9361bb
commit a064a67
Showing
6 changed files
with
169 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 35 additions & 63 deletions
98
...e-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/NetServices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 27 additions & 20 deletions
47
...h/pegasys/pantheon/tests/acceptance/dsl/transaction/NetServicesJsonRpcRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
74 changes: 51 additions & 23 deletions
74
...c/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
Oops, something went wrong.