testutil

package
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2020 License: GPL-3.0 Imports: 33 Imported by: 39

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BazelDirectoryNonEmpty added in v1.0.0

func BazelDirectoryNonEmpty(filePath string) (bool, error)

BazelDirectoryNonEmpty returns true if directory exists and is not empty.

func BazelFileBytes

func BazelFileBytes(filePaths ...string) ([]byte, error)

BazelFileBytes returns the byte array of the bazel file path given.

func BlockSignature added in v0.3.0

func BlockSignature(
	bState *stateTrie.BeaconState,
	block *ethpb.BeaconBlock,
	privKeys []bls.SecretKey,
) (bls.Signature, error)

BlockSignature calculates the post-state root of the block and returns the signature.

func DepositTrieFromDeposits added in v0.3.0

func DepositTrieFromDeposits(deposits []*ethpb.Deposit) (*trieutil.SparseMerkleTrie, [][32]byte, error)

DepositTrieFromDeposits takes an array of deposits and returns the deposit trie.

func DeterministicDepositTrie added in v0.3.0

func DeterministicDepositTrie(size int) (*trieutil.SparseMerkleTrie, [][32]byte, error)

DeterministicDepositTrie returns a merkle trie of the requested size from the deterministic deposits.

func DeterministicDepositsAndKeys added in v0.3.0

func DeterministicDepositsAndKeys(numDeposits uint64) ([]*ethpb.Deposit, []bls.SecretKey, error)

DeterministicDepositsAndKeys returns the entered amount of deposits 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 DeterministicDepositsAndKeysSameValidator added in v0.3.0

func DeterministicDepositsAndKeysSameValidator(numDeposits uint64) ([]*ethpb.Deposit, []bls.SecretKey, error)

DeterministicDepositsAndKeysSameValidator returns the entered amount of deposits and secret keys of the same validator. This is for negative test cases such as same deposits from same validators in a block don't result in duplicated validator indices.

func DeterministicEth1Data added in v0.3.0

func DeterministicEth1Data(size int) (*ethpb.Eth1Data, error)

DeterministicEth1Data takes an array of deposits and returns the eth1Data made from the deposit trie.

func DeterministicGenesisState added in v0.3.0

func DeterministicGenesisState(t testing.TB, numValidators uint64) (*stateTrie.BeaconState, []bls.SecretKey)

DeterministicGenesisState returns a genesis state made using the deterministic deposits.

func GenerateAttestations added in v0.3.0

func GenerateAttestations(bState *stateTrie.BeaconState, privs []bls.SecretKey, numToGen, slot uint64, randomRoot bool) ([]*ethpb.Attestation, error)

GenerateAttestations creates attestations that are entirely valid, for all the committees of the current state slot. This function expects attestations requested to be cleanly divisible by committees per slot. If there is 1 committee in the slot, and numToGen is set to 4, then it will return 4 attestations for the same data with their aggregation bits split uniformly.

If you request 4 attestations, but there are 8 committees, you will get 4 fully aggregated attestations.

func GenerateAttesterSlashingForValidator added in v0.3.2

func GenerateAttesterSlashingForValidator(
	bState *stateTrie.BeaconState,
	priv bls.SecretKey,
	idx uint64,
) (*ethpb.AttesterSlashing, error)

GenerateAttesterSlashingForValidator for a specific validator index.

func GenerateFullBlock

func GenerateFullBlock(
	bState *stateTrie.BeaconState,
	privs []bls.SecretKey,
	conf *BlockGenConfig,
	slot uint64,
) (*ethpb.SignedBeaconBlock, error)

GenerateFullBlock generates a fully valid block with the requested parameters. Use BlockGenConfig to declare the conditions you would like the block generated under.

func GenerateProposerSlashingForValidator added in v0.3.2

func GenerateProposerSlashingForValidator(
	bState *stateTrie.BeaconState,
	priv bls.SecretKey,
	idx uint64,
) (*ethpb.ProposerSlashing, error)

GenerateProposerSlashingForValidator for a specific validator index.

func NewAttestation added in v1.0.0

func NewAttestation() *ethpb.Attestation

NewAttestation creates an attestation block with minimum marshalable fields.

func NewBeaconBlock added in v1.0.0

func NewBeaconBlock() *ethpb.SignedBeaconBlock

NewBeaconBlock creates a beacon block with minimum marshalable fields.

func NewBeaconState added in v1.0.0

func NewBeaconState() *stateTrie.BeaconState

NewBeaconState creates a beacon state with minimum marshalable fields.

func RandaoReveal added in v0.3.0

func RandaoReveal(beaconState *stateTrie.BeaconState, epoch uint64, privKeys []bls.SecretKey) ([]byte, error)

RandaoReveal returns a signature of the requested epoch using the beacon proposer private key.

func Random32Bytes

func Random32Bytes(t *testing.T) []byte

Random32Bytes generates a random 32 byte slice.

func ResetCache

func ResetCache()

ResetCache clears out the old trie, private keys and deposits.

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

func RunEpochOperationTest(
	t *testing.T,
	testFolderPath string,
	operationFn epochOperation,
)

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 TempDir

func TempDir() string

TempDir returns a directory path for temporary test storage.

func TestFolders

func TestFolders(t testing.TB, config, folderPath string) ([]os.FileInfo, string)

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

func UnmarshalYaml(y []byte, dest interface{}) error

UnmarshalYaml using a customized json encoder that supports "spec-name" override tag.

func WaitTimeout

func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool

WaitTimeout will wait for a WaitGroup to resolve within a timeout interval. Returns true if the waitgroup exceeded the timeout.

Types

type BlockGenConfig

type BlockGenConfig struct {
	NumProposerSlashings uint64
	NumAttesterSlashings uint64
	NumAttestations      uint64
	NumDeposits          uint64
	NumVoluntaryExits    uint64
}

BlockGenConfig is used to define the requested conditions for block generation.

func DefaultBlockGenConfig added in v0.2.3

func DefaultBlockGenConfig() *BlockGenConfig

DefaultBlockGenConfig returns the block config that utilizes the current params in the beacon config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL