mock

package
v0.0.0-...-90009c5 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parameter

type Parameter interface {
	// contains filtered or unexported methods
}

Parameter is the interface for service parameters.

func WithGenesisTime

func WithGenesisTime(genesisTime time.Time) Parameter

WithGenesisTime sets the genesis time for the mock.

func WithLogLevel

func WithLogLevel(logLevel zerolog.Level) Parameter

WithLogLevel sets the log level for the module.

func WithName

func WithName(name string) Parameter

WithName sets the name for the module.

func WithTimeout

func WithTimeout(timeout time.Duration) Parameter

WithTimeout sets the maximum duration for all requests to the endpoint.

type Service

type Service struct {

	// Values that can be altered if required.
	HeadSlot     phase0.Slot
	SyncDistance phase0.Slot

	// Functions that can be provided to mock specific responses from this client.
	AggregateAttestationFunc      func(context.Context, *api.AggregateAttestationOpts) (*api.Response[*spec.VersionedAttestation], error)
	AttesterDutiesFunc            func(context.Context, *api.AttesterDutiesOpts) (*api.Response[[]*apiv1.AttesterDuty], error)
	AttestationDataFunc           func(context.Context, *api.AttestationDataOpts) (*api.Response[*phase0.AttestationData], error)
	AttestationRewardsFunc        func(context.Context, *api.AttestationRewardsOpts) (*api.Response[*apiv1.AttestationRewards], error)
	BeaconBlockHeaderFunc         func(context.Context, *api.BeaconBlockHeaderOpts) (*api.Response[*apiv1.BeaconBlockHeader], error)
	BeaconBlockRootFunc           func(context.Context, *api.BeaconBlockRootOpts) (*api.Response[*phase0.Root], error)
	BeaconStateFunc               func(context.Context, *api.BeaconStateOpts) (*api.Response[*spec.VersionedBeaconState], error)
	BeaconStateRandaoFunc         func(context.Context, *api.BeaconStateRandaoOpts) (*api.Response[*phase0.Root], error)
	BeaconStateRootFunc           func(context.Context, *api.BeaconStateRootOpts) (*api.Response[*phase0.Root], error)
	BlockRewardsFunc              func(context.Context, *api.BlockRewardsOpts) (*api.Response[*apiv1.BlockRewards], error)
	DepositContractFunc           func(context.Context, *api.DepositContractOpts) (*api.Response[*apiv1.DepositContract], error)
	EventsFunc                    func(context.Context, *api.EventsOpts) error
	FinalityFunc                  func(context.Context, *api.FinalityOpts) (*api.Response[*apiv1.Finality], error)
	ForkChoiceFunc                func(context.Context, *api.ForkChoiceOpts) (*api.Response[*apiv1.ForkChoice], error)
	ForkFunc                      func(context.Context, *api.ForkOpts) (*api.Response[*phase0.Fork], error)
	ForkScheduleFunc              func(context.Context, *api.ForkScheduleOpts) (*api.Response[[]*phase0.Fork], error)
	GenesisFunc                   func(context.Context, *api.GenesisOpts) (*api.Response[*apiv1.Genesis], error)
	NodePeersFunc                 func(context.Context, *api.NodePeersOpts) (*api.Response[[]*apiv1.Peer], error)
	NodeSyncingFunc               func(context.Context, *api.NodeSyncingOpts) (*api.Response[*apiv1.SyncState], error)
	NodeVersionFunc               func(context.Context, *api.NodeVersionOpts) (*api.Response[string], error)
	PendingDepositsFunc           func(context.Context, *api.PendingDepositsOpts) (*api.Response[[]*electra.PendingDeposit], error)
	ProposalFunc                  func(context.Context, *api.ProposalOpts) (*api.Response[*api.VersionedProposal], error)
	ProposerDutiesFunc            func(context.Context, *api.ProposerDutiesOpts) (*api.Response[[]*apiv1.ProposerDuty], error)
	SignedBeaconBlockFunc         func(context.Context, *api.SignedBeaconBlockOpts) (*api.Response[*spec.VersionedSignedBeaconBlock], error)
	SpecFunc                      func(context.Context, *api.SpecOpts) (*api.Response[map[string]any], error)
	SyncCommitteeContributionFunc func(context.Context, *api.SyncCommitteeContributionOpts) (*api.Response[*altair.SyncCommitteeContribution], error)
	SyncCommitteeDutiesFunc       func(context.Context, *api.SyncCommitteeDutiesOpts) (*api.Response[[]*apiv1.SyncCommitteeDuty], error)
	SyncCommitteeRewardsFunc      func(context.Context, *api.SyncCommitteeRewardsOpts) (*api.Response[[]*apiv1.SyncCommitteeReward], error)
	ValidatorBalancesFunc         func(context.Context, *api.ValidatorBalancesOpts) (*api.Response[map[phase0.ValidatorIndex]phase0.Gwei], error)
	ValidatorLivenessFunc         func(context.Context, *api.ValidatorLivenessOpts) (*api.Response[[]*apiv1.ValidatorLiveness], error)
	ValidatorsFunc                func(context.Context, *api.ValidatorsOpts) (*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator], error)
	VoluntaryExitPoolFunc         func(context.Context, *api.VoluntaryExitPoolOpts) (*api.Response[[]*phase0.SignedVoluntaryExit], error)
	// contains filtered or unexported fields
}

Service is a mock Ethereum 2 client service, providing data locally.

func New

func New(ctx context.Context, params ...Parameter) (*Service, error)

New creates a new Ethereum 2 client service, mocking connections.

func (*Service) Address

func (s *Service) Address() string

Address provides the address of the service.

func (*Service) AggregateAndProofDomain

func (*Service) AggregateAndProofDomain(_ context.Context) (spec.DomainType, error)

AggregateAndProofDomain provides the aggregate and proof domain.

func (*Service) AggregateAttestation

func (s *Service) AggregateAttestation(ctx context.Context,
	opts *api.AggregateAttestationOpts,
) (
	*api.Response[*spec.VersionedAttestation],
	error,
)

AggregateAttestation fetches the aggregate attestation for the given options.

func (*Service) AttestationData

func (s *Service) AttestationData(ctx context.Context,
	opts *api.AttestationDataOpts,
) (
	*api.Response[*phase0.AttestationData],
	error,
)

AttestationData fetches the attestation data for the given slot and committee index.

func (*Service) AttestationPool

AttestationPool fetches the attestation pool for the given slot.

func (*Service) AttestationRewards

func (s *Service) AttestationRewards(ctx context.Context,
	opts *api.AttestationRewardsOpts,
) (
	*api.Response[*apiv1.AttestationRewards],
	error,
)

AttestationRewards provides rewards to the given validators for attesting.

func (*Service) AttesterDuties

func (s *Service) AttesterDuties(ctx context.Context,
	opts *api.AttesterDutiesOpts,
) (
	*api.Response[[]*apiv1.AttesterDuty],
	error,
)

AttesterDuties obtains attester duties. If validatorIndices is nil it will return all duties for the given epoch.

func (*Service) BeaconAttesterDomain

func (*Service) BeaconAttesterDomain(_ context.Context) (spec.DomainType, error)

BeaconAttesterDomain provides the beacon attester domain.

func (*Service) BeaconBlockHeader

func (s *Service) BeaconBlockHeader(ctx context.Context,
	opts *api.BeaconBlockHeaderOpts,
) (
	*api.Response[*apiv1.BeaconBlockHeader],
	error,
)

BeaconBlockHeader provides the block header of a given block ID.

func (*Service) BeaconBlockRoot

func (s *Service) BeaconBlockRoot(ctx context.Context,
	opts *api.BeaconBlockRootOpts,
) (
	*api.Response[*phase0.Root],
	error,
)

BeaconBlockRoot fetches a block's root given a block ID.

func (*Service) BeaconCommittees

func (*Service) BeaconCommittees(_ context.Context,
	_ *api.BeaconCommitteesOpts,
) (
	*api.Response[[]*apiv1.BeaconCommittee],
	error,
)

BeaconCommittees fetches all beacon committees for the epoch at the given state.

func (*Service) BeaconProposerDomain

func (*Service) BeaconProposerDomain(_ context.Context) (spec.DomainType, error)

BeaconProposerDomain provides the beacon proposer domain.

func (*Service) BeaconState

func (s *Service) BeaconState(ctx context.Context,
	opts *api.BeaconStateOpts,
) (
	*api.Response[*spec.VersionedBeaconState],
	error,
)

BeaconState fetches a beacon state given a state ID.

func (*Service) BeaconStateRoot

func (s *Service) BeaconStateRoot(ctx context.Context,
	opts *api.BeaconStateRootOpts,
) (
	*api.Response[*phase0.Root],
	error,
)

BeaconStateRoot fetches a beacon state's root given a state ID.

func (*Service) BlindedProposal

BlindedProposal fetches a blinded proposal for signing.

func (*Service) BlockRewards

func (s *Service) BlockRewards(ctx context.Context,
	opts *api.BlockRewardsOpts,
) (
	*api.Response[*apiv1.BlockRewards],
	error,
)

BlockRewards provides rewards for proposing a block.

func (*Service) DepositContract

func (s *Service) DepositContract(ctx context.Context,
	opts *api.DepositContractOpts,
) (
	*api.Response[*apiv1.DepositContract],
	error,
)

DepositContract provides details of the execution layer deposit contract for the chain.

func (*Service) DepositDomain

func (*Service) DepositDomain(_ context.Context) (spec.DomainType, error)

DepositDomain provides the deposit domain.

func (*Service) Domain

func (s *Service) Domain(ctx context.Context, domainType phase0.DomainType, epoch phase0.Epoch) (phase0.Domain, error)

Domain provides a domain for a given domain type at a given epoch.

func (*Service) Events

func (s *Service) Events(ctx context.Context, opts *api.EventsOpts) error

Events feeds requested events with the given topics to the supplied handler.

func (*Service) FarFutureEpoch

func (*Service) FarFutureEpoch(_ context.Context) (spec.Epoch, error)

FarFutureEpoch provides the values for FAR_FUTURE_EPOCH of the chain.

func (*Service) Finality

func (s *Service) Finality(ctx context.Context, opts *api.FinalityOpts) (*api.Response[*apiv1.Finality], error)

Finality provides the finality given a state ID.

func (*Service) Fork

func (s *Service) Fork(ctx context.Context,
	opts *api.ForkOpts,
) (
	*api.Response[*phase0.Fork],
	error,
)

Fork fetches fork information for the given state.

func (*Service) ForkChoice

func (s *Service) ForkChoice(ctx context.Context,
	opts *api.ForkChoiceOpts,
) (
	*api.Response[*apiv1.ForkChoice],
	error,
)

ForkChoice fetches all current fork choice context.

func (*Service) ForkSchedule

func (s *Service) ForkSchedule(ctx context.Context,
	opts *api.ForkScheduleOpts,
) (
	*api.Response[[]*phase0.Fork],
	error,
)

ForkSchedule provides details of past and future changes in the chain's fork version.

func (*Service) Genesis

func (s *Service) Genesis(ctx context.Context, opts *api.GenesisOpts) (*api.Response[*apiv1.Genesis], error)

Genesis provides the genesis information of the chain.

func (*Service) GenesisDomain

func (s *Service) GenesisDomain(ctx context.Context, domainType phase0.DomainType) (phase0.Domain, error)

GenesisDomain returns the domain for the given domain type at genesis. N.B. this is not always the same as the domain at epoch 0. It is possible for a chain's fork schedule to have multiple forks at genesis. In this situation, GenesisDomain() will return the first, and Domain() will return the last.

func (*Service) GenesisTime

func (s *Service) GenesisTime(ctx context.Context) (time.Time, error)

GenesisTime provides the genesis time of the chain.

func (*Service) IsActive

func (*Service) IsActive() bool

IsActive returns true if the client is active.

func (*Service) IsSynced

func (s *Service) IsSynced() bool

IsSynced returns true if the client is synced.

func (*Service) Name

func (*Service) Name() string

Name provides the name of the service.

func (*Service) NodePeers

func (s *Service) NodePeers(ctx context.Context,
	opts *api.NodePeersOpts,
) (
	*api.Response[[]*apiv1.Peer],
	error,
)

NodePeers provides the peers of the node.

func (*Service) NodeSyncing

func (s *Service) NodeSyncing(ctx context.Context,
	opts *api.NodeSyncingOpts,
) (
	*api.Response[*apiv1.SyncState],
	error,
)

NodeSyncing provides the state of the node's synchronization with the chain.

func (*Service) NodeVersion

func (s *Service) NodeVersion(ctx context.Context,
	opts *api.NodeVersionOpts,
) (
	*api.Response[string],
	error,
)

NodeVersion returns a free-text string with the node version.

func (*Service) PendingDeposits

func (s *Service) PendingDeposits(ctx context.Context,
	opts *api.PendingDepositsOpts,
) (
	*api.Response[[]*electra.PendingDeposit],
	error,
)

PendingDeposits provides the pending deposits for a given state.

func (*Service) Proposal

func (s *Service) Proposal(ctx context.Context,
	opts *api.ProposalOpts,
) (
	*api.Response[*api.VersionedProposal], error,
)

Proposal fetches a proposal for signing.

func (*Service) ProposerDuties

func (s *Service) ProposerDuties(ctx context.Context, opts *api.ProposerDutiesOpts) (*api.Response[[]*apiv1.ProposerDuty], error)

ProposerDuties obtains proposer duties for the given epoch. If validatorIndices is empty all duties are returned, otherwise only matching duties are returned.

func (*Service) RANDAODomain

func (*Service) RANDAODomain(_ context.Context) (spec.DomainType, error)

RANDAODomain provides the RANDAO domain.

func (*Service) SelectionProofDomain

func (*Service) SelectionProofDomain(_ context.Context) (spec.DomainType, error)

SelectionProofDomain provides the selection proof domain.

func (*Service) SignedBeaconBlock

func (s *Service) SignedBeaconBlock(ctx context.Context,
	opts *api.SignedBeaconBlockOpts,
) (
	*api.Response[*spec.VersionedSignedBeaconBlock],
	error,
)

SignedBeaconBlock fetches a signed beacon block given a block ID.

func (*Service) SlotDuration

func (*Service) SlotDuration(_ context.Context) (time.Duration, error)

SlotDuration provides the duration of a slot of the chain.

func (*Service) SlotsPerEpoch

func (*Service) SlotsPerEpoch(_ context.Context) (uint64, error)

SlotsPerEpoch provides the slots per epoch of the chain.

func (*Service) Spec

func (s *Service) Spec(ctx context.Context, opts *api.SpecOpts) (*api.Response[map[string]any], error)

Spec provides the spec information of the chain. This returns various useful values.

func (*Service) SubmitAggregateAttestations

func (*Service) SubmitAggregateAttestations(_ context.Context, _ *api.SubmitAggregateAttestationsOpts) error

SubmitAggregateAttestations submits aggregate attestations.

func (*Service) SubmitAttestations

func (*Service) SubmitAttestations(_ context.Context, _ *api.SubmitAttestationsOpts) error

SubmitAttestations submits attestations.

func (*Service) SubmitAttesterSlashing

func (*Service) SubmitAttesterSlashing(_ context.Context, _ *phase0.AttesterSlashing) error

SubmitAttesterSlashing submits a proposal slashing.

func (*Service) SubmitBLSToExecutionChange

func (*Service) SubmitBLSToExecutionChange(_ context.Context, _ *capella.SignedBLSToExecutionChange) error

SubmitBLSToExecutionChange submits a BLS to execution address change operation.

func (*Service) SubmitBeaconBlock

func (*Service) SubmitBeaconBlock(_ context.Context, _ *spec.VersionedSignedBeaconBlock) error

SubmitBeaconBlock submits a beacon block.

func (*Service) SubmitBeaconCommitteeSubscriptions

func (*Service) SubmitBeaconCommitteeSubscriptions(_ context.Context, _ []*api.BeaconCommitteeSubscription) error

SubmitBeaconCommitteeSubscriptions subscribes to beacon committees.

func (*Service) SubmitBlindedBeaconBlock

func (*Service) SubmitBlindedBeaconBlock(_ context.Context, _ *api.VersionedSignedBlindedBeaconBlock) error

SubmitBlindedBeaconBlock submits a blinded beacon block.

func (*Service) SubmitProposal

func (*Service) SubmitProposal(_ context.Context, _ *api.VersionedSignedProposal) error

SubmitProposal submits a proposal.

func (*Service) SubmitProposalPreparations

func (*Service) SubmitProposalPreparations(_ context.Context, _ []*apiv1.ProposalPreparation) error

SubmitProposalPreparations provides the beacon node with information required if a proposal for the given validators shows up in the next epoch.

func (*Service) SubmitProposalSlashing

func (*Service) SubmitProposalSlashing(_ context.Context, _ *phase0.ProposerSlashing) error

SubmitProposalSlashing submits a proposal slashing.

func (*Service) SubmitSyncCommitteeContributions

func (*Service) SubmitSyncCommitteeContributions(_ context.Context, _ []*altair.SignedContributionAndProof) error

SubmitSyncCommitteeContributions submits sync committee contributions.

func (*Service) SubmitSyncCommitteeMessages

func (*Service) SubmitSyncCommitteeMessages(_ context.Context, _ []*altair.SyncCommitteeMessage) error

SubmitSyncCommitteeMessages submits sync committee messages.

func (*Service) SubmitSyncCommitteeSubscriptions

func (*Service) SubmitSyncCommitteeSubscriptions(_ context.Context, _ []*api.SyncCommitteeSubscription) error

SubmitSyncCommitteeSubscriptions subscribes to sync committees.

func (*Service) SubmitValidatorRegistrations

func (*Service) SubmitValidatorRegistrations(_ context.Context, _ []*api.VersionedSignedValidatorRegistration) error

SubmitValidatorRegistrations submits a validator registration.

func (*Service) SubmitVoluntaryExit

func (*Service) SubmitVoluntaryExit(_ context.Context, _ *spec.SignedVoluntaryExit) error

SubmitVoluntaryExit submits a voluntary exit.

func (*Service) SyncCommittee

SyncCommittee fetches the sync committee for the given state.

func (*Service) SyncCommitteeContribution

func (s *Service) SyncCommitteeContribution(ctx context.Context,
	opts *api.SyncCommitteeContributionOpts,
) (
	*api.Response[*altair.SyncCommitteeContribution],
	error,
)

SyncCommitteeContribution provides a sync committee contribution.

func (*Service) SyncCommitteeDuties

func (s *Service) SyncCommitteeDuties(ctx context.Context,
	opts *api.SyncCommitteeDutiesOpts,
) (
	*api.Response[[]*apiv1.SyncCommitteeDuty],
	error,
)

SyncCommitteeDuties obtains sync committee duties.

func (*Service) SyncCommitteeRewards

func (s *Service) SyncCommitteeRewards(ctx context.Context,
	opts *api.SyncCommitteeRewardsOpts,
) (
	*api.Response[[]*apiv1.SyncCommitteeReward],
	error,
)

SyncCommitteeRewards provides rewards to the given validators for being members of a sync committee.

func (*Service) TargetAggregatorsPerCommittee

func (*Service) TargetAggregatorsPerCommittee(_ context.Context) (uint64, error)

TargetAggregatorsPerCommittee provides the target number of aggregators for each attestation committee.

func (*Service) ValidatorBalances

func (s *Service) ValidatorBalances(ctx context.Context,
	opts *api.ValidatorBalancesOpts,
) (
	*api.Response[map[phase0.ValidatorIndex]phase0.Gwei],
	error,
)

ValidatorBalances provides the validator balances for a given state. stateID can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized". validatorIndices is a list of validator indices to restrict the returned values. If no validators are supplied no filter will be applied.

func (*Service) ValidatorLiveness

func (s *Service) ValidatorLiveness(ctx context.Context,
	opts *api.ValidatorLivenessOpts,
) (
	*api.Response[[]*apiv1.ValidatorLiveness],
	error,
)

ValidatorLiveness provides the liveness data to the given validators.

func (*Service) Validators

func (s *Service) Validators(ctx context.Context,
	opts *api.ValidatorsOpts,
) (
	*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator],
	error,
)

Validators provides the validators, with their balance and status, for a given state.

func (*Service) VoluntaryExitDomain

func (*Service) VoluntaryExitDomain(_ context.Context) (spec.DomainType, error)

VoluntaryExitDomain provides the voluntary exit domain.

func (*Service) VoluntaryExitPool

func (s *Service) VoluntaryExitPool(ctx context.Context,
	opts *api.VoluntaryExitPoolOpts,
) (
	*api.Response[[]*phase0.SignedVoluntaryExit],
	error,
)

VoluntaryExitPool fetches the voluntary exit pool.

Jump to

Keyboard shortcuts

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