beaconmock

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package beaconmock provides a mock beacon node server and client primarily for testing.

 beaconmock.Mock     validatorapi.Router
┌────┬──────────┐      ┌───────────┐
│    │HTTPServer◄──────┤ proxy     │
│    └────▲─────┐ http │           │           VC
│         │     │      │           ◄────────── (validatormock)
│         │http │      │ served    │   http    (lighthouse)
│      ┌──┴─────┤      │ endpoints │           (teku)
│      │HTTPMock│      └────┬──────┘
└──────┴────────┘           │go
       ▲                    │
       │  ┌─────────────────▼──────┐
       │go│                        │
       └──┤core workflow components│
          │                        │
          └────────────────────────┘

HTTPServer: Serves stubs and static.json endpoints. Used by Mock and proxy.
HTTPMock: *eth2http.Service client connected to HTTPServer.
Mock: Wraps HTTPMock, adds customisable logic. Used by simnet core workflow components.

Index

Constants

This section is empty.

Variables

View Source
var ValidatorSetA = ValidatorSet{
	1: {
		Index:   1,
		Balance: 1,
		Status:  eth2v1.ValidatorStateActiveOngoing,
		Validator: &eth2p0.Validator{
			PublicKey:                  mustPKFromHex("0x914cff835a769156ba43ad50b931083c2dadd94e8359ce394bc7a3e06424d0214922ddf15f81640530b9c25c0bc0d490"),
			EffectiveBalance:           1,
			ActivationEligibilityEpoch: 1,
			ActivationEpoch:            2,
			WithdrawalCredentials:      []byte("12345678901234567890123456789012"),
		},
	},
	2: {
		Index:   2,
		Balance: 2,
		Status:  eth2v1.ValidatorStateActiveOngoing,
		Validator: &eth2p0.Validator{
			PublicKey:                  mustPKFromHex("0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea"),
			EffectiveBalance:           2,
			ActivationEligibilityEpoch: 2,
			ActivationEpoch:            3,
			WithdrawalCredentials:      []byte("12345678901234567890123456789012"),
		},
	},
	3: {
		Index:   3,
		Balance: 3,
		Status:  eth2v1.ValidatorStateActiveOngoing,
		Validator: &eth2p0.Validator{
			PublicKey:                  mustPKFromHex("0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76"),
			EffectiveBalance:           3,
			ActivationEligibilityEpoch: 3,
			ActivationEpoch:            4,
			WithdrawalCredentials:      []byte("12345678901234567890123456789012"),
		},
	},
}

ValidatorSetA defines a set of 3 validators.

Functions

This section is empty.

Types

type HTTPMock

HTTPMock defines the endpoints served by the beacon API mock http server. It serves all proxied endpoints not handled by charon's validatorapi. Endpoints include static endpoints defined in static.json and a few stubbed paths.

type Mock

type Mock struct {
	HTTPMock

	AttestationDataFunc                    func(context.Context, eth2p0.Slot, eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error)
	AttesterDutiesFunc                     func(context.Context, eth2p0.Epoch, []eth2p0.ValidatorIndex) ([]*eth2v1.AttesterDuty, error)
	BlockAttestationsFunc                  func(ctx context.Context, stateID string) ([]*eth2p0.Attestation, error)
	BlindedBeaconBlockProposalFunc         func(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*eth2api.VersionedBlindedBeaconBlock, error)
	BeaconCommitteesFunc                   func(ctx context.Context, stateID string) ([]*eth2v1.BeaconCommittee, error)
	BeaconBlockProposalFunc                func(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*spec.VersionedBeaconBlock, error)
	BeaconBlockRootFunc                    func(ctx context.Context, blockID string) (*eth2p0.Root, error)
	SignedBeaconBlockFunc                  func(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error)
	ProposerDutiesFunc                     func(context.Context, eth2p0.Epoch, []eth2p0.ValidatorIndex) ([]*eth2v1.ProposerDuty, error)
	SubmitAttestationsFunc                 func(context.Context, []*eth2p0.Attestation) error
	SubmitBeaconBlockFunc                  func(context.Context, *spec.VersionedSignedBeaconBlock) error
	SubmitBlindedBeaconBlockFunc           func(context.Context, *eth2api.VersionedSignedBlindedBeaconBlock) error
	SubmitVoluntaryExitFunc                func(context.Context, *eth2p0.SignedVoluntaryExit) error
	ValidatorsByPubKeyFunc                 func(context.Context, string, []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
	ValidatorsFunc                         func(context.Context, string, []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
	GenesisTimeFunc                        func(context.Context) (time.Time, error)
	NodeSyncingFunc                        func(context.Context) (*eth2v1.SyncState, error)
	EventsFunc                             func(context.Context, []string, eth2client.EventHandlerFunc) error
	SubmitValidatorRegistrationsFunc       func(context.Context, []*eth2api.VersionedSignedValidatorRegistration) error
	SlotsPerEpochFunc                      func(context.Context) (uint64, error)
	AggregateBeaconCommitteeSelectionsFunc func(context.Context, []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error)
	AggregateSyncCommitteeSelectionsFunc   func(context.Context, []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error)
	SubmitBeaconCommitteeSubscriptionsFunc func(ctx context.Context, subscriptions []*eth2v1.BeaconCommitteeSubscription) error
	AggregateAttestationFunc               func(ctx context.Context, slot eth2p0.Slot, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error)
	SubmitAggregateAttestationsFunc        func(ctx context.Context, aggregateAndProofs []*eth2p0.SignedAggregateAndProof) error
	SyncCommitteeDutiesFunc                func(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.SyncCommitteeDuty, error)
	SubmitSyncCommitteeMessagesFunc        func(ctx context.Context, messages []*altair.SyncCommitteeMessage) error
	SubmitSyncCommitteeContributionsFunc   func(ctx context.Context, contributionAndProofs []*altair.SignedContributionAndProof) error
	SyncCommitteeContributionFunc          func(ctx context.Context, slot eth2p0.Slot, subcommitteeIndex uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)
	SubmitSyncCommitteeSubscriptionsFunc   func(ctx context.Context, subscriptions []*eth2v1.SyncCommitteeSubscription) error
	SubmitProposalPreparationsFunc         func(ctx context.Context, preparations []*eth2v1.ProposalPreparation) error
	// contains filtered or unexported fields
}

Mock provides a mock beacon client and implements eth2wrap.Client. Create a new instance with default behaviour via New and then override any function.

func New

func New(opts ...Option) (Mock, error)

New returns a new beacon client mock configured with the default and provided options.

func (Mock) Address

func (m Mock) Address() string

func (Mock) AggregateAttestation added in v0.10.1

func (m Mock) AggregateAttestation(ctx context.Context, slot eth2p0.Slot, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error)

func (Mock) AggregateBeaconCommitteeSelections added in v0.11.0

func (m Mock) AggregateBeaconCommitteeSelections(ctx context.Context, selections []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error)

func (Mock) AggregateSyncCommitteeSelections added in v0.12.0

func (m Mock) AggregateSyncCommitteeSelections(ctx context.Context, selections []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error)

func (Mock) AttestationData

func (m Mock) AttestationData(ctx context.Context, slot eth2p0.Slot, committeeIndex eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error)

func (Mock) AttesterDuties

func (m Mock) AttesterDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.AttesterDuty, error)

func (Mock) BeaconBlockProposal

func (m Mock) BeaconBlockProposal(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*spec.VersionedBeaconBlock, error)

func (Mock) BeaconBlockRoot added in v0.11.0

func (m Mock) BeaconBlockRoot(ctx context.Context, blockID string) (*eth2p0.Root, error)

func (Mock) BeaconCommittees added in v0.10.1

func (m Mock) BeaconCommittees(ctx context.Context, stateID string) ([]*eth2v1.BeaconCommittee, error)

func (Mock) BlindedBeaconBlockProposal added in v0.9.0

func (m Mock) BlindedBeaconBlockProposal(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*eth2api.VersionedBlindedBeaconBlock, error)

func (Mock) BlockAttestations added in v0.12.0

func (m Mock) BlockAttestations(ctx context.Context, stateID string) ([]*eth2p0.Attestation, error)

func (Mock) Close

func (m Mock) Close() error

func (Mock) Events added in v0.8.0

func (m Mock) Events(ctx context.Context, topics []string, handler eth2client.EventHandlerFunc) error

func (Mock) GenesisTime

func (m Mock) GenesisTime(ctx context.Context) (time.Time, error)

func (Mock) Name

func (Mock) Name() string

func (Mock) NodeSyncing

func (m Mock) NodeSyncing(ctx context.Context) (*eth2v1.SyncState, error)

func (Mock) ProposerDuties

func (m Mock) ProposerDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.ProposerDuty, error)

func (Mock) SignedBeaconBlock added in v0.13.0

func (m Mock) SignedBeaconBlock(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error)

func (Mock) SlotsPerEpoch added in v0.10.0

func (m Mock) SlotsPerEpoch(ctx context.Context) (uint64, error)

func (Mock) SubmitAggregateAttestations added in v0.10.1

func (m Mock) SubmitAggregateAttestations(ctx context.Context, aggregateAndProofs []*eth2p0.SignedAggregateAndProof) error

func (Mock) SubmitAttestations

func (m Mock) SubmitAttestations(ctx context.Context, attestations []*eth2p0.Attestation) error

func (Mock) SubmitBeaconBlock added in v0.3.0

func (m Mock) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error

func (Mock) SubmitBeaconCommitteeSubscriptions added in v0.10.1

func (m Mock) SubmitBeaconCommitteeSubscriptions(ctx context.Context, subscriptions []*eth2v1.BeaconCommitteeSubscription) error

func (Mock) SubmitBlindedBeaconBlock added in v0.9.0

func (m Mock) SubmitBlindedBeaconBlock(ctx context.Context, block *eth2api.VersionedSignedBlindedBeaconBlock) error

func (Mock) SubmitProposalPreparations added in v0.11.0

func (m Mock) SubmitProposalPreparations(ctx context.Context, preparations []*eth2v1.ProposalPreparation) error

func (Mock) SubmitSyncCommitteeContributions added in v0.10.1

func (m Mock) SubmitSyncCommitteeContributions(ctx context.Context, contributionAndProofs []*altair.SignedContributionAndProof) error

func (Mock) SubmitSyncCommitteeMessages added in v0.10.1

func (m Mock) SubmitSyncCommitteeMessages(ctx context.Context, messages []*altair.SyncCommitteeMessage) error

func (Mock) SubmitSyncCommitteeSubscriptions added in v0.10.1

func (m Mock) SubmitSyncCommitteeSubscriptions(ctx context.Context, subscriptions []*eth2v1.SyncCommitteeSubscription) error

func (Mock) SubmitValidatorRegistrations added in v0.10.0

func (m Mock) SubmitValidatorRegistrations(ctx context.Context, registrations []*eth2api.VersionedSignedValidatorRegistration) error

func (Mock) SubmitVoluntaryExit added in v0.6.0

func (m Mock) SubmitVoluntaryExit(ctx context.Context, exit *eth2p0.SignedVoluntaryExit) error

func (Mock) SyncCommitteeContribution added in v0.10.1

func (m Mock) SyncCommitteeContribution(ctx context.Context, slot eth2p0.Slot, subcommitteeIndex uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)

func (Mock) SyncCommitteeDuties added in v0.10.1

func (m Mock) SyncCommitteeDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.SyncCommitteeDuty, error)

func (Mock) TekuProposerConfig added in v0.12.0

func (Mock) Validators

func (m Mock) Validators(ctx context.Context, stateID string, validatorIndices []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)

func (Mock) ValidatorsByPubKey

func (m Mock) ValidatorsByPubKey(ctx context.Context, stateID string, validatorPubKeys []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)

type Option

type Option func(*Mock)

Option defines a functional option to configure the mock beacon client.

func WithClock

func WithClock(clock clockwork.Clock) Option

WithClock configures the mock with the provided clock.

func WithDeterministicAttesterDuties added in v0.4.0

func WithDeterministicAttesterDuties(factor int) Option

WithDeterministicAttesterDuties configures the mock to provide deterministic duties based on provided arguments and config. Note it depends on ValidatorsFunc being populated, e.g. via WithValidatorSet.

func WithDeterministicProposerDuties added in v0.4.0

func WithDeterministicProposerDuties(factor int) Option

WithDeterministicProposerDuties configures the mock to provide deterministic duties based on provided arguments and config. Note it depends on ValidatorsFunc being populated, e.g. via WithValidatorSet.

func WithDeterministicSyncCommDuties added in v0.12.0

func WithDeterministicSyncCommDuties(n, k int) Option

WithDeterministicSyncCommDuties configures the mock to override SyncCommitteeDutiesFunc to return sync committee duties for all validators for first N epochs in every K epochs. N is also used as EPOCHS_PER_SYNC_COMMITTEE_PERIOD.

func WithEndpoint

func WithEndpoint(endpoint string, value string) Option

WithEndpoint configures the http mock with the endpoint override.

func WithGenesisTime

func WithGenesisTime(t0 time.Time) Option

WithGenesisTime configures the http mock with the provided genesis time.

func WithGenesisValidatorsRoot

func WithGenesisValidatorsRoot(root [32]byte) Option

WithGenesisValidatorsRoot configures the http mock with the provided genesis validators root.

func WithNoAttesterDuties added in v0.4.0

func WithNoAttesterDuties() Option

WithNoAttesterDuties configures the mock to override AttesterDutiesFunc to return nothing.

func WithNoProposerDuties

func WithNoProposerDuties() Option

WithNoProposerDuties configures the mock to override ProposerDutiesFunc to return nothing.

func WithNoSyncCommitteeDuties added in v0.11.0

func WithNoSyncCommitteeDuties() Option

WithNoSyncCommitteeDuties configures the mock to override SyncCommitteeDutiesFunc to return nothing.

func WithSlotDuration

func WithSlotDuration(duration time.Duration) Option

WithSlotDuration configures the http mock with the provided slots duration.

func WithSlotsPerEpoch

func WithSlotsPerEpoch(slotsPerEpoch int) Option

WithSlotsPerEpoch configures the http mock with the provided slots per epoch.

func WithSyncCommitteeSize added in v0.13.0

func WithSyncCommitteeSize(size int) Option

WithSyncCommitteeSize configures the http mock with the provided sync committee size.

func WithSyncCommitteeSubnetCount added in v0.13.0

func WithSyncCommitteeSubnetCount(count int) Option

WithSyncCommitteeSubnetCount configures the http mock with the provided sync committee subnet count.

func WithValidatorSet

func WithValidatorSet(set ValidatorSet) Option

WithValidatorSet configures the mock with the provided validator set.

type ValidatorSet

type ValidatorSet map[eth2p0.ValidatorIndex]*eth2v1.Validator

func (ValidatorSet) ByPublicKey

func (s ValidatorSet) ByPublicKey(pubkey eth2p0.BLSPubKey) (*eth2v1.Validator, bool)

ByPublicKey is a convenience function to return a validator by its public key.

func (ValidatorSet) Clone added in v0.12.0

func (s ValidatorSet) Clone() (ValidatorSet, error)

Clone returns a copy of this validator set.

func (ValidatorSet) CorePubKeys

func (s ValidatorSet) CorePubKeys() ([]core.PubKey, error)

CorePubKeys is a convenience function to extract the core workflow public keys from the validators.

func (ValidatorSet) PublicKeys

func (s ValidatorSet) PublicKeys() []eth2p0.BLSPubKey

PublicKeys is a convenience function to extract the eth2 client bls public keys from the validators.

func (ValidatorSet) Validators added in v0.12.0

func (s ValidatorSet) Validators() []*eth2v1.Validator

Validators is a convenience function to return the validators as a slice.

Jump to

Keyboard shortcuts

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