Update spectests to v1.1.0 (#9680)

* Update spectests to v1.1.0

* ignore placeholder fields, fix spec config check
This commit is contained in:
Preston Van Loon 2021-09-27 19:50:06 -05:00 committed by GitHub
parent 328e3e6caf
commit cbb4361c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 23 deletions

View File

@ -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"
@ -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,
)
@ -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,
)
@ -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,
)
@ -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,
)

View File

@ -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) {
@ -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())
})
}
@ -226,13 +234,14 @@ func presetsFilePath(t *testing.T, config string) string {
return configFilePath
}
func fieldsFromYaml(t *testing.T, fp string) []string {
func fieldsFromYamls(t *testing.T, fps []string) []string {
var keys []string
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))
var keys []string
for k := range m {
keys = append(keys, k)
}
@ -240,6 +249,7 @@ func fieldsFromYaml(t *testing.T, fp string) []string {
if len(keys) == 0 {
t.Errorf("No fields loaded from yaml file %s", fp)
}
}
return keys
}
@ -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()
@ -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
}

View File

@ -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())
}