Skip to content

Commit

Permalink
Extend TestSpecFactory by adding Merge Spec creations (#4527)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Oct 27, 2021
1 parent 3f14b77 commit ff76fb3
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
import tech.pegasys.teku.spec.config.SpecConfigLoader;
import tech.pegasys.teku.spec.config.SpecConfigMerge;
import tech.pegasys.teku.spec.config.TestConfigLoader;
import tech.pegasys.teku.spec.networks.Eth2Network;

Expand All @@ -26,18 +27,14 @@ public static Spec createDefault() {
return createMinimalPhase0();
}

public static Spec createMinimalAltair() {
final SpecConfigAltair specConfig = getAltairSpecConfig(Eth2Network.MINIMAL);
return create(specConfig, SpecMilestone.ALTAIR);
}

public static Spec createMinimal(final SpecMilestone specMilestone) {
switch (specMilestone) {
case PHASE0:
return createMinimalPhase0();
case ALTAIR:
return createMinimalAltair();
case MERGE:
return createMinimalMerge();
default:
throw new IllegalStateException("unsupported milestone");
}
Expand All @@ -50,11 +47,22 @@ public static Spec createMainnet(final SpecMilestone specMilestone) {
case ALTAIR:
return createMainnetAltair();
case MERGE:
return createMainnetMerge();
default:
throw new IllegalStateException("unsupported milestone");
}
}

public static Spec createMinimalMerge() {
final SpecConfigMerge specConfig = getMergeSpecConfig(Eth2Network.MINIMAL);
return create(specConfig, SpecMilestone.MERGE);
}

public static Spec createMinimalAltair() {
final SpecConfigAltair specConfig = getAltairSpecConfig(Eth2Network.MINIMAL);
return create(specConfig, SpecMilestone.ALTAIR);
}

/**
* Create a spec that forks to altair at the provided slot
*
Expand All @@ -71,6 +79,11 @@ public static Spec createMinimalPhase0() {
return create(specConfig, SpecMilestone.PHASE0);
}

public static Spec createMainnetMerge() {
final SpecConfigMerge specConfig = getMergeSpecConfig(Eth2Network.MAINNET);
return create(specConfig, SpecMilestone.MERGE);
}

public static Spec createMainnetAltair() {
final SpecConfigAltair specConfig = getAltairSpecConfig(Eth2Network.MAINNET);
return create(specConfig, SpecMilestone.ALTAIR);
Expand All @@ -94,6 +107,10 @@ public static Spec createAltair(final SpecConfig config) {
return create(config, SpecMilestone.ALTAIR);
}

public static Spec createMerge(final SpecConfig config) {
return create(config, SpecMilestone.MERGE);
}

private static Spec create(
final SpecConfig config, final SpecMilestone highestSupportedMilestone) {
return Spec.create(config, highestSupportedMilestone);
Expand All @@ -109,4 +126,18 @@ private static SpecConfigAltair getAltairSpecConfig(
TestConfigLoader.loadConfig(
network.configName(), c -> c.altairBuilder(a -> a.altairForkEpoch(altairForkEpoch))));
}

private static SpecConfigMerge getMergeSpecConfig(final Eth2Network network) {
return getMergeSpecConfig(network, UInt64.ZERO, UInt64.ZERO);
}

private static SpecConfigMerge getMergeSpecConfig(
final Eth2Network network, final UInt64 altairForkEpoch, UInt64 mergeForkEpoch) {
return SpecConfigMerge.required(
TestConfigLoader.loadConfig(
network.configName(),
c ->
c.altairBuilder(a -> a.altairForkEpoch(altairForkEpoch))
.mergeBuilder(m -> m.mergeForkEpoch(mergeForkEpoch))));
}
}

0 comments on commit ff76fb3

Please sign in to comment.