Skip to content

Commit

Permalink
Refactor shared/testutil/spectest.go (#8800)
Browse files Browse the repository at this point in the history
* Refactor shared/testutil/spectest

* update operations

* update epoch_processing

* rename spectest.go
  • Loading branch information
farazdagi authored Apr 22, 2021
1 parent 23ff14c commit 648e360
Show file tree
Hide file tree
Showing 37 changed files with 312 additions and 266 deletions.
8 changes: 1 addition & 7 deletions shared/testutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ go_library(
testonly = True,
srcs = [
"attestation.go",
"bazel.go",
"block.go",
"deposits.go",
"helpers.go",
"spectest.go",
"state.go",
"wait_timeout.go",
],
Expand All @@ -27,20 +27,14 @@ go_library(
"//shared/interop:go_default_library",
"//shared/params:go_default_library",
"//shared/rand:go_default_library",
"//shared/testutil/require:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@com_github_json_iterator_go//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
Expand Down
34 changes: 34 additions & 0 deletions shared/testutil/bazel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package testutil

import (
"io/ioutil"
"path"

"github.com/bazelbuild/rules_go/go/tools/bazel"
)

// BazelDirectoryNonEmpty returns true if directory exists and is not empty.
func BazelDirectoryNonEmpty(filePath string) (bool, error) {
p, err := bazel.Runfile(filePath)
if err != nil {
return false, err
}
fs, err := ioutil.ReadDir(p)
if err != nil {
return false, err
}
return len(fs) > 0, nil
}

// BazelFileBytes returns the byte array of the bazel file path given.
func BazelFileBytes(filePaths ...string) ([]byte, error) {
filepath, err := bazel.Runfile(path.Join(filePaths...))
if err != nil {
return nil, err
}
fileBytes, err := ioutil.ReadFile(filepath)
if err != nil {
return nil, err
}
return fileBytes, nil
}
201 changes: 0 additions & 201 deletions shared/testutil/spectest.go

This file was deleted.

1 change: 1 addition & 0 deletions spectest/general/phase0/bls/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go_test(
"//shared/bytesutil:go_default_library",
"//shared/testutil:go_default_library",
"//shared/testutil/require:go_default_library",
"//spectest/utils:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
],
)
3 changes: 2 additions & 1 deletion spectest/general/phase0/bls/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
)

func TestAggregate(t *testing.T) {
t.Run("blst", testAggregate)
}

func testAggregate(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/aggregate/small")
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/aggregate/small")

for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion spectest/general/phase0/bls/aggregate_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
)

func TestAggregateVerify(t *testing.T) {
t.Run("blst", testAggregateVerify)
}

func testAggregateVerify(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/aggregate_verify/small")
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/aggregate_verify/small")

for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion spectest/general/phase0/bls/fast_aggregate_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
)

func TestFastAggregateVerify(t *testing.T) {
t.Run("blst", testFastAggregateVerify)
}

func testFastAggregateVerify(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/fast_aggregate_verify/small")
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/fast_aggregate_verify/small")

for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion spectest/general/phase0/bls/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
)

func TestSign(t *testing.T) {
t.Run("blst", testSign)
}

func testSign(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/sign/small")
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/sign/small")

for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion spectest/general/phase0/bls/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
)

func TestVerify(t *testing.T) {
t.Run("blst", testVerify)
}

func testVerify(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/verify/small")
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/verify/small")

for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions spectest/shared/phase0/epoch_processing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
srcs = [
"effective_balance_updates.go",
"eth1_data_reset.go",
"helpers.go",
"historical_roots_update.go",
"justification_and_finalization.go",
"participation_record_updates.go",
Expand All @@ -22,8 +23,14 @@ go_library(
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state/stateV0:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/testutil:go_default_library",
"//shared/testutil/require:go_default_library",
"//spectest/utils:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
Loading

0 comments on commit 648e360

Please sign in to comment.