2023-08-11 16:39:35 +00:00
|
|
|
//go:build go1.18
|
2022-01-29 08:01:58 +00:00
|
|
|
|
|
|
|
package ssz_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-06-28 13:03:24 +00:00
|
|
|
fssz "github.com/prysmaticlabs/fastssz"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/encoding/ssz"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
2022-01-29 08:01:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func FuzzUint64Root(f *testing.F) {
|
|
|
|
f.Fuzz(func(t *testing.T, i uint64) {
|
|
|
|
_ = ssz.Uint64Root(i)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzForkRoot(f *testing.F) {
|
|
|
|
frk := &pb.Fork{
|
|
|
|
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
|
|
|
CurrentVersion: params.BeaconConfig().AltairForkVersion,
|
|
|
|
Epoch: 100,
|
|
|
|
}
|
|
|
|
example, err := frk.MarshalSSZ()
|
|
|
|
if err != nil {
|
|
|
|
f.Fatal(err)
|
|
|
|
}
|
|
|
|
f.Add(example)
|
|
|
|
|
|
|
|
f.Fuzz(func(t *testing.T, b []byte) {
|
|
|
|
frk := &pb.Fork{}
|
|
|
|
if err := frk.UnmarshalSSZ(b); err != nil {
|
|
|
|
if errors.Is(err, fssz.ErrSize) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := ssz.ForkRoot(frk); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func FuzzPackChunks(f *testing.F) {
|
|
|
|
f.Fuzz(func(t *testing.T, b []byte) {
|
2022-03-04 15:19:07 +00:00
|
|
|
if _, err := ssz.PackByChunk([][]byte{b}); err != nil {
|
2022-01-29 08:01:58 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|