2021-09-21 15:02:48 +00:00
|
|
|
package params_test
|
2020-05-05 17:58:07 +00:00
|
|
|
|
|
|
|
import (
|
2022-05-20 07:16:53 +00:00
|
|
|
"bytes"
|
|
|
|
"io"
|
2022-04-18 20:42:07 +00:00
|
|
|
"os"
|
2020-05-05 17:58:07 +00:00
|
|
|
"path"
|
2022-02-02 06:56:07 +00:00
|
|
|
"path/filepath"
|
2021-08-09 18:40:06 +00:00
|
|
|
"reflect"
|
2023-08-31 18:06:45 +00:00
|
|
|
"sort"
|
2020-05-05 17:58:07 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/io/file"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2021-08-09 18:40:06 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2020-05-05 17:58:07 +00:00
|
|
|
)
|
|
|
|
|
2022-09-26 15:19:04 +00:00
|
|
|
// Variables defined in the placeholderFields will not be tested in `TestLoadConfigFile`.
|
|
|
|
// These are variables that we don't use in Prysm. (i.e. future hardfork, light client... etc)
|
2023-08-31 18:06:45 +00:00
|
|
|
// IMPORTANT: Use one field per line and sort these alphabetically to reduce conflicts.
|
|
|
|
var placeholderFields = []string{
|
|
|
|
"EIP6110_FORK_EPOCH",
|
|
|
|
"EIP6110_FORK_VERSION",
|
|
|
|
"EIP7002_FORK_EPOCH",
|
|
|
|
"EIP7002_FORK_VERSION",
|
2024-02-09 17:01:44 +00:00
|
|
|
"EIP7594_FORK_EPOCH",
|
|
|
|
"EIP7594_FORK_VERSION",
|
2023-08-31 18:06:45 +00:00
|
|
|
"MAX_BLOBS_PER_BLOCK",
|
2023-12-12 18:27:48 +00:00
|
|
|
"REORG_HEAD_WEIGHT_THRESHOLD",
|
2023-08-31 18:06:45 +00:00
|
|
|
"UPDATE_TIMEOUT",
|
2023-09-28 21:05:23 +00:00
|
|
|
"WHISK_EPOCHS_PER_SHUFFLING_PHASE",
|
2023-08-31 18:06:45 +00:00
|
|
|
"WHISK_FORK_EPOCH",
|
|
|
|
"WHISK_FORK_VERSION",
|
2023-09-28 21:05:23 +00:00
|
|
|
"WHISK_PROPOSER_SELECTION_GAP",
|
2023-08-31 18:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlaceholderFieldsDistinctSorted(t *testing.T) {
|
|
|
|
m := make(map[string]struct{})
|
|
|
|
for i := 0; i < len(placeholderFields)-1; i++ {
|
|
|
|
if _, ok := m[placeholderFields[i]]; ok {
|
|
|
|
t.Fatalf("duplicate placeholder field %s", placeholderFields[i])
|
|
|
|
}
|
|
|
|
m[placeholderFields[i]] = struct{}{}
|
|
|
|
}
|
|
|
|
if !sort.StringsAreSorted(placeholderFields) {
|
|
|
|
t.Fatal("placeholderFields must be sorted")
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 00:50:06 +00:00
|
|
|
|
2022-12-21 04:43:29 +00:00
|
|
|
func assertEqualConfigs(t *testing.T, name string, fields []string, expected, actual *params.BeaconChainConfig) {
|
|
|
|
// Misc params.
|
|
|
|
assert.Equal(t, expected.MaxCommitteesPerSlot, actual.MaxCommitteesPerSlot, "%s: MaxCommitteesPerSlot", name)
|
|
|
|
assert.Equal(t, expected.TargetCommitteeSize, actual.TargetCommitteeSize, "%s: TargetCommitteeSize", name)
|
|
|
|
assert.Equal(t, expected.MaxValidatorsPerCommittee, actual.MaxValidatorsPerCommittee, "%s: MaxValidatorsPerCommittee", name)
|
|
|
|
assert.Equal(t, expected.MinPerEpochChurnLimit, actual.MinPerEpochChurnLimit, "%s: MinPerEpochChurnLimit", name)
|
|
|
|
assert.Equal(t, expected.ChurnLimitQuotient, actual.ChurnLimitQuotient, "%s: ChurnLimitQuotient", name)
|
|
|
|
assert.Equal(t, expected.ShuffleRoundCount, actual.ShuffleRoundCount, "%s: ShuffleRoundCount", name)
|
|
|
|
assert.Equal(t, expected.MinGenesisActiveValidatorCount, actual.MinGenesisActiveValidatorCount, "%s: MinGenesisActiveValidatorCount", name)
|
|
|
|
assert.Equal(t, expected.MinGenesisTime, actual.MinGenesisTime, "%s: MinGenesisTime", name)
|
|
|
|
assert.Equal(t, expected.HysteresisQuotient, actual.HysteresisQuotient, "%s: HysteresisQuotient", name)
|
|
|
|
assert.Equal(t, expected.HysteresisDownwardMultiplier, actual.HysteresisDownwardMultiplier, "%s: HysteresisDownwardMultiplier", name)
|
|
|
|
assert.Equal(t, expected.HysteresisUpwardMultiplier, actual.HysteresisUpwardMultiplier, "%s: HysteresisUpwardMultiplier", name)
|
|
|
|
|
|
|
|
// Validator params.
|
|
|
|
assert.Equal(t, expected.Eth1FollowDistance, actual.Eth1FollowDistance, "%s: Eth1FollowDistance", name)
|
|
|
|
assert.Equal(t, expected.TargetAggregatorsPerCommittee, actual.TargetAggregatorsPerCommittee, "%s: TargetAggregatorsPerCommittee", name)
|
|
|
|
assert.Equal(t, expected.RandomSubnetsPerValidator, actual.RandomSubnetsPerValidator, "%s: RandomSubnetsPerValidator", name)
|
|
|
|
assert.Equal(t, expected.EpochsPerRandomSubnetSubscription, actual.EpochsPerRandomSubnetSubscription, "%s: EpochsPerRandomSubnetSubscription", name)
|
|
|
|
assert.Equal(t, expected.SecondsPerETH1Block, actual.SecondsPerETH1Block, "%s: SecondsPerETH1Block", name)
|
|
|
|
|
|
|
|
// Deposit contract.
|
|
|
|
assert.Equal(t, expected.DepositChainID, actual.DepositChainID, "%s: DepositChainID", name)
|
|
|
|
assert.Equal(t, expected.DepositNetworkID, actual.DepositNetworkID, "%s: DepositNetworkID", name)
|
|
|
|
assert.Equal(t, expected.DepositContractAddress, actual.DepositContractAddress, "%s: DepositContractAddress", name)
|
|
|
|
|
|
|
|
// Gwei values.
|
|
|
|
assert.Equal(t, expected.MinDepositAmount, actual.MinDepositAmount, "%s: MinDepositAmount", name)
|
|
|
|
assert.Equal(t, expected.MaxEffectiveBalance, actual.MaxEffectiveBalance, "%s: MaxEffectiveBalance", name)
|
|
|
|
assert.Equal(t, expected.EjectionBalance, actual.EjectionBalance, "%s: EjectionBalance", name)
|
|
|
|
assert.Equal(t, expected.EffectiveBalanceIncrement, actual.EffectiveBalanceIncrement, "%s: EffectiveBalanceIncrement", name)
|
|
|
|
|
|
|
|
// Initial values.
|
|
|
|
assert.DeepEqual(t, expected.GenesisForkVersion, actual.GenesisForkVersion, "%s: GenesisForkVersion", name)
|
|
|
|
assert.DeepEqual(t, expected.BLSWithdrawalPrefixByte, actual.BLSWithdrawalPrefixByte, "%s: BLSWithdrawalPrefixByte", name)
|
|
|
|
assert.DeepEqual(t, expected.ETH1AddressWithdrawalPrefixByte, actual.ETH1AddressWithdrawalPrefixByte, "%s: ETH1AddressWithdrawalPrefixByte", name)
|
|
|
|
|
|
|
|
// Time parameters.
|
|
|
|
assert.Equal(t, expected.GenesisDelay, actual.GenesisDelay, "%s: GenesisDelay", name)
|
|
|
|
assert.Equal(t, expected.SecondsPerSlot, actual.SecondsPerSlot, "%s: SecondsPerSlot", name)
|
|
|
|
assert.Equal(t, expected.MinAttestationInclusionDelay, actual.MinAttestationInclusionDelay, "%s: MinAttestationInclusionDelay", name)
|
|
|
|
assert.Equal(t, expected.SlotsPerEpoch, actual.SlotsPerEpoch, "%s: SlotsPerEpoch", name)
|
|
|
|
assert.Equal(t, expected.MinSeedLookahead, actual.MinSeedLookahead, "%s: MinSeedLookahead", name)
|
|
|
|
assert.Equal(t, expected.MaxSeedLookahead, actual.MaxSeedLookahead, "%s: MaxSeedLookahead", name)
|
|
|
|
assert.Equal(t, expected.EpochsPerEth1VotingPeriod, actual.EpochsPerEth1VotingPeriod, "%s: EpochsPerEth1VotingPeriod", name)
|
|
|
|
assert.Equal(t, expected.SlotsPerHistoricalRoot, actual.SlotsPerHistoricalRoot, "%s: SlotsPerHistoricalRoot", name)
|
|
|
|
assert.Equal(t, expected.MinValidatorWithdrawabilityDelay, actual.MinValidatorWithdrawabilityDelay, "%s: MinValidatorWithdrawabilityDelay", name)
|
|
|
|
assert.Equal(t, expected.ShardCommitteePeriod, actual.ShardCommitteePeriod, "%s: ShardCommitteePeriod", name)
|
|
|
|
assert.Equal(t, expected.MinEpochsToInactivityPenalty, actual.MinEpochsToInactivityPenalty, "%s: MinEpochsToInactivityPenalty", name)
|
|
|
|
|
|
|
|
// State vector lengths.
|
|
|
|
assert.Equal(t, expected.EpochsPerHistoricalVector, actual.EpochsPerHistoricalVector, "%s: EpochsPerHistoricalVector", name)
|
|
|
|
assert.Equal(t, expected.EpochsPerSlashingsVector, actual.EpochsPerSlashingsVector, "%s: EpochsPerSlashingsVector", name)
|
|
|
|
assert.Equal(t, expected.HistoricalRootsLimit, actual.HistoricalRootsLimit, "%s: HistoricalRootsLimit", name)
|
|
|
|
assert.Equal(t, expected.ValidatorRegistryLimit, actual.ValidatorRegistryLimit, "%s: ValidatorRegistryLimit", name)
|
|
|
|
|
|
|
|
// Reward and penalty quotients.
|
|
|
|
assert.Equal(t, expected.BaseRewardFactor, actual.BaseRewardFactor, "%s: BaseRewardFactor", name)
|
|
|
|
assert.Equal(t, expected.WhistleBlowerRewardQuotient, actual.WhistleBlowerRewardQuotient, "%s: WhistleBlowerRewardQuotient", name)
|
|
|
|
assert.Equal(t, expected.ProposerRewardQuotient, actual.ProposerRewardQuotient, "%s: ProposerRewardQuotient", name)
|
|
|
|
assert.Equal(t, expected.InactivityPenaltyQuotient, actual.InactivityPenaltyQuotient, "%s: InactivityPenaltyQuotient", name)
|
|
|
|
assert.Equal(t, expected.InactivityPenaltyQuotientAltair, actual.InactivityPenaltyQuotientAltair, "%s: InactivityPenaltyQuotientAltair", name)
|
|
|
|
assert.Equal(t, expected.MinSlashingPenaltyQuotient, actual.MinSlashingPenaltyQuotient, "%s: MinSlashingPenaltyQuotient", name)
|
|
|
|
assert.Equal(t, expected.MinSlashingPenaltyQuotientAltair, actual.MinSlashingPenaltyQuotientAltair, "%s: MinSlashingPenaltyQuotientAltair", name)
|
|
|
|
assert.Equal(t, expected.ProportionalSlashingMultiplier, actual.ProportionalSlashingMultiplier, "%s: ProportionalSlashingMultiplier", name)
|
|
|
|
assert.Equal(t, expected.ProportionalSlashingMultiplierAltair, actual.ProportionalSlashingMultiplierAltair, "%s: ProportionalSlashingMultiplierAltair", name)
|
|
|
|
|
|
|
|
// Max operations per block.
|
|
|
|
assert.Equal(t, expected.MaxProposerSlashings, actual.MaxProposerSlashings, "%s: MaxProposerSlashings", name)
|
|
|
|
assert.Equal(t, expected.MaxAttesterSlashings, actual.MaxAttesterSlashings, "%s: MaxAttesterSlashings", name)
|
|
|
|
assert.Equal(t, expected.MaxAttestations, actual.MaxAttestations, "%s: MaxAttestations", name)
|
|
|
|
assert.Equal(t, expected.MaxDeposits, actual.MaxDeposits, "%s: MaxDeposits", name)
|
|
|
|
assert.Equal(t, expected.MaxVoluntaryExits, actual.MaxVoluntaryExits, "%s: MaxVoluntaryExits", name)
|
|
|
|
|
|
|
|
// Signature domains.
|
|
|
|
assert.Equal(t, expected.DomainBeaconProposer, actual.DomainBeaconProposer, "%s: DomainBeaconProposer", name)
|
|
|
|
assert.Equal(t, expected.DomainBeaconAttester, actual.DomainBeaconAttester, "%s: DomainBeaconAttester", name)
|
|
|
|
assert.Equal(t, expected.DomainRandao, actual.DomainRandao, "%s: DomainRandao", name)
|
|
|
|
assert.Equal(t, expected.DomainDeposit, actual.DomainDeposit, "%s: DomainDeposit", name)
|
|
|
|
assert.Equal(t, expected.DomainVoluntaryExit, actual.DomainVoluntaryExit, "%s: DomainVoluntaryExit", name)
|
|
|
|
assert.Equal(t, expected.DomainSelectionProof, actual.DomainSelectionProof, "%s: DomainSelectionProof", name)
|
|
|
|
assert.Equal(t, expected.DomainAggregateAndProof, actual.DomainAggregateAndProof, "%s: DomainAggregateAndProof", name)
|
2023-01-13 04:04:37 +00:00
|
|
|
assert.Equal(t, expected.TerminalTotalDifficulty, actual.TerminalTotalDifficulty, "%s: TerminalTotalDifficulty", name)
|
|
|
|
assert.Equal(t, expected.AltairForkEpoch, actual.AltairForkEpoch, "%s: AltairForkEpoch", name)
|
|
|
|
assert.Equal(t, expected.BellatrixForkEpoch, actual.BellatrixForkEpoch, "%s: BellatrixForkEpoch", name)
|
|
|
|
assert.Equal(t, expected.CapellaForkEpoch, actual.CapellaForkEpoch, "%s: CapellaForkEpoch", name)
|
2023-08-23 20:07:25 +00:00
|
|
|
assert.Equal(t, expected.DenebForkEpoch, actual.DenebForkEpoch, "%s: DenebForkEpoch", name)
|
2023-01-13 04:04:37 +00:00
|
|
|
assert.Equal(t, expected.SqrRootSlotsPerEpoch, actual.SqrRootSlotsPerEpoch, "%s: SqrRootSlotsPerEpoch", name)
|
|
|
|
assert.DeepEqual(t, expected.GenesisForkVersion, actual.GenesisForkVersion, "%s: GenesisForkVersion", name)
|
|
|
|
assert.DeepEqual(t, expected.AltairForkVersion, actual.AltairForkVersion, "%s: AltairForkVersion", name)
|
|
|
|
assert.DeepEqual(t, expected.BellatrixForkVersion, actual.BellatrixForkVersion, "%s: BellatrixForkVersion", name)
|
|
|
|
assert.DeepEqual(t, expected.CapellaForkVersion, actual.CapellaForkVersion, "%s: CapellaForkVersion", name)
|
2023-08-23 20:07:25 +00:00
|
|
|
assert.DeepEqual(t, expected.DenebForkVersion, actual.DenebForkVersion, "%s: DenebForkVersion", name)
|
2022-12-21 04:43:29 +00:00
|
|
|
|
|
|
|
assertYamlFieldsMatch(t, name, fields, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestModifiedE2E(t *testing.T) {
|
|
|
|
c := params.E2ETestConfig().Copy()
|
|
|
|
c.DepositContractAddress = "0x4242424242424242424242424242424242424242"
|
|
|
|
c.TerminalTotalDifficulty = "0"
|
2023-07-10 19:02:44 +00:00
|
|
|
c.AltairForkEpoch = 112
|
|
|
|
c.BellatrixForkEpoch = 123
|
|
|
|
c.CapellaForkEpoch = 235
|
2023-08-23 20:07:25 +00:00
|
|
|
c.DenebForkEpoch = 358
|
2022-12-21 04:43:29 +00:00
|
|
|
y := params.ConfigToYaml(c)
|
|
|
|
cfg, err := params.UnmarshalConfig(y, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assertEqualConfigs(t, "modified-e2e", []string{}, c, cfg)
|
|
|
|
}
|
2020-12-18 22:22:48 +00:00
|
|
|
|
2022-12-21 04:43:29 +00:00
|
|
|
func TestLoadConfigFile(t *testing.T) {
|
2020-12-18 22:22:48 +00:00
|
|
|
t.Run("mainnet", func(t *testing.T) {
|
2022-05-20 07:16:53 +00:00
|
|
|
mn := params.MainnetConfig().Copy()
|
2021-09-28 20:02:12 +00:00
|
|
|
mainnetPresetsFiles := presetsFilePath(t, "mainnet")
|
2022-05-20 07:16:53 +00:00
|
|
|
var err error
|
2021-09-28 20:02:12 +00:00
|
|
|
for _, fp := range mainnetPresetsFiles {
|
2022-05-20 07:16:53 +00:00
|
|
|
mn, err = params.UnmarshalConfigFile(fp, mn)
|
|
|
|
require.NoError(t, err)
|
2021-09-28 20:02:12 +00:00
|
|
|
}
|
2022-05-20 07:16:53 +00:00
|
|
|
// configs loaded from file get the name 'devnet' unless they specify a specific name in the yaml itself.
|
|
|
|
// since these are partial patches for presets, they do not have the config name
|
|
|
|
mn.ConfigName = params.MainnetName
|
2021-09-28 00:50:06 +00:00
|
|
|
mainnetConfigFile := configFilePath(t, "mainnet")
|
2022-05-20 07:16:53 +00:00
|
|
|
mnf, err := params.UnmarshalConfigFile(mainnetConfigFile, nil)
|
|
|
|
require.NoError(t, err)
|
2021-09-28 20:02:12 +00:00
|
|
|
fields := fieldsFromYamls(t, append(mainnetPresetsFiles, mainnetConfigFile))
|
2022-12-21 04:43:29 +00:00
|
|
|
assertEqualConfigs(t, "mainnet", fields, mn, mnf)
|
2020-12-18 22:22:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("minimal", func(t *testing.T) {
|
2022-05-20 07:16:53 +00:00
|
|
|
min := params.MinimalSpecConfig().Copy()
|
2021-09-28 20:02:12 +00:00
|
|
|
minimalPresetsFiles := presetsFilePath(t, "minimal")
|
2022-05-20 07:16:53 +00:00
|
|
|
var err error
|
2021-09-28 20:02:12 +00:00
|
|
|
for _, fp := range minimalPresetsFiles {
|
2022-05-20 07:16:53 +00:00
|
|
|
min, err = params.UnmarshalConfigFile(fp, min)
|
|
|
|
require.NoError(t, err)
|
2021-09-28 20:02:12 +00:00
|
|
|
}
|
2022-05-20 07:16:53 +00:00
|
|
|
// configs loaded from file get the name 'devnet' unless they specify a specific name in the yaml itself.
|
|
|
|
// since these are partial patches for presets, they do not have the config name
|
|
|
|
min.ConfigName = params.MinimalName
|
2021-09-28 00:50:06 +00:00
|
|
|
minimalConfigFile := configFilePath(t, "minimal")
|
2022-05-20 07:16:53 +00:00
|
|
|
minf, err := params.UnmarshalConfigFile(minimalConfigFile, nil)
|
|
|
|
require.NoError(t, err)
|
2021-09-28 20:02:12 +00:00
|
|
|
fields := fieldsFromYamls(t, append(minimalPresetsFiles, minimalConfigFile))
|
2022-12-21 04:43:29 +00:00
|
|
|
assertEqualConfigs(t, "minimal", fields, min, minf)
|
2020-12-18 22:22:48 +00:00
|
|
|
})
|
2022-04-12 16:57:46 +00:00
|
|
|
|
|
|
|
t.Run("e2e", func(t *testing.T) {
|
2022-05-20 07:16:53 +00:00
|
|
|
e2e, err := params.ByName(params.EndToEndName)
|
|
|
|
require.NoError(t, err)
|
2022-04-12 16:57:46 +00:00
|
|
|
configFile := "testdata/e2e_config.yaml"
|
2022-05-20 07:16:53 +00:00
|
|
|
e2ef, err := params.UnmarshalConfigFile(configFile, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
fields := fieldsFromYamls(t, []string{configFile})
|
2022-12-21 04:43:29 +00:00
|
|
|
assertEqualConfigs(t, "e2e", fields, e2e, e2ef)
|
2022-04-12 16:57:46 +00:00
|
|
|
})
|
2020-05-05 17:58:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 15:42:24 +00:00
|
|
|
func TestLoadConfigFile_OverwriteCorrectly(t *testing.T) {
|
2022-06-27 13:34:38 +00:00
|
|
|
f, err := os.CreateTemp("", "")
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-19 15:42:24 +00:00
|
|
|
// Set current config to minimal config
|
2022-05-20 07:16:53 +00:00
|
|
|
cfg := params.MinimalSpecConfig().Copy()
|
|
|
|
params.FillTestVersions(cfg, 128)
|
2022-06-27 13:34:38 +00:00
|
|
|
_, err = io.Copy(f, bytes.NewBuffer(params.ConfigToYaml(cfg)))
|
2022-05-20 07:16:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// set active config to mainnet, so that we can confirm LoadChainConfigFile overrides it
|
|
|
|
mainnet, err := params.ByName(params.MainnetName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
undo, err := params.SetActiveWithUndo(mainnet)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
err := undo()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}()
|
2020-08-19 15:42:24 +00:00
|
|
|
|
|
|
|
// load empty config file, so that it defaults to mainnet values
|
2022-06-27 13:34:38 +00:00
|
|
|
require.NoError(t, params.LoadChainConfigFile(f.Name(), nil))
|
2022-05-20 07:16:53 +00:00
|
|
|
if params.BeaconConfig().MinGenesisTime != cfg.MinGenesisTime {
|
|
|
|
t.Errorf("Expected MinGenesisTime to be set to value written to config: %d found: %d",
|
|
|
|
cfg.MinGenesisTime,
|
2021-09-21 15:02:48 +00:00
|
|
|
params.BeaconConfig().MinGenesisTime)
|
2020-08-19 15:42:24 +00:00
|
|
|
}
|
2022-05-20 07:16:53 +00:00
|
|
|
if params.BeaconConfig().SlotsPerEpoch != cfg.SlotsPerEpoch {
|
|
|
|
t.Errorf("Expected SlotsPerEpoch to be set to value written to config: %d found: %d",
|
|
|
|
cfg.SlotsPerEpoch,
|
2021-09-21 15:02:48 +00:00
|
|
|
params.BeaconConfig().SlotsPerEpoch)
|
2020-08-19 15:42:24 +00:00
|
|
|
}
|
2022-05-20 07:16:53 +00:00
|
|
|
require.Equal(t, params.MinimalName, params.BeaconConfig().ConfigName)
|
2020-08-19 15:42:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:58:07 +00:00
|
|
|
func Test_replaceHexStringWithYAMLFormat(t *testing.T) {
|
|
|
|
|
|
|
|
testLines := []struct {
|
|
|
|
line string
|
|
|
|
wanted string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
line: "ONE_BYTE: 0x41",
|
|
|
|
wanted: "ONE_BYTE: 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "FOUR_BYTES: 0x41414141",
|
|
|
|
wanted: "FOUR_BYTES: \n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "THREE_BYTES: 0x414141",
|
|
|
|
wanted: "THREE_BYTES: \n- 65\n- 65\n- 65\n- 0\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "EIGHT_BYTES: 0x4141414141414141",
|
|
|
|
wanted: "EIGHT_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "SIXTEEN_BYTES: 0x41414141414141414141414141414141",
|
|
|
|
wanted: "SIXTEEN_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "TWENTY_BYTES: 0x4141414141414141414141414141414141414141",
|
|
|
|
wanted: "TWENTY_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "THIRTY_TWO_BYTES: 0x4141414141414141414141414141414141414141414141414141414141414141",
|
|
|
|
wanted: "THIRTY_TWO_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "FORTY_EIGHT_BYTES: 0x41414141414141414141414141414141414141414141414141414141414141414141" +
|
|
|
|
"4141414141414141414141414141",
|
|
|
|
wanted: "FORTY_EIGHT_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: "NINETY_SIX_BYTES: 0x414141414141414141414141414141414141414141414141414141414141414141414141" +
|
|
|
|
"4141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141" +
|
|
|
|
"41414141414141414141414141",
|
|
|
|
wanted: "NINETY_SIX_BYTES: \n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n" +
|
|
|
|
"- 65\n- 65\n- 65\n- 65\n- 65\n- 65\n",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, line := range testLines {
|
2021-09-21 15:02:48 +00:00
|
|
|
parts := params.ReplaceHexStringWithYAMLFormat(line.line)
|
2020-05-05 17:58:07 +00:00
|
|
|
res := strings.Join(parts, "\n")
|
|
|
|
|
|
|
|
if res != line.wanted {
|
|
|
|
t.Errorf("expected conversion to be: %v got: %v", line.wanted, res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 06:56:07 +00:00
|
|
|
func TestConfigParityYaml(t *testing.T) {
|
|
|
|
params.SetupTestConfigCleanup(t)
|
|
|
|
testDir := bazel.TestTmpDir()
|
|
|
|
yamlDir := filepath.Join(testDir, "config.yaml")
|
|
|
|
|
|
|
|
testCfg := params.E2ETestConfig()
|
|
|
|
yamlObj := params.ConfigToYaml(testCfg)
|
|
|
|
assert.NoError(t, file.WriteFile(yamlDir, yamlObj))
|
|
|
|
|
2022-05-20 07:16:53 +00:00
|
|
|
require.NoError(t, params.LoadChainConfigFile(yamlDir, params.E2ETestConfig().Copy()))
|
2022-02-02 06:56:07 +00:00
|
|
|
assert.DeepEqual(t, params.BeaconConfig(), testCfg)
|
|
|
|
}
|
|
|
|
|
2021-08-13 05:11:11 +00:00
|
|
|
// configFilePath sets the proper config and returns the relevant
|
2020-05-05 17:58:07 +00:00
|
|
|
// config file path from eth2-spec-tests directory.
|
2021-08-13 05:11:11 +00:00
|
|
|
func configFilePath(t *testing.T, config string) string {
|
2022-06-27 13:34:38 +00:00
|
|
|
fPath, err := bazel.Runfile("external/consensus_spec")
|
2021-08-13 05:11:11 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-27 13:34:38 +00:00
|
|
|
configFilePath := path.Join(fPath, "configs", config+".yaml")
|
2021-08-13 05:11:11 +00:00
|
|
|
return configFilePath
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:02:12 +00:00
|
|
|
// presetsFilePath returns the relevant preset file paths from eth2-spec-tests
|
|
|
|
// directory. This method returns a preset file path for each hard fork or
|
|
|
|
// major network upgrade, in order.
|
|
|
|
func presetsFilePath(t *testing.T, config string) []string {
|
2022-06-27 13:34:38 +00:00
|
|
|
fPath, err := bazel.Runfile("external/consensus_spec")
|
2021-08-13 05:11:11 +00:00
|
|
|
require.NoError(t, err)
|
2021-09-28 20:02:12 +00:00
|
|
|
return []string{
|
2022-06-27 13:34:38 +00:00
|
|
|
path.Join(fPath, "presets", config, "phase0.yaml"),
|
|
|
|
path.Join(fPath, "presets", config, "altair.yaml"),
|
2021-09-28 20:02:12 +00:00
|
|
|
}
|
2021-08-13 05:11:11 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 00:50:06 +00:00
|
|
|
func fieldsFromYamls(t *testing.T, fps []string) []string {
|
2021-08-09 18:40:06 +00:00
|
|
|
var keys []string
|
2021-09-28 00:50:06 +00:00
|
|
|
for _, fp := range fps {
|
2022-04-18 20:42:07 +00:00
|
|
|
yamlFile, err := os.ReadFile(fp)
|
2021-09-28 00:50:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
m := make(map[string]interface{})
|
|
|
|
require.NoError(t, yaml.Unmarshal(yamlFile, &m))
|
|
|
|
|
|
|
|
for k := range m {
|
2023-01-13 17:11:33 +00:00
|
|
|
if k == "SHARDING_FORK_VERSION" || k == "SHARDING_FORK_EPOCH" {
|
|
|
|
continue
|
|
|
|
}
|
2021-09-28 00:50:06 +00:00
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
2021-08-09 18:40:06 +00:00
|
|
|
|
2021-09-28 00:50:06 +00:00
|
|
|
if len(keys) == 0 {
|
|
|
|
t.Errorf("No fields loaded from yaml file %s", fp)
|
|
|
|
}
|
2021-08-09 18:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return keys
|
|
|
|
}
|
2021-08-25 17:18:29 +00:00
|
|
|
|
2021-09-21 15:02:48 +00:00
|
|
|
func assertYamlFieldsMatch(t *testing.T, name string, fields []string, c1, c2 *params.BeaconChainConfig) {
|
2021-08-25 17:18:29 +00:00
|
|
|
// Ensure all fields from the yaml file exist, were set, and correctly match the expected value.
|
|
|
|
ft1 := reflect.TypeOf(*c1)
|
|
|
|
for _, field := range fields {
|
|
|
|
var found bool
|
|
|
|
for i := 0; i < ft1.NumField(); i++ {
|
|
|
|
v, ok := ft1.Field(i).Tag.Lookup("yaml")
|
|
|
|
if ok && v == field {
|
2021-09-28 00:50:06 +00:00
|
|
|
if isPlaceholderField(v) {
|
|
|
|
// If you see this error, remove the field from placeholderFields.
|
|
|
|
t.Errorf("beacon config has a placeholder field defined, remove %s from the placeholder fields variable", v)
|
|
|
|
continue
|
|
|
|
}
|
2021-08-25 17:18:29 +00:00
|
|
|
found = true
|
|
|
|
v1 := reflect.ValueOf(*c1).Field(i).Interface()
|
|
|
|
v2 := reflect.ValueOf(*c2).Field(i).Interface()
|
|
|
|
if reflect.ValueOf(v1).Kind() == reflect.Slice {
|
|
|
|
assert.DeepEqual(t, v1, v2, "%s: %s", name, field)
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, v1, v2, "%s: %s", name, field)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 00:50:06 +00:00
|
|
|
if !found && !isPlaceholderField(field) { // Ignore placeholder fields
|
2021-08-25 17:18:29 +00:00
|
|
|
t.Errorf("No struct tag found `yaml:%s`", field)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 00:50:06 +00:00
|
|
|
|
|
|
|
func isPlaceholderField(field string) bool {
|
|
|
|
for _, f := range placeholderFields {
|
|
|
|
if f == field {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|