util

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: GPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BazelDirectoryNonEmpty

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 BazelListDirectories

func BazelListDirectories(filepath string) ([]string, error)

BazelListDirectories lists all of the directories in the given directory. Excludes regular files. Returns error when no directories exist.

func BazelListFiles

func BazelListFiles(filepath string) ([]string, error)

BazelListFiles lists all of the file names in a given directory. Excludes directories. Returns an error when no non-directory files exist.

func BlockSignature

func BlockSignature(
	bState state.BeaconState,
	block interface{},
	privKeys []dilithium.DilithiumKey,
) (dilithium.Signature, error)

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

func ConvertToCommittee

func ConvertToCommittee(inputKeys [][]byte) *zondpb.SyncCommittee

ConvertToCommittee takes a list of pubkeys and returns a SyncCommittee with these keys as members. Some keys may appear repeated

func DepositTrieFromDeposits

func DepositTrieFromDeposits(deposits []*zondpb.Deposit) (*trie.SparseMerkleTrie, [][32]byte, error)

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

func DepositTrieSubset

func DepositTrieSubset(sparseTrie *trie.SparseMerkleTrie, size int) (*trie.SparseMerkleTrie, [][32]byte, error)

DepositTrieSubset takes in a full tree and the desired size and returns a subset of the deposit trie.

func DepositsWithBalance

func DepositsWithBalance(balances []uint64) ([]*zondpb.Deposit, *trie.SparseMerkleTrie, error)

DepositsWithBalance generates N amount of deposits with the balances taken from the passed in balances array. If an empty array is passed,

func DeterministicDepositTrie

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

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

func DeterministicDepositsAndKeys

func DeterministicDepositsAndKeys(numDeposits uint64) ([]*zondpb.Deposit, []dilithium.DilithiumKey, 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

func DeterministicDepositsAndKeysSameValidator(numDeposits uint64) ([]*zondpb.Deposit, []dilithium.DilithiumKey, 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

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

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

func DeterministicGenesisStateCapella

func DeterministicGenesisStateCapella(t testing.TB, numValidators uint64) (state.BeaconState, []dilithium.DilithiumKey)

DeterministicGenesisStateCapella returns a genesis state in Capella format made using the deterministic deposits.

func DeterministicGenesisStateCapellaWithGenesisBlock

func DeterministicGenesisStateCapellaWithGenesisBlock(
	t *testing.T,
	ctx context.Context,
	db iface.HeadAccessDatabase,
	numValidators uint64,
) (state.BeaconState, [32]byte, []dilithium.DilithiumKey)

DeterministicGenesisStateCapellaWithGenesisBlock creates a genesis state, saves the genesis block, genesis state and head block root. It returns the genesis state, genesis block's root and validator private keys.

func FillRootsNaturalOptCapella

func FillRootsNaturalOptCapella(state *zondpb.BeaconStateCapella) error

FillRootsNaturalOptCapella is meant to be used as an option when calling NewBeaconStateCapella. It fills state and block roots with hex representations of natural numbers starting with 0. Example: 16 becomes 0x00...0f.

func GenerateAttestations

func GenerateAttestations(
	bState state.BeaconState, privs []dilithium.DilithiumKey, numToGen uint64, slot primitives.Slot, randomRoot bool,
) ([]*zondpb.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

func GenerateAttesterSlashingForValidator(
	bState state.BeaconState,
	priv dilithium.DilithiumKey,
	idx primitives.ValidatorIndex,
) (*zondpb.AttesterSlashing, error)

GenerateAttesterSlashingForValidator for a specific validator index.

func GenerateDilithiumToExecutionChange

GenerateDilithiumToExecutionChange generates a valid dilithium to exec changes for validator `val` and its private key `priv` with the given beacon state `st`.

func GenerateFullBlockCapella

func GenerateFullBlockCapella(
	bState state.BeaconState,
	privs []dilithium.DilithiumKey,
	conf *BlockGenConfig,
	slot primitives.Slot,
) (*zondpb.SignedBeaconBlockCapella, error)

GenerateFullBlockCapella generates a fully valid Capella block with the requested parameters. Use BlockGenConfig to declare the conditions you would like the block generated under. This function modifies the passed state as follows:

func GenerateProposerSlashingForValidator

func GenerateProposerSlashingForValidator(
	bState state.BeaconState,
	priv dilithium.DilithiumKey,
	idx primitives.ValidatorIndex,
) (*zondpb.ProposerSlashing, error)

GenerateProposerSlashingForValidator for a specific validator index.

func GenesisBeaconStateCapella

func GenesisBeaconStateCapella(ctx context.Context, deposits []*zondpb.Deposit, genesisTime uint64, eth1Data *zondpb.Eth1Data) (state.BeaconState, error)

GenesisBeaconStateCapella returns the genesis beacon state.

func HydrateAttestation

func HydrateAttestation(a *zondpb.Attestation) *zondpb.Attestation

HydrateAttestation hydrates an attestation object with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateAttestationData

func HydrateAttestationData(d *zondpb.AttestationData) *zondpb.AttestationData

HydrateAttestationData hydrates an attestation data object with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateBeaconBlockBodyCapella

func HydrateBeaconBlockBodyCapella(b *zondpb.BeaconBlockBodyCapella) *zondpb.BeaconBlockBodyCapella

HydrateBeaconBlockBodyCapella hydrates a beacon block body with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateBeaconBlockCapella

func HydrateBeaconBlockCapella(b *zondpb.BeaconBlockCapella) *zondpb.BeaconBlockCapella

HydrateBeaconBlockCapella hydrates a beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateBeaconHeader

func HydrateBeaconHeader(h *zondpb.BeaconBlockHeader) *zondpb.BeaconBlockHeader

HydrateBeaconHeader hydrates a beacon block header with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateBlindedBeaconBlockBodyCapella

func HydrateBlindedBeaconBlockBodyCapella(b *zondpb.BlindedBeaconBlockBodyCapella) *zondpb.BlindedBeaconBlockBodyCapella

HydrateBlindedBeaconBlockBodyCapella hydrates a blinded beacon block body with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateBlindedBeaconBlockCapella

func HydrateBlindedBeaconBlockCapella(b *zondpb.BlindedBeaconBlockCapella) *zondpb.BlindedBeaconBlockCapella

HydrateBlindedBeaconBlockCapella hydrates a blinded beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateIndexedAttestation

func HydrateIndexedAttestation(a *zondpb.IndexedAttestation) *zondpb.IndexedAttestation

HydrateIndexedAttestation hydrates an indexed attestation with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateSignedBeaconBlockCapella

func HydrateSignedBeaconBlockCapella(b *zondpb.SignedBeaconBlockCapella) *zondpb.SignedBeaconBlockCapella

HydrateSignedBeaconBlockCapella hydrates a signed beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateSignedBeaconHeader

func HydrateSignedBeaconHeader(h *zondpb.SignedBeaconBlockHeader) *zondpb.SignedBeaconBlockHeader

HydrateSignedBeaconHeader hydrates a signed beacon block header with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateSignedBlindedBeaconBlockCapella

func HydrateSignedBlindedBeaconBlockCapella(b *zondpb.SignedBlindedBeaconBlockCapella) *zondpb.SignedBlindedBeaconBlockCapella

HydrateSignedBlindedBeaconBlockCapella hydrates a signed blinded beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateSyncCommittee

func HydrateSyncCommittee(s *zondpb.SyncCommitteeMessage) *zondpb.SyncCommitteeMessage

HydrateSyncCommittee hydrates the provided sync committee message.

func HydrateV1Attestation

func HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation

HydrateV1Attestation hydrates a v1 attestation object with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1AttestationData

func HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData

HydrateV1AttestationData hydrates a v1 attestation data object with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1BlindedBeaconBlockBodyCapella

func HydrateV1BlindedBeaconBlockBodyCapella(b *v1.BlindedBeaconBlockBodyCapella) *v1.BlindedBeaconBlockBodyCapella

HydrateV1BlindedBeaconBlockBodyCapella hydrates a blinded beacon block body with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1BlindedBeaconBlockCapella

func HydrateV1BlindedBeaconBlockCapella(b *v1.BlindedBeaconBlockCapella) *v1.BlindedBeaconBlockCapella

HydrateV1BlindedBeaconBlockCapella hydrates a blinded beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1CapellaBeaconBlock

func HydrateV1CapellaBeaconBlock(b *v1.BeaconBlockCapella) *v1.BeaconBlockCapella

HydrateV1CapellaBeaconBlock hydrates a beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1CapellaBeaconBlockBody

func HydrateV1CapellaBeaconBlockBody(b *v1.BeaconBlockBodyCapella) *v1.BeaconBlockBodyCapella

HydrateV1CapellaBeaconBlockBody hydrates a beacon block body with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1CapellaSignedBeaconBlock

func HydrateV1CapellaSignedBeaconBlock(b *v1.SignedBeaconBlockCapella) *v1.SignedBeaconBlockCapella

HydrateV1CapellaSignedBeaconBlock hydrates a signed beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func HydrateV1SignedBlindedBeaconBlockCapella

func HydrateV1SignedBlindedBeaconBlockCapella(b *v1.SignedBlindedBeaconBlockCapella) *v1.SignedBlindedBeaconBlockCapella

HydrateV1SignedBlindedBeaconBlockCapella hydrates a signed blinded beacon block with correct field length sizes to comply with fssz marshalling and unmarshalling rules.

func NewAttestation

func NewAttestation() *zondpb.Attestation

NewAttestation creates an attestation block with minimum marshalable fields.

func NewBeaconBlockCapella

func NewBeaconBlockCapella() *zondpb.SignedBeaconBlockCapella

NewBeaconBlockCapella creates a beacon block with minimum marshalable fields.

func NewBeaconStateCapella

func NewBeaconStateCapella(options ...func(state *zondpb.BeaconStateCapella) error) (state.BeaconState, error)

NewBeaconStateCapella creates a beacon state with minimum marshalable fields.

func NewBlindedBeaconBlockCapella

func NewBlindedBeaconBlockCapella() *zondpb.SignedBlindedBeaconBlockCapella

NewBlindedBeaconBlockCapella creates a blinded beacon block with minimum marshalable fields.

func NewBlindedBeaconBlockCapellaV1

func NewBlindedBeaconBlockCapellaV1() *v1.SignedBlindedBeaconBlockCapella

NewBlindedBeaconBlockCapellaV1 creates a blinded beacon block with minimum marshalable fields.

func PrepareRoots

func PrepareRoots(size int) ([][]byte, error)

PrepareRoots returns a list of roots with hex representations of natural numbers starting with 0. Example: 16 becomes 0x00...0f.

func RandaoReveal

func RandaoReveal(beaconState state.ReadOnlyBeaconState, epoch primitives.Epoch, privKeys []dilithium.DilithiumKey) ([]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 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
	NumTransactions      uint64
	FullSyncAggregate    bool
	NumDilithiumChanges  uint64
}

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

func DefaultBlockGenConfig

func DefaultBlockGenConfig() *BlockGenConfig

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

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

Waiter offers an alternate ux for building tests that want to ensure contexts are used in certain ways.

func NewWaiter

func NewWaiter() *Waiter

NewWaiter internally create the chan that Waiter relies on.

func (*Waiter) Done

func (w *Waiter) Done()

Done is used with RequireDoneAfter and RequireDoneBefore to make assertions that certain test code is reached before a timeout or context cancelation.

func (*Waiter) RequireDoneAfter

func (w *Waiter) RequireDoneAfter(t *testing.T, timeout time.Duration)

RequireDoneAfter forces the test to fail if the timeout is reached before Done is called.

func (*Waiter) RequireDoneBeforeCancel

func (w *Waiter) RequireDoneBeforeCancel(ctx context.Context, t *testing.T)

RequireDoneBeforeCancel forces the test to fail if the context is cancelled before Done is called.

Jump to

Keyboard shortcuts

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