-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update `consensus_spec_version` to `v1.5.0-alpha.1`. * `CustodyColumns`: Fix and implement spec tests. * Make deepsource happy. * `^uint64(0)` => `math.MaxUint64`. * Fix `TestLoadConfigFile` test.
- Loading branch information
Showing
9 changed files
with
168 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@prysm//tools/go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "go_default_test", | ||
size = "small", | ||
srcs = ["custody_columns_test.go"], | ||
data = glob(["*.yaml"]) + [ | ||
"@consensus_spec_tests_mainnet//:test_data", | ||
], | ||
tags = ["spectest"], | ||
deps = ["//testing/spectest/shared/eip7594/networking:go_default_library"], | ||
) |
11 changes: 11 additions & 0 deletions
11
testing/spectest/mainnet/eip7594/networking/custody_columns_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package networking | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/eip7594/networking" | ||
) | ||
|
||
func TestMainnet_EIP7594_Networking_CustodyColumns(t *testing.T) { | ||
networking.RunCustodyColumnsTest(t, "mainnet") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@prysm//tools/go:def.bzl", "go_test") | ||
|
||
go_test( | ||
name = "go_default_test", | ||
size = "small", | ||
srcs = ["custody_columns_test.go"], | ||
data = glob(["*.yaml"]) + [ | ||
"@consensus_spec_tests_minimal//:test_data", | ||
], | ||
tags = ["spectest"], | ||
deps = ["//testing/spectest/shared/eip7594/networking:go_default_library"], | ||
) |
11 changes: 11 additions & 0 deletions
11
testing/spectest/minimal/eip7594/networking/custody_columns_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package networking | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/eip7594/networking" | ||
) | ||
|
||
func TestMainnet_EIP7594_Networking_CustodyColumns(t *testing.T) { | ||
networking.RunCustodyColumnsTest(t, "minimal") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@prysm//tools/go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
testonly = True, | ||
srcs = ["custody_columns.go"], | ||
importpath = "github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/eip7594/networking", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//beacon-chain/core/peerdas:go_default_library", | ||
"//testing/require:go_default_library", | ||
"//testing/spectest/utils:go_default_library", | ||
"//testing/util:go_default_library", | ||
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library", | ||
"@in_gopkg_yaml_v3//:go_default_library", | ||
], | ||
) |
64 changes: 64 additions & 0 deletions
64
testing/spectest/shared/eip7594/networking/custody_columns.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package networking | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/p2p/enode" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/utils" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type Config struct { | ||
NodeId *big.Int `yaml:"node_id"` | ||
CustodySubnetCount uint64 `yaml:"custody_subnet_count"` | ||
Expected []uint64 `yaml:"result"` | ||
} | ||
|
||
// RunCustodyColumnsTest executes custody columns spec tests. | ||
func RunCustodyColumnsTest(t *testing.T, config string) { | ||
err := utils.SetConfig(t, config) | ||
require.NoError(t, err, "failed to set config") | ||
|
||
// Retrieve the test vector folders. | ||
testFolders, testsFolderPath := utils.TestFolders(t, config, "eip7594", "networking/get_custody_columns/pyspec_tests") | ||
if len(testFolders) == 0 { | ||
t.Fatalf("no test folders found for %s", testsFolderPath) | ||
} | ||
|
||
for _, folder := range testFolders { | ||
t.Run(folder.Name(), func(t *testing.T) { | ||
var ( | ||
config Config | ||
nodeIdBytes [32]byte | ||
) | ||
|
||
// Load the test vector. | ||
file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml") | ||
require.NoError(t, err, "failed to retrieve the `meta.yaml` YAML file") | ||
|
||
// Unmarshal the test vector. | ||
err = yaml.Unmarshal(file, &config) | ||
require.NoError(t, err, "failed to unmarshal the YAML file") | ||
|
||
// Get the node ID. | ||
copy(nodeIdBytes[:], config.NodeId.Bytes()) | ||
nodeId := enode.ID(nodeIdBytes) | ||
|
||
// Compute the custodied columns. | ||
actual, err := peerdas.CustodyColumns(nodeId, config.CustodySubnetCount) | ||
require.NoError(t, err, "failed to compute the custody columns") | ||
|
||
// Compare the results. | ||
require.Equal(t, len(config.Expected), len(actual), "expected %d custody columns, got %d", len(config.Expected), len(actual)) | ||
|
||
for _, result := range config.Expected { | ||
ok := actual[result] | ||
require.Equal(t, true, ok, "expected column %d to be in custody columns", result) | ||
} | ||
}) | ||
} | ||
} |