mirror of https://github.com/hyperledger/besu
Acceptance test refactor to use the Node interface and a Factory to create instances (#226)
parent
9f8512b4c0
commit
ea0e323336
@ -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)); |
||||||
|
} |
||||||
|
} |
@ -1,32 +0,0 @@ |
|||||||
/* |
|
||||||
* 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 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; |
|
||||||
|
|
||||||
public class JsonRpc { |
|
||||||
|
|
||||||
private final Cluster nodes; |
|
||||||
|
|
||||||
public JsonRpc(final Cluster nodes) { |
|
||||||
this.nodes = nodes; |
|
||||||
} |
|
||||||
|
|
||||||
public void waitForPeersConnected(final PantheonNode node, final int expectedNumberOfPeers) { |
|
||||||
WaitUtils.waitFor(() -> assertThat(node.getPeerCount()).isEqualTo(expectedNumberOfPeers)); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,31 @@ |
|||||||
|
/* |
||||||
|
* 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.node; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
public interface NodeConfiguration { |
||||||
|
|
||||||
|
String enodeUrl(); |
||||||
|
|
||||||
|
void bootnodes(List<String> bootnodes); |
||||||
|
|
||||||
|
void useWebSocketsForJsonRpc(); |
||||||
|
|
||||||
|
Optional<Integer> jsonRpcWebSocketPort(); |
||||||
|
|
||||||
|
String hostName(); |
||||||
|
|
||||||
|
boolean jsonRpcEnabled(); |
||||||
|
} |
@ -1,123 +0,0 @@ |
|||||||
/* |
|
||||||
* 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.node; |
|
||||||
|
|
||||||
import tech.pegasys.pantheon.ethereum.core.MiningParameters; |
|
||||||
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; |
|
||||||
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; |
|
||||||
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; |
|
||||||
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.net.ServerSocket; |
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
public class PantheonNodeConfig { |
|
||||||
|
|
||||||
private final String name; |
|
||||||
private final MiningParameters miningParameters; |
|
||||||
private final JsonRpcConfiguration jsonRpcConfiguration; |
|
||||||
private final WebSocketConfiguration webSocketConfiguration; |
|
||||||
private ServerSocket serverSocket; |
|
||||||
|
|
||||||
private PantheonNodeConfig( |
|
||||||
final String name, |
|
||||||
final MiningParameters miningParameters, |
|
||||||
final JsonRpcConfiguration jsonRpcConfiguration, |
|
||||||
final WebSocketConfiguration webSocketConfiguration) { |
|
||||||
this.name = name; |
|
||||||
this.miningParameters = miningParameters; |
|
||||||
this.jsonRpcConfiguration = jsonRpcConfiguration; |
|
||||||
this.webSocketConfiguration = webSocketConfiguration; |
|
||||||
} |
|
||||||
|
|
||||||
private PantheonNodeConfig(final String name, final MiningParameters miningParameters) { |
|
||||||
this.name = name; |
|
||||||
this.miningParameters = miningParameters; |
|
||||||
this.jsonRpcConfiguration = createJsonRpcConfig(); |
|
||||||
this.webSocketConfiguration = createWebSocketConfig(); |
|
||||||
} |
|
||||||
|
|
||||||
private static MiningParameters createMiningParameters(final boolean miner) { |
|
||||||
return new MiningParametersTestBuilder().enabled(miner).build(); |
|
||||||
} |
|
||||||
|
|
||||||
public static PantheonNodeConfig pantheonMinerNode(final String name) { |
|
||||||
return new PantheonNodeConfig(name, createMiningParameters(true)); |
|
||||||
} |
|
||||||
|
|
||||||
public static PantheonNodeConfig pantheonNode(final String name) { |
|
||||||
return new PantheonNodeConfig(name, createMiningParameters(false)); |
|
||||||
} |
|
||||||
|
|
||||||
public static PantheonNodeConfig pantheonRpcDisabledNode(final String name) { |
|
||||||
return new PantheonNodeConfig( |
|
||||||
name, |
|
||||||
createMiningParameters(false), |
|
||||||
JsonRpcConfiguration.createDefault(), |
|
||||||
WebSocketConfiguration.createDefault()); |
|
||||||
} |
|
||||||
|
|
||||||
public static PantheonNodeConfig patheonNodeWithRpcApis( |
|
||||||
final String name, final RpcApi... enabledRpcApis) { |
|
||||||
final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig(); |
|
||||||
jsonRpcConfig.setRpcApis(Arrays.asList(enabledRpcApis)); |
|
||||||
final WebSocketConfiguration webSocketConfig = createWebSocketConfig(); |
|
||||||
webSocketConfig.setRpcApis(Arrays.asList(enabledRpcApis)); |
|
||||||
|
|
||||||
return new PantheonNodeConfig( |
|
||||||
name, createMiningParameters(false), jsonRpcConfig, webSocketConfig); |
|
||||||
} |
|
||||||
|
|
||||||
private static JsonRpcConfiguration createJsonRpcConfig() { |
|
||||||
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); |
|
||||||
config.setEnabled(true); |
|
||||||
config.setPort(0); |
|
||||||
return config; |
|
||||||
} |
|
||||||
|
|
||||||
private static WebSocketConfiguration createWebSocketConfig() { |
|
||||||
final WebSocketConfiguration config = WebSocketConfiguration.createDefault(); |
|
||||||
config.setEnabled(true); |
|
||||||
config.setPort(0); |
|
||||||
return config; |
|
||||||
} |
|
||||||
|
|
||||||
public void initSocket() throws IOException { |
|
||||||
serverSocket = new ServerSocket(0); |
|
||||||
} |
|
||||||
|
|
||||||
public void closeSocket() throws IOException { |
|
||||||
serverSocket.close(); |
|
||||||
} |
|
||||||
|
|
||||||
public int getSocketPort() { |
|
||||||
return serverSocket.getLocalPort(); |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() { |
|
||||||
return name; |
|
||||||
} |
|
||||||
|
|
||||||
public MiningParameters getMiningParameters() { |
|
||||||
return miningParameters; |
|
||||||
} |
|
||||||
|
|
||||||
public JsonRpcConfiguration getJsonRpcConfiguration() { |
|
||||||
return jsonRpcConfiguration; |
|
||||||
} |
|
||||||
|
|
||||||
public WebSocketConfiguration getWebSocketConfiguration() { |
|
||||||
return webSocketConfiguration; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,126 @@ |
|||||||
|
/* |
||||||
|
* 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.node; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.ethereum.core.MiningParameters; |
||||||
|
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.net.ServerSocket; |
||||||
|
import java.util.Arrays; |
||||||
|
|
||||||
|
public class PantheonNodeFactory { |
||||||
|
|
||||||
|
private PantheonNode create(final PantheonFactoryConfiguration config) throws IOException { |
||||||
|
ServerSocket serverSocket = new ServerSocket(0); |
||||||
|
final PantheonNode node = |
||||||
|
new PantheonNode( |
||||||
|
config.getName(), |
||||||
|
config.getMiningParameters(), |
||||||
|
config.getJsonRpcConfiguration(), |
||||||
|
config.getWebSocketConfiguration(), |
||||||
|
serverSocket.getLocalPort()); |
||||||
|
serverSocket.close(); |
||||||
|
|
||||||
|
return node; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonNode createMinerNode(final String name) throws IOException { |
||||||
|
return create( |
||||||
|
new PantheonFactoryConfiguration( |
||||||
|
name, createMiningParameters(true), createJsonRpcConfig(), createWebSocketConfig())); |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonNode createArchiveNode(final String name) throws IOException { |
||||||
|
return create( |
||||||
|
new PantheonFactoryConfiguration( |
||||||
|
name, createMiningParameters(false), createJsonRpcConfig(), createWebSocketConfig())); |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonNode createArchiveNodeWithRpcDisabled(final String name) throws IOException { |
||||||
|
return create( |
||||||
|
new PantheonFactoryConfiguration( |
||||||
|
name, |
||||||
|
createMiningParameters(false), |
||||||
|
JsonRpcConfiguration.createDefault(), |
||||||
|
WebSocketConfiguration.createDefault())); |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonNode createArchiveNodeWithRpcApis( |
||||||
|
final String name, final RpcApi... enabledRpcApis) throws IOException { |
||||||
|
final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig(); |
||||||
|
jsonRpcConfig.setRpcApis(Arrays.asList(enabledRpcApis)); |
||||||
|
final WebSocketConfiguration webSocketConfig = createWebSocketConfig(); |
||||||
|
webSocketConfig.setRpcApis(Arrays.asList(enabledRpcApis)); |
||||||
|
|
||||||
|
return create( |
||||||
|
new PantheonFactoryConfiguration( |
||||||
|
name, createMiningParameters(false), jsonRpcConfig, webSocketConfig)); |
||||||
|
} |
||||||
|
|
||||||
|
private MiningParameters createMiningParameters(final boolean miner) { |
||||||
|
return new MiningParametersTestBuilder().enabled(miner).build(); |
||||||
|
} |
||||||
|
|
||||||
|
private JsonRpcConfiguration createJsonRpcConfig() { |
||||||
|
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); |
||||||
|
config.setEnabled(true); |
||||||
|
config.setPort(0); |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
private WebSocketConfiguration createWebSocketConfig() { |
||||||
|
final WebSocketConfiguration config = WebSocketConfiguration.createDefault(); |
||||||
|
config.setEnabled(true); |
||||||
|
config.setPort(0); |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
static class PantheonFactoryConfiguration { |
||||||
|
|
||||||
|
private final String name; |
||||||
|
private final MiningParameters miningParameters; |
||||||
|
private final JsonRpcConfiguration jsonRpcConfiguration; |
||||||
|
private final WebSocketConfiguration webSocketConfiguration; |
||||||
|
|
||||||
|
public PantheonFactoryConfiguration( |
||||||
|
final String name, |
||||||
|
final MiningParameters miningParameters, |
||||||
|
final JsonRpcConfiguration jsonRpcConfiguration, |
||||||
|
final WebSocketConfiguration webSocketConfiguration) { |
||||||
|
this.name = name; |
||||||
|
this.miningParameters = miningParameters; |
||||||
|
this.jsonRpcConfiguration = jsonRpcConfiguration; |
||||||
|
this.webSocketConfiguration = webSocketConfiguration; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public MiningParameters getMiningParameters() { |
||||||
|
return miningParameters; |
||||||
|
} |
||||||
|
|
||||||
|
public JsonRpcConfiguration getJsonRpcConfiguration() { |
||||||
|
return jsonRpcConfiguration; |
||||||
|
} |
||||||
|
|
||||||
|
public WebSocketConfiguration getWebSocketConfiguration() { |
||||||
|
return webSocketConfiguration; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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.node; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||||
|
|
||||||
|
public interface RunnableNode extends Node { |
||||||
|
|
||||||
|
void stop(); |
||||||
|
|
||||||
|
void close(); |
||||||
|
|
||||||
|
void start(PantheonNodeRunner runner); |
||||||
|
|
||||||
|
NodeConfiguration getConfiguration(); |
||||||
|
|
||||||
|
void awaitPeerDiscovery(final Condition condition); |
||||||
|
|
||||||
|
String getName(); |
||||||
|
} |
@ -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.transaction.net; |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
import org.web3j.protocol.Web3j; |
||||||
|
import org.web3j.protocol.core.methods.response.NetPeerCount; |
||||||
|
|
||||||
|
public class NetPeerCountTransaction implements Transaction<BigInteger> { |
||||||
|
|
||||||
|
NetPeerCountTransaction() {} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BigInteger execute(final Web3j node) { |
||||||
|
try { |
||||||
|
final NetPeerCount result = node.netPeerCount().send(); |
||||||
|
assertThat(result).isNotNull(); |
||||||
|
assertThat(result.hasError()).isFalse(); |
||||||
|
return result.getQuantity(); |
||||||
|
} catch (final IOException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue