From 9ced433d760c0ccad7e8b3c25951a58abc7ec316 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 6 Mar 2026 20:37:40 +0100 Subject: [PATCH] Remove Clique RPC APIs and remaining DSL test infrastructure (Phase 2) Delete the Clique JSON-RPC method implementations (clique_getSigners, clique_propose, clique_discard, clique_proposals, clique_getSignerMetrics, clique_getSignersAtHash) and all supporting classes: - consensus/clique/.../jsonrpc/ (production + test, 12 files) - CliqueQueryPluginServiceFactory (replaced with NoopPluginServiceFactory) - Acceptance-test DSL: condition/clique/ and transaction/clique/ packages - NodeRequests: drop CliqueRequestFactory field and clique() accessor - AcceptanceTestBase: drop clique/cliqueTransactions fields - BesuNode: remove CliqueRequestFactory from NodeRequests construction - NodeConfigurationFactory: remove createJsonRpcWithCliqueEnabledConfig() - BftConditions / AwaitValidatorSetChange: inline "latest" constant Remove RpcMethod entries CLIQUE_* and RpcApis.CLIQUE enum value. CliqueBesuControllerBuilder no longer overrides createAdditionalJsonRpcMethodFactory. Signed-off-by: Fabio Di Fabio Co-Authored-By: Claude Sonnet 4.6 --- .../acceptance/dsl/AcceptanceTestBase.java | 6 - .../bft/AwaitValidatorSetChange.java | 4 +- .../dsl/condition/bft/BftConditions.java | 4 +- .../clique/AwaitSignerSetChange.java | 45 --- .../condition/clique/CliqueConditions.java | 132 --------- .../dsl/condition/clique/ExpectNonceVote.java | 46 --- .../dsl/condition/clique/ExpectProposals.java | 41 --- .../condition/clique/ExpectValidators.java | 41 --- .../clique/ExpectValidatorsAtBlock.java | 44 --- .../clique/ExpectValidatorsAtBlockHash.java | 45 --- .../clique/ExpectedBlockHasProposer.java | 52 ---- .../tests/acceptance/dsl/node/BesuNode.java | 2 - .../NodeConfigurationFactory.java | 7 - .../dsl/transaction/NodeRequests.java | 8 - .../dsl/transaction/clique/CliqueDiscard.java | 44 --- .../transaction/clique/CliqueGetSigners.java | 45 --- .../clique/CliqueGetSignersAtHash.java | 46 --- .../transaction/clique/CliqueProposals.java | 39 --- .../dsl/transaction/clique/CliquePropose.java | 45 --- .../clique/CliqueRequestFactory.java | 76 ----- .../clique/CliqueTransactions.java | 50 ---- .../CliqueBesuControllerBuilder.java | 12 +- .../CliqueQueryPluginServiceFactory.java | 49 ---- .../clique/jsonrpc/CliqueJsonRpcMethods.java | 98 ------- .../methods/CliqueGetSignerMetrics.java | 46 --- .../jsonrpc/methods/CliqueGetSigners.java | 83 ------ .../methods/CliqueGetSignersAtHash.java | 81 ------ .../jsonrpc/methods/CliqueProposals.java | 38 --- .../clique/jsonrpc/methods/Discard.java | 62 ----- .../clique/jsonrpc/methods/Propose.java | 81 ------ .../methods/CliqueGetSignerMetricsTest.java | 262 ------------------ .../methods/CliqueGetSignersAtHashTest.java | 135 --------- .../jsonrpc/methods/CliqueGetSignersTest.java | 122 -------- .../jsonrpc/methods/CliqueProposalsTest.java | 48 ---- .../clique/jsonrpc/methods/DiscardTest.java | 131 --------- .../clique/jsonrpc/methods/ProposeTest.java | 170 ------------ .../besu/ethereum/api/jsonrpc/RpcApis.java | 1 - .../besu/ethereum/api/jsonrpc/RpcMethod.java | 6 - 38 files changed, 4 insertions(+), 2243 deletions(-) delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/AwaitSignerSetChange.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/CliqueConditions.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectNonceVote.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectProposals.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidators.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlock.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlockHash.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectedBlockHasProposer.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueProposals.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliquePropose.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueRequestFactory.java delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueTransactions.java delete mode 100644 app/src/main/java/org/hyperledger/besu/controller/CliqueQueryPluginServiceFactory.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetrics.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposals.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java delete mode 100644 consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersTest.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposalsTest.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java delete mode 100644 consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/ProposeTest.java diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java index 8146db2d089..201333f5988 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.blockchain.Blockchain; import org.hyperledger.besu.tests.acceptance.dsl.condition.admin.AdminConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.bft.BftConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.clique.CliqueConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.eth.EthConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.login.LoginConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions; @@ -37,7 +36,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.account.AccountTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.contract.ContractTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.debug.DebugTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; @@ -84,8 +82,6 @@ public class AcceptanceTestBase { protected final AdminConditions admin; protected final AdminTransactions adminTransactions; protected final Blockchain blockchain; - protected final CliqueConditions clique; - protected final CliqueTransactions cliqueTransactions; protected final Cluster cluster; protected final ContractVerifier contractVerifier; protected final ContractTransactions contractTransactions; @@ -113,14 +109,12 @@ protected AcceptanceTestBase() { ethTransactions = new EthTransactions(); accounts = new Accounts(ethTransactions); adminTransactions = new AdminTransactions(); - cliqueTransactions = new CliqueTransactions(); bftTransactions = new BftTransactions(); accountTransactions = new AccountTransactions(accounts); permissioningTransactions = new PermissioningTransactions(); contractTransactions = new ContractTransactions(); minerTransactions = new MinerTransactions(); blockchain = new Blockchain(ethTransactions); - clique = new CliqueConditions(ethTransactions, cliqueTransactions); eth = new EthConditions(ethTransactions); bft = new BftConditions(bftTransactions); login = new LoginConditions(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java index 85c448eff92..21dfca41d67 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; @@ -40,6 +39,7 @@ public void verify(final Node node) { WaitUtils.waitFor( 60, () -> - assertThat(node.execute(bft.createGetValidators(LATEST))).isNotEqualTo(initialSigners)); + assertThat(node.execute(bft.createGetValidators("latest"))) + .isNotEqualTo(initialSigners)); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java index 8439bce81c9..b10c62d0ade 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; - import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; @@ -56,7 +54,7 @@ private Address[] validatorAddresses(final BesuNode[] validators) { } public Condition awaitValidatorSetChange(final Node node) { - return new AwaitValidatorSetChange(node.execute(bft.createGetValidators(LATEST)), bft); + return new AwaitValidatorSetChange(node.execute(bft.createGetValidators("latest")), bft); } public Condition noProposals() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/AwaitSignerSetChange.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/AwaitSignerSetChange.java deleted file mode 100644 index f332b387c0d..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/AwaitSignerSetChange.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; - -import java.util.List; - -public class AwaitSignerSetChange implements Condition { - - private final CliqueTransactions clique; - private final List
initialSigners; - - public AwaitSignerSetChange(final List
initialSigners, final CliqueTransactions clique) { - this.initialSigners = initialSigners; - this.clique = clique; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - 60, - () -> - assertThat(node.execute(clique.createGetSigners(LATEST))).isNotEqualTo(initialSigners)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/CliqueConditions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/CliqueConditions.java deleted file mode 100644 index 4490a2b2a2e..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/CliqueConditions.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static java.util.Collections.emptyList; -import static org.hyperledger.besu.datatypes.Hash.fromHexString; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; - -import org.hyperledger.besu.config.CliqueConfigOptions; -import org.hyperledger.besu.config.GenesisConfig; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.condition.blockchain.ExpectBlockNotCreated; -import org.hyperledger.besu.tests.acceptance.dsl.condition.clique.ExpectNonceVote.CLIQUE_NONCE_VOTE; -import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableMap; -import org.web3j.protocol.core.DefaultBlockParameter; - -public class CliqueConditions { - - private final EthTransactions eth; - private final CliqueTransactions clique; - - public CliqueConditions(final EthTransactions eth, final CliqueTransactions clique) { - this.eth = eth; - this.clique = clique; - } - - public Condition validatorsEqual(final BesuNode... validators) { - return new ExpectValidators(clique, validatorAddresses(validators)); - } - - public Condition validatorsAtBlockEqual(final String blockNumber, final BesuNode... validators) { - return new ExpectValidatorsAtBlock(clique, blockNumber, validatorAddresses(validators)); - } - - public Condition validatorsAtBlockHashFromBlockNumberEqual( - final Node node, final long blockNumber, final BesuNode... validators) { - final DefaultBlockParameter blockParameter = - DefaultBlockParameter.valueOf(BigInteger.valueOf(blockNumber)); - final String blockHash = node.execute(eth.block(blockParameter)).getHash(); - return new ExpectValidatorsAtBlockHash( - clique, fromHexString(blockHash), validatorAddresses(validators)); - } - - public ProposalsConfig proposalsEqual() { - return new ProposalsConfig(clique); - } - - public Condition noProposals() { - return new ExpectProposals(clique, ImmutableMap.of()); - } - - public Condition nonceVoteEquals(final CLIQUE_NONCE_VOTE clique_nonce_vote) { - return new ExpectNonceVote(eth, clique_nonce_vote); - } - - public Condition noNewBlockCreated(final BesuNode node) { - final int blockPeriodSeconds = cliqueBlockPeriod(node); - final int blockPeriodWait = blockPeriodSeconds * 1000; - return new ExpectBlockNotCreated(eth, blockPeriodWait, blockPeriodWait); - } - - public Condition awaitSignerSetChange(final Node node) { - return new AwaitSignerSetChange(node.execute(clique.createGetSigners(LATEST)), clique); - } - - private int cliqueBlockPeriod(final BesuNode node) { - final String config = node.getGenesisConfigProvider().create(emptyList()).get(); - final GenesisConfig genesisConfig = GenesisConfig.fromConfig(config); - final CliqueConfigOptions cliqueConfigOptions = - genesisConfig.getConfigOptions().getCliqueConfigOptions(); - return cliqueConfigOptions.getBlockPeriodSeconds(); - } - - private Address[] validatorAddresses(final BesuNode[] validators) { - return Arrays.stream(validators).map(BesuNode::getAddress).sorted().toArray(Address[]::new); - } - - public Condition blockIsCreatedByProposer(final BesuNode proposer) { - return new ExpectedBlockHasProposer(eth, proposer.getAddress()); - } - - public static class ProposalsConfig { - - private final Map proposals = new HashMap<>(); - private final CliqueTransactions clique; - - public ProposalsConfig(final CliqueTransactions clique) { - this.clique = clique; - } - - public ProposalsConfig addProposal(final BesuNode node) { - proposals.put(node, true); - return this; - } - - public ProposalsConfig removeProposal(final BesuNode node) { - proposals.put(node, false); - return this; - } - - public Condition build() { - final Map proposalsAsAddress = - this.proposals.entrySet().stream() - .collect(Collectors.toMap(p -> p.getKey().getAddress(), Map.Entry::getValue)); - return new ExpectProposals(clique, proposalsAsAddress); - } - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectNonceVote.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectNonceVote.java deleted file mode 100644 index 1e8f4b8a99f..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectNonceVote.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.tests.acceptance.dsl.condition.clique.ExpectNonceVote.CLIQUE_NONCE_VOTE.AUTH; - -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; - -public class ExpectNonceVote implements Condition { - private static final String NONCE_AUTH = "0xffffffffffffffff"; - private static final String NONCE_DROP = "0x0000000000000000"; - private final EthTransactions eth; - private final String expectedNonce; - - public enum CLIQUE_NONCE_VOTE { - AUTH, - DROP - } - - public ExpectNonceVote(final EthTransactions eth, final CLIQUE_NONCE_VOTE vote) { - this.eth = eth; - this.expectedNonce = vote == AUTH ? NONCE_AUTH : NONCE_DROP; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - () -> assertThat(node.execute(eth.block()).getNonceRaw()).isEqualTo(expectedNonce)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectProposals.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectProposals.java deleted file mode 100644 index 715c3501672..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectProposals.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; - -import java.util.Map; - -public class ExpectProposals implements Condition { - private final CliqueTransactions clique; - private final Map proposers; - - public ExpectProposals(final CliqueTransactions clique, final Map proposers) { - this.clique = clique; - this.proposers = proposers; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - () -> assertThat(node.execute(clique.createProposals())).isEqualTo(proposers)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidators.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidators.java deleted file mode 100644 index 4d25745333b..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidators.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; - -public class ExpectValidators implements Condition { - private final CliqueTransactions clique; - private final Address[] validators; - - public ExpectValidators(final CliqueTransactions clique, final Address... validators) { - this.clique = clique; - this.validators = validators; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - () -> - assertThat(node.execute(clique.createGetSigners(LATEST))).containsExactly(validators)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlock.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlock.java deleted file mode 100644 index 6482dd13e6c..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlock.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; - -public class ExpectValidatorsAtBlock implements Condition { - private final CliqueTransactions clique; - private final String blockParameter; - private final Address[] validators; - - public ExpectValidatorsAtBlock( - final CliqueTransactions clique, final String blockNumber, final Address... validators) { - this.clique = clique; - this.blockParameter = blockNumber; - this.validators = validators; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - () -> - assertThat(node.execute(clique.createGetSigners(blockParameter))) - .containsExactly(validators)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlockHash.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlockHash.java deleted file mode 100644 index f9d3e26289d..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectValidatorsAtBlockHash.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; - -public class ExpectValidatorsAtBlockHash implements Condition { - private final CliqueTransactions clique; - private final Hash blockHash; - private final Address[] validators; - - public ExpectValidatorsAtBlockHash( - final CliqueTransactions clique, final Hash blockHash, final Address... validators) { - this.clique = clique; - this.blockHash = blockHash; - this.validators = validators; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor( - () -> - assertThat(node.execute(clique.createGetSignersAtHash(blockHash))) - .containsExactly(validators)); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectedBlockHasProposer.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectedBlockHasProposer.java deleted file mode 100644 index 4abba67a0d5..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/clique/ExpectedBlockHasProposer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions; -import org.hyperledger.besu.consensus.clique.CliqueExtraData; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.tests.acceptance.dsl.BlockUtils; -import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; -import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; - -import org.web3j.protocol.core.methods.response.EthBlock.Block; - -public class ExpectedBlockHasProposer implements Condition { - private final EthTransactions eth; - private final Address proposer; - - public ExpectedBlockHasProposer(final EthTransactions eth, final Address proposer) { - this.eth = eth; - this.proposer = proposer; - } - - @Override - public void verify(final Node node) { - WaitUtils.waitFor(() -> assertThat(proposerAddress(node)).isEqualTo(proposer)); - } - - private Address proposerAddress(final Node node) { - final Block block = node.execute(eth.block()); - final BlockHeader blockHeader = - BlockUtils.createBlockHeader(block, new CliqueBlockHeaderFunctions()); - final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(blockHeader); - return cliqueExtraData.getProposerAddress(); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index 3421072ff09..5574ff72582 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -45,7 +45,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.ConsensusType; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.debug.DebugRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.login.LoginRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerRequestFactory; @@ -490,7 +489,6 @@ public NodeRequests nodeRequests() { new NodeRequests( web3jService, new JsonRpc2_0Web3j(web3jService, 2000, Async.defaultExecutorService()), - new CliqueRequestFactory(web3jService), new BftRequestFactory(web3jService, bftType), new PermissioningJsonRpcRequestFactory(web3jService), new AdminRequestFactory(web3jService), diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java index c2e82c0f835..e2f5b2d444f 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java @@ -17,7 +17,6 @@ import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ADMIN; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.CLIQUE; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.IBFT; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.MINER; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.QBFT; @@ -48,12 +47,6 @@ public Optional createGenesisConfigForValidators( return genesisConfigProvider.create(nodes); } - public JsonRpcConfiguration createJsonRpcWithCliqueEnabledConfig(final Set extraRpcApis) { - final var enabledApis = new HashSet<>(extraRpcApis); - enabledApis.add(CLIQUE.name()); - return createJsonRpcWithRpcApiEnabledConfig(enabledApis.toArray(String[]::new)); - } - public JsonRpcConfiguration createJsonRpcWithIbft2EnabledConfig(final boolean minerEnabled) { return minerEnabled ? createJsonRpcWithRpcApiEnabledConfig(IBFT.name(), MINER.name()) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java index e5bddf8e9bd..f36fded86a6 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java @@ -16,7 +16,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftRequestFactory; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.debug.DebugRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.login.LoginRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerRequestFactory; @@ -34,7 +33,6 @@ public class NodeRequests { private final Web3jService web3jService; private final Web3j netEth; - private final CliqueRequestFactory clique; private final BftRequestFactory bft; private final PermissioningJsonRpcRequestFactory perm; private final AdminRequestFactory admin; @@ -49,7 +47,6 @@ public class NodeRequests { public NodeRequests( final Web3jService web3jService, final Web3j netEth, - final CliqueRequestFactory clique, final BftRequestFactory bft, final PermissioningJsonRpcRequestFactory perm, final AdminRequestFactory admin, @@ -62,7 +59,6 @@ public NodeRequests( final PluginsRequestFactory plugins) { this.web3jService = web3jService; this.netEth = netEth; - this.clique = clique; this.bft = bft; this.perm = perm; this.admin = admin; @@ -83,10 +79,6 @@ public Web3j net() { return netEth; } - public CliqueRequestFactory clique() { - return clique; - } - public BftRequestFactory bft() { return bft; } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java deleted file mode 100644 index 5888913760b..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueDiscard.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; - -import java.io.IOException; - -import org.web3j.protocol.core.Response; - -public class CliqueDiscard implements Transaction { - private final String address; - - public CliqueDiscard(final String address) { - this.address = address; - } - - @Override - public Boolean execute(final NodeRequests node) { - try { - final Response result = node.clique().cliqueDiscard(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/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java deleted file mode 100644 index 481d6bd3460..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSigners.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; - -import java.io.IOException; -import java.util.List; - -public class CliqueGetSigners implements Transaction> { - private final String blockNumber; - - public CliqueGetSigners(final String blockNumber) { - this.blockNumber = blockNumber; - } - - @Override - public List
execute(final NodeRequests node) { - try { - final CliqueRequestFactory.SignersBlockResponse result = - node.clique().cliqueGetSigners(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/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java deleted file mode 100644 index 31a1e8872cc..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueGetSignersAtHash.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; - -import java.io.IOException; -import java.util.List; - -public class CliqueGetSignersAtHash implements Transaction> { - private final Hash hash; - - public CliqueGetSignersAtHash(final Hash hash) { - this.hash = hash; - } - - @Override - public List
execute(final NodeRequests node) { - try { - final CliqueRequestFactory.SignersBlockResponse result = - node.clique().cliqueGetSignersAtHash(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/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueProposals.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueProposals.java deleted file mode 100644 index 634af775be9..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueProposals.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; - -import java.io.IOException; -import java.util.Map; - -public class CliqueProposals implements Transaction> { - - @Override - public Map execute(final NodeRequests node) { - try { - final CliqueRequestFactory.ProposalsResponse result = node.clique().cliqueProposals().send(); - assertThat(result).isNotNull(); - assertThat(result.hasError()).isFalse(); - return result.getResult(); - } catch (final IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliquePropose.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliquePropose.java deleted file mode 100644 index 69462e29de6..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliquePropose.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; - -import java.io.IOException; - -public class CliquePropose implements Transaction { - private final String address; - private final boolean auth; - - public CliquePropose(final String address, final boolean auth) { - this.address = address; - this.auth = auth; - } - - @Override - public Boolean execute(final NodeRequests node) { - try { - final CliqueRequestFactory.ProposeResponse result = - node.clique().cliquePropose(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/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueRequestFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueRequestFactory.java deleted file mode 100644 index a25b568eae0..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueRequestFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.web3j.protocol.Web3jService; -import org.web3j.protocol.core.Request; -import org.web3j.protocol.core.Response; - -public class CliqueRequestFactory { - - public static class ProposeResponse extends Response {} - - public static class DiscardResponse extends Response {} - - public static class SignersBlockResponse extends Response> {} - - public static class ProposalsResponse extends Response> {} - - private final Web3jService web3jService; - - public CliqueRequestFactory(final Web3jService web3jService) { - this.web3jService = web3jService; - } - - Request cliquePropose(final String address, final Boolean auth) { - return new Request<>( - "clique_propose", - Arrays.asList(address, auth.toString()), - web3jService, - ProposeResponse.class); - } - - Request cliqueDiscard(final String address) { - return new Request<>( - "clique_discard", singletonList(address), web3jService, DiscardResponse.class); - } - - Request cliqueProposals() { - return new Request<>("clique_proposals", emptyList(), web3jService, ProposalsResponse.class); - } - - Request cliqueGetSigners(final String blockNumber) { - return new Request<>( - "clique_getSigners", singletonList(blockNumber), web3jService, SignersBlockResponse.class); - } - - Request cliqueGetSignersAtHash(final Hash hash) { - return new Request<>( - "clique_getSignersAtHash", - singletonList(hash.toString()), - web3jService, - SignersBlockResponse.class); - } -} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueTransactions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueTransactions.java deleted file mode 100644 index 9df60f969a9..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/clique/CliqueTransactions.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.clique; - -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; - -public class CliqueTransactions { - public static final String LATEST = "latest"; - - public CliquePropose createRemoveProposal(final BesuNode node) { - return propose(node.getAddress().toString(), false); - } - - public CliquePropose createAddProposal(final BesuNode node) { - return propose(node.getAddress().toString(), true); - } - - private CliquePropose propose(final String address, final boolean auth) { - return new CliquePropose(address, auth); - } - - public CliqueProposals createProposals() { - return new CliqueProposals(); - } - - public CliqueGetSigners createGetSigners(final String blockNumber) { - return new CliqueGetSigners(blockNumber); - } - - public CliqueGetSignersAtHash createGetSignersAtHash(final Hash blockHash) { - return new CliqueGetSignersAtHash(blockHash); - } - - public CliqueDiscard createDiscardProposal(final BesuNode node) { - return new CliqueDiscard(node.getAddress().toString()); - } -} diff --git a/app/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/app/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index 93374af51b0..564709ed034 100644 --- a/app/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/app/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -24,14 +24,12 @@ import org.hyperledger.besu.consensus.clique.blockcreation.CliqueBlockScheduler; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueMinerExecutor; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueMiningCoordinator; -import org.hyperledger.besu.consensus.clique.jsonrpc.CliqueJsonRpcMethods; import org.hyperledger.besu.consensus.common.BlockInterface; import org.hyperledger.besu.consensus.common.EpochManager; import org.hyperledger.besu.consensus.common.ForksSchedule; import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -69,14 +67,6 @@ protected void prepForBuild() { forksSchedule = CliqueForksSchedulesFactory.create(genesisConfigOptions); } - @Override - protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( - final ProtocolContext protocolContext, - final ProtocolSchedule protocolSchedule, - final MiningConfiguration miningConfiguration) { - return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningConfiguration); - } - @Override protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, @@ -152,7 +142,7 @@ protected void validateContext(final ProtocolContext context) { @Override protected PluginServiceFactory createAdditionalPluginServices( final Blockchain blockchain, final ProtocolContext protocolContext) { - return new CliqueQueryPluginServiceFactory(blockchain, nodeKey); + return new NoopPluginServiceFactory(); } @Override diff --git a/app/src/main/java/org/hyperledger/besu/controller/CliqueQueryPluginServiceFactory.java b/app/src/main/java/org/hyperledger/besu/controller/CliqueQueryPluginServiceFactory.java deleted file mode 100644 index 9d9a2a901c8..00000000000 --- a/app/src/main/java/org/hyperledger/besu/controller/CliqueQueryPluginServiceFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.controller; - -import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.PoaQueryServiceImpl; -import org.hyperledger.besu.cryptoservices.NodeKey; -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.plugin.services.query.PoaQueryService; -import org.hyperledger.besu.services.BesuPluginContextImpl; - -/** The Clique query plugin service factory. */ -public class CliqueQueryPluginServiceFactory implements PluginServiceFactory { - - private final Blockchain blockchain; - private final NodeKey nodeKey; - - /** - * Instantiates a new Clique query plugin service factory. - * - * @param blockchain the blockchain - * @param nodeKey the node key - */ - public CliqueQueryPluginServiceFactory(final Blockchain blockchain, final NodeKey nodeKey) { - this.blockchain = blockchain; - this.nodeKey = nodeKey; - } - - @Override - public void appendPluginServices(final BesuPluginContextImpl besuContext) { - final BlockInterface blockInterface = new CliqueBlockInterface(); - final PoaQueryServiceImpl service = - new PoaQueryServiceImpl(blockInterface, blockchain, nodeKey); - besuContext.addService(PoaQueryService.class, service); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java deleted file mode 100644 index 4e1e75f54c8..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc; - -import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; -import org.hyperledger.besu.consensus.clique.CliqueContext; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.CliqueGetSignerMetrics; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.CliqueGetSigners; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.CliqueGetSignersAtHash; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.CliqueProposals; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.Discard; -import org.hyperledger.besu.consensus.clique.jsonrpc.methods.Propose; -import org.hyperledger.besu.consensus.common.EpochManager; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningConfiguration; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; - -import java.util.Map; - -/** The Clique json rpc methods. */ -public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods { - private final ProtocolContext context; - private final ProtocolSchedule protocolSchedule; - private final MiningConfiguration miningConfiguration; - - /** - * Instantiates a new Clique json rpc methods. - * - * @param context the protocol context - * @param protocolSchedule the protocol schedule - * @param miningConfiguration the mining parameters - */ - public CliqueJsonRpcMethods( - final ProtocolContext context, - final ProtocolSchedule protocolSchedule, - final MiningConfiguration miningConfiguration) { - this.context = context; - this.protocolSchedule = protocolSchedule; - this.miningConfiguration = miningConfiguration; - } - - @Override - protected String getApiGroup() { - return RpcApis.CLIQUE.name(); - } - - @Override - protected Map create() { - final MutableBlockchain blockchain = context.getBlockchain(); - final WorldStateArchive worldStateArchive = context.getWorldStateArchive(); - final BlockchainQueries blockchainQueries = - new BlockchainQueries(protocolSchedule, blockchain, worldStateArchive, miningConfiguration); - final ValidatorProvider validatorProvider = - context.getConsensusContext(CliqueContext.class).getValidatorProvider(); - - // Must create our own voteTallyCache as using this would pollute the main voteTallyCache - final ValidatorProvider readOnlyValidatorProvider = - createValidatorProvider(context, blockchain); - - return mapOf( - new CliqueGetSigners(blockchainQueries, readOnlyValidatorProvider), - new CliqueGetSignersAtHash(blockchainQueries, readOnlyValidatorProvider), - new Propose(validatorProvider), - new Discard(validatorProvider), - new CliqueProposals(validatorProvider), - new CliqueGetSignerMetrics( - readOnlyValidatorProvider, new CliqueBlockInterface(), blockchainQueries)); - } - - private ValidatorProvider createValidatorProvider( - final ProtocolContext context, final MutableBlockchain blockchain) { - final EpochManager epochManager = - context.getConsensusContext(CliqueContext.class).getEpochManager(); - final CliqueBlockInterface cliqueBlockInterface = new CliqueBlockInterface(); - return BlockValidatorProvider.nonForkingValidatorProvider( - blockchain, epochManager, cliqueBlockInterface); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetrics.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetrics.java deleted file mode 100644 index 514ab0a4e60..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetrics.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.jsonrpc.AbstractGetSignerMetricsMethod; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; - -/** The Clique get signer metrics. */ -public class CliqueGetSignerMetrics extends AbstractGetSignerMetricsMethod - implements JsonRpcMethod { - - /** - * Instantiates a new Clique get signer metrics. - * - * @param validatorProvider the validator provider - * @param blockInterface the block interface - * @param blockchainQueries the blockchain queries - */ - public CliqueGetSignerMetrics( - final ValidatorProvider validatorProvider, - final BlockInterface blockInterface, - final BlockchainQueries blockchainQueries) { - super(validatorProvider, blockInterface, blockchainQueries); - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_GET_SIGNER_METRICS.getMethodName(); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java deleted file mode 100644 index 057fb30ee5e..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.core.BlockHeader; - -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -/** The Clique get signers. */ -public class CliqueGetSigners implements JsonRpcMethod { - private final BlockchainQueries blockchainQueries; - private final ValidatorProvider validatorProvider; - - /** - * Instantiates a new Clique get signers. - * - * @param blockchainQueries the blockchain queries - * @param validatorProvider the validator provider - */ - public CliqueGetSigners( - final BlockchainQueries blockchainQueries, final ValidatorProvider validatorProvider) { - this.blockchainQueries = blockchainQueries; - this.validatorProvider = validatorProvider; - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_GET_SIGNERS.getMethodName(); - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional blockHeader = determineBlockHeader(requestContext); - return blockHeader - .map(validatorProvider::getValidatorsAfterBlock) - .map(addresses -> addresses.stream().map(Objects::toString).collect(Collectors.toList())) - .map( - addresses -> new JsonRpcSuccessResponse(requestContext.getRequest().getId(), addresses)) - .orElse( - new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INTERNAL_ERROR)); - } - - private Optional determineBlockHeader(final JsonRpcRequestContext request) { - final Optional blockParameter; - try { - blockParameter = request.getOptionalParameter(0, BlockParameter.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); - } - final long latest = blockchainQueries.headBlockNumber(); - final long blockNumber = blockParameter.map(b -> b.getNumber().orElse(latest)).orElse(latest); - return blockchainQueries.blockByNumber(blockNumber).map(BlockWithMetadata::getHeader); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java deleted file mode 100644 index 908ff9f4123..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.core.BlockHeader; - -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -/** The Clique get signers at hash. */ -public class CliqueGetSignersAtHash implements JsonRpcMethod { - private final BlockchainQueries blockchainQueries; - private final ValidatorProvider validatorProvider; - - /** - * Instantiates a new Clique get signers at hash. - * - * @param blockchainQueries the blockchain queries - * @param validatorProvider the validator provider - */ - public CliqueGetSignersAtHash( - final BlockchainQueries blockchainQueries, final ValidatorProvider validatorProvider) { - this.blockchainQueries = blockchainQueries; - this.validatorProvider = validatorProvider; - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_GET_SIGNERS_AT_HASH.getMethodName(); - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional blockHeader = determineBlockHeader(requestContext); - return blockHeader - .map(validatorProvider::getValidatorsAfterBlock) - .map(addresses -> addresses.stream().map(Objects::toString).collect(Collectors.toList())) - .map( - addresses -> new JsonRpcSuccessResponse(requestContext.getRequest().getId(), addresses)) - .orElse( - new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INTERNAL_ERROR)); - } - - private Optional determineBlockHeader(final JsonRpcRequestContext request) { - final Hash hash; - try { - hash = request.getRequiredParameter(0, Hash.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); - } - return blockchainQueries.blockByHash(hash).map(BlockWithMetadata::getHeader); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposals.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposals.java deleted file mode 100644 index 02a266c4364..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposals.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import org.hyperledger.besu.consensus.common.jsonrpc.AbstractVoteProposerMethod; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; - -/** The Clique proposals. */ -public class CliqueProposals extends AbstractVoteProposerMethod implements JsonRpcMethod { - - /** - * Instantiates a new Clique proposals. - * - * @param validatorProvider the validator provider - */ - public CliqueProposals(final ValidatorProvider validatorProvider) { - super(validatorProvider); - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_GET_PROPOSALS.getMethodName(); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java deleted file mode 100644 index da3214b1ef0..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static com.google.common.base.Preconditions.checkState; - -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; - -/** The Discard Json RPC method. */ -public class Discard implements JsonRpcMethod { - private final ValidatorProvider validatorProvider; - - /** - * Instantiates a new Discard. - * - * @param validatorProvider the validator provider - */ - public Discard(final ValidatorProvider validatorProvider) { - this.validatorProvider = validatorProvider; - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_DISCARD.getMethodName(); - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - checkState( - validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider"); - final Address address; - try { - address = requestContext.getRequiredParameter(0, Address.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); - } - validatorProvider.getVoteProviderAtHead().get().discardVote(address); - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } -} diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java deleted file mode 100644 index 26ab19c9882..00000000000 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static com.google.common.base.Preconditions.checkState; - -import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; - -/** The Propose Json Rpc method. */ -public class Propose implements JsonRpcMethod { - private final ValidatorProvider validatorProvider; - - /** - * Instantiates a new Propose. - * - * @param validatorProvider the validator provider - */ - public Propose(final ValidatorProvider validatorProvider) { - this.validatorProvider = validatorProvider; - } - - @Override - public String getName() { - return RpcMethod.CLIQUE_PROPOSE.getMethodName(); - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - checkState( - validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider"); - final Address address; - try { - address = requestContext.getRequiredParameter(0, Address.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); - } - final Boolean auth; - try { - auth = requestContext.getRequiredParameter(1, Boolean.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid auth parameter (index 1)", RpcErrorType.INVALID_PROPOSAL_PARAMS, e); - } - if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST); - } - - if (auth) { - validatorProvider.getVoteProviderAtHead().get().authVote(address); - } else { - validatorProvider.getVoteProviderAtHead().get().dropVote(address); - } - // Return true regardless, the vote is always recorded - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java deleted file mode 100644 index 310b3b1017d..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.AdditionalMatchers.lt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SignerMetricResult; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.stream.LongStream; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class CliqueGetSignerMetricsTest { - - private static final Address[] VALIDATORS = { - Address.fromHexString("0x1"), Address.fromHexString("0x2"), Address.fromHexString("0x3") - }; - - private final String CLIQUE_METHOD = "clique_getSignerMetrics"; - private final String JSON_RPC_VERSION = "2.0"; - private CliqueGetSignerMetrics method; - - private ValidatorProvider validatorProvider; - private BlockchainQueries blockchainQueries; - private BlockInterface blockInterface; - - @BeforeEach - public void setup() { - validatorProvider = mock(ValidatorProvider.class); - blockchainQueries = mock(BlockchainQueries.class); - blockInterface = mock(BlockInterface.class); - method = new CliqueGetSignerMetrics(validatorProvider, blockInterface, blockchainQueries); - } - - @Test - public void returnsCorrectMethodName() { - assertThat(method.getName()).isEqualTo(CLIQUE_METHOD); - } - - @Test - public void exceptionWhenInvalidStartBlockSupplied() { - assertThatThrownBy(() -> method.response(requestWithParams("INVALID"))) - .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid start block parameter (index 0)"); - } - - @Test - public void exceptionWhenInvalidEndBlockSupplied() { - assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID"))) - .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid end block parameter (index 1)"); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetricsWhenNoParams() { - - final long startBlock = 1L; - final long endBlock = 3L; - - when(blockchainQueries.headBlockNumber()).thenReturn(endBlock); - - final List signerMetricResultList = new ArrayList<>(); - - LongStream.range(startBlock, endBlock) - .forEach(value -> signerMetricResultList.add(generateBlock(value))); - - signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0])); // missing validator - - final JsonRpcRequestContext request = requestWithParams(); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetrics() { - - final long startBlock = 1L; - final long endBlock = 5L; - - when(blockchainQueries.headBlockNumber()).thenReturn(endBlock); - - final List signerMetricResultList = new ArrayList<>(); - - // sign a first block with keypairs number 1 - final SignerMetricResult signerMetricResultFirstKeyPairs = generateBlock(startBlock); - signerMetricResultList.add(signerMetricResultFirstKeyPairs); - // sign a second block with keypairs number 2 - final SignerMetricResult signerMetricResultSecondKeyPairs = generateBlock(startBlock + 1); - signerMetricResultList.add(signerMetricResultSecondKeyPairs); - // sign a third block with keypairs number 3 - final SignerMetricResult signerMetricResultThirdKeyPairs = generateBlock(startBlock + 2); - signerMetricResultList.add(signerMetricResultThirdKeyPairs); - // sign the last block with the keypairs number 1 - generateBlock(startBlock + 3); - signerMetricResultFirstKeyPairs.setLastProposedBlockNumber(startBlock + 3); - signerMetricResultFirstKeyPairs.incrementeNbBlock(); - - final JsonRpcRequestContext request = requestWithParams(); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetricsWhenThereAreFewerBlocksThanTheDefaultRange() { - final long startBlock = 0L; - final long headBlock = 2L; - - final List signerMetricResultList = new ArrayList<>(); - - when(blockchainQueries.headBlockNumber()).thenReturn(headBlock); - - LongStream.range(startBlock, headBlock) - .forEach(value -> signerMetricResultList.add(generateBlock(value))); - - signerMetricResultList.add(new SignerMetricResult(VALIDATORS[2])); // missing validator - - final JsonRpcRequestContext request = requestWithParams(); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - // verify getBlockHeaderByNumber is not called with negative values - verify(blockchainQueries, never()).getBlockHeaderByNumber(lt(0L)); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetricsWithLatest() { - - final long startBlock = 1L; - final long endBlock = 3L; - - final List signerMetricResultList = new ArrayList<>(); - - when(blockchainQueries.headBlockNumber()).thenReturn(endBlock); - - LongStream.range(startBlock, endBlock) - .forEach(value -> signerMetricResultList.add(generateBlock(value))); - - signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0])); // missing validator - - final JsonRpcRequestContext request = requestWithParams(String.valueOf(startBlock), "latest"); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetricsWithPending() { - - final long startBlock = 1L; - final long endBlock = 3L; - - final List signerMetricResultList = new ArrayList<>(); - - when(blockchainQueries.headBlockNumber()).thenReturn(endBlock); - - LongStream.range(startBlock, endBlock) - .forEach(value -> signerMetricResultList.add(generateBlock(value))); - - signerMetricResultList.add(new SignerMetricResult(VALIDATORS[0])); // missing validator - - final JsonRpcRequestContext request = requestWithParams(String.valueOf(startBlock), "pending"); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - @Test - @SuppressWarnings("unchecked") - public void getSignerMetricsWithEarliest() { - - final long startBlock = 0L; - final long endBlock = 3L; - - final List signerMetricResultList = new ArrayList<>(); - - when(blockchainQueries.headBlockNumber()).thenReturn(endBlock); - - LongStream.range(startBlock, endBlock) - .forEach(value -> signerMetricResultList.add(generateBlock(value))); - - final JsonRpcRequestContext request = requestWithParams("earliest", String.valueOf(endBlock)); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - - assertThat((Collection) response.getResult()) - .containsExactlyInAnyOrderElementsOf(signerMetricResultList); - } - - private JsonRpcRequestContext requestWithParams(final Object... params) { - return new JsonRpcRequestContext(new JsonRpcRequest(JSON_RPC_VERSION, CLIQUE_METHOD, params)); - } - - private SignerMetricResult generateBlock(final long number) { - - final Address proposerAddressBlock = VALIDATORS[(int) (number % VALIDATORS.length)]; - - final BlockHeader header = new BlockHeaderTestFixture().number(number).buildHeader(); - - when(blockchainQueries.getBlockHeaderByNumber(number)).thenReturn(Optional.of(header)); - when(blockInterface.getProposerOfBlock(header)).thenReturn(proposerAddressBlock); - - when(validatorProvider.getValidatorsAfterBlock(header)).thenReturn((Arrays.asList(VALIDATORS))); - - final SignerMetricResult signerMetricResult = new SignerMetricResult(proposerAddressBlock); - signerMetricResult.incrementeNbBlock(); - signerMetricResult.setLastProposedBlockNumber(number); - - return signerMetricResult; - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java deleted file mode 100644 index 3699ccf6eed..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.datatypes.Address.fromHexString; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; - -import java.util.List; -import java.util.Optional; - -import org.apache.tuweni.bytes.Bytes; -import org.assertj.core.api.AssertionsForClassTypes; -import org.bouncycastle.util.encoders.Hex; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class CliqueGetSignersAtHashTest { - - private CliqueGetSignersAtHash method; - private BlockHeader blockHeader; - private List
validators; - private List validatorsAsStrings; - - @Mock private BlockchainQueries blockchainQueries; - @Mock private BlockWithMetadata blockWithMetadata; - @Mock private ValidatorProvider validatorProvider; - - public static final String BLOCK_HASH = - "0xe36a3edf0d8664002a72ef7c5f8e271485e7ce5c66455a07cb679d855818415f"; - - @BeforeEach - public void setup() { - method = new CliqueGetSignersAtHash(blockchainQueries, validatorProvider); - - final byte[] genesisBlockExtraData = - Hex.decode( - "52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - - blockHeader = - new BlockHeaderTestFixture() - .blockHeaderFunctions(new CliqueBlockHeaderFunctions()) - .extraData(Bytes.wrap(genesisBlockExtraData)) - .buildHeader(); - - validators = - asList( - fromHexString("0x42eb768f2244c8811c63729a21a3569731535f06"), - fromHexString("0x7ffc57839b00206d1ad20c69a1981b489f772031"), - fromHexString("0xb279182d99e65703f0076e4812653aab85fca0f0")); - validatorsAsStrings = validators.stream().map(Object::toString).collect(toList()); - } - - @Test - public void returnsMethodName() { - assertThat(method.getName()).isEqualTo("clique_getSignersAtHash"); - } - - @Test - @SuppressWarnings("unchecked") - public void failsWhenNoParam() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] {})); - - final Throwable thrown = AssertionsForClassTypes.catchThrowable(() -> method.response(request)); - - assertThat(thrown) - .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid block hash parameter (index 0)"); - } - - @Test - @SuppressWarnings("unchecked") - public void returnsValidatorsForBlockHash() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "clique_getSignersAtHash", new Object[] {BLOCK_HASH})); - - when(blockchainQueries.blockByHash(Hash.fromHexString(BLOCK_HASH))) - .thenReturn(Optional.of(blockWithMetadata)); - when(blockWithMetadata.getHeader()).thenReturn(blockHeader); - when(validatorProvider.getValidatorsAfterBlock(blockHeader)).thenReturn(validators); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - assertThat(response.getResult()).isEqualTo(validatorsAsStrings); - } - - @Test - public void failsOnInvalidBlockHash() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {BLOCK_HASH})); - - when(blockchainQueries.blockByHash(Hash.fromHexString(BLOCK_HASH))) - .thenReturn(Optional.empty()); - - final JsonRpcErrorResponse response = (JsonRpcErrorResponse) method.response(request); - assertThat(response.getErrorType()).isEqualTo(RpcErrorType.INTERNAL_ERROR); - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersTest.java deleted file mode 100644 index 8cb6fd11039..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.datatypes.Address.fromHexString; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; - -import java.util.List; -import java.util.Optional; - -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class CliqueGetSignersTest { - private CliqueGetSigners method; - private BlockHeader blockHeader; - private List
validators; - private List validatorAsStrings; - - @Mock private BlockchainQueries blockchainQueries; - @Mock private ValidatorProvider validatorProvider; - @Mock private BlockWithMetadata blockWithMetadata; - - @BeforeEach - public void setup() { - method = new CliqueGetSigners(blockchainQueries, validatorProvider); - - final String genesisBlockExtraData = - "52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - final Bytes bufferToInject = Bytes.fromHexString(genesisBlockExtraData); - final BlockHeaderTestFixture blockHeaderTestFixture = new BlockHeaderTestFixture(); - blockHeader = blockHeaderTestFixture.extraData(bufferToInject).buildHeader(); - - validators = - asList( - fromHexString("0x42eb768f2244c8811c63729a21a3569731535f06"), - fromHexString("0x7ffc57839b00206d1ad20c69a1981b489f772031"), - fromHexString("0xb279182d99e65703f0076e4812653aab85fca0f0")); - validatorAsStrings = validators.stream().map(Object::toString).collect(toList()); - } - - @Test - public void returnsMethodName() { - assertThat(method.getName()).isEqualTo("clique_getSigners"); - } - - @Test - @SuppressWarnings("unchecked") - public void returnsValidatorsWhenNoParam() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext(new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {})); - - when(blockchainQueries.headBlockNumber()).thenReturn(3065995L); - when(blockchainQueries.blockByNumber(3065995L)).thenReturn(Optional.of(blockWithMetadata)); - when(blockWithMetadata.getHeader()).thenReturn(blockHeader); - when(validatorProvider.getValidatorsAfterBlock(blockHeader)).thenReturn(validators); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - assertThat(response.getResult()).isEqualTo(validatorAsStrings); - } - - @Test - @SuppressWarnings("unchecked") - public void returnsValidatorsForBlockNumber() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {"0x2EC88B"})); - - when(blockchainQueries.blockByNumber(3065995L)).thenReturn(Optional.of(blockWithMetadata)); - when(blockWithMetadata.getHeader()).thenReturn(blockHeader); - when(validatorProvider.getValidatorsAfterBlock(blockHeader)).thenReturn(validators); - - final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) method.response(request); - assertThat(response.getResult()).isEqualTo(validatorAsStrings); - } - - @Test - public void failsOnInvalidBlockNumber() { - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "clique_getSigners", new Object[] {"0x1234"})); - - when(blockchainQueries.blockByNumber(4660)).thenReturn(Optional.empty()); - - final JsonRpcErrorResponse response = (JsonRpcErrorResponse) method.response(request); - assertThat(response.getErrorType()).isEqualTo(RpcErrorType.INTERNAL_ERROR); - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposalsTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposalsTest.java deleted file mode 100644 index cdfbeb6299b..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueProposalsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.consensus.common.jsonrpc.AbstractVoteProposerMethod; -import org.hyperledger.besu.consensus.common.jsonrpc.AbstractVoteProposerMethodTest; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class CliqueProposalsTest extends AbstractVoteProposerMethodTest { - - private CliqueProposals method; - - @Override - protected AbstractVoteProposerMethod getMethod() { - return method; - } - - @Override - protected String getMethodName() { - return "clique_proposals"; - } - - @BeforeEach - public void setup() { - method = new CliqueProposals(getValidatorProvider()); - } - - @Test - public void returnsCorrectMethodName() { - assertThat(method.getName()).isEqualTo(getMethodName()); - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java deleted file mode 100644 index 80220a3f04a..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.EpochManager; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.consensus.common.validator.VoteType; -import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class DiscardTest { - private final String JSON_RPC_VERSION = "2.0"; - private final String METHOD = "clique_discard"; - - private ValidatorProvider validatorProvider; - - @BeforeEach - public void setup() { - final Blockchain blockchain = mock(Blockchain.class); - final EpochManager epochManager = mock(EpochManager.class); - final BlockInterface blockInterface = mock(BlockInterface.class); - validatorProvider = - BlockValidatorProvider.nonForkingValidatorProvider( - blockchain, epochManager, blockInterface); - } - - @Test - public void discardEmpty() { - final Discard discard = new Discard(validatorProvider); - final Address a0 = Address.fromHexString("0"); - - final JsonRpcResponse response = discard.response(requestWithParams(a0)); - - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - } - - @Test - public void discardAuth() { - final Discard discard = new Discard(validatorProvider); - final Address a0 = Address.fromHexString("0"); - - validatorProvider.getVoteProviderAtHead().get().authVote(a0); - - final JsonRpcResponse response = discard.response(requestWithParams(a0)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void discardDrop() { - final Discard discard = new Discard(validatorProvider); - final Address a0 = Address.fromHexString("0"); - - validatorProvider.getVoteProviderAtHead().get().dropVote(a0); - - final JsonRpcResponse response = discard.response(requestWithParams(a0)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void discardIsolation() { - final Discard discard = new Discard(validatorProvider); - final Address a0 = Address.fromHexString("0"); - final Address a1 = Address.fromHexString("1"); - - validatorProvider.getVoteProviderAtHead().get().authVote(a0); - validatorProvider.getVoteProviderAtHead().get().authVote(a1); - - final JsonRpcResponse response = discard.response(requestWithParams(a0)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.ADD); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void discardWithoutAddress() { - final Discard discard = new Discard(validatorProvider); - - assertThatThrownBy(() -> discard.response(requestWithParams())) - .hasMessage("Invalid address parameter (index 0)") - .isInstanceOf(InvalidJsonRpcParameters.class); - } - - private JsonRpcRequestContext requestWithParams(final Object... params) { - return new JsonRpcRequestContext(new JsonRpcRequest(JSON_RPC_VERSION, METHOD, params)); - } -} diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/ProposeTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/ProposeTest.java deleted file mode 100644 index 7e7d7bf7704..00000000000 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/ProposeTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.clique.jsonrpc.methods; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.EpochManager; -import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; -import org.hyperledger.besu.consensus.common.validator.VoteType; -import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class ProposeTest { - private final String JSON_RPC_VERSION = "2.0"; - private final String METHOD = "clique_propose"; - private ValidatorProvider validatorProvider; - - @BeforeEach - public void setup() { - final Blockchain blockchain = mock(Blockchain.class); - final EpochManager epochManager = mock(EpochManager.class); - final BlockInterface blockInterface = mock(BlockInterface.class); - validatorProvider = - BlockValidatorProvider.nonForkingValidatorProvider( - blockchain, epochManager, blockInterface); - } - - @Test - public void testAuth() { - final Propose propose = new Propose(validatorProvider); - final Address a1 = Address.fromHexString("1"); - - final JsonRpcResponse response = propose.response(requestWithParams(a1, true)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.ADD); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void testAuthWithAddressZeroResultsInError() { - final Propose propose = new Propose(validatorProvider); - final Address a0 = Address.fromHexString("0"); - - final JsonRpcResponse response = propose.response(requestWithParams(a0, true)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response; - assertThat(errorResponse.getErrorType()).isEqualTo(RpcErrorType.INVALID_REQUEST); - } - - @Test - public void testDrop() { - final Propose propose = new Propose(validatorProvider); - final Address a1 = Address.fromHexString("1"); - - final JsonRpcResponse response = propose.response(requestWithParams(a1, false)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.DROP); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void testDropWithAddressZeroResultsInError() { - final Propose propose = new Propose(validatorProvider); - final Address a0 = Address.fromHexString("0"); - - final JsonRpcResponse response = propose.response(requestWithParams(a0, false)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)).isNull(); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - final JsonRpcErrorResponse errorResponse = (JsonRpcErrorResponse) response; - assertThat(errorResponse.getErrorType()).isEqualTo(RpcErrorType.INVALID_REQUEST); - } - - @Test - public void testRepeatAuth() { - final Propose propose = new Propose(validatorProvider); - final Address a1 = Address.fromHexString("1"); - - validatorProvider.getVoteProviderAtHead().get().authVote(a1); - final JsonRpcResponse response = propose.response(requestWithParams(a1, true)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.ADD); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void testRepeatDrop() { - final Propose propose = new Propose(validatorProvider); - final Address a1 = Address.fromHexString("1"); - - validatorProvider.getVoteProviderAtHead().get().dropVote(a1); - final JsonRpcResponse response = propose.response(requestWithParams(a1, false)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.DROP); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void testChangeToAuth() { - final Propose propose = new Propose(validatorProvider); - final Address a1 = Address.fromHexString("1"); - - validatorProvider.getVoteProviderAtHead().get().dropVote(a1); - final JsonRpcResponse response = propose.response(requestWithParams(a1, true)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a1)) - .isEqualTo(VoteType.ADD); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - @Test - public void testChangeToDrop() { - final Propose propose = new Propose(validatorProvider); - final Address a0 = Address.fromHexString("1"); - - validatorProvider.getVoteProviderAtHead().get().authVote(a0); - final JsonRpcResponse response = propose.response(requestWithParams(a0, false)); - - assertThat(validatorProvider.getVoteProviderAtHead().get().getProposals().get(a0)) - .isEqualTo(VoteType.DROP); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response; - assertThat(successResponse.getResult()).isEqualTo(true); - } - - private JsonRpcRequestContext requestWithParams(final Object... params) { - return new JsonRpcRequestContext(new JsonRpcRequest(JSON_RPC_VERSION, METHOD, params)); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java index a90134dac22..c426e03dedd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java @@ -30,7 +30,6 @@ public enum RpcApis { TXPOOL, TRACE, PLUGINS, - CLIQUE, IBFT, ENGINE, QBFT, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java index f813e59ac31..679f1be52b1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java @@ -26,12 +26,6 @@ public enum RpcMethod { ADMIN_GENERATE_LOG_BLOOM_CACHE("admin_generateLogBloomCache"), ADMIN_LOGS_REPAIR_CACHE("admin_logsRepairCache"), ADMIN_LOGS_REMOVE_CACHE("admin_logsRemoveCache"), - CLIQUE_DISCARD("clique_discard"), - CLIQUE_GET_SIGNERS("clique_getSigners"), - CLIQUE_GET_SIGNERS_AT_HASH("clique_getSignersAtHash"), - CLIQUE_GET_PROPOSALS("clique_proposals"), - CLIQUE_PROPOSE("clique_propose"), - CLIQUE_GET_SIGNER_METRICS("clique_getSignerMetrics"), DEBUG_ACCOUNT_AT("debug_accountAt"), DEBUG_ACCOUNT_RANGE("debug_accountRange"), DEBUG_METRICS("debug_metrics"),