Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Starting TestCommitteeKeyFuzz_OK * Added fuzz tests for committeees by epoch and active indices
- Loading branch information
1 parent
624c424
commit a69cb5c
Showing
3 changed files
with
71 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cache | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
) | ||
|
||
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) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if k != key(c.Seed) { | ||
t.Errorf("Incorrect hash k: %s, expected %s", k, key(c.Seed)) | ||
} | ||
} | ||
} | ||
|
||
func TestCommitteeCache_FuzzCommitteesByEpoch(t *testing.T) { | ||
cache := NewCommitteesCache() | ||
fuzzer := fuzz.NewWithSeed(0) | ||
c := &Committees{} | ||
|
||
for i := 0; i < 100000; i++ { | ||
fuzzer.Fuzz(c) | ||
if err := cache.AddCommitteeShuffledList(c); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := cache.Committee(0, c.Seed, 0); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
if len(cache.CommitteeCache.ListKeys()) != maxCommitteesCacheSize { | ||
t.Error("Incorrect key size") | ||
} | ||
} | ||
|
||
func TestCommitteeCache_FuzzActiveIndices(t *testing.T) { | ||
cache := NewCommitteesCache() | ||
fuzzer := fuzz.NewWithSeed(0) | ||
c := &Committees{} | ||
|
||
for i := 0; i < 100000; i++ { | ||
fuzzer.Fuzz(c) | ||
if err := cache.AddCommitteeShuffledList(c); err != nil { | ||
t.Fatal(err) | ||
} | ||
indices, err := cache.ActiveIndices(c.Seed) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !reflect.DeepEqual(indices, c.SortedIndices) { | ||
t.Error("Saved indices not the same") | ||
} | ||
} | ||
|
||
if len(cache.CommitteeCache.ListKeys()) != maxCommitteesCacheSize { | ||
t.Error("Incorrect key size") | ||
} | ||
} |
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