testing

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 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

This section is empty.

Functions

This section is empty.

Types

type ChainService

type ChainService struct {
	State                       iface.BeaconState
	Root                        []byte
	Block                       *ethpb.SignedBeaconBlock
	FinalizedCheckPoint         *ethpb.Checkpoint
	CurrentJustifiedCheckPoint  *ethpb.Checkpoint
	PreviousJustifiedCheckPoint *ethpb.Checkpoint
	BlocksReceived              []*ethpb.SignedBeaconBlock
	Balance                     *precompute.Balance
	Genesis                     time.Time
	ValidatorsRoot              [32]byte
	CanonicalRoots              map[[32]byte]bool
	Fork                        *pb.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.
	// contains filtered or unexported fields
}

ChainService defines the mock interface for testing

func (*ChainService) AttestationPreState added in v1.0.0

func (s *ChainService) AttestationPreState(_ context.Context, _ *ethpb.Attestation) (iface.BeaconState, error)

AttestationPreState mocks AttestationPreState method in chain service.

func (*ChainService) BlockNotifier added in v0.3.2

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

BlockNotifier mocks the same method in the chain service.

func (*ChainService) ChainHeads added in v1.3.6

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

ChainHeads mocks ChainHeads and always return nil.

func (*ChainService) CurrentFork added in v0.2.3

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

CurrentFork mocks HeadState method in chain service.

func (*ChainService) CurrentJustifiedCheckpt added in v0.3.0

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

CurrentJustifiedCheckpt mocks CurrentJustifiedCheckpt method in chain service.

func (*ChainService) CurrentSlot added in v0.3.2

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 added in v1.0.0

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

GenesisValidatorRoot mocks the same method in the chain service.

func (*ChainService) HasInitSyncBlock added in v0.3.9

func (s *ChainService) HasInitSyncBlock(_ [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 added in v1.0.0

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

HeadETH1Data provides the current ETH1Data of the head state.

func (*ChainService) HeadGenesisValidatorRoot added in v1.0.0

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

HeadGenesisValidatorRoot mocks HeadGenesisValidatorRoot method in chain service.

func (*ChainService) HeadRoot

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

HeadRoot mocks HeadRoot method in chain service.

func (*ChainService) HeadSeed added in v0.3.0

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) HeadValidatorsIndices added in v0.3.0

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

HeadValidatorsIndices mocks the same method in the chain service.

func (*ChainService) IsCanonical added in v1.0.0

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 added in v0.3.2

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

IsValidAttestation always returns true.

func (*ChainService) OperationNotifier added in v0.3.0

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

OperationNotifier mocks the same method in the chain service.

func (*ChainService) Participation added in v0.3.0

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

Participation mocks the same method in the chain service.

func (*ChainService) PreviousJustifiedCheckpt added in v0.3.0

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

PreviousJustifiedCheckpt mocks PreviousJustifiedCheckpt method in chain service.

func (*ChainService) ProtoArrayStore added in v1.0.0

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 *ethpb.SignedBeaconBlock, _ [32]byte) error

ReceiveBlock mocks ReceiveBlock method in chain service.

func (*ChainService) ReceiveBlockBatch added in v1.0.0

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

ReceiveBlockBatch processes blocks in batches from initial-sync.

func (*ChainService) ReceiveBlockInitialSync added in v1.0.0

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

ReceiveBlockInitialSync mocks ReceiveBlockInitialSync method in chain service.

func (*ChainService) StateNotifier added in v0.3.0

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

StateNotifier mocks the same method in the chain service.

func (*ChainService) VerifyBlkDescendant added in v1.0.0

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

VerifyBlkDescendant mocks VerifyBlkDescendant and always returns nil.

func (*ChainService) VerifyFinalizedConsistency added in v1.0.0

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

VerifyFinalizedConsistency mocks VerifyFinalizedConsistency and always returns nil.

func (*ChainService) VerifyLmdFfgConsistency added in v1.0.0

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

VerifyLmdFfgConsistency mocks VerifyLmdFfgConsistency and always returns nil.

type MockBlockNotifier added in v0.3.2

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

MockBlockNotifier mocks the block notifier.

func (*MockBlockNotifier) BlockFeed added in v0.3.2

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

BlockFeed returns a block feed.

type MockOperationNotifier added in v0.3.0

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

MockOperationNotifier mocks the operation notifier.

func (*MockOperationNotifier) OperationFeed added in v0.3.0

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

OperationFeed returns an operation feed.

type MockStateNotifier added in v0.3.0

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

MockStateNotifier mocks the state notifier.

func (*MockStateNotifier) ReceivedEvents added in v1.0.0

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

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

func (*MockStateNotifier) StateFeed added in v0.3.0

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