Skip to content

Commit af80f3c

Browse files
authored
Refactored acceptance test DSL (Consensys#8040)
Acceptance test DSL is getting a little out of control so moved a few things around... Reduces the duplication of code, hopefully overall a fair amount cleaner. Signed-off-by: Paul Harris <[email protected]>
1 parent d50be78 commit af80f3c

File tree

45 files changed

+2267
-2173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2267
-2173
lines changed

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/AddValidatorsAcceptanceTest.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import org.junit.jupiter.api.Test;
1717
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
1818
import tech.pegasys.teku.test.acceptance.dsl.GenesisGenerator.InitialStateData;
19-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
19+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
20+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2021
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores;
2122

2223
public class AddValidatorsAcceptanceTest extends AcceptanceTestBase {
@@ -37,13 +38,13 @@ void shouldLoadAdditionalValidatorsWithoutRestart() throws Exception {
3738
.validatorKeys(initialKeystores, additionalKeystores)
3839
.generate();
3940

40-
final TekuNode node =
41-
createTekuNode(
42-
config ->
43-
config
44-
.withNetwork(networkName)
45-
.withInitialState(genesis)
46-
.withReadOnlyKeystorePath(initialKeystores));
41+
final TekuBeaconNode node =
42+
createTekuBeaconNode(
43+
TekuNodeConfigBuilder.createBeaconNode()
44+
.withNetwork(networkName)
45+
.withInitialState(genesis)
46+
.withReadOnlyKeystorePath(initialKeystores)
47+
.build());
4748
node.start();
4849

4950
node.waitForOwnedValidatorCount(2);

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/AttestationGossipAcceptanceTest.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,30 @@
1616
import org.junit.jupiter.api.Test;
1717
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
1818
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
19-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
19+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
20+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2021

2122
public class AttestationGossipAcceptanceTest extends AcceptanceTestBase {
2223
@Test
2324
public void shouldFinalizeWithTwoNodes() throws Exception {
24-
final TekuNode node1 =
25-
createTekuNode(
26-
config -> config.withRealNetwork().withNetwork("minimal").withInteropValidators(0, 32));
25+
final TekuBeaconNode node1 =
26+
createTekuBeaconNode(
27+
TekuNodeConfigBuilder.createBeaconNode()
28+
.withRealNetwork()
29+
.withInteropValidators(0, 32)
30+
.build());
2731

2832
node1.start();
2933
final UInt64 genesisTime = node1.getGenesisTime();
3034

31-
final TekuNode node2 =
32-
createTekuNode(
33-
config ->
34-
config
35-
.withNetwork("minimal")
36-
.withGenesisTime(genesisTime.intValue())
37-
.withRealNetwork()
38-
.withPeers(node1)
39-
.withInteropValidators(32, 32));
35+
final TekuBeaconNode node2 =
36+
createTekuBeaconNode(
37+
TekuNodeConfigBuilder.createBeaconNode()
38+
.withGenesisTime(genesisTime.intValue())
39+
.withRealNetwork()
40+
.withPeers(node1)
41+
.withInteropValidators(32, 32)
42+
.build());
4043
node2.start();
4144

4245
node2.waitForAttestationBeingGossiped(32, 64);

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/BellatrixMergeTransitionAcceptanceTest.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
package tech.pegasys.teku.test.acceptance;
1515

1616
import com.google.common.io.Resources;
17+
import java.io.IOException;
1718
import java.net.URL;
1819
import org.junit.jupiter.api.BeforeEach;
1920
import org.junit.jupiter.api.Test;
2021
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
2122
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2223
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
2324
import tech.pegasys.teku.test.acceptance.dsl.BesuNode;
24-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
25+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
26+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2527
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores;
2628

2729
public class BellatrixMergeTransitionAcceptanceTest extends AcceptanceTestBase {
@@ -31,7 +33,7 @@ public class BellatrixMergeTransitionAcceptanceTest extends AcceptanceTestBase {
3133

3234
private final SystemTimeProvider timeProvider = new SystemTimeProvider();
3335
private BesuNode eth1Node;
34-
private TekuNode tekuNode;
36+
private TekuBeaconNode tekuNode;
3537

3638
@BeforeEach
3739
void setup() throws Exception {
@@ -50,16 +52,16 @@ void setup() throws Exception {
5052
final ValidatorKeystores validatorKeystores =
5153
createTekuDepositSender(NETWORK_NAME).sendValidatorDeposits(eth1Node, totalValidators);
5254
tekuNode =
53-
createTekuNode(
54-
config ->
55-
configureTekuNode(config, genesisTime)
56-
.withDepositsFrom(eth1Node)
57-
.withStartupTargetPeerCount(0)
58-
.withReadOnlyKeystorePath(validatorKeystores)
59-
.withValidatorProposerDefaultFeeRecipient(
60-
"0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73")
61-
.withExecutionEngine(eth1Node)
62-
.withJwtSecretFile(JWT_FILE));
55+
createTekuBeaconNode(
56+
configureTekuNode(genesisTime)
57+
.withDepositsFrom(eth1Node)
58+
.withExecutionEngine(eth1Node)
59+
.withStartupTargetPeerCount(0)
60+
.withReadOnlyKeystorePath(validatorKeystores)
61+
.withValidatorProposerDefaultFeeRecipient(
62+
"0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73")
63+
.withJwtSecretFile(JWT_FILE)
64+
.build());
6365
tekuNode.start();
6466
}
6567

@@ -71,8 +73,8 @@ void shouldHaveNonDefaultExecutionPayloadAndFinalizeAfterMergeTransition() {
7173
tekuNode.waitForNewFinalization();
7274
}
7375

74-
private TekuNode.Config configureTekuNode(final TekuNode.Config node, final int genesisTime) {
75-
return node.withNetwork(NETWORK_NAME)
76+
private TekuNodeConfigBuilder configureTekuNode(final int genesisTime) throws IOException {
77+
return TekuNodeConfigBuilder.createBeaconNode()
7678
.withBellatrixEpoch(UInt64.ONE)
7779
.withTotalTerminalDifficulty(10001)
7880
.withGenesisTime(genesisTime);

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/BlsToExecutionChangeAcceptanceTest.java

+33-33
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package tech.pegasys.teku.test.acceptance;
1515

16+
import java.io.IOException;
1617
import java.util.List;
1718
import org.junit.jupiter.api.Test;
1819
import tech.pegasys.teku.api.response.v1.EventType;
@@ -21,13 +22,11 @@
2122
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2223
import tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory;
2324
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
24-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
25-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode.Config;
25+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
26+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2627

2728
public class BlsToExecutionChangeAcceptanceTest extends AcceptanceTestBase {
2829

29-
private static final String NETWORK_NAME = "swift";
30-
3130
@Test
3231
void shouldUpdateWithdrawalCredentials() throws Exception {
3332
final int validatorIndex = 0;
@@ -39,12 +38,12 @@ void shouldUpdateWithdrawalCredentials() throws Exception {
3938
Eth1Address.fromHexString("0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73");
4039
final UInt64 capellaActivationEpoch = UInt64.ONE;
4140

42-
final TekuNode primaryNode = createPrimaryNode(executionAddress, capellaActivationEpoch);
41+
final TekuBeaconNode primaryNode = createPrimaryNode(executionAddress, capellaActivationEpoch);
4342
primaryNode.start();
4443
primaryNode.waitForNextEpoch();
4544
primaryNode.startEventListener(EventType.bls_to_execution_change);
4645

47-
final TekuNode lateJoiningNode =
46+
final TekuBeaconNode lateJoiningNode =
4847
createLateJoiningNode(capellaActivationEpoch, primaryNode, primaryNode.getGenesisTime());
4948
lateJoiningNode.start();
5049
lateJoiningNode.waitUntilInSyncWith(primaryNode);
@@ -57,36 +56,37 @@ void shouldUpdateWithdrawalCredentials() throws Exception {
5756
lateJoiningNode.waitForBlsToExecutionChangeEventForValidator(0);
5857
}
5958

60-
private TekuNode createPrimaryNode(
61-
final Eth1Address executionAddress, final UInt64 capellaActivationEpoch) {
62-
return createTekuNode(
63-
c -> {
64-
c.withNetwork(NETWORK_NAME)
65-
.withRealNetwork()
66-
.withStartupTargetPeerCount(0)
67-
.withValidatorProposerDefaultFeeRecipient(executionAddress.toHexString());
68-
applyMilestoneConfig(c, capellaActivationEpoch);
69-
});
59+
private TekuBeaconNode createPrimaryNode(
60+
final Eth1Address executionAddress, final UInt64 capellaActivationEpoch) throws IOException {
61+
return createTekuBeaconNode(
62+
beaconNodeWithMilestones(capellaActivationEpoch)
63+
.withStartupTargetPeerCount(0)
64+
.withValidatorProposerDefaultFeeRecipient(executionAddress.toHexString())
65+
.build());
7066
}
7167

72-
private TekuNode createLateJoiningNode(
73-
final UInt64 capellaActivationEpoch, final TekuNode primaryNode, final UInt64 genesisTime) {
74-
return createTekuNode(
75-
c -> {
76-
c.withGenesisTime(genesisTime.intValue())
77-
.withNetwork(NETWORK_NAME)
78-
.withRealNetwork()
79-
.withPeers(primaryNode)
80-
.withInteropValidators(0, 0);
81-
applyMilestoneConfig(c, capellaActivationEpoch);
82-
});
68+
private TekuBeaconNode createLateJoiningNode(
69+
final UInt64 capellaActivationEpoch,
70+
final TekuBeaconNode primaryNode,
71+
final UInt64 genesisTime)
72+
throws IOException {
73+
return createTekuBeaconNode(
74+
beaconNodeWithMilestones(capellaActivationEpoch)
75+
.withPeers(primaryNode)
76+
.withGenesisTime(genesisTime.intValue())
77+
.withInteropValidators(0, 0)
78+
.build());
8379
}
8480

85-
private static void applyMilestoneConfig(final Config c, final UInt64 capellaForkEpoch) {
86-
c.withAltairEpoch(UInt64.ZERO);
87-
c.withBellatrixEpoch(UInt64.ZERO);
88-
c.withCapellaEpoch(capellaForkEpoch);
89-
c.withTotalTerminalDifficulty(0);
90-
c.withStubExecutionEngine("0x14e88057b0b7538a8205cb07726a0de03dd69d9a70e88bcffae15ca3fc6b5215");
81+
private static TekuNodeConfigBuilder beaconNodeWithMilestones(final UInt64 capellaActivationEpoch)
82+
throws IOException {
83+
return TekuNodeConfigBuilder.createBeaconNode()
84+
.withRealNetwork()
85+
.withAltairEpoch(UInt64.ZERO)
86+
.withBellatrixEpoch(UInt64.ZERO)
87+
.withCapellaEpoch(capellaActivationEpoch)
88+
.withTotalTerminalDifficulty(0)
89+
.withStubExecutionEngine(
90+
"0x14e88057b0b7538a8205cb07726a0de03dd69d9a70e88bcffae15ca3fc6b5215");
9191
}
9292
}

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/CapellaUpgradeAcceptanceTest.java

+21-27
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
2525
import tech.pegasys.teku.test.acceptance.dsl.BesuDockerVersion;
2626
import tech.pegasys.teku.test.acceptance.dsl.BesuNode;
27-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
28-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode.Config;
27+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
28+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2929

3030
/**
3131
* The test is based on `shanghaiTime` in Besu EL genesis config as the only option to start
@@ -72,46 +72,40 @@ void shouldUpgradeToCapella() throws Exception {
7272
secondaryEL.start();
7373
secondaryEL.addPeer(primaryEL);
7474

75-
TekuNode primaryNode =
76-
createTekuNode(
77-
config -> {
78-
config
79-
.withGenesisTime(genesisTime)
80-
.withRealNetwork()
81-
.withStartupTargetPeerCount(0)
82-
.withExecutionEngine(primaryEL)
83-
.withJwtSecretFile(JWT_FILE);
84-
applyMilestoneConfig(config);
85-
});
75+
TekuBeaconNode primaryNode =
76+
createTekuBeaconNode(
77+
beaconNodeConfigWithForks(genesisTime, primaryEL)
78+
.withStartupTargetPeerCount(0)
79+
.build());
8680

8781
primaryNode.start();
8882
primaryNode.waitForMilestone(SpecMilestone.CAPELLA);
8983

9084
final int primaryNodeGenesisTime = primaryNode.getGenesisTime().intValue();
9185

92-
TekuNode lateJoiningNode =
93-
createTekuNode(
94-
c -> {
95-
c.withGenesisTime(primaryNodeGenesisTime)
96-
.withRealNetwork()
97-
.withPeers(primaryNode)
98-
.withInteropValidators(0, 0)
99-
.withExecutionEngine(secondaryEL)
100-
.withJwtSecretFile(JWT_FILE);
101-
applyMilestoneConfig(c);
102-
});
86+
TekuBeaconNode lateJoiningNode =
87+
createTekuBeaconNode(
88+
beaconNodeConfigWithForks(primaryNodeGenesisTime, secondaryEL)
89+
.withPeers(primaryNode)
90+
.withInteropValidators(0, 0)
91+
.build());
10392

10493
lateJoiningNode.start();
10594
lateJoiningNode.waitUntilInSyncWith(primaryNode);
10695

10796
primaryNode.waitForNewBlock();
10897
}
10998

110-
private static void applyMilestoneConfig(final Config config) {
111-
config
99+
private static TekuNodeConfigBuilder beaconNodeConfigWithForks(
100+
final int genesisTime, final BesuNode besuNode) throws Exception {
101+
return TekuNodeConfigBuilder.createBeaconNode()
112102
.withAltairEpoch(UInt64.ZERO)
113103
.withBellatrixEpoch(UInt64.ZERO)
114104
.withCapellaEpoch(UInt64.ONE)
115-
.withTotalTerminalDifficulty(0);
105+
.withTotalTerminalDifficulty(0)
106+
.withGenesisTime(genesisTime)
107+
.withExecutionEngine(besuNode)
108+
.withJwtSecretFile(JWT_FILE)
109+
.withRealNetwork();
116110
}
117111
}

acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/DenebUpgradeAcceptanceTest.java

+20-26
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
2525
import tech.pegasys.teku.test.acceptance.dsl.BesuDockerVersion;
2626
import tech.pegasys.teku.test.acceptance.dsl.BesuNode;
27-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode;
28-
import tech.pegasys.teku.test.acceptance.dsl.TekuNode.Config;
27+
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
28+
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
2929

3030
/**
3131
* The test is based on `shanghaiTime` and `cancunTime` in Besu EL genesis config as the only option
@@ -77,46 +77,40 @@ void shouldUpgradeToDeneb() throws Exception {
7777
secondaryEL.start();
7878
secondaryEL.addPeer(primaryEL);
7979

80-
TekuNode primaryNode =
81-
createTekuNode(
82-
config -> {
83-
config
84-
.withGenesisTime(genesisTime)
85-
.withRealNetwork()
86-
.withStartupTargetPeerCount(0)
87-
.withExecutionEngine(primaryEL)
88-
.withJwtSecretFile(JWT_FILE);
89-
applyMilestoneConfig(config);
90-
});
80+
TekuBeaconNode primaryNode =
81+
createTekuBeaconNode(
82+
beaconNodeWithTrustedSetup(genesisTime, primaryEL)
83+
.withStartupTargetPeerCount(0)
84+
.build());
9185

9286
primaryNode.start();
9387
primaryNode.waitForMilestone(SpecMilestone.DENEB);
9488

9589
final int primaryNodeGenesisTime = primaryNode.getGenesisTime().intValue();
9690

97-
TekuNode lateJoiningNode =
98-
createTekuNode(
99-
c -> {
100-
c.withGenesisTime(primaryNodeGenesisTime)
101-
.withRealNetwork()
102-
.withPeers(primaryNode)
103-
.withInteropValidators(0, 0)
104-
.withExecutionEngine(secondaryEL)
105-
.withJwtSecretFile(JWT_FILE);
106-
applyMilestoneConfig(c);
107-
});
91+
TekuBeaconNode lateJoiningNode =
92+
createTekuBeaconNode(
93+
beaconNodeWithTrustedSetup(primaryNodeGenesisTime, secondaryEL)
94+
.withPeers(primaryNode)
95+
.withInteropValidators(0, 0)
96+
.build());
10897

10998
lateJoiningNode.start();
11099
lateJoiningNode.waitUntilInSyncWith(primaryNode);
111100

112101
primaryNode.waitForNewBlock();
113102
}
114103

115-
private static void applyMilestoneConfig(final Config config) {
116-
config
104+
private static TekuNodeConfigBuilder beaconNodeWithTrustedSetup(
105+
final int genesisTime, final BesuNode besuNode) throws Exception {
106+
return TekuNodeConfigBuilder.createBeaconNode()
117107
.withAltairEpoch(UInt64.ZERO)
118108
.withBellatrixEpoch(UInt64.ZERO)
119109
.withCapellaEpoch(UInt64.ONE)
110+
.withGenesisTime(genesisTime)
111+
.withExecutionEngine(besuNode)
112+
.withRealNetwork()
113+
.withJwtSecretFile(JWT_FILE)
120114
.withDenebEpoch(UInt64.valueOf(2))
121115
.withTrustedSetupFromClasspath("mainnet-trusted-setup.txt")
122116
.withTotalTerminalDifficulty(0);

0 commit comments

Comments
 (0)