Documentation ¶
Overview ¶
Package testutil defines the testing utils such as asserting logs.
Index ¶
- func AssertLogsContain(t *testing.T, hook *test.Hook, want string)
- func AssertLogsDoNotContain(t *testing.T, hook *test.Hook, want string)
- func BazelFileBytes(filePaths ...string) ([]byte, error)
- func BitLength(b int) int
- func BitSetCount(bytes []byte) int
- func ConvertToPb(i interface{}, p proto.Message) error
- func CreateRandaoReveal(beaconState *pb.BeaconState, epoch uint64, privKeys []*bls.SecretKey) ([]byte, error)
- func GenerateDepositProof(t testing.TB, deposits []*ethpb.Deposit) ([]*ethpb.Deposit, [32]byte)
- func GenerateEth1Data(t testing.TB, deposits []*ethpb.Deposit) *ethpb.Eth1Data
- func GenerateFullBlock(t testing.TB, bState *pb.BeaconState, privs []*bls.SecretKey, ...) *ethpb.BeaconBlock
- func IsEmpty(item interface{}) bool
- func Random32Bytes(t *testing.T) []byte
- func ResetCache()
- func RunBlockOperationTest(t *testing.T, folderPath string, body *ethpb.BeaconBlockBody, ...)
- func RunEpochOperationTest(t *testing.T, testFolderPath string, operationFn epochOperation)
- func SetupInitialDeposits(t testing.TB, numDeposits uint64) ([]*ethpb.Deposit, [][32]byte, []*bls.SecretKey)
- func SignBlock(beaconState *pb.BeaconState, block *ethpb.BeaconBlock, ...) (*ethpb.BeaconBlock, error)
- func TempDir() string
- func TestFolders(t *testing.T, config string, folderPath string) ([]os.FileInfo, string)
- func UnmarshalYaml(y []byte, dest interface{}) error
- func WaitForLog(t *testing.T, hook *test.Hook, want string)
- func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool
- type BlockGenConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLogsContain ¶
AssertLogsContain checks that the desired string is a subset of the current log output. Set exitOnFail to true to immediately exit the test on failure
func AssertLogsDoNotContain ¶
AssertLogsDoNotContain is the inverse check of AssertLogsContain
func BazelFileBytes ¶
BazelFileBytes returns the byte array of the bazel file path given.
func BitLength ¶
BitLength returns the length of the bitfield for a giben number of attesters in bytes.
func BitSetCount ¶
BitSetCount counts the number of 1s in a byte using the following algo: https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
func ConvertToPb ¶
ConvertToPb converts some JSON compatible struct to given protobuf.
func CreateRandaoReveal ¶
func CreateRandaoReveal(beaconState *pb.BeaconState, epoch uint64, privKeys []*bls.SecretKey) ([]byte, error)
CreateRandaoReveal generates a epoch signature using the beacon proposer priv key.
func GenerateDepositProof ¶
GenerateDepositProof takes an array of deposits and generates the deposit trie for them and proofs.
func GenerateEth1Data ¶
GenerateEth1Data takes an array of deposits and generates the deposit trie for them.
func GenerateFullBlock ¶
func GenerateFullBlock( t testing.TB, bState *pb.BeaconState, privs []*bls.SecretKey, conf *BlockGenConfig, ) *ethpb.BeaconBlock
GenerateFullBlock generates a fully valid block with the requested parameters. Use BlockGenConfig to declare the conditions you would like the block generated under.
func Random32Bytes ¶
Random32Bytes generates a random 32 byte slice.
func RunBlockOperationTest ¶
func RunBlockOperationTest( t *testing.T, folderPath string, body *ethpb.BeaconBlockBody, operationFn blockOperation, )
RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the passed in block operation function and checks the post state with the expected post state.
func RunEpochOperationTest ¶
RunEpochOperationTest takes in the prestate and processes it through the passed in epoch operation function and checks the post state with the expected post state.
func SetupInitialDeposits ¶
func SetupInitialDeposits(t testing.TB, numDeposits uint64) ([]*ethpb.Deposit, [][32]byte, []*bls.SecretKey)
SetupInitialDeposits prepares the entered amount of deposits, deposit data roots, and secret keys. The deposits are configured such that for deposit n the validator account is key n and the withdrawal account is key n+1. As such, if all secret keys for n validators are required then numDeposits should be n+1
func SignBlock ¶
func SignBlock(beaconState *pb.BeaconState, block *ethpb.BeaconBlock, privKeys []*bls.SecretKey) (*ethpb.BeaconBlock, error)
SignBlock generates a signed block using the block slot and the beacon proposer priv key.
func TestFolders ¶
TestFolders sets the proper config and returns the result of ReadDir on the passed in eth2-spec-tests directory along with its path.
func UnmarshalYaml ¶
UnmarshalYaml using a customized json encoder that supports "spec-name" override tag.
func WaitForLog ¶
WaitForLog waits for the desired string to appear the logs within a time period. If it does not appear within the limit, the function will throw an error.