diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java index 14f5b58a6d..a53bea61bd 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java @@ -27,6 +27,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3.Web3Transactions; import tech.pegasys.pantheon.tests.acceptance.dsl.waitcondition.WaitConditions; @@ -39,6 +40,7 @@ public class AcceptanceTestBase { protected final Blockchain blockchain; protected final Cluster cluster; protected final CliqueTransactions cliqueTransactions; + protected final IbftTransactions ibftTransactions; protected final Transactions transactions; protected final Clique clique; protected final Ibft ibft; @@ -57,8 +59,10 @@ protected AcceptanceTestBase() { blockchain = new Blockchain(ethTransactions); eth = new Eth(ethTransactions); cliqueTransactions = new CliqueTransactions(); + ibftTransactions = new IbftTransactions(); + clique = new Clique(ethTransactions, cliqueTransactions); - ibft = new Ibft(); + ibft = new Ibft(ibftTransactions); net = new Net(new NetTransactions()); cluster = new Cluster(net); transactions = new Transactions(accounts); @@ -67,7 +71,7 @@ protected AcceptanceTestBase() { web3 = new Web3(new Web3Transactions()); pantheon = new PantheonNodeFactory(); contractVerifier = new ContractVerifier(accounts.getPrimaryBenefactor()); - wait = new WaitConditions(ethTransactions, cliqueTransactions); + wait = new WaitConditions(ethTransactions, cliqueTransactions, ibftTransactions); } @After diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectProposals.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectProposals.java new file mode 100644 index 0000000000..0443e018c8 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectProposals.java @@ -0,0 +1,38 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; +import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; + +import tech.pegasys.pantheon.ethereum.core.Address; +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.ibft.IbftTransactions; + +import java.util.Map; + +public class ExpectProposals implements Condition { + private final IbftTransactions ibft; + private final Map proposers; + + public ExpectProposals(final IbftTransactions ibft, final Map proposers) { + this.ibft = ibft; + this.proposers = proposers; + } + + @Override + public void verify(final Node node) { + waitFor(() -> assertThat(node.execute(ibft.createProposals())).isEqualTo(proposers)); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectValidators.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectValidators.java new file mode 100644 index 0000000000..a398d592e5 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/ibft/ExpectValidators.java @@ -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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; +import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; +import static tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions.LATEST; + +import tech.pegasys.pantheon.ethereum.core.Address; +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.ibft.IbftTransactions; + +public class ExpectValidators implements Condition { + private final IbftTransactions ibft; + private final Address[] validators; + + public ExpectValidators(final IbftTransactions ibft, final Address... validators) { + this.ibft = ibft; + this.validators = validators; + } + + @Override + public void verify(final Node node) { + waitFor( + () -> + assertThat(node.execute(ibft.createGetValidators(LATEST))).containsExactly(validators)); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java index b047a5ee9e..c90377ece0 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Admin.java @@ -25,7 +25,7 @@ public class Admin { private Transaction addPeerTransaction(final String enode) { return (n) -> { try { - final Response resp = n.adminAddPeer(enode).send(); + final Response resp = n.admin().adminAddPeer(enode).send(); assertThat(resp).isNotNull(); assertThat(resp.hasError()).isFalse(); return resp.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Ibft.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Ibft.java index 3c6f30c8b1..37c9bbbaaa 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Ibft.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Ibft.java @@ -12,14 +12,31 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc; +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectProposals; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectValidators; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableMap; public class Ibft { + private final IbftTransactions ibft; + + public Ibft(final IbftTransactions ibft) { + this.ibft = ibft; + } + public List validators(final PantheonNode[] nodes) { final Comparator compareByAddress = Comparator.comparing(PantheonNode::getAddress); @@ -27,4 +44,49 @@ public List validators(final PantheonNode[] nodes) { pantheonNodes.sort(compareByAddress); return pantheonNodes; } + + public ExpectValidators validatorsEqual(final PantheonNode... validators) { + return new ExpectValidators(ibft, validatorAddresses(validators)); + } + + private Address[] validatorAddresses(final PantheonNode[] validators) { + return Arrays.stream(validators).map(PantheonNode::getAddress).sorted().toArray(Address[]::new); + } + + public Condition noProposals() { + return new ExpectProposals(ibft, ImmutableMap.of()); + } + + public PendingVotesConfig pendingVotesEqual() { + return new PendingVotesConfig(ibft); + } + + public static class PendingVotesConfig { + private final Map proposals = new HashMap<>(); + private final IbftTransactions ibft; + + public PendingVotesConfig(final IbftTransactions ibft) { + this.ibft = ibft; + } + + public PendingVotesConfig addProposal(final PantheonNode node) { + proposals.put(node, true); + return this; + } + + public PendingVotesConfig removeProposal(final PantheonNode node) { + proposals.put(node, false); + return this; + } + + public Condition build() { + final Map proposalsAsAddress = + this.proposals + .entrySet() + .stream() + .collect(Collectors.toMap(p -> p.getKey().getAddress(), Entry::getValue)); + return new tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectProposals( + ibft, proposalsAsAddress); + } + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index fc0608c405..05c0097638 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -25,7 +25,11 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.AdminJsonRpcRequestFactory; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.CliqueJsonRpcRequestFactory; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.IbftJsonRpcRequestFactory; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PermissioningJsonRpcRequestFactory; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import tech.pegasys.pantheon.tests.acceptance.dsl.waitcondition.WaitCondition; @@ -50,6 +54,8 @@ import org.awaitility.Awaitility; import org.awaitility.core.ConditionTimeoutException; import org.java_websocket.exceptions.WebsocketNotConnectedException; +import org.web3j.protocol.Web3jService; +import org.web3j.protocol.core.JsonRpc2_0Web3j; import org.web3j.protocol.http.HttpService; import org.web3j.protocol.websocket.WebSocketClient; import org.web3j.protocol.websocket.WebSocketListener; @@ -78,7 +84,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto private final boolean discoveryEnabled; private List bootnodes = new ArrayList<>(); - private PantheonWeb3j pantheonWeb3j; + private JsonRequestFactories jsonRequestFactories; private Optional ethNetworkConfig = Optional.empty(); public PantheonNode( @@ -163,19 +169,23 @@ public String hostName() { return LOCALHOST; } - private PantheonWeb3j pantheonWeb3j() { - - if (pantheonWeb3j == null) { - if (!jsonRpcBaseUrl().isPresent()) { - return new PantheonWeb3j( - new HttpService("http://" + LOCALHOST + ":8545"), 2000, Async.defaultExecutorService()); - } - - return new PantheonWeb3j( - new HttpService(jsonRpcBaseUrl().get()), 2000, Async.defaultExecutorService()); + private JsonRequestFactories jsonRequestFactories() { + if (jsonRequestFactories == null) { + final Web3jService web3jService = + jsonRpcBaseUrl() + .map(url -> new HttpService(url)) + .orElse(new HttpService("http://" + LOCALHOST + ":8545")); + + jsonRequestFactories = + new JsonRequestFactories( + new JsonRpc2_0Web3j(web3jService, 2000, Async.defaultExecutorService()), + new CliqueJsonRpcRequestFactory(web3jService), + new IbftJsonRpcRequestFactory(web3jService), + new PermissioningJsonRpcRequestFactory(web3jService), + new AdminJsonRpcRequestFactory(web3jService)); } - return pantheonWeb3j; + return jsonRequestFactories; } /** All future JSON-RPC calls are made via a web sockets connection. */ @@ -192,11 +202,9 @@ public void useWebSocketsForJsonRpc() { throw new RuntimeException("Error connection to WebSocket endpoint", e); } - if (pantheonWeb3j != null) { - pantheonWeb3j.shutdown(); + if (jsonRequestFactories != null) { + jsonRequestFactories.shutdown(); } - - pantheonWeb3j = new PantheonWeb3j(webSocketService, 2000, Async.defaultExecutorService()); } private void checkIfWebSocketEndpointIsAvailable(final String url) { @@ -358,9 +366,9 @@ public String toString() { @Override public void stop() { - if (pantheonWeb3j != null) { - pantheonWeb3j.shutdown(); - pantheonWeb3j = null; + if (jsonRequestFactories != null) { + jsonRequestFactories.shutdown(); + jsonRequestFactories = null; } } @@ -391,7 +399,7 @@ public void ethNetworkConfig(final Optional ethNetworkConfig) @Override public T execute(final Transaction transaction) { - return transaction.execute(pantheonWeb3j()); + return transaction.execute(jsonRequestFactories()); } @Override diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/AdminJsonRpcRequestFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/AdminJsonRpcRequestFactory.java new file mode 100644 index 0000000000..68c7a99417 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/AdminJsonRpcRequestFactory.java @@ -0,0 +1,38 @@ +/* + * 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 org.web3j.protocol.Web3jService; +import org.web3j.protocol.core.Request; +import org.web3j.protocol.core.Response; + +public class AdminJsonRpcRequestFactory { + + public static class AdminAddPeerResponse extends Response {} + + private final Web3jService web3jService; + + public AdminJsonRpcRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + } + + public Request adminAddPeer(final String enodeAddress) { + return new Request<>( + "admin_addPeer", + Collections.singletonList(enodeAddress), + web3jService, + AdminAddPeerResponse.class); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/CliqueJsonRpcRequestFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/CliqueJsonRpcRequestFactory.java new file mode 100644 index 0000000000..7d4a53960c --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/CliqueJsonRpcRequestFactory.java @@ -0,0 +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.dsl.transaction; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.DiscardResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposalsResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; + +import java.util.Arrays; + +import org.web3j.protocol.Web3jService; +import org.web3j.protocol.core.Request; + +public class CliqueJsonRpcRequestFactory { + + private final Web3jService web3jService; + + public CliqueJsonRpcRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + } + + public Request cliquePropose(final String address, final Boolean auth) { + return new Request<>( + "clique_propose", + Arrays.asList(address, auth.toString()), + web3jService, + ProposeResponse.class); + } + + public Request cliqueDiscard(final String address) { + return new Request<>( + "clique_discard", singletonList(address), web3jService, DiscardResponse.class); + } + + public Request cliqueProposals() { + return new Request<>("clique_proposals", emptyList(), web3jService, ProposalsResponse.class); + } + + public Request cliqueGetSigners(final String blockNumber) { + return new Request<>( + "clique_getSigners", singletonList(blockNumber), web3jService, SignersBlockResponse.class); + } + + public Request cliqueGetSignersAtHash(final Hash hash) { + return new Request<>( + "clique_getSignersAtHash", + singletonList(hash.toString()), + web3jService, + SignersBlockResponse.class); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/DeploySmartContractTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/DeploySmartContractTransaction.java index 2d82324992..294420def8 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/DeploySmartContractTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/DeploySmartContractTransaction.java @@ -37,7 +37,7 @@ public class DeploySmartContractTransaction implements Trans } @Override - public T execute(final PantheonWeb3j node) { + public T execute(final JsonRequestFactories node) { try { final Method method = clazz.getMethod( @@ -45,7 +45,7 @@ public T execute(final PantheonWeb3j node) { final Object invoked = method.invoke( - METHOD_IS_STATIC, node, BENEFACTOR_ONE, DEFAULT_GAS_PRICE, DEFAULT_GAS_LIMIT); + METHOD_IS_STATIC, node.eth(), BENEFACTOR_ONE, DEFAULT_GAS_PRICE, DEFAULT_GAS_LIMIT); return cast(invoked).send(); } catch (final Exception e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/IbftJsonRpcRequestFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/IbftJsonRpcRequestFactory.java new file mode 100644 index 0000000000..05635c0d15 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/IbftJsonRpcRequestFactory.java @@ -0,0 +1,70 @@ +/* + * 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 static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.DiscardResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposalsResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; + +import java.util.Arrays; + +import org.web3j.protocol.Web3jService; +import org.web3j.protocol.core.Request; + +public class IbftJsonRpcRequestFactory { + + private final Web3jService web3jService; + + public IbftJsonRpcRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + } + + public Request ibftPropose(final String address, final Boolean auth) { + return new Request<>( + "ibft_proposeValidatorVote", + Arrays.asList(address, auth.toString()), + web3jService, + ProposeResponse.class); + } + + public Request ibftDiscard(final String address) { + return new Request<>( + "ibft_discardValidatorVote", singletonList(address), web3jService, DiscardResponse.class); + } + + public Request ibftProposals() { + return new Request<>( + "ibft_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class); + } + + public Request ibftGetValidators(final String blockNumber) { + return new Request<>( + "ibft_getValidatorsByBlockNumber", + singletonList(blockNumber), + web3jService, + SignersBlockResponse.class); + } + + public Request ibftGetSignersAtHash(final Hash hash) { + return new Request<>( + "ibft_getValidatorsByBlockHash", + singletonList(hash.toString()), + web3jService, + SignersBlockResponse.class); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/JsonRequestFactories.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/JsonRequestFactories.java new file mode 100644 index 0000000000..e3f72d097c --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/JsonRequestFactories.java @@ -0,0 +1,65 @@ +/* + * 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 org.web3j.protocol.core.JsonRpc2_0Web3j; + +public class JsonRequestFactories { + + private final JsonRpc2_0Web3j netEth; + private final CliqueJsonRpcRequestFactory clique; + private final IbftJsonRpcRequestFactory ibft; + private final PermissioningJsonRpcRequestFactory perm; + private final AdminJsonRpcRequestFactory admin; + + public JsonRequestFactories( + final JsonRpc2_0Web3j netEth, + final CliqueJsonRpcRequestFactory clique, + final IbftJsonRpcRequestFactory ibft, + final PermissioningJsonRpcRequestFactory perm, + final AdminJsonRpcRequestFactory admin) { + this.netEth = netEth; + this.clique = clique; + this.ibft = ibft; + this.perm = perm; + this.admin = admin; + } + + public JsonRpc2_0Web3j eth() { + return netEth; + } + + public JsonRpc2_0Web3j net() { + return netEth; + } + + public CliqueJsonRpcRequestFactory clique() { + return clique; + } + + public IbftJsonRpcRequestFactory ibft() { + return ibft; + } + + public PermissioningJsonRpcRequestFactory perm() { + return perm; + } + + public AdminJsonRpcRequestFactory admin() { + return admin; + } + + public void shutdown() { + netEth.shutdown(); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PantheonWeb3j.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PantheonWeb3j.java deleted file mode 100644 index 3bbbce5c20..0000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PantheonWeb3j.java +++ /dev/null @@ -1,149 +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.transaction; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -import tech.pegasys.pantheon.ethereum.core.Address; -import tech.pegasys.pantheon.ethereum.core.Hash; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ScheduledExecutorService; - -import org.assertj.core.util.Lists; -import org.web3j.protocol.Web3jService; -import org.web3j.protocol.core.JsonRpc2_0Web3j; -import org.web3j.protocol.core.Request; -import org.web3j.protocol.core.Response; - -public class PantheonWeb3j extends JsonRpc2_0Web3j { - - public PantheonWeb3j(final Web3jService web3jService) { - super(web3jService); - } - - public PantheonWeb3j( - final Web3jService web3jService, - final long pollingInterval, - final ScheduledExecutorService scheduledExecutorService) { - super(web3jService, pollingInterval, scheduledExecutorService); - } - - public Request cliquePropose(final String address, final Boolean auth) { - return new Request<>( - "clique_propose", - Arrays.asList(address, auth.toString()), - web3jService, - ProposeResponse.class); - } - - public Request cliqueDiscard(final String address) { - return new Request<>( - "clique_discard", singletonList(address), web3jService, DiscardResponse.class); - } - - public Request cliqueProposals() { - return new Request<>("clique_proposals", emptyList(), web3jService, ProposalsResponse.class); - } - - public Request cliqueGetSigners(final String blockNumber) { - return new Request<>( - "clique_getSigners", singletonList(blockNumber), web3jService, SignersBlockResponse.class); - } - - public Request cliqueGetSignersAtHash(final Hash hash) { - return new Request<>( - "clique_getSignersAtHash", - singletonList(hash.toString()), - web3jService, - SignersBlockResponse.class); - } - - public static class ProposeResponse extends Response {} - - public static class DiscardResponse extends Response {} - - public static class SignersBlockResponse extends Response> {} - - public static class ProposalsResponse extends Response> {} - - public Request addAccountsToWhitelist( - final List accounts) { - return new Request<>( - "perm_addAccountsToWhitelist", - Collections.singletonList(accounts), - web3jService, - AddAccountsToWhitelistResponse.class); - } - - public Request removeAccountsFromWhitelist( - final List accounts) { - return new Request<>( - "perm_removeAccountsFromWhitelist", - Collections.singletonList(accounts), - web3jService, - RemoveAccountsFromWhitelistResponse.class); - } - - public Request getAccountsWhitelist() { - return new Request<>( - "perm_getAccountsWhitelist", null, web3jService, GetAccountsWhitelistResponse.class); - } - - public static class AddAccountsToWhitelistResponse extends Response {} - - public static class RemoveAccountsFromWhitelistResponse extends Response {} - - public static class GetAccountsWhitelistResponse extends Response> {} - - public Request addNodesToWhitelist(final List enodeList) { - return new Request<>( - "perm_addNodesToWhitelist", - Collections.singletonList(enodeList), - web3jService, - AddNodeResponse.class); - } - - public Request removeNodesFromWhitelist(final List enodeList) { - return new Request<>( - "perm_removeNodesFromWhitelist", - Collections.singletonList(enodeList), - web3jService, - RemoveNodeResponse.class); - } - - public Request getNodesWhitelist() { - return new Request<>( - "perm_getNodesWhitelist", Lists.emptyList(), web3jService, GetNodesWhitelistResponse.class); - } - - public static class AddNodeResponse extends Response {} - - public static class RemoveNodeResponse extends Response {} - - public static class GetNodesWhitelistResponse extends Response> {} - - public static class AdminAddPeerResponse extends Response {} - - public Request adminAddPeer(final String enodeAddress) { - return new Request<>( - "admin_addPeer", - Collections.singletonList(enodeAddress), - web3jService, - AdminAddPeerResponse.class); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PermissioningJsonRpcRequestFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PermissioningJsonRpcRequestFactory.java new file mode 100644 index 0000000000..a05fd263e6 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/PermissioningJsonRpcRequestFactory.java @@ -0,0 +1,79 @@ +/* + * 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 tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.AddAccountsToWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.AddNodeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.GetAccountsWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.GetNodesWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.RemoveAccountsFromWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.RemoveNodeResponse; + +import java.util.Collections; +import java.util.List; + +import org.assertj.core.util.Lists; +import org.web3j.protocol.Web3jService; +import org.web3j.protocol.core.Request; + +public class PermissioningJsonRpcRequestFactory { + private final Web3jService web3jService; + + public PermissioningJsonRpcRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + } + + public Request addNodesToWhitelist(final List enodeList) { + return new Request<>( + "perm_addNodesToWhitelist", + Collections.singletonList(enodeList), + web3jService, + AddNodeResponse.class); + } + + public Request removeNodesFromWhitelist(final List enodeList) { + return new Request<>( + "perm_removeNodesFromWhitelist", + Collections.singletonList(enodeList), + web3jService, + RemoveNodeResponse.class); + } + + public Request getNodesWhitelist() { + return new Request<>( + "perm_getNodesWhitelist", Lists.emptyList(), web3jService, GetNodesWhitelistResponse.class); + } + + public Request getAccountsWhitelist() { + return new Request<>( + "perm_getAccountsWhitelist", null, web3jService, GetAccountsWhitelistResponse.class); + } + + public Request addAccountsToWhitelist( + final List accounts) { + return new Request<>( + "perm_addAccountsToWhitelist", + Collections.singletonList(accounts), + web3jService, + AddAccountsToWhitelistResponse.class); + } + + public Request removeAccountsFromWhitelist( + final List accounts) { + return new Request<>( + "perm_removeAccountsFromWhitelist", + Collections.singletonList(accounts), + web3jService, + RemoveAccountsFromWhitelistResponse.class); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ResponseTypes.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ResponseTypes.java new file mode 100644 index 0000000000..6df0e623e9 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ResponseTypes.java @@ -0,0 +1,42 @@ +/* + * 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 tech.pegasys.pantheon.ethereum.core.Address; + +import java.util.List; +import java.util.Map; + +import org.web3j.protocol.core.Response; + +public class ResponseTypes { + public static class ProposeResponse extends Response {} + + public static class DiscardResponse extends Response {} + + public static class SignersBlockResponse extends Response> {} + + public static class ProposalsResponse extends Response> {} + + public static class AddAccountsToWhitelistResponse extends Response {} + + public static class RemoveAccountsFromWhitelistResponse extends Response {} + + public static class GetAccountsWhitelistResponse extends Response> {} + + public static class AddNodeResponse extends Response {} + + public static class RemoveNodeResponse extends Response {} + + public static class GetNodesWhitelistResponse extends Response> {} +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Transaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Transaction.java index 474f378c33..761491b442 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Transaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/Transaction.java @@ -15,5 +15,5 @@ @FunctionalInterface public interface Transaction { - T execute(final PantheonWeb3j node); + T execute(final JsonRequestFactories node); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransaction.java index 88e04a5211..191b226e4d 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransaction.java @@ -16,7 +16,7 @@ import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -62,11 +62,11 @@ public TransferTransaction( } @Override - public Hash execute(final PantheonWeb3j node) { + public Hash execute(final JsonRequestFactories node) { final String signedTransactionData = signedTransactionData(); try { return Hash.fromHexString( - node.ethSendRawTransaction(signedTransactionData).send().getTransactionHash()); + node.eth().ethSendRawTransaction(signedTransactionData).send().getTransactionHash()); } catch (final IOException e) { throw new RuntimeException(e); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionSet.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionSet.java index b0cab54977..3e1037c005 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionSet.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionSet.java @@ -13,7 +13,7 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.util.ArrayList; @@ -28,7 +28,7 @@ public TransferTransactionSet(final List transactions) { } @Override - public List execute(final PantheonWeb3j node) { + public List execute(final JsonRequestFactories node) { final List hashes = new ArrayList<>(); for (final TransferTransaction transaction : transactions) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java index 237c8b15f3..4763fcc1d0 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java @@ -14,12 +14,13 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.DiscardResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; +import org.web3j.protocol.core.Response; + public class CliqueDiscard implements Transaction { private final String address; @@ -28,9 +29,9 @@ public CliqueDiscard(final String address) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { - final DiscardResponse result = node.cliqueDiscard(address).send(); + final Response result = node.clique().cliqueDiscard(address).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java index 0b7ca14f1f..3e4caaa9c6 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java @@ -15,8 +15,8 @@ import static org.assertj.core.api.Assertions.assertThat; import tech.pegasys.pantheon.ethereum.core.Address; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.SignersBlockResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,9 +30,9 @@ public CliqueGetSigners(final String blockNumber) { } @Override - public List
execute(final PantheonWeb3j node) { + public List
execute(final JsonRequestFactories node) { try { - final SignersBlockResponse result = node.cliqueGetSigners(blockNumber).send(); + final SignersBlockResponse result = node.clique().cliqueGetSigners(blockNumber).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java index 953903fca9..1dc06f24c9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java @@ -16,8 +16,8 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.SignersBlockResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -31,9 +31,9 @@ public CliqueGetSignersAtHash(final Hash hash) { } @Override - public List
execute(final PantheonWeb3j node) { + public List
execute(final JsonRequestFactories node) { try { - final SignersBlockResponse result = node.cliqueGetSignersAtHash(hash).send(); + final SignersBlockResponse result = node.clique().cliqueGetSignersAtHash(hash).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueProposals.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueProposals.java index a81f84909b..a00b266a69 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueProposals.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliqueProposals.java @@ -15,8 +15,8 @@ import static org.assertj.core.api.Assertions.assertThat; import tech.pegasys.pantheon.ethereum.core.Address; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.ProposalsResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposalsResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -25,9 +25,9 @@ public class CliqueProposals implements Transaction> { @Override - public Map execute(final PantheonWeb3j node) { + public Map execute(final JsonRequestFactories node) { try { - final ProposalsResponse result = node.cliqueProposals().send(); + final ProposalsResponse result = node.clique().cliqueProposals().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliquePropose.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliquePropose.java index e4f4d7212e..f767e07800 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliquePropose.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/clique/CliquePropose.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.ProposeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposeResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,9 +30,9 @@ public CliquePropose(final String address, final boolean auth) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { - final ProposeResponse result = node.cliquePropose(address, auth).send(); + final ProposeResponse result = node.clique().cliquePropose(address, auth).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthAccountsTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthAccountsTransaction.java index b8a9c2dd21..b70d23e1d3 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthAccountsTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthAccountsTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -27,9 +27,9 @@ public class EthAccountsTransaction implements Transaction> { EthAccountsTransaction() {} @Override - public List execute(final PantheonWeb3j node) { + public List execute(final JsonRequestFactories node) { try { - final EthAccounts result = node.ethAccounts().send(); + final EthAccounts result = node.eth().ethAccounts().send(); assertThat(result).isNotNull(); return result.getAccounts(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthBlockNumberTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthBlockNumberTransaction.java index fe7a1a87ce..3f686d84d9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthBlockNumberTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthBlockNumberTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -25,10 +25,10 @@ public class EthBlockNumberTransaction implements Transaction { EthBlockNumberTransaction() {} @Override - public BigInteger execute(final PantheonWeb3j node) { + public BigInteger execute(final JsonRequestFactories node) { try { final org.web3j.protocol.core.methods.response.EthBlockNumber result = - node.ethBlockNumber().send(); + node.eth().ethBlockNumber().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getBlockNumber(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBalanceTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBalanceTransaction.java index 57ea00b0c3..16e45858e4 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBalanceTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBalanceTransaction.java @@ -16,7 +16,7 @@ import static org.web3j.protocol.core.DefaultBlockParameterName.LATEST; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -33,9 +33,9 @@ public class EthGetBalanceTransaction implements Transaction { } @Override - public BigInteger execute(final PantheonWeb3j node) { + public BigInteger execute(final JsonRequestFactories node) { try { - final EthGetBalance result = node.ethGetBalance(account.getAddress(), LATEST).send(); + final EthGetBalance result = node.eth().ethGetBalance(account.getAddress(), LATEST).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBlockTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBlockTransaction.java index 9cb5e1a623..993c8d46c5 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBlockTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetBlockTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -34,10 +34,10 @@ public class EthGetBlockTransaction implements Transaction { } @Override - public Block execute(final PantheonWeb3j node) { + public Block execute(final JsonRequestFactories node) { try { final EthBlock result = - node.ethGetBlockByNumber(blockParameter, fullTransactionObjects).send(); + node.eth().ethGetBlockByNumber(blockParameter, fullTransactionObjects).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getBlock(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionCountTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionCountTransaction.java index ae31f9783f..23d6df7480 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionCountTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionCountTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -32,10 +32,12 @@ public EthGetTransactionCountTransaction(final String accountAddress) { } @Override - public BigInteger execute(final PantheonWeb3j node) { + public BigInteger execute(final JsonRequestFactories node) { try { EthGetTransactionCount result = - node.ethGetTransactionCount(accountAddress, DefaultBlockParameterName.LATEST).send(); + node.eth() + .ethGetTransactionCount(accountAddress, DefaultBlockParameterName.LATEST) + .send(); assertThat(result).isNotNull(); return result.getTransactionCount(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java index 2784ce1991..58e5eecaa2 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetTransactionReceiptTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -33,9 +33,9 @@ public class EthGetTransactionReceiptTransaction } @Override - public Optional execute(final PantheonWeb3j node) { + public Optional execute(final JsonRequestFactories node) { try { - final EthGetTransactionReceipt result = node.ethGetTransactionReceipt(input).send(); + final EthGetTransactionReceipt result = node.eth().ethGetTransactionReceipt(input).send(); assertThat(result.hasError()).isFalse(); return result.getTransactionReceipt(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetWorkTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetWorkTransaction.java index f98199c420..7d58e64f60 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetWorkTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthGetWorkTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -26,9 +26,9 @@ public class EthGetWorkTransaction implements Transaction { EthGetWorkTransaction() {} @Override - public String[] execute(final PantheonWeb3j node) { + public String[] execute(final JsonRequestFactories node) { try { - final EthGetWork result = node.ethGetWork().send(); + final EthGetWork result = node.eth().ethGetWork().send(); assertThat(result).isNotNull(); return new String[] { result.getCurrentBlockHeaderPowHash(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthSendRawTransactionTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthSendRawTransactionTransaction.java index 6a17dcd0cb..3e3332fd8e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthSendRawTransactionTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eth/EthSendRawTransactionTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,9 +30,9 @@ public class EthSendRawTransactionTransaction implements Transaction { } @Override - public String execute(final PantheonWeb3j node) { + public String execute(final JsonRequestFactories node) { try { - EthSendTransaction response = node.ethSendRawTransaction(transactionData).send(); + EthSendTransaction response = node.eth().ethSendRawTransaction(transactionData).send(); assertThat(response.getTransactionHash()).isNotNull(); return response.getTransactionHash(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftDiscard.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftDiscard.java new file mode 100644 index 0000000000..58f5b497b4 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftDiscard.java @@ -0,0 +1,41 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.DiscardResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class IbftDiscard implements Transaction { + private final String address; + + public IbftDiscard(final String address) { + this.address = address; + } + + @Override + public Boolean execute(final JsonRequestFactories node) { + try { + final DiscardResponse result = node.ibft().ibftDiscard(address).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidators.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidators.java new file mode 100644 index 0000000000..d773ece7b1 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidators.java @@ -0,0 +1,43 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; +import java.util.List; + +public class IbftGetValidators implements Transaction> { + private final String blockNumber; + + public IbftGetValidators(final String blockNumber) { + this.blockNumber = blockNumber; + } + + @Override + public List
execute(final JsonRequestFactories node) { + try { + final SignersBlockResponse result = node.ibft().ibftGetValidators(blockNumber).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidatorsAtHash.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidatorsAtHash.java new file mode 100644 index 0000000000..1a9caf4e54 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftGetValidatorsAtHash.java @@ -0,0 +1,44 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.SignersBlockResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; +import java.util.List; + +public class IbftGetValidatorsAtHash implements Transaction> { + private final Hash hash; + + public IbftGetValidatorsAtHash(final Hash hash) { + this.hash = hash; + } + + @Override + public List
execute(final JsonRequestFactories node) { + try { + final SignersBlockResponse result = node.ibft().ibftGetSignersAtHash(hash).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftProposals.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftProposals.java new file mode 100644 index 0000000000..6724ac964d --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftProposals.java @@ -0,0 +1,38 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposalsResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; +import java.util.Map; + +public class IbftProposals implements Transaction> { + + @Override + public Map execute(final JsonRequestFactories node) { + try { + final ProposalsResponse result = node.ibft().ibftProposals().send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftPropose.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftPropose.java new file mode 100644 index 0000000000..88ff88d446 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftPropose.java @@ -0,0 +1,43 @@ +/* + * 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.ibft; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.ProposeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class IbftPropose implements Transaction { + private final String address; + private final boolean auth; + + public IbftPropose(final String address, final boolean auth) { + this.address = address; + this.auth = auth; + } + + @Override + public Boolean execute(final JsonRequestFactories node) { + try { + final ProposeResponse result = node.ibft().ibftPropose(address, auth).send(); + assertThat(result).isNotNull(); + assertThat(result.hasError()).isFalse(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftTransactions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftTransactions.java new file mode 100644 index 0000000000..4b9e9bda11 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/ibft/IbftTransactions.java @@ -0,0 +1,48 @@ +/* + * 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.ibft; + +import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; + +public class IbftTransactions { + public static final String LATEST = "latest"; + + public IbftPropose createRemoveProposal(final PantheonNode node) { + return propose(node.getAddress().toString(), false); + } + + public IbftPropose createAddProposal(final PantheonNode node) { + return propose(node.getAddress().toString(), true); + } + + private IbftPropose propose(final String address, final boolean auth) { + return new IbftPropose(address, auth); + } + + public IbftProposals createProposals() { + return new IbftProposals(); + } + + public IbftGetValidators createGetValidators(final String blockNumber) { + return new IbftGetValidators(blockNumber); + } + + public IbftGetValidatorsAtHash createGetValidatorsAtHash(final Hash blockHash) { + return new IbftGetValidatorsAtHash(blockHash); + } + + public IbftDiscard createDiscardProposal(final PantheonNode node) { + return new IbftDiscard(node.getAddress().toString()); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetPeerCountTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetPeerCountTransaction.java index e52e2f4f1e..f400e1a559 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetPeerCountTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetPeerCountTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -27,9 +27,9 @@ public class NetPeerCountTransaction implements Transaction { NetPeerCountTransaction() {} @Override - public BigInteger execute(final PantheonWeb3j node) { + public BigInteger execute(final JsonRequestFactories node) { try { - final NetPeerCount result = node.netPeerCount().send(); + final NetPeerCount result = node.net().netPeerCount().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getQuantity(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetVersionTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetVersionTransaction.java index 6effb90bdc..9217a60d48 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetVersionTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/net/NetVersionTransaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -26,9 +26,9 @@ public class NetVersionTransaction implements Transaction { NetVersionTransaction() {} @Override - public String execute(final PantheonWeb3j node) { + public String execute(final JsonRequestFactories node) { try { - final NetVersion result = node.netVersion().send(); + final NetVersion result = node.net().netVersion().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getNetVersion(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddAccountsToWhitelistTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddAccountsToWhitelistTransaction.java index d624a185bc..313d9cd981 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddAccountsToWhitelistTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddAccountsToWhitelistTransaction.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.AddAccountsToWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.AddAccountsToWhitelistResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,9 +30,9 @@ public PermAddAccountsToWhitelistTransaction(final List accounts) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { - AddAccountsToWhitelistResponse response = node.addAccountsToWhitelist(accounts).send(); + AddAccountsToWhitelistResponse response = node.perm().addAccountsToWhitelist(accounts).send(); assertThat(response.getResult()).isTrue(); return response.getResult(); } catch (IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddNodeTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddNodeTransaction.java index a1be4d199c..a1319dab25 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddNodeTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermAddNodeTransaction.java @@ -13,9 +13,9 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm; import static org.assertj.core.api.Assertions.assertThat; -import static tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.AddNodeResponse; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.AddNodeResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -29,9 +29,9 @@ public PermAddNodeTransaction(final List enodeList) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { - final AddNodeResponse result = node.addNodesToWhitelist(enodeList).send(); + final AddNodeResponse result = node.perm().addNodesToWhitelist(enodeList).send(); assertThat(result).isNotNull(); return result.getResult(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetAccountsWhitelistTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetAccountsWhitelistTransaction.java index 42ccf85aaa..11622ad188 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetAccountsWhitelistTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetAccountsWhitelistTransaction.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.GetAccountsWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.GetAccountsWhitelistResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -24,9 +24,9 @@ public class PermGetAccountsWhitelistTransaction implements Transaction> { @Override - public List execute(final PantheonWeb3j node) { + public List execute(final JsonRequestFactories node) { try { - GetAccountsWhitelistResponse response = node.getAccountsWhitelist().send(); + GetAccountsWhitelistResponse response = node.perm().getAccountsWhitelist().send(); assertThat(response.getResult()).isNotNull(); return response.getResult(); } catch (IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetNodesWhitelistTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetNodesWhitelistTransaction.java index 0687bedad1..56067e731c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetNodesWhitelistTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermGetNodesWhitelistTransaction.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.GetNodesWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.GetNodesWhitelistResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -23,9 +23,9 @@ public class PermGetNodesWhitelistTransaction implements Transaction> { @Override - public List execute(final PantheonWeb3j node) { + public List execute(final JsonRequestFactories node) { try { - GetNodesWhitelistResponse result = node.getNodesWhitelist().send(); + GetNodesWhitelistResponse result = node.perm().getNodesWhitelist().send(); assertThat(result).isNotNull(); return result.getResult(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveAccountsFromWhitelistTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveAccountsFromWhitelistTransaction.java index 5c85e49f76..e62a58a636 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveAccountsFromWhitelistTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveAccountsFromWhitelistTransaction.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.RemoveAccountsFromWhitelistResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.RemoveAccountsFromWhitelistResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,10 +30,10 @@ public PermRemoveAccountsFromWhitelistTransaction(final List accounts) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { RemoveAccountsFromWhitelistResponse response = - node.removeAccountsFromWhitelist(accounts).send(); + node.perm().removeAccountsFromWhitelist(accounts).send(); assertThat(response.getResult()).isTrue(); return response.getResult(); } catch (IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveNodeTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveNodeTransaction.java index 1a1ad6f9ea..7495ddd74b 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveNodeTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/PermRemoveNodeTransaction.java @@ -14,8 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.RemoveNodeResponse; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes.RemoveNodeResponse; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -29,9 +29,9 @@ public PermRemoveNodeTransaction(final List enodeList) { } @Override - public Boolean execute(final PantheonWeb3j node) { + public Boolean execute(final JsonRequestFactories node) { try { - final RemoveNodeResponse result = node.removeNodesFromWhitelist(enodeList).send(); + final RemoveNodeResponse result = node.perm().removeNodesFromWhitelist(enodeList).send(); assertThat(result).isNotNull(); return result.getResult(); } catch (final IOException e) { diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Sha3Transaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Sha3Transaction.java index 15341a0a65..4e218d0155 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Sha3Transaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/web3/Web3Sha3Transaction.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.JsonRequestFactories; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; @@ -30,9 +30,9 @@ public class Web3Sha3Transaction implements Transaction { } @Override - public String execute(final PantheonWeb3j node) { + public String execute(final JsonRequestFactories node) { try { - final Web3Sha3 result = node.web3Sha3(input).send(); + final Web3Sha3 result = node.net().web3Sha3(input).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitConditions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitConditions.java index 3f5b86f55f..9870c2d7a8 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitConditions.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitConditions.java @@ -19,16 +19,20 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; import java.math.BigInteger; public class WaitConditions { private final EthTransactions eth; private final CliqueTransactions clique; + private final IbftTransactions ibft; - public WaitConditions(final EthTransactions eth, final CliqueTransactions clique) { + public WaitConditions( + final EthTransactions eth, final CliqueTransactions clique, final IbftTransactions ibft) { this.eth = eth; this.clique = clique; + this.ibft = ibft; } public WaitCondition chainHeadHasProgressed( @@ -42,6 +46,10 @@ public WaitCondition cliqueValidatorsChanged(final Node node) { return new WaitUntilSignersChanged(node.execute(clique.createGetSigners(LATEST)), clique); } + public WaitCondition ibftValidatorsChanged(final Node node) { + return new WaitUntilValidatorsChanged(node.execute(ibft.createGetValidators(LATEST)), ibft); + } + public WaitCondition chainHeadIsAt(final long blockNumber) { return new ExpectBlockNumber(eth, BigInteger.valueOf(blockNumber))::verify; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitUntilValidatorsChanged.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitUntilValidatorsChanged.java new file mode 100644 index 0000000000..a1de59928f --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/waitcondition/WaitUntilValidatorsChanged.java @@ -0,0 +1,44 @@ +/* + * 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.waitcondition; + +import static org.assertj.core.api.Assertions.assertThat; +import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; +import static tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; + +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; + +import java.util.List; + +public class WaitUntilValidatorsChanged implements WaitCondition { + + private final IbftTransactions ibft; + private final List
initialSigners; + + public WaitUntilValidatorsChanged( + final List
initialSigners, final IbftTransactions ibft) { + this.initialSigners = initialSigners; + this.ibft = ibft; + } + + @Override + public void waitUntil(final Node node) { + waitFor( + 60, + () -> + assertThat(node.execute(ibft.createGetValidators(LATEST))) + .isNotEqualTo(initialSigners)); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftDiscardRpcAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftDiscardRpcAcceptanceTest.java new file mode 100644 index 0000000000..59cacd89b0 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftDiscardRpcAcceptanceTest.java @@ -0,0 +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.ibft; + +import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; + +import java.io.IOException; + +import org.junit.Test; + +public class IbftDiscardRpcAcceptanceTest extends AcceptanceTestBase { + + @Test + public void shouldDiscardVotes() throws IOException { + final String[] validators = {"validator1", "validator2"}; + final PantheonNode validator1 = pantheon.createIbftNodeWithValidators("validator1", validators); + final PantheonNode validator2 = pantheon.createIbftNodeWithValidators("validator2", validators); + final PantheonNode validator3 = pantheon.createIbftNodeWithValidators("validator3", validators); + cluster.start(validator1, validator2, validator3); + + validator1.execute(ibftTransactions.createRemoveProposal(validator2)); + validator1.execute(ibftTransactions.createAddProposal(validator3)); + + validator2.execute(ibftTransactions.createRemoveProposal(validator2)); + validator2.execute(ibftTransactions.createAddProposal(validator3)); + + validator1.execute(ibftTransactions.createDiscardProposal(validator2)); + validator1.execute(ibftTransactions.createDiscardProposal(validator3)); + + validator1.waitUntil(wait.chainHeadHasProgressed(validator1, 2)); + + cluster.verify(ibft.validatorsEqual(validator1, validator2)); + validator1.verify(ibft.noProposals()); + validator2.verify( + ibft.pendingVotesEqual().removeProposal(validator2).addProposal(validator3).build()); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposalRpcAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposalRpcAcceptanceTest.java new file mode 100644 index 0000000000..7c91904492 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposalRpcAcceptanceTest.java @@ -0,0 +1,42 @@ +/* + * 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.ibft; + +import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; + +import java.io.IOException; + +import org.junit.Test; + +public class IbftProposalRpcAcceptanceTest extends AcceptanceTestBase { + + @Test + public void shouldReturnProposals() throws IOException { + final String[] validators = {"validator1", "validator2", "validator3"}; + final PantheonNode validator1 = pantheon.createIbftNodeWithValidators("validator1", validators); + final PantheonNode validator2 = pantheon.createIbftNodeWithValidators("validator2", validators); + final PantheonNode validator3 = pantheon.createIbftNodeWithValidators("validator3", validators); + cluster.start(validator1, validator2, validator3); + + cluster.verify(ibft.noProposals()); + validator1.execute(ibftTransactions.createAddProposal(validator3)); + validator1.execute(ibftTransactions.createRemoveProposal(validator2)); + validator2.execute(ibftTransactions.createRemoveProposal(validator3)); + + validator1.verify( + ibft.pendingVotesEqual().addProposal(validator3).removeProposal(validator2).build()); + validator2.verify(ibft.pendingVotesEqual().removeProposal(validator3).build()); + validator3.verify(ibft.noProposals()); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposeRpcAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposeRpcAcceptanceTest.java new file mode 100644 index 0000000000..0ea14c3905 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/ibft/IbftProposeRpcAcceptanceTest.java @@ -0,0 +1,52 @@ +/* + * 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.ibft; + +import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; +import tech.pegasys.pantheon.tests.acceptance.dsl.waitcondition.WaitCondition; + +import java.io.IOException; + +import org.junit.Test; + +// These tests prove the ibft_proposeValidatorVote and ibft_getValidatorsByBlockNumber (implicitly) +// JSON RPC calls. +public class IbftProposeRpcAcceptanceTest extends AcceptanceTestBase { + + @Test + public void validatorsCanBeAddedAndThenRemoved() throws IOException { + final String[] validators = {"validator1", "validator2", "validator3"}; + final PantheonNode validator1 = pantheon.createIbftNodeWithValidators("validator1", validators); + final PantheonNode validator2 = pantheon.createIbftNodeWithValidators("validator2", validators); + final PantheonNode validator3 = pantheon.createIbftNodeWithValidators("validator3", validators); + final PantheonNode nonValidatorNode = + pantheon.createIbftNodeWithValidators("non-validator", validators); + cluster.start(validator1, validator2, validator3, nonValidatorNode); + + cluster.verify(ibft.validatorsEqual(validator1, validator2, validator3)); + final WaitCondition addedCondition = wait.ibftValidatorsChanged(validator1); + validator1.execute(ibftTransactions.createAddProposal(nonValidatorNode)); + validator2.execute(ibftTransactions.createAddProposal(nonValidatorNode)); + + cluster.waitUntil(addedCondition); + cluster.verify(ibft.validatorsEqual(validator1, validator2, validator3, nonValidatorNode)); + + final WaitCondition removedCondition = wait.ibftValidatorsChanged(validator1); + validator2.execute(ibftTransactions.createRemoveProposal(nonValidatorNode)); + validator3.execute(ibftTransactions.createRemoveProposal(nonValidatorNode)); + nonValidatorNode.execute(ibftTransactions.createRemoveProposal(nonValidatorNode)); + cluster.waitUntil(removedCondition); + cluster.verify(ibft.validatorsEqual(validator1, validator2, validator3)); + } +}