forked from Consensys/teku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance test for liveness endpoint
partially addresses Consensys#4453 Signed-off-by: Paul Harris <[email protected]>
- Loading branch information
Showing
4 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...ceptance-test/java/tech/pegasys/teku/test/acceptance/ValidatorLivenessAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2021 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.teku.test.acceptance; | ||
|
||
import static tech.pegasys.teku.test.acceptance.dsl.ValidatorLivenessExpectation.expectLive; | ||
import static tech.pegasys.teku.test.acceptance.dsl.ValidatorLivenessExpectation.expectNotLive; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase; | ||
import tech.pegasys.teku.test.acceptance.dsl.TekuNode; | ||
|
||
public class ValidatorLivenessAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private static final int NODE_VALIDATORS = 8; | ||
private static final int TOTAL_VALIDATORS = NODE_VALIDATORS * 2; | ||
private final List<UInt64> validators = new ArrayList<>(); | ||
|
||
private final SystemTimeProvider timeProvider = new SystemTimeProvider(); | ||
private TekuNode primaryNode; | ||
private TekuNode secondaryNode; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
final int genesisTime = timeProvider.getTimeInSeconds().plus(5).intValue(); | ||
for (UInt64 i = UInt64.ZERO; i.isLessThan(TOTAL_VALIDATORS); i = i.increment()) { | ||
validators.add(i); | ||
} | ||
primaryNode = | ||
createTekuNode( | ||
config -> configureNode(config, genesisTime).withInteropValidators(0, NODE_VALIDATORS)); | ||
secondaryNode = | ||
createTekuNode( | ||
config -> | ||
configureNode(config, genesisTime) | ||
.withInteropValidators(NODE_VALIDATORS, NODE_VALIDATORS) | ||
.withPeers(primaryNode)); | ||
} | ||
|
||
/* | ||
* Primary and Secondary node, each with half of the validators | ||
* - Primary is online at genesis, so during epoch 1 all validators should be performing duties. | ||
* - no validator keys from the secondary will be seen as active in epoch 1. | ||
* - Secondary is online at epoch 2, so by epoch 3 should all be performing duties. | ||
* - by epoch 4, all validators should be seen as performing duties in epoch 3 | ||
*/ | ||
@Test | ||
void shouldTrackValidatorLivenessOverEpochs() throws Exception { | ||
primaryNode.start(); | ||
|
||
primaryNode.waitForSlot(8); | ||
secondaryNode.start(); | ||
primaryNode.checkValidatorLiveness( | ||
1, | ||
TOTAL_VALIDATORS, | ||
expectLive(0, NODE_VALIDATORS), | ||
expectNotLive(NODE_VALIDATORS, NODE_VALIDATORS)); | ||
|
||
primaryNode.waitForSlot(16); | ||
primaryNode.checkValidatorLiveness(3, TOTAL_VALIDATORS, expectLive(0, TOTAL_VALIDATORS)); | ||
secondaryNode.checkValidatorLiveness(3, TOTAL_VALIDATORS, expectLive(0, TOTAL_VALIDATORS)); | ||
} | ||
|
||
private TekuNode.Config configureNode(final TekuNode.Config node, final int genesisTime) { | ||
return node.withNetwork("swift") | ||
.withGenesisTime(genesisTime) | ||
.withValidatorLivenessTracking() | ||
.withInteropNumberOfValidators(TOTAL_VALIDATORS) | ||
.withRealNetwork(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...testFixtures/java/tech/pegasys/teku/test/acceptance/dsl/ValidatorLivenessExpectation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2021 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.teku.test.acceptance.dsl; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.util.Map; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
|
||
public class ValidatorLivenessExpectation { | ||
private final int start; | ||
private final int count; | ||
private final boolean isLive; | ||
|
||
public ValidatorLivenessExpectation(final int start, final int count, final boolean isLive) { | ||
this.start = start; | ||
this.count = count; | ||
this.isLive = isLive; | ||
} | ||
|
||
public void verify(final Map<UInt64, Boolean> liveness) { | ||
StringBuilder result = new StringBuilder(); | ||
for (int i = start; i < start + count; i++) { | ||
if (liveness.get(UInt64.valueOf(i)) != isLive) { | ||
result.append( | ||
String.format( | ||
"Validator %s was expected to be %s, but was not.\n", | ||
i, isLive ? "live" : "offline")); | ||
} | ||
} | ||
assertThat(result.toString()).isEmpty(); | ||
} | ||
|
||
public static ValidatorLivenessExpectation expectLive(final int start, final int count) { | ||
return new ValidatorLivenessExpectation(start, count, true); | ||
} | ||
|
||
public static ValidatorLivenessExpectation expectNotLive(final int start, final int count) { | ||
return new ValidatorLivenessExpectation(start, count, false); | ||
} | ||
} |