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 ¶
- Variables
- type HTTPMock
- type Mock
- func (Mock) Address() string
- func (m Mock) AttestationData(ctx context.Context, slot eth2p0.Slot, committeeIndex eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error)
- func (m Mock) AttesterDuties(ctx context.Context, epoch eth2p0.Epoch, ...) ([]*eth2v1.AttesterDuty, error)
- func (m Mock) BeaconBlockProposal(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, ...) (*spec.VersionedBeaconBlock, error)
- func (m Mock) Close() error
- func (m Mock) GenesisTime(ctx context.Context) (time.Time, error)
- func (m Mock) HTTPAddr() string
- func (Mock) Name() string
- func (m Mock) NodeSyncing(ctx context.Context) (*eth2v1.SyncState, error)
- func (m Mock) ProposerDuties(ctx context.Context, epoch eth2p0.Epoch, ...) ([]*eth2v1.ProposerDuty, error)
- func (m Mock) SubmitAttestations(ctx context.Context, attestations []*eth2p0.Attestation) error
- func (m Mock) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error
- func (m Mock) Validators(ctx context.Context, stateID string, validatorIndices []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
- func (m Mock) ValidatorsByPubKey(ctx context.Context, stateID string, validatorPubKeys []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
- type Option
- func WithClock(clock clockwork.Clock) Option
- func WithDeterministicAttesterDuties(factor int) Option
- func WithDeterministicProposerDuties(factor int) Option
- func WithEndpoint(endpoint string, value string) Option
- func WithGenesisTime(t0 time.Time) Option
- func WithGenesisValidatorsRoot(root [32]byte) Option
- func WithNoAttesterDuties() Option
- func WithNoProposerDuties() Option
- func WithSlotDuration(duration time.Duration) Option
- func WithSlotsPerEpoch(slotsPerEpoch int) Option
- func WithValidatorSet(set ValidatorSet) Option
- type ValidatorSet
Constants ¶
This section is empty.
Variables ¶
var ValidatorSetA = ValidatorSet{ 1: { Index: 1, Balance: 1, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x914cff835a769156ba43ad50b931083c2dadd94e8359ce394bc7a3e06424d0214922ddf15f81640530b9c25c0bc0d490"), EffectiveBalance: 1, ActivationEligibilityEpoch: 1, ActivationEpoch: 2, }, }, 2: { Index: 2, Balance: 2, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea"), EffectiveBalance: 2, ActivationEligibilityEpoch: 2, ActivationEpoch: 3, }, }, 3: { Index: 3, Balance: 3, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76"), EffectiveBalance: 3, ActivationEligibilityEpoch: 3, ActivationEpoch: 4, }, }, }
ValidatorSetA defines a set 3 validators.
Functions ¶
This section is empty.
Types ¶
type HTTPMock ¶
type HTTPMock interface { eth2client.BeaconCommitteesProvider eth2client.DepositContractProvider eth2client.DomainProvider eth2client.ForkProvider eth2client.ForkScheduleProvider eth2client.GenesisProvider eth2client.GenesisTimeProvider eth2client.NodeSyncingProvider eth2client.NodeVersionProvider eth2client.SlotDurationProvider eth2client.SlotsPerEpochProvider eth2client.SpecProvider eth2client.SyncCommitteeDutiesProvider }
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) BeaconBlockProposalFunc func(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*spec.VersionedBeaconBlock, 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 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(ctx context.Context) (time.Time, error) NodeSyncingFunc func(context.Context) (*eth2v1.SyncState, error) // contains filtered or unexported fields }
Mock provides a mock beacon client and implements eth2client.Service and many of the eth2client Providers. Create a new instance with default behaviour via New and then override any function.
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 (Mock) ProposerDuties ¶
func (m Mock) ProposerDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.ProposerDuty, error)
func (Mock) SubmitAttestations ¶
func (Mock) SubmitBeaconBlock ¶ added in v0.3.0
func (Mock) Validators ¶
type Option ¶
type Option func(*Mock)
Option defines a functional option to configure the mock beacon client.
func WithDeterministicAttesterDuties ¶ added in v0.4.0
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
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 WithEndpoint ¶
WithEndpoint configures the http mock with the endpoint override.
func WithGenesisTime ¶
WithGenesisTime configures the http mock with the provided genesis time.
func WithGenesisValidatorsRoot ¶
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 WithSlotDuration ¶
WithSlotDuration configures the http mock with the provided slots duration.
func WithSlotsPerEpoch ¶
WithSlotsPerEpoch configures the http mock with the provided slots per epoch.
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 ¶
ByPublicKey is a convenience function to return a validator by its public key.
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.