beaconmock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: GPL-3.0 Imports: 27 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,
		},
	},
	2: {
		Index:   2,
		Balance: 2,
		Status:  eth2v1.ValidatorStateActiveOngoing,
		Validator: &eth2p0.Validator{
			PublicKey:                  mustPKFromHex("0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea"),
			EffectiveBalance:           2,
			ActivationEligibilityEpoch: 2,
			ActivationEpoch:            3,
		},
	},
	3: {
		Index:   3,
		Balance: 3,
		Status:  eth2v1.ValidatorStateActiveOngoing,
		Validator: &eth2p0.Validator{
			PublicKey:                  mustPKFromHex("0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76"),
			EffectiveBalance:           3,
			ActivationEligibilityEpoch: 3,
			ActivationEpoch:            4,
		},
	},
}

ValidatorSetA defines a set 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)
	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 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 (Mock) Address() string

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) Close

func (m Mock) Close() error

func (Mock) GenesisTime

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

func (Mock) HTTPAddr

func (m Mock) HTTPAddr() string

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) 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) 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 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 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 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) 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.

Jump to

Keyboard shortcuts

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