2022-05-04 06:15:09 +00:00
|
|
|
//go:build !fuzz
|
|
|
|
// +build !fuzz
|
|
|
|
|
2020-01-08 17:13:39 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2021-09-26 15:27:57 +00:00
|
|
|
"context"
|
2020-01-08 17:13:39 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
fuzz "github.com/google/gofuzz"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2020-01-08 17:13:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommitteeKeyFuzz_OK(t *testing.T) {
|
|
|
|
fuzzer := fuzz.NewWithSeed(0)
|
|
|
|
c := &Committees{}
|
|
|
|
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
|
|
fuzzer.Fuzz(c)
|
|
|
|
k, err := committeeKeyFn(c)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, key(c.Seed), k)
|
2020-01-08 17:13:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitteeCache_FuzzCommitteesByEpoch(t *testing.T) {
|
|
|
|
cache := NewCommitteesCache()
|
|
|
|
fuzzer := fuzz.NewWithSeed(0)
|
|
|
|
c := &Committees{}
|
|
|
|
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
|
|
fuzzer.Fuzz(c)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, cache.AddCommitteeShuffledList(c))
|
2021-09-26 15:27:57 +00:00
|
|
|
_, err := cache.Committee(context.Background(), 0, c.Seed, 0)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-08 17:13:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 09:34:30 +00:00
|
|
|
assert.Equal(t, maxCommitteesCacheSize, len(cache.CommitteeCache.Keys()), "Incorrect key size")
|
2020-01-08 17:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitteeCache_FuzzActiveIndices(t *testing.T) {
|
|
|
|
cache := NewCommitteesCache()
|
|
|
|
fuzzer := fuzz.NewWithSeed(0)
|
|
|
|
c := &Committees{}
|
|
|
|
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
|
|
fuzzer.Fuzz(c)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, cache.AddCommitteeShuffledList(c))
|
|
|
|
|
2021-09-26 15:27:57 +00:00
|
|
|
indices, err := cache.ActiveIndices(context.Background(), c.Seed)
|
2020-07-16 19:34:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, c.SortedIndices, indices)
|
2020-01-08 17:13:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 09:34:30 +00:00
|
|
|
assert.Equal(t, maxCommitteesCacheSize, len(cache.CommitteeCache.Keys()), "Incorrect key size")
|
2020-01-08 17:13:39 +00:00
|
|
|
}
|