From d2dbc13427d66ddd3b6303b0c73e5b6244bad29b Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 4 May 2022 01:15:09 -0500 Subject: [PATCH] fuzz: Fix tests with fuzz tags (#10619) * some fixes to fuzz building * use len * remove comments * fix test Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/cache/active_balance_test.go | 3 + beacon-chain/cache/committee_fuzz_test.go | 3 + beacon-chain/cache/committee_test.go | 3 + beacon-chain/cache/proposer_indices.go | 17 +- .../cache/proposer_indices_disabled.go | 4 + beacon-chain/cache/proposer_indices_test.go | 7 +- beacon-chain/core/helpers/validators_test.go | 2 +- crypto/bls/blst/BUILD.bazel | 354 ++++++++---------- 8 files changed, 180 insertions(+), 213 deletions(-) diff --git a/beacon-chain/cache/active_balance_test.go b/beacon-chain/cache/active_balance_test.go index 72aa84eef7..281c096d4a 100644 --- a/beacon-chain/cache/active_balance_test.go +++ b/beacon-chain/cache/active_balance_test.go @@ -1,3 +1,6 @@ +//go:build !fuzz +// +build !fuzz + package cache import ( diff --git a/beacon-chain/cache/committee_fuzz_test.go b/beacon-chain/cache/committee_fuzz_test.go index a7a59ed5c8..dc01be88b0 100644 --- a/beacon-chain/cache/committee_fuzz_test.go +++ b/beacon-chain/cache/committee_fuzz_test.go @@ -1,3 +1,6 @@ +//go:build !fuzz +// +build !fuzz + package cache import ( diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index a812313736..76006f3ecb 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -1,3 +1,6 @@ +//go:build !fuzz +// +build !fuzz + package cache import ( diff --git a/beacon-chain/cache/proposer_indices.go b/beacon-chain/cache/proposer_indices.go index 1856b128b6..cf7dd0d9fd 100644 --- a/beacon-chain/cache/proposer_indices.go +++ b/beacon-chain/cache/proposer_indices.go @@ -31,7 +31,7 @@ var ( // ProposerIndicesCache is a struct with 1 queue for looking up proposer indices by root. type ProposerIndicesCache struct { - ProposerIndicesCache *cache.FIFO + proposerIndicesCache *cache.FIFO lock sync.RWMutex } @@ -48,7 +48,7 @@ func proposerIndicesKeyFn(obj interface{}) (string, error) { // NewProposerIndicesCache creates a new proposer indices cache for storing/accessing proposer index assignments of an epoch. func NewProposerIndicesCache() *ProposerIndicesCache { return &ProposerIndicesCache{ - ProposerIndicesCache: cache.NewFIFO(proposerIndicesKeyFn), + proposerIndicesCache: cache.NewFIFO(proposerIndicesKeyFn), } } @@ -58,10 +58,10 @@ func (c *ProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error { c.lock.Lock() defer c.lock.Unlock() - if err := c.ProposerIndicesCache.AddIfNotPresent(p); err != nil { + if err := c.proposerIndicesCache.AddIfNotPresent(p); err != nil { return err } - trim(c.ProposerIndicesCache, maxProposerIndicesCacheSize) + trim(c.proposerIndicesCache, maxProposerIndicesCacheSize) return nil } @@ -69,7 +69,7 @@ func (c *ProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error { func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) { c.lock.RLock() defer c.lock.RUnlock() - _, exists, err := c.ProposerIndicesCache.GetByKey(key(r)) + _, exists, err := c.proposerIndicesCache.GetByKey(key(r)) if err != nil { return false, err } @@ -80,7 +80,7 @@ func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) { func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorIndex, error) { c.lock.RLock() defer c.lock.RUnlock() - obj, exists, err := c.ProposerIndicesCache.GetByKey(key(r)) + obj, exists, err := c.proposerIndicesCache.GetByKey(key(r)) if err != nil { return nil, err } @@ -99,3 +99,8 @@ func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorInd return item.ProposerIndices, nil } + +// Len returns the number of keys in the underlying cache. +func (c *ProposerIndicesCache) Len() int { + return len(c.proposerIndicesCache.ListKeys()) +} diff --git a/beacon-chain/cache/proposer_indices_disabled.go b/beacon-chain/cache/proposer_indices_disabled.go index 5ac49a4339..7b99098345 100644 --- a/beacon-chain/cache/proposer_indices_disabled.go +++ b/beacon-chain/cache/proposer_indices_disabled.go @@ -30,3 +30,7 @@ func (c *FakeProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.Validato func (c *FakeProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) { return false, nil } + +func (c *FakeProposerIndicesCache) Len() int { + return 0 +} diff --git a/beacon-chain/cache/proposer_indices_test.go b/beacon-chain/cache/proposer_indices_test.go index 64bc359dce..e7faa691a7 100644 --- a/beacon-chain/cache/proposer_indices_test.go +++ b/beacon-chain/cache/proposer_indices_test.go @@ -1,3 +1,6 @@ +//go:build !fuzz +// +build !fuzz + package cache import ( @@ -68,7 +71,5 @@ func TestProposerCache_CanRotate(t *testing.T) { item := &ProposerIndices{BlockRoot: bytesutil.ToBytes32(s)} require.NoError(t, cache.AddProposerIndices(item)) } - - k := cache.ProposerIndicesCache.ListKeys() - assert.Equal(t, maxProposerIndicesCacheSize, uint64(len(k))) + assert.Equal(t, int(maxProposerIndicesCacheSize), cache.Len()) } diff --git a/beacon-chain/core/helpers/validators_test.go b/beacon-chain/core/helpers/validators_test.go index 9d827c63fb..b91e13a8ee 100644 --- a/beacon-chain/core/helpers/validators_test.go +++ b/beacon-chain/core/helpers/validators_test.go @@ -233,7 +233,7 @@ func TestBeaconProposerIndex_BadState(t *testing.T) { require.NoError(t, state.SetSlot(100)) _, err = BeaconProposerIndex(context.Background(), state) require.NoError(t, err) - assert.Equal(t, 0, len(proposerIndicesCache.ProposerIndicesCache.ListKeys())) + assert.Equal(t, 0, proposerIndicesCache.Len()) } func TestComputeProposerIndex_Compatibility(t *testing.T) { diff --git a/crypto/bls/blst/BUILD.bazel b/crypto/bls/blst/BUILD.bazel index beb101ba19..125d51196f 100644 --- a/crypto/bls/blst/BUILD.bazel +++ b/crypto/bls/blst/BUILD.bazel @@ -1,205 +1,177 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_test") load("@bazel_skylib//lib:selects.bzl", "selects") -load("@prysm//tools/go:def.bzl", "go_library") - -# Build with --define=blst_disabled=true to exclude blst library. -config_setting( - name = "linux_amd64", - constraint_values = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "darwin_amd64", - constraint_values = [ - "@platforms//os:osx", - "@platforms//cpu:x86_64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "darwin_arm64", - constraint_values = [ - "@platforms//os:osx", - "@platforms//cpu:arm64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "windows_amd64", - constraint_values = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "linux_arm64", - constraint_values = [ - "@platforms//os:linux", - "@platforms//cpu:aarch64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "android_amd64", - constraint_values = [ - "@platforms//os:android", - "@platforms//cpu:x86_64", - ], - values = { - "define": "blst_disabled=false", - }, -) - -config_setting( - name = "android_arm64", - constraint_values = [ - "@platforms//os:android", - "@platforms//cpu:aarch64", - ], - values = { - "define": "blst_disabled=false", - }, -) +load("@prysm//tools/go:def.bzl", "go_library", "go_test") # gazelle:resolve go github.com/supranational/blst/bindings/go @com_github_supranational_blst//:go_default_library go_library( name = "go_default_library", - srcs = - selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ - "aliases.go", - "doc.go", - "init.go", - "public_key.go", - "secret_key.go", - "signature.go", - ], - "//conditions:default": [ - "stub.go", - ], - }), + srcs = [ + "aliases.go", + "doc.go", + "init.go", + "public_key.go", + "secret_key.go", + "signature.go", + "stub.go", # keep + ], importpath = "github.com/prysmaticlabs/prysm/crypto/bls/blst", visibility = [ "//crypto/bls:__pkg__", ], - deps = selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ - "//crypto/bls/common:go_default_library", + deps = select({ + "@io_bazel_rules_go//go/platform:android_amd64": [ + "//cache/lru:go_default_library", "//config/features:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", "//crypto/rand:go_default_library", - "//cache/lru:go_default_library", - "@com_github_dgraph_io_ristretto//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_supranational_blst//:go_default_library", ], - "//conditions:default": ["//crypto/bls/common:go_default_library"], + "@io_bazel_rules_go//go/platform:android_arm64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:darwin_amd64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:darwin_arm64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:ios_amd64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:ios_arm64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:linux_amd64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:linux_arm64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:windows_amd64": [ + "//cache/lru:go_default_library", + "//config/features:go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//crypto/bls/common:go_default_library", + "//crypto/rand:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_supranational_blst//:go_default_library", + ], + "//conditions:default": [], }), ) -# gazelle:ignore go_test( name = "go_default_test", - srcs = selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ - "public_key_test.go", - "secret_key_test.go", - ], - "//conditions:default": [], - }), - deps = selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ - "//crypto/bls/blst:go_default_library", - "//crypto/bls/common:go_default_library", - "//encoding/bytesutil:go_default_library", - "//testing/assert:go_default_library", - "//testing/require:go_default_library", - ], - "//conditions:default": [], - }), -) - -# gazelle:ignore -go_test( - name = "go_signature_test", - srcs = selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ - "signature_test.go", - ], - "//conditions:default": [], - }), + srcs = [ + "bls_benchmark_test.go", + "public_key_test.go", + "secret_key_test.go", + "signature_test.go", + ], embed = [":go_default_library"], - deps = selects.with_or({ - ( - ":linux_amd64", - ":linux_arm64", - ":darwin_amd64", - ":darwin_arm64", - ":windows_amd64", - ":android_amd64", - ":android_arm64", - ): [ + deps = select({ + "@io_bazel_rules_go//go/platform:android_amd64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:android_arm64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:darwin_amd64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:darwin_arm64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:ios_amd64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:ios_arm64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:linux_amd64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:linux_arm64": [ + "//crypto/bls/common:go_default_library", + "//encoding/bytesutil:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + ], + "@io_bazel_rules_go//go/platform:windows_amd64": [ "//crypto/bls/common:go_default_library", "//encoding/bytesutil:go_default_library", "//testing/assert:go_default_library", @@ -208,27 +180,3 @@ go_test( "//conditions:default": [], }), ) - -# gazelle:exclude bls_benchmark_test.go -go_test( - name = "go_benchmark_test", - size = "small", - srcs = ["bls_benchmark_test.go"], - args = [ - "-test.bench=.", - "-test.benchmem", - "-test.v", - ], - local = True, - tags = [ - "benchmark", - "manual", - "no-cache", - ], - deps = [ - ":go_default_library", - "//crypto/bls/common:go_default_library", - "//crypto/hash:go_default_library", - "//encoding/bytesutil:go_default_library", - ], -)