prysm-pulse/fuzz/testing/beacon_fuzz_states.go
terence tsao b954db9704
Revert "Update fastssz" (#7100)
* Revert "Update fastssz (#6760)"

This reverts commit 78a25f99c3.
* Merge refs/heads/master into revert-6760-update-fssz
2020-08-24 20:06:28 +00:00

40 lines
1.0 KiB
Go

package testing
import (
"fmt"
"os"
"strconv"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
const fileBase = "0-11-0/mainnet/beaconstate"
const fileBaseENV = "BEACONSTATES_PATH"
// GetBeaconFuzzState returns a beacon state by ID using the beacon-fuzz corpora.
func GetBeaconFuzzState(ID uint16) (*pb.BeaconState, error) {
base := fileBase
// Using an environment variable allows a host image to specify the path when only the binary
// executable was uploaded (without the runfiles). i.e. fuzzit's platform.
if p, ok := os.LookupEnv(fileBaseENV); ok {
base = p
}
ok, err := testutil.BazelDirectoryNonEmpty(base)
if err != nil {
panic(err)
}
if !ok {
panic(fmt.Sprintf("Beacon states directory (%s) does not exist or has no files.", base))
}
b, err := testutil.BazelFileBytes(base, strconv.Itoa(int(ID)))
if err != nil {
return nil, err
}
st := &pb.BeaconState{}
if err := st.UnmarshalSSZ(b); err != nil {
return nil, err
}
return st, nil
}