prysm-pulse/encoding/ssz/htrutils_fuzz_test.go
Håvard Anda Estensen b55ddb5a34
Use go:build lines and remove obsolete +build lines (#10704)
* Use go:build lines and remove obsolete +build lines

* Run gazelle

* Update crypto/bls/blst/stub.go

* Update crypto/bls/blst/stub.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Nishant Das <nishdas93@gmail.com>
2022-06-14 11:47:27 +00:00

55 lines
1.1 KiB
Go

//go:build fuzz && go1.18
package ssz_test
import (
"testing"
fssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/encoding/ssz"
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
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) {
if _, err := ssz.PackByChunk([][]byte{b}); err != nil {
t.Fatal(err)
}
})
}