testing

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

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

This section is empty.

Functions

This section is empty.

Types

type ChainService

type ChainService struct {
	State                       state.BeaconState
	Root                        []byte
	Block                       block.SignedBeaconBlock
	FinalizedCheckPoint         *ethpb.Checkpoint
	CurrentJustifiedCheckPoint  *ethpb.Checkpoint
	PreviousJustifiedCheckPoint *ethpb.Checkpoint
	BlocksReceived              []block.SignedBeaconBlock
	Balance                     *precompute.Balance
	Genesis                     time.Time
	ValidatorsRoot              [32]byte
	CanonicalRoots              map[[32]byte]bool
	Fork                        *ethpb.Fork
	ETH1Data                    *ethpb.Eth1Data
	DB                          db.Database

	ValidAttestation            bool
	ForkChoiceStore             *protoarray.Store
	VerifyBlkDescendantErr      error
	Slot                        *types.Slot // Pointer because 0 is a useful value, so checking against it can be incorrect.
	SyncCommitteeIndices        []types.CommitteeIndex
	SyncCommitteeDomain         []byte
	SyncSelectionProofDomain    []byte
	SyncContributionProofDomain []byte
	PublicKey                   [48]byte
	SyncCommitteePubkeys        [][]byte
	InitSyncBlockRoots          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 (s *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) GenesisTime

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

GenesisTime mocks the same method in the chain service.

func (*ChainService) GenesisValidatorRoot

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

GenesisValidatorRoot mocks the same method in the chain service.

func (*ChainService) HasInitSyncBlock

func (s *ChainService) HasInitSyncBlock(rt [32]byte) bool

HasInitSyncBlock 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) HeadGenesisValidatorRoot

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

HeadGenesisValidatorRoot mocks HeadGenesisValidatorRoot method in chain service.

func (*ChainService) HeadPublicKeyToValidatorIndex

func (s *ChainService) HeadPublicKeyToValidatorIndex(_ context.Context, _ [48]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) HeadSeed

func (s *ChainService) HeadSeed(_ context.Context, epoch types.Epoch) ([32]byte, error)

HeadSeed mocks the same method in the 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, index types.ValidatorIndex, slot 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) ([48]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) 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) ProtoArrayStore

func (s *ChainService) ProtoArrayStore() *protoarray.Store

ProtoArrayStore mocks the same method in the chain service.

func (*ChainService) ReceiveAttestation

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

ReceiveAttestation mocks ReceiveAttestation method in chain service.

func (*ChainService) ReceiveAttestationNoPubsub

func (s *ChainService) ReceiveAttestationNoPubsub(context.Context, *ethpb.Attestation) error

ReceiveAttestationNoPubsub mocks ReceiveAttestationNoPubsub method in chain service.

func (*ChainService) ReceiveBlock

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

ReceiveBlock mocks ReceiveBlock method in chain service.

func (*ChainService) ReceiveBlockBatch

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

ReceiveBlockBatch processes blocks in batches from initial-sync.

func (*ChainService) ReceiveBlockInitialSync

func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block block.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) VerifyBlkDescendant

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

VerifyBlkDescendant 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 (s *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