Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spectests to v1.1.0 #9680

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ filegroup(
url = "https://github.com/eth2-clients/slashing-protection-interchange-tests/archive/b8413ca42dc92308019d0d4db52c87e9e125c4e9.tar.gz",
)

consensus_spec_version = "v1.1.0-beta.4"
consensus_spec_version = "v1.1.0"

bls_test_version = "v0.1.1"

Expand All @@ -213,7 +213,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "d2d501453cf29777896a5f9ae52e93921f34330e57fcc5b55e4982d4795236b9",
sha256 = "0f58ec1c8995ab2c0a3aada873e1a02f333c8659fdacaa1c76fbdce28b6177dc",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version,
)

Expand All @@ -229,7 +229,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "b152f1f03a4fdacd1882fe867bdfbd5067e74ed3c532bd01d81e7adf6cc3737a",
sha256 = "d2eeadef3f8885748f769a06eb916bea60fb00112a90cec3288ea78db5557df3",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version,
)

Expand All @@ -245,7 +245,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "6046f89c679a9ffda217dee6f021eb7c4fe91aad6ff940fae4d2cf894cc61cbb",
sha256 = "bbc345432f4eaa4babe2619e16fcf3f607113ede82d1bd0fff2633c1376419f7",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version,
)

Expand All @@ -260,7 +260,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "26a0a2c3022a3c5354f3204c7e441580df2e585dbde22a43a1d43f885b3a221c",
sha256 = "787a50c2a03bebab92f089333f598780ca7b4849b36a4897e6603ddd3e86ec24",
strip_prefix = "consensus-specs-" + consensus_spec_version[1:],
url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version,
)
Expand Down
58 changes: 41 additions & 17 deletions config/params/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"gopkg.in/yaml.v2"
)

var placeholderFields = []string{
"TERMINAL_TOTAL_DIFFICULTY",
"TERMINAL_BLOCK_HASH",
}

func TestLoadConfigFileMainnet(t *testing.T) {
// See https://media.githubusercontent.com/media/ethereum/consensus-spec-tests/master/tests/minimal/config/phase0.yaml
assertVals := func(name string, fields []string, c1, c2 *params.BeaconChainConfig) {
Expand Down Expand Up @@ -105,16 +110,19 @@ func TestLoadConfigFileMainnet(t *testing.T) {
}

t.Run("mainnet", func(t *testing.T) {
mainnetConfigFile := presetsFilePath(t, "mainnet")
mainnetPresetsFile := presetsFilePath(t, "mainnet")
params.LoadChainConfigFile(mainnetPresetsFile)
mainnetConfigFile := configFilePath(t, "mainnet")
params.LoadChainConfigFile(mainnetConfigFile)
fields := fieldsFromYaml(t, mainnetConfigFile)
fields := fieldsFromYamls(t, []string{mainnetPresetsFile, mainnetConfigFile})
assertVals("mainnet", fields, params.MainnetConfig(), params.BeaconConfig())
})

t.Run("minimal", func(t *testing.T) {
minimalConfigFile := presetsFilePath(t, "minimal")
params.LoadChainConfigFile(minimalConfigFile)
fields := fieldsFromYaml(t, minimalConfigFile)
minimalPresetsFile := presetsFilePath(t, "minimal")
params.LoadChainConfigFile(minimalPresetsFile)
minimalConfigFile := configFilePath(t, "minimal")
fields := fieldsFromYamls(t, []string{minimalPresetsFile, minimalConfigFile})
assertVals("minimal", fields, params.MinimalSpecConfig(), params.BeaconConfig())
})
}
Expand Down Expand Up @@ -226,19 +234,21 @@ func presetsFilePath(t *testing.T, config string) string {
return configFilePath
}

func fieldsFromYaml(t *testing.T, fp string) []string {
yamlFile, err := ioutil.ReadFile(fp)
require.NoError(t, err)
m := make(map[string]interface{})
require.NoError(t, yaml.Unmarshal(yamlFile, &m))

func fieldsFromYamls(t *testing.T, fps []string) []string {
var keys []string
for k := range m {
keys = append(keys, k)
}
for _, fp := range fps {
yamlFile, err := ioutil.ReadFile(fp)
require.NoError(t, err)
m := make(map[string]interface{})
require.NoError(t, yaml.Unmarshal(yamlFile, &m))

for k := range m {
keys = append(keys, k)
}

if len(keys) == 0 {
t.Errorf("No fields loaded from yaml file %s", fp)
if len(keys) == 0 {
t.Errorf("No fields loaded from yaml file %s", fp)
}
}

return keys
Expand All @@ -252,6 +262,11 @@ func assertYamlFieldsMatch(t *testing.T, name string, fields []string, c1, c2 *p
for i := 0; i < ft1.NumField(); i++ {
v, ok := ft1.Field(i).Tag.Lookup("yaml")
if ok && v == field {
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
}
found = true
v1 := reflect.ValueOf(*c1).Field(i).Interface()
v2 := reflect.ValueOf(*c2).Field(i).Interface()
Expand All @@ -263,8 +278,17 @@ func assertYamlFieldsMatch(t *testing.T, name string, fields []string, c1, c2 *p
break
}
}
if !found {
if !found && !isPlaceholderField(field) { // Ignore placeholder fields
t.Errorf("No struct tag found `yaml:%s`", field)
}
}
}

func isPlaceholderField(field string) bool {
for _, f := range placeholderFields {
if f == field {
return true
}
}
return false
}
4 changes: 3 additions & 1 deletion config/params/testnet_prater_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
)

func TestPraterConfigMatchesUpstreamYaml(t *testing.T) {
presetFP := presetsFilePath(t, "mainnet")
params.LoadChainConfigFile(presetFP)
configFP := testnetConfigFilePath(t, "prater")
params.LoadChainConfigFile(configFP)
fields := fieldsFromYaml(t, configFP)
fields := fieldsFromYamls(t, []string{configFP, presetFP})
assertYamlFieldsMatch(t, "prater", fields, params.BeaconConfig(), params.PraterConfig())
}