Documentation ¶
Overview ¶
Package testing includes useful mocks for writing unit tests which depend on logic from the blockchain package.
Index ¶
- Variables
- type ChainService
- func (s *ChainService) Ancestor(ctx context.Context, root []byte, slot primitives.Slot) ([]byte, error)
- func (s *ChainService) AttestationTargetState(_ context.Context, _ *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error)
- func (c *ChainService) BlockBeingSynced(root [32]byte) bool
- func (s *ChainService) BlockNotifier() blockfeed.Notifier
- func (s *ChainService) CachedHeadRoot() [32]byte
- func (*ChainService) ChainHeads() ([][32]byte, []primitives.Slot)
- func (s *ChainService) CurrentFork() *ethpb.Fork
- func (s *ChainService) CurrentJustifiedCheckpt() *ethpb.Checkpoint
- func (s *ChainService) CurrentSlot() primitives.Slot
- func (*ChainService) FinalizedBlockHash() [32]byte
- func (s *ChainService) FinalizedCheckpt() *ethpb.Checkpoint
- func (s *ChainService) ForkChoiceDump(ctx context.Context) (*forkchoice2.Dump, error)
- func (s *ChainService) GenesisTime() time.Time
- func (s *ChainService) GenesisValidatorsRoot() [32]byte
- func (s *ChainService) GetProposerHead() [32]byte
- func (s *ChainService) HasBlock(ctx context.Context, rt [32]byte) bool
- func (s *ChainService) HeadBlock(context.Context) (interfaces.ReadOnlySignedBeaconBlock, error)
- func (s *ChainService) HeadETH1Data() *ethpb.Eth1Data
- func (*ChainService) HeadGenesisValidatorsRoot() [32]byte
- func (*ChainService) HeadPublicKeyToValidatorIndex(_ [fieldparams.BLSPubkeyLength]byte) (primitives.ValidatorIndex, bool)
- func (s *ChainService) HeadRoot(_ context.Context) ([]byte, error)
- func (s *ChainService) HeadSlot() primitives.Slot
- func (s *ChainService) HeadState(context.Context) (state.BeaconState, error)
- func (s *ChainService) HeadStateReadOnly(context.Context) (state.ReadOnlyBeaconState, error)
- func (s *ChainService) HeadSyncCommitteeDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
- func (s *ChainService) HeadSyncCommitteeIndices(_ context.Context, _ primitives.ValidatorIndex, _ primitives.Slot) ([]primitives.CommitteeIndex, error)
- func (s *ChainService) HeadSyncCommitteePubKeys(_ context.Context, _ primitives.Slot, _ primitives.CommitteeIndex) ([][]byte, error)
- func (s *ChainService) HeadSyncContributionProofDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
- func (s *ChainService) HeadSyncSelectionProofDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
- func (s *ChainService) HeadValidatorIndexToPublicKey(_ context.Context, _ primitives.ValidatorIndex) ([fieldparams.BLSPubkeyLength]byte, error)
- func (s *ChainService) HeadValidatorsIndices(ctx context.Context, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error)
- func (s *ChainService) HighestReceivedBlockSlot() primitives.Slot
- func (s *ChainService) InForkchoice(_ [32]byte) bool
- func (s *ChainService) InsertNode(ctx context.Context, st state.BeaconState, root [32]byte) error
- func (s *ChainService) IsCanonical(_ context.Context, r [32]byte) (bool, error)
- func (s *ChainService) IsFinalized(_ context.Context, blockRoot [32]byte) bool
- func (s *ChainService) IsOptimistic(_ context.Context) (bool, error)
- func (s *ChainService) IsOptimisticForRoot(_ context.Context, root [32]byte) (bool, error)
- func (s *ChainService) IsValidAttestation(_ context.Context, _ *ethpb.Attestation) bool
- func (s *ChainService) NewSlot(ctx context.Context, slot primitives.Slot) error
- func (s *ChainService) OperationNotifier() opfeed.Notifier
- func (s *ChainService) Participation(_ uint64) *precompute.Balance
- func (s *ChainService) PreviousJustifiedCheckpt() *ethpb.Checkpoint
- func (s *ChainService) ProposerBoost() [32]byte
- func (*ChainService) ReceiveAttestation(_ context.Context, _ *ethpb.Attestation) error
- func (*ChainService) ReceiveAttesterSlashing(context.Context, ethpb.AttSlashing)
- func (c *ChainService) ReceiveBlob(_ context.Context, b blocks.VerifiedROBlob) error
- func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte, ...) error
- func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBlock, _ das.AvailabilityStore) error
- func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte) error
- func (s *ChainService) ReceivedBlocksLastEpoch() (uint64, error)
- func (s *ChainService) RecentBlockSlot([32]byte) (primitives.Slot, error)
- func (s *ChainService) SetForkChoiceGenesisTime(timestamp uint64)
- func (s *ChainService) StateNotifier() statefeed.Notifier
- func (c *ChainService) TargetRootForEpoch(_ [32]byte, _ primitives.Epoch) ([32]byte, error)
- func (*ChainService) UnrealizedJustifiedPayloadBlockHash() [32]byte
- func (s *ChainService) UpdateHead(ctx context.Context, slot primitives.Slot)
- func (*ChainService) VerifyLmdFfgConsistency(_ context.Context, a ethpb.Att) error
- type EventFeedWrapper
- type MockBlockNotifier
- type MockChecker
- type MockOperationNotifier
- type MockStateNotifier
- type SimpleNotifier
Constants ¶
This section is empty.
Variables ¶
var ErrNilState = errors.New("nil state")
Functions ¶
This section is empty.
Types ¶
type ChainService ¶
type ChainService struct { NotFinalized bool Optimistic bool ValidAttestation bool ValidatorsRoot [32]byte PublicKey [fieldparams.BLSPubkeyLength]byte FinalizedCheckPoint *ethpb.Checkpoint CurrentJustifiedCheckPoint *ethpb.Checkpoint PreviousJustifiedCheckPoint *ethpb.Checkpoint Slot *primitives.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.ReadOnlySignedBeaconBlock VerifyBlkDescendantErr error BlocksReceived []interfaces.ReadOnlySignedBeaconBlock SyncCommitteeIndices []primitives.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 OptimisticRoots map[[32]byte]bool BlockSlot primitives.Slot SyncingRoot [32]byte Blobs []blocks.VerifiedROBlob TargetRoot [32]byte // contains filtered or unexported fields }
ChainService defines the mock interface for testing
func (*ChainService) Ancestor ¶
func (s *ChainService) Ancestor(ctx context.Context, root []byte, slot primitives.Slot) ([]byte, error)
func (*ChainService) AttestationTargetState ¶
func (s *ChainService) AttestationTargetState(_ context.Context, _ *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error)
AttestationTargetState mocks AttestationTargetState method in chain service.
func (*ChainService) BlockBeingSynced ¶
func (c *ChainService) BlockBeingSynced(root [32]byte) bool
BlockBeingSynced mocks the same method in the chain service
func (*ChainService) BlockNotifier ¶
func (s *ChainService) BlockNotifier() blockfeed.Notifier
BlockNotifier mocks the same method in the chain service.
func (*ChainService) CachedHeadRoot ¶
func (s *ChainService) CachedHeadRoot() [32]byte
CachedHeadRoot mocks the same method in the chain service
func (*ChainService) ChainHeads ¶
func (*ChainService) ChainHeads() ([][32]byte, []primitives.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() primitives.Slot
CurrentSlot mocks the same method in the chain service.
func (*ChainService) FinalizedBlockHash ¶
func (*ChainService) FinalizedBlockHash() [32]byte
FinalizedBlockHash 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) ForkChoiceDump ¶
func (s *ChainService) ForkChoiceDump(ctx context.Context) (*forkchoice2.Dump, error)
ForkChoiceDump 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) GetProposerHead ¶
func (s *ChainService) GetProposerHead() [32]byte
GetProposerHead 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 ¶
func (s *ChainService) HeadBlock(context.Context) (interfaces.ReadOnlySignedBeaconBlock, error)
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) (primitives.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() primitives.Slot
HeadSlot mocks HeadSlot method in chain service.
func (*ChainService) HeadState ¶
func (s *ChainService) HeadState(context.Context) (state.BeaconState, error)
HeadState mocks HeadState method in chain service.
func (*ChainService) HeadStateReadOnly ¶
func (s *ChainService) HeadStateReadOnly(context.Context) (state.ReadOnlyBeaconState, error)
HeadStateReadOnly mocks HeadStateReadOnly method in chain service.
func (*ChainService) HeadSyncCommitteeDomain ¶
func (s *ChainService) HeadSyncCommitteeDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
HeadSyncCommitteeDomain mocks HeadSyncCommitteeDomain and always return empty nil.
func (*ChainService) HeadSyncCommitteeIndices ¶
func (s *ChainService) HeadSyncCommitteeIndices(_ context.Context, _ primitives.ValidatorIndex, _ primitives.Slot) ([]primitives.CommitteeIndex, error)
HeadSyncCommitteeIndices mocks HeadSyncCommitteeIndices and always return `HeadNextSyncCommitteeIndices`.
func (*ChainService) HeadSyncCommitteePubKeys ¶
func (s *ChainService) HeadSyncCommitteePubKeys(_ context.Context, _ primitives.Slot, _ primitives.CommitteeIndex) ([][]byte, error)
HeadSyncCommitteePubKeys mocks HeadSyncCommitteePubKeys and always return empty nil.
func (*ChainService) HeadSyncContributionProofDomain ¶
func (s *ChainService) HeadSyncContributionProofDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
HeadSyncContributionProofDomain mocks HeadSyncContributionProofDomain and always return empty nil.
func (*ChainService) HeadSyncSelectionProofDomain ¶
func (s *ChainService) HeadSyncSelectionProofDomain(_ context.Context, _ primitives.Slot) ([]byte, error)
HeadSyncSelectionProofDomain mocks HeadSyncSelectionProofDomain and always return empty nil.
func (*ChainService) HeadValidatorIndexToPublicKey ¶
func (s *ChainService) HeadValidatorIndexToPublicKey(_ context.Context, _ primitives.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 primitives.Epoch) ([]primitives.ValidatorIndex, error)
HeadValidatorsIndices mocks the same method in the chain service.
func (*ChainService) HighestReceivedBlockSlot ¶
func (s *ChainService) HighestReceivedBlockSlot() primitives.Slot
HighestReceivedBlockSlot mocks the same method in the chain service
func (*ChainService) InForkchoice ¶
func (s *ChainService) InForkchoice(_ [32]byte) bool
InForkchoice mocks the same method in the chain service
func (*ChainService) InsertNode ¶
func (s *ChainService) InsertNode(ctx context.Context, st state.BeaconState, root [32]byte) error
InsertNode mocks the same method in the chain service
func (*ChainService) IsCanonical ¶
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 ¶
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) NewSlot ¶
func (s *ChainService) NewSlot(ctx context.Context, slot primitives.Slot) error
NewSlot mocks the same method in the chain service
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) ProposerBoost ¶
func (s *ChainService) ProposerBoost() [32]byte
ProposerBoost mocks the same method in the chain service
func (*ChainService) ReceiveAttestation ¶
func (*ChainService) ReceiveAttestation(_ context.Context, _ *ethpb.Attestation) error
ReceiveAttestation mocks ReceiveAttestation method in chain service.
func (*ChainService) ReceiveAttesterSlashing ¶
func (*ChainService) ReceiveAttesterSlashing(context.Context, ethpb.AttSlashing)
ReceiveAttesterSlashing mocks the same method in the chain service.
func (*ChainService) ReceiveBlob ¶
func (c *ChainService) ReceiveBlob(_ context.Context, b blocks.VerifiedROBlob) error
ReceiveBlob implements the same method in the chain service
func (*ChainService) ReceiveBlock ¶
func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte, _ das.AvailabilityStore) error
ReceiveBlock mocks ReceiveBlock method in chain service.
func (*ChainService) ReceiveBlockBatch ¶
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBlock, _ das.AvailabilityStore) error
ReceiveBlockBatch processes blocks in batches from initial-sync.
func (*ChainService) ReceiveBlockInitialSync ¶
func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte) error
ReceiveBlockInitialSync mocks ReceiveBlockInitialSync method in chain service.
func (*ChainService) ReceivedBlocksLastEpoch ¶
func (s *ChainService) ReceivedBlocksLastEpoch() (uint64, error)
ReceivedBlocksLastEpoch mocks the same method in the chain service
func (*ChainService) RecentBlockSlot ¶
func (s *ChainService) RecentBlockSlot([32]byte) (primitives.Slot, error)
RecentBlockSlot mocks the same method in the chain service.
func (*ChainService) SetForkChoiceGenesisTime ¶
func (s *ChainService) SetForkChoiceGenesisTime(timestamp uint64)
SetForkChoiceGenesisTime mocks the same method in the chain service
func (*ChainService) StateNotifier ¶
func (s *ChainService) StateNotifier() statefeed.Notifier
StateNotifier mocks the same method in the chain service.
func (*ChainService) TargetRootForEpoch ¶
func (c *ChainService) TargetRootForEpoch(_ [32]byte, _ primitives.Epoch) ([32]byte, error)
TargetRootForEpoch mocks the same method in the chain service
func (*ChainService) UnrealizedJustifiedPayloadBlockHash ¶
func (*ChainService) UnrealizedJustifiedPayloadBlockHash() [32]byte
UnrealizedJustifiedPayloadBlockHash mocks the same method in the chain service
func (*ChainService) UpdateHead ¶
func (s *ChainService) UpdateHead(ctx context.Context, slot primitives.Slot)
UpdateHead mocks the same method in the chain service.
func (*ChainService) VerifyLmdFfgConsistency ¶
VerifyLmdFfgConsistency mocks VerifyLmdFfgConsistency and always returns nil.
type EventFeedWrapper ¶ added in v5.1.1
type EventFeedWrapper struct {
// contains filtered or unexported fields
}
func NewEventFeedWrapper ¶ added in v5.1.1
func NewEventFeedWrapper() *EventFeedWrapper
func (*EventFeedWrapper) Send ¶ added in v5.1.1
func (w *EventFeedWrapper) Send(value interface{}) int
func (*EventFeedWrapper) Subscribe ¶ added in v5.1.1
func (w *EventFeedWrapper) Subscribe(channel interface{}) event.Subscription
func (*EventFeedWrapper) WaitForSubscription ¶ added in v5.1.1
func (w *EventFeedWrapper) WaitForSubscription(ctx context.Context) error
WaitForSubscription allows test to wait for the feed to have a subscription before beginning to send events.
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.SubscriberSender
OperationFeed returns an operation feed.
type MockStateNotifier ¶
type MockStateNotifier struct { RecordEvents bool // contains filtered or unexported fields }
MockStateNotifier mocks the state notifier.
func NewSimpleStateNotifier ¶ added in v5.1.1
func NewSimpleStateNotifier() *MockStateNotifier
NewSimpleStateNotifier makes a state feed without the custom mock feed machinery.
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.SubscriberSender
StateFeed returns a state feed.
type SimpleNotifier ¶ added in v5.1.1
type SimpleNotifier struct {
Feed event.SubscriberSender
}
func (*SimpleNotifier) OperationFeed ¶ added in v5.1.1
func (n *SimpleNotifier) OperationFeed() event.SubscriberSender
func (*SimpleNotifier) StateFeed ¶ added in v5.1.1
func (n *SimpleNotifier) StateFeed() event.SubscriberSender