From 4966300c9690b15811de238002a19589cabdfebf Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 17 Aug 2021 16:23:38 -0500 Subject: [PATCH] Update spectests to v1.1.0-beta.1 from hf1 branch (#9403) * Update spectests to v1.1.0-beta.1 from hf1 branch * fix params loading --- WORKSPACE | 30 ++++++++++++++++++++++++------ shared/params/BUILD.bazel | 1 + shared/params/loader.go | 2 +- shared/params/loader_test.go | 15 ++------------- shared/testutil/bazel.go | 4 ++++ spectest/utils/utils.go | 4 ++++ 6 files changed, 36 insertions(+), 20 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 5153bfe84..b78d4b093 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -197,6 +197,8 @@ filegroup( url = "https://github.com/eth2-clients/slashing-protection-interchange-tests/archive/b8413ca42dc92308019d0d4db52c87e9e125c4e9.tar.gz", ) +eth2_spec_version = "v1.1.0-beta.1" + http_archive( name = "eth2_spec_tests_general", build_file_content = """ @@ -209,8 +211,8 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "deacc076365c727d653ac064894ecf0d1b0a675d86704dc8de271259f6a7314b", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/general.tar.gz", + sha256 = "e9b4cc60a3e676c6b4a9348424e44cff1ebada603ffb31b0df600dbd70e7fbf6", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/%s/general.tar.gz" % eth2_spec_version, ) http_archive( @@ -225,8 +227,8 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "6e9886af3d2f024e563249d70388129e28e3e92f742f289238ed9b7ec7a7f930", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/minimal.tar.gz", + sha256 = "cf82dc729ffe7b924f852e57d1973e1a6377c5b52acc903c953277fa9b4e6de8", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/%s/minimal.tar.gz" % eth2_spec_version, ) http_archive( @@ -241,8 +243,24 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "a7b3d0ffc02a567250f424d69b2474fdc9477cd56eada60af7474560b46a8527", - url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/mainnet.tar.gz", + sha256 = "6c6792375b81858037014e282d28a64b0cf12e12daf16054265c85403b8b329f", + url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/%s/mainnet.tar.gz" % eth2_spec_version, +) + +http_archive( + name = "eth2_spec", + build_file_content = """ +filegroup( + name = "spec_data", + srcs = glob([ + "**/*.yaml", + ]), + visibility = ["//visibility:public"], +) + """, + sha256 = "16094dad1bab4e8ab3adb60c10e311cd1e294cd7bbf5a89505f24bebd3d0e513", + strip_prefix = "eth2.0-specs-" + eth2_spec_version[1:], + url = "https://github.com/ethereum/eth2.0-specs/archive/refs/tags/%s.tar.gz" % eth2_spec_version, ) http_archive( diff --git a/shared/params/BUILD.bazel b/shared/params/BUILD.bazel index bef9e31cb..e83e16682 100644 --- a/shared/params/BUILD.bazel +++ b/shared/params/BUILD.bazel @@ -39,6 +39,7 @@ go_test( "loader_test.go", ], data = glob(["*.yaml"]) + [ + "@eth2_spec//:spec_data", "@eth2_spec_tests_mainnet//:test_data", "@eth2_spec_tests_minimal//:test_data", ], diff --git a/shared/params/loader.go b/shared/params/loader.go index 3a81ad290..02d66c01a 100644 --- a/shared/params/loader.go +++ b/shared/params/loader.go @@ -25,7 +25,7 @@ func LoadChainConfigFile(chainConfigFileName string) { if strings.HasPrefix(line, "DEPOSIT_CONTRACT_ADDRESS") { continue } - if strings.HasPrefix(line, "PRESET_BASE: 'minimal'") { + if strings.HasPrefix(line, "PRESET_BASE: 'minimal'") || strings.HasPrefix(line, "# Minimal preset") { conf = MinimalSpecConfig().Copy() } diff --git a/shared/params/loader_test.go b/shared/params/loader_test.go index 865a2021c..81b4b932d 100644 --- a/shared/params/loader_test.go +++ b/shared/params/loader_test.go @@ -125,14 +125,14 @@ func TestLoadConfigFileMainnet(t *testing.T) { } t.Run("mainnet", func(t *testing.T) { - mainnetConfigFile := deprecatedConfigFilePath(t, "mainnet") + mainnetConfigFile := presetsFilePath(t, "mainnet") LoadChainConfigFile(mainnetConfigFile) fields := fieldsFromYaml(t, mainnetConfigFile) assertVals("mainnet", fields, MainnetConfig(), BeaconConfig()) }) t.Run("minimal", func(t *testing.T) { - minimalConfigFile := deprecatedConfigFilePath(t, "minimal") + minimalConfigFile := presetsFilePath(t, "minimal") LoadChainConfigFile(minimalConfigFile) fields := fieldsFromYaml(t, minimalConfigFile) assertVals("minimal", fields, MinimalSpecConfig(), BeaconConfig()) @@ -246,17 +246,6 @@ func presetsFilePath(t *testing.T, config string) string { return configFilePath } -// Deprecated: This sets the proper config and returns the relevant -// config file path from eth2-spec-tests directory. From altair onwards -// we use the other methods to retrieve the spec config. -func deprecatedConfigFilePath(t *testing.T, config string) string { - configFolderPath := path.Join("tests", config) - filepath, err := bazel.Runfile(configFolderPath) - require.NoError(t, err) - configFilePath := path.Join(filepath, "config", "phase0.yaml") - return configFilePath -} - func fieldsFromYaml(t *testing.T, fp string) []string { yamlFile, err := ioutil.ReadFile(fp) require.NoError(t, err) diff --git a/shared/testutil/bazel.go b/shared/testutil/bazel.go index 7d51a0857..6f3bf58ac 100644 --- a/shared/testutil/bazel.go +++ b/shared/testutil/bazel.go @@ -5,6 +5,7 @@ import ( "path" "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/pkg/errors" ) // BazelDirectoryNonEmpty returns true if directory exists and is not empty. @@ -30,5 +31,8 @@ func BazelFileBytes(filePaths ...string) ([]byte, error) { if err != nil { return nil, err } + if len(fileBytes) == 0 { + return nil, errors.New("empty file") + } return fileBytes, nil } diff --git a/spectest/utils/utils.go b/spectest/utils/utils.go index 6bcb43fba..747697af7 100644 --- a/spectest/utils/utils.go +++ b/spectest/utils/utils.go @@ -38,5 +38,9 @@ func TestFolders(t testing.TB, config, forkOrPhase, folderPath string) ([]os.Fil testFolders, err := ioutil.ReadDir(filepath) require.NoError(t, err) + if len(testFolders) == 0 { + t.Fatalf("No test folders found at %s", testsFolderPath) + } + return testFolders, testsFolderPath }