-
Notifications
You must be signed in to change notification settings - Fork 130
Ibft Json Acceptance tests #634
Changes from 5 commits
0dcfdd7
bc74070
ce4627f
10ff989
d4ff5e2
c2df59f
3d2d3fd
01cf37c
6d041bf
a97162d
08ae3d6
686c348
e20674a
cca7ae8
8a0efa1
53c435c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; | ||
|
||
import java.util.Map; | ||
|
||
public class ExpectProposals implements Condition { | ||
private final IbftTransactions ibft; | ||
private final Map<Address, Boolean> proposers; | ||
|
||
public ExpectProposals(final IbftTransactions ibft, final Map<Address, Boolean> proposers) { | ||
this.ibft = ibft; | ||
this.proposers = proposers; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
waitFor(() -> assertThat(node.execute(ibft.createProposals())).isEqualTo(proposers)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; | ||
import static tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; | ||
|
||
public class ExpectValidators implements Condition { | ||
private final IbftTransactions ibft; | ||
private final Address[] validators; | ||
|
||
public ExpectValidators(final IbftTransactions ibft, final Address... validators) { | ||
this.ibft = ibft; | ||
this.validators = validators; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
waitFor( | ||
() -> | ||
assertThat(node.execute(ibft.createGetValidators(LATEST))).containsExactly(validators)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; | ||
|
||
public class ExpectValidatorsAtBlock implements Condition { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like this is being used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
private final IbftTransactions ibft; | ||
private final String blockParameter; | ||
private final Address[] validators; | ||
|
||
public ExpectValidatorsAtBlock( | ||
final IbftTransactions ibft, final String blockNumber, final Address... validators) { | ||
this.ibft = ibft; | ||
this.blockParameter = blockNumber; | ||
this.validators = validators; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
waitFor( | ||
() -> | ||
assertThat(node.execute(ibft.createGetValidators(blockParameter))) | ||
.containsExactly(validators)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; | ||
|
||
public class ExpectValidatorsAtBlockHash implements Condition { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like this is being used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
private final IbftTransactions ibft; | ||
private final Hash blockHash; | ||
private final Address[] validators; | ||
|
||
public ExpectValidatorsAtBlockHash( | ||
final IbftTransactions ibft, final Hash blockHash, final Address... validators) { | ||
this.ibft = ibft; | ||
this.blockHash = blockHash; | ||
this.validators = validators; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
waitFor( | ||
() -> | ||
assertThat(node.execute(ibft.createGetValidatorsAtHash(blockHash))) | ||
.containsExactly(validators)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,84 @@ | |
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectProposals; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectValidators; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class Ibft { | ||
|
||
private final EthTransactions eth; | ||
private final IbftTransactions ibft; | ||
|
||
public Ibft(final EthTransactions eth, final IbftTransactions ibft) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like EthTransactions is used |
||
this.eth = eth; | ||
this.ibft = ibft; | ||
} | ||
|
||
public List<PantheonNode> validators(final PantheonNode[] nodes) { | ||
final Comparator<PantheonNode> compareByAddress = | ||
Comparator.comparing(PantheonNode::getAddress); | ||
List<PantheonNode> pantheonNodes = Arrays.asList(nodes); | ||
pantheonNodes.sort(compareByAddress); | ||
return pantheonNodes; | ||
} | ||
|
||
public ExpectValidators validatorsEqual(final PantheonNode... validators) { | ||
return new ExpectValidators(ibft, validatorAddresses(validators)); | ||
} | ||
|
||
private Address[] validatorAddresses(final PantheonNode[] validators) { | ||
return Arrays.stream(validators).map(PantheonNode::getAddress).sorted().toArray(Address[]::new); | ||
} | ||
|
||
public Condition noProposals() { | ||
return new ExpectProposals(ibft, ImmutableMap.of()); | ||
} | ||
|
||
public ProposalsConfig proposalsEqual() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ibft is using pending votes instead of proposals for this concept, so I think it would be clearer in the ibft tests if we used the term pending votes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
return new ProposalsConfig(ibft); | ||
} | ||
|
||
public static class ProposalsConfig { | ||
private final Map<PantheonNode, Boolean> proposals = new HashMap<>(); | ||
private final IbftTransactions ibft; | ||
|
||
public ProposalsConfig(final IbftTransactions ibft) { | ||
this.ibft = ibft; | ||
} | ||
|
||
public Ibft.ProposalsConfig addProposal(final PantheonNode node) { | ||
proposals.put(node, true); | ||
return this; | ||
} | ||
|
||
public Ibft.ProposalsConfig removeProposal(final PantheonNode node) { | ||
proposals.put(node, false); | ||
return this; | ||
} | ||
|
||
public Condition build() { | ||
final Map<Address, Boolean> proposalsAsAddress = | ||
this.proposals | ||
.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap(p -> p.getKey().getAddress(), Entry::getValue)); | ||
return new tech.pegasys.pantheon.tests.acceptance.dsl.condition.ibft.ExpectProposals( | ||
ibft, proposalsAsAddress); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,40 @@ public Request<?, SignersBlockResponse> cliqueGetSignersAtHash(final Hash hash) | |
SignersBlockResponse.class); | ||
} | ||
|
||
CjHare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public Request<?, ProposeResponse> ibftPropose(final String address, final Boolean auth) { | ||
return new Request<>( | ||
"ibft_proposeValidatorVote", | ||
Arrays.asList(address, auth.toString()), | ||
web3jService, | ||
ProposeResponse.class); | ||
} | ||
|
||
public Request<?, DiscardResponse> ibftDiscard(final String address) { | ||
return new Request<>( | ||
"ibft_discardValidatorVote", singletonList(address), web3jService, DiscardResponse.class); | ||
} | ||
|
||
public Request<?, ProposalsResponse> ibftProposals() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really match up with the rpc method name. Original intent for the clique rpcs was that these method names corresponded to the underlying rpc method. |
||
return new Request<>( | ||
"ibft_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class); | ||
} | ||
|
||
public Request<?, SignersBlockResponse> ibftGetValidators(final String blockNumber) { | ||
return new Request<>( | ||
"ibft_getValidatorsByBlockNumber", | ||
singletonList(blockNumber), | ||
web3jService, | ||
SignersBlockResponse.class); | ||
} | ||
|
||
public Request<?, SignersBlockResponse> ibftGetSignersAtHash(final Hash hash) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look this is being used. But we I think we should have a test to verify this rpc is working. |
||
return new Request<>( | ||
"ibft_getValidatorsByBlockHash", | ||
singletonList(hash.toString()), | ||
web3jService, | ||
SignersBlockResponse.class); | ||
} | ||
|
||
public static class ProposeResponse extends Response<Boolean> {} | ||
|
||
public static class DiscardResponse extends Response<Boolean> {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j.DiscardResponse; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; | ||
|
||
import java.io.IOException; | ||
|
||
public class IbftDiscard implements Transaction<Boolean> { | ||
private final String address; | ||
|
||
public IbftDiscard(final String address) { | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public Boolean execute(final PantheonWeb3j node) { | ||
try { | ||
final DiscardResponse result = node.ibftDiscard(address).send(); | ||
assertThat(result).isNotNull(); | ||
assertThat(result.hasError()).isFalse(); | ||
return result.getResult(); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be depending on this constant Clique even though it will work. This seems very generic LATEST could probably move somewhere more common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true.