testing

package
v3.2.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package testing includes useful mocks for writing unit tests which depend on logic from the blockchain package.

Index

Constants

This section is empty.

Variables

View Source
var ErrNilState = errors.New("nil state")

Functions

This section is empty.

Types

type ChainService

type ChainService struct {
	Optimistic                  bool
	ValidAttestation            bool
	ValidatorsRoot              [32]byte
	PublicKey                   [fieldparams.BLSPubkeyLength]byte
	FinalizedCheckPoint         *ethpb.Checkpoint
	CurrentJustifiedCheckPoint  *ethpb.Checkpoint
	PreviousJustifiedCheckPoint *ethpb.Checkpoint
	Slot                        *types.Slot // Pointer because 0 is a useful value, so checking against it can be incorrect.
	Balance                     *precompute.Balance
	CanonicalRoots              map[[32]byte]bool
	Fork                        *ethpb.Fork
	ETH1Data                    *ethpb.Eth1Data
	InitSyncBlockRoots          map[[32]byte]bool
	DB                          db.Database
	State                       state.BeaconState
	Block                       interfaces.SignedBeaconBlock
	VerifyBlkDescendantErr      error

	BlocksReceived       []interfaces.SignedBeaconBlock
	SyncCommitteeIndices []types.CommitteeIndex

	Root                        []byte
	SyncCommitteeDomain         []byte
	SyncSelectionProofDomain    []byte
	SyncContributionProofDomain []byte
	SyncCommitteePubkeys        [][]byte
	Genesis                     time.Time
	ForkChoiceStore             forkchoice.ForkChoicer
	ReceiveBlockMockErr         error
	OptimisticCheckRootReceived [32]byte
	FinalizedRoots              map[[32]byte]bool
	// contains filtered or unexported fields
}

ChainService defines the mock interface for testing

func (*ChainService) AttestationTargetState

func (s *ChainService) AttestationTargetState(_ context.Context, _ *ethpb.Checkpoint) (state.BeaconState, error)

AttestationTargetState mocks AttestationTargetState method in chain service.

func (*ChainService) BlockNotifier

func (s *ChainService) BlockNotifier() blockfeed.Notifier

BlockNotifier mocks the same method in the chain service.

func (*ChainService) ChainHeads

func (_ *ChainService) ChainHeads() ([][32]byte, []types.Slot)

ChainHeads mocks ChainHeads and always return nil.

func (*ChainService) CurrentFork

func (s *ChainService) CurrentFork() *ethpb.Fork

CurrentFork mocks HeadState method in chain service.

func (*ChainService) CurrentJustifiedCheckpt

func (s *ChainService) CurrentJustifiedCheckpt() *ethpb.Checkpoint

CurrentJustifiedCheckpt mocks CurrentJustifiedCheckpt method in chain service.

func (*ChainService) CurrentSlot

func (s *ChainService) CurrentSlot() types.Slot

CurrentSlot mocks the same method in the chain service.

func (*ChainService) FinalizedCheckpt

func (s *ChainService) FinalizedCheckpt() *ethpb.Checkpoint

FinalizedCheckpt mocks FinalizedCheckpt method in chain service.

func (*ChainService) ForkChoicer

func (s *ChainService) ForkChoicer() forkchoice.ForkChoicer

ForkChoicer mocks the same method in the chain service

func (*ChainService) GenesisTime

func (s *ChainService) GenesisTime() time.Time

GenesisTime mocks the same method in the chain service.

func (*ChainService) GenesisValidatorsRoot

func (s *ChainService) GenesisValidatorsRoot() [32]byte

GenesisValidatorsRoot mocks the same method in the chain service.

func (*ChainService) HasBlock

func (s *ChainService) HasBlock(ctx context.Context, rt [32]byte) bool

HasBlock mocks the same method in the chain service.

func (*ChainService) HeadBlock

HeadBlock mocks HeadBlock method in chain service.

func (*ChainService) HeadETH1Data

func (s *ChainService) HeadETH1Data() *ethpb.Eth1Data

HeadETH1Data provides the current ETH1Data of the head state.

func (*ChainService) HeadGenesisValidatorsRoot

func (_ *ChainService) HeadGenesisValidatorsRoot() [32]byte

HeadGenesisValidatorsRoot mocks HeadGenesisValidatorsRoot method in chain service.

func (*ChainService) HeadPublicKeyToValidatorIndex

func (_ *ChainService) HeadPublicKeyToValidatorIndex(_ [fieldparams.BLSPubkeyLength]byte) (types.ValidatorIndex, bool)

HeadPublicKeyToValidatorIndex mocks HeadPublicKeyToValidatorIndex and always return 0 and true.

func (*ChainService) HeadRoot

func (s *ChainService) HeadRoot(_ context.Context) ([]byte, error)

HeadRoot mocks HeadRoot method in chain service.

func (*ChainService) HeadSlot

func (s *ChainService) HeadSlot() types.Slot

HeadSlot mocks HeadSlot method in chain service.

func (*ChainService) HeadState

HeadState mocks HeadState method in chain service.

func (*ChainService) HeadSyncCommitteeDomain

func (s *ChainService) HeadSyncCommitteeDomain(_ context.Context, _ types.Slot) ([]byte, error)

HeadSyncCommitteeDomain mocks HeadSyncCommitteeDomain and always return empty nil.

func (*ChainService) HeadSyncCommitteeIndices

func (s *ChainService) HeadSyncCommitteeIndices(_ context.Context, _ types.ValidatorIndex, _ types.Slot) ([]types.CommitteeIndex, error)

HeadSyncCommitteeIndices mocks HeadSyncCommitteeIndices and always return `HeadNextSyncCommitteeIndices`.

func (*ChainService) HeadSyncCommitteePubKeys

func (s *ChainService) HeadSyncCommitteePubKeys(_ context.Context, _ types.Slot, _ types.CommitteeIndex) ([][]byte, error)

HeadSyncCommitteePubKeys mocks HeadSyncCommitteePubKeys and always return empty nil.

func (*ChainService) HeadSyncContributionProofDomain

func (s *ChainService) HeadSyncContributionProofDomain(_ context.Context, _ types.Slot) ([]byte, error)

HeadSyncContributionProofDomain mocks HeadSyncContributionProofDomain and always return empty nil.

func (*ChainService) HeadSyncSelectionProofDomain

func (s *ChainService) HeadSyncSelectionProofDomain(_ context.Context, _ types.Slot) ([]byte, error)

HeadSyncSelectionProofDomain mocks HeadSyncSelectionProofDomain and always return empty nil.

func (*ChainService) HeadValidatorIndexToPublicKey

func (s *ChainService) HeadValidatorIndexToPublicKey(_ context.Context, _ types.ValidatorIndex) ([fieldparams.BLSPubkeyLength]byte, error)

HeadValidatorIndexToPublicKey mocks HeadValidatorIndexToPublicKey and always return empty and nil.

func (*ChainService) HeadValidatorsIndices

func (s *ChainService) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)

HeadValidatorsIndices mocks the same method in the chain service.

func (*ChainService) IsCanonical

func (s *ChainService) IsCanonical(_ context.Context, r [32]byte) (bool, error)

IsCanonical returns and determines whether a block with the provided root is part of the canonical chain.

func (*ChainService) IsFinalized

func (s *ChainService) IsFinalized(_ context.Context, blockRoot [32]byte) bool

IsFinalized mocks the same method in the chain service.

func (*ChainService) IsOptimistic

func (s *ChainService) IsOptimistic(_ context.Context) (bool, error)

IsOptimistic mocks the same method in the chain service.

func (*ChainService) IsOptimisticForRoot

func (s *ChainService) IsOptimisticForRoot(_ context.Context, root [32]byte) (bool, error)

IsOptimisticForRoot mocks the same method in the chain service.

func (*ChainService) IsValidAttestation

func (s *ChainService) IsValidAttestation(_ context.Context, _ *ethpb.Attestation) bool

IsValidAttestation always returns true.

func (*ChainService) OperationNotifier

func (s *ChainService) OperationNotifier() opfeed.Notifier

OperationNotifier mocks the same method in the chain service.

func (*ChainService) Participation

func (s *ChainService) Participation(_ uint64) *precompute.Balance

Participation mocks the same method in the chain service.

func (*ChainService) PreviousJustifiedCheckpt

func (s *ChainService) PreviousJustifiedCheckpt() *ethpb.Checkpoint

PreviousJustifiedCheckpt mocks PreviousJustifiedCheckpt method in chain service.

func (*ChainService) ReceiveAttestation

func (_ *ChainService) ReceiveAttestation(_ context.Context, _ *ethpb.Attestation) error

ReceiveAttestation mocks ReceiveAttestation method in chain service.

func (*ChainService) ReceiveAttesterSlashing

func (s *ChainService) ReceiveAttesterSlashing(context.Context, *ethpb.AttesterSlashing)

ReceiveAttesterSlashing mocks the same method in the chain service.

func (*ChainService) ReceiveBlock

func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte) error

ReceiveBlock mocks ReceiveBlock method in chain service.

func (*ChainService) ReceiveBlockBatch

func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock, _ [][32]byte) error

ReceiveBlockBatch processes blocks in batches from initial-sync.

func (*ChainService) ReceiveBlockInitialSync

func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte) error

ReceiveBlockInitialSync mocks ReceiveBlockInitialSync method in chain service.

func (*ChainService) StateNotifier

func (s *ChainService) StateNotifier() statefeed.Notifier

StateNotifier mocks the same method in the chain service.

func (*ChainService) UpdateHead

func (s *ChainService) UpdateHead(_ context.Context) error

UpdateHead mocks the same method in the chain service.

func (*ChainService) VerifyFinalizedBlkDescendant

func (s *ChainService) VerifyFinalizedBlkDescendant(_ context.Context, _ [32]byte) error

VerifyFinalizedBlkDescendant mocks VerifyBlkDescendant and always returns nil.

func (*ChainService) VerifyFinalizedConsistency

func (s *ChainService) VerifyFinalizedConsistency(_ context.Context, r []byte) error

VerifyFinalizedConsistency mocks VerifyFinalizedConsistency and always returns nil.

func (*ChainService) VerifyLmdFfgConsistency

func (_ *ChainService) VerifyLmdFfgConsistency(_ context.Context, a *ethpb.Attestation) error

VerifyLmdFfgConsistency mocks VerifyLmdFfgConsistency and always returns nil.

type MockBlockNotifier

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

MockBlockNotifier mocks the block notifier.

func (*MockBlockNotifier) BlockFeed

func (mbn *MockBlockNotifier) BlockFeed() *event.Feed

BlockFeed returns a block feed.

type MockOperationNotifier

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

MockOperationNotifier mocks the operation notifier.

func (*MockOperationNotifier) OperationFeed

func (mon *MockOperationNotifier) OperationFeed() *event.Feed

OperationFeed returns an operation feed.

type MockStateNotifier

type MockStateNotifier struct {
	RecordEvents bool
	// contains filtered or unexported fields
}

MockStateNotifier mocks the state notifier.

func (*MockStateNotifier) ReceivedEvents

func (msn *MockStateNotifier) ReceivedEvents() []*feed.Event

ReceivedEvents returns the events received by the state feed in this mock.

func (*MockStateNotifier) StateFeed

func (msn *MockStateNotifier) StateFeed() *event.Feed

StateFeed returns a state feed.

Jump to

Keyboard shortcuts

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