test

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMockHistoryGenesis = 1577836800
View Source
const FarFutureEpoch uint64 = 0xffffffffffffffff

Variables

View Source
var (
	BondSizeEightEth   = BondSize(eth.EthToWei(8))
	BondSizeSixteenEth = BondSize(eth.EthToWei(16))
)

Functions

This section is empty.

Types

type BondSize

type BondSize *big.Int

type MockBeaconClient

type MockBeaconClient struct {
	// contains filtered or unexported fields
}

func NewMockBeaconClient

func NewMockBeaconClient(t *testing.T) *MockBeaconClient

func (*MockBeaconClient) AddWithdrawal

func (bc *MockBeaconClient) AddWithdrawal(s uint64, index string, amount *big.Int)

func (*MockBeaconClient) GetAttestations

func (bc *MockBeaconClient) GetAttestations(_slot string) ([]beacon.AttestationInfo, bool, error)

func (*MockBeaconClient) GetBeaconBlock

func (bc *MockBeaconClient) GetBeaconBlock(s string) (beacon.BeaconBlock, bool, error)

func (*MockBeaconClient) GetBeaconHead

func (bc *MockBeaconClient) GetBeaconHead() (beacon.BeaconHead, error)

func (*MockBeaconClient) GetCommitteesForEpoch

func (bc *MockBeaconClient) GetCommitteesForEpoch(_epoch *uint64) (beacon.Committees, error)

func (*MockBeaconClient) GetEth2Config

func (bc *MockBeaconClient) GetEth2Config() (beacon.Eth2Config, error)

func (*MockBeaconClient) GetStateForSlot

func (bc *MockBeaconClient) GetStateForSlot(slot uint64) (*state.NetworkState, error)

func (*MockBeaconClient) SetBeaconBlock

func (bc *MockBeaconClient) SetBeaconBlock(slot string, block beacon.BeaconBlock)

func (*MockBeaconClient) SetCriticalDutiesSlots

func (bc *MockBeaconClient) SetCriticalDutiesSlots(criticalDutiesSlots *state.CriticalDutiesSlots)

func (*MockBeaconClient) SetMinipoolPerformance

func (bc *MockBeaconClient) SetMinipoolPerformance(index string, missedSlots []uint64)

SetMinipoolPerformance notes the minipool's performance to be mocked in the response to GetAttestations

func (*MockBeaconClient) SetState

func (m *MockBeaconClient) SetState(state *state.NetworkState)

type MockBeaconCommittees

type MockBeaconCommittees struct {
	// contains filtered or unexported fields
}

func (*MockBeaconCommittees) Count

func (mbc *MockBeaconCommittees) Count() int

Count returns the number of committees in the response

func (*MockBeaconCommittees) Index

func (mbc *MockBeaconCommittees) Index(index int) uint64

Index returns the index of the committee at the provided offset

func (*MockBeaconCommittees) Release

func (mbc *MockBeaconCommittees) Release()

Release is a no-op

func (*MockBeaconCommittees) Slot

func (mbc *MockBeaconCommittees) Slot(index int) uint64

Slot returns the slot of the committee at the provided offset

func (*MockBeaconCommittees) Validators

func (mbc *MockBeaconCommittees) Validators(index int) []string

Validators returns the list of validators of the committee at the provided offset

type MockHistory

type MockHistory struct {
	StartEpoch   uint64
	EndEpoch     uint64
	BlockOffset  uint64
	BeaconConfig beacon.Eth2Config

	// Network details for the final slot
	NetworkDetails *rpstate.NetworkDetails

	Nodes []*MockNode
	// contains filtered or unexported fields
}

func NewDefaultMockHistory

func NewDefaultMockHistory() *MockHistory

func NewDefaultMockHistoryNoNodes

func NewDefaultMockHistoryNoNodes() *MockHistory

func (*MockHistory) GetConsensusEndBlock

func (h *MockHistory) GetConsensusEndBlock() uint64

func (*MockHistory) GetConsensusStartBlock

func (h *MockHistory) GetConsensusStartBlock() uint64

Boring derived data getters

func (*MockHistory) GetDefaultMockNodes

func (h *MockHistory) GetDefaultMockNodes() []*MockNode

Returns a list of nodes with various attributes- some will have active minipools, some will not. some will be under and over collateralized. some will have opted in or out during the interval some will have bond reduced during the interval

func (*MockHistory) GetDefaultMockODAONodes

func (h *MockHistory) GetDefaultMockODAONodes() []*MockNode

func (*MockHistory) GetEndNetworkState

func (h *MockHistory) GetEndNetworkState() *state.NetworkState

func (*MockHistory) GetEndTime

func (h *MockHistory) GetEndTime() time.Time

func (*MockHistory) GetExecutionEndBlock

func (h *MockHistory) GetExecutionEndBlock() uint64

func (*MockHistory) GetExecutionStartBlock

func (h *MockHistory) GetExecutionStartBlock() uint64

func (*MockHistory) GetMinipoolAddress

func (h *MockHistory) GetMinipoolAddress() common.Address

func (*MockHistory) GetMinipoolAttestationScoreAndCount

func (h *MockHistory) GetMinipoolAttestationScoreAndCount(address common.Address, state *state.NetworkState) (*big.Int, uint64)

func (*MockHistory) GetNewDefaultMockMinipool

func (h *MockHistory) GetNewDefaultMockMinipool(bondSize BondSize) *MockMinipool

func (*MockHistory) GetNewDefaultMockNode

func (h *MockHistory) GetNewDefaultMockNode(params *NewMockNodeParams) *MockNode

func (*MockHistory) GetNodeAddress

func (h *MockHistory) GetNodeAddress() common.Address

func (*MockHistory) GetNodeSummary

func (h *MockHistory) GetNodeSummary() map[string][]*MockNode

func (*MockHistory) GetPreviousRewardSnapshotEvent

func (h *MockHistory) GetPreviousRewardSnapshotEvent() rprewards.RewardsEvent

func (*MockHistory) GetStartTime

func (h *MockHistory) GetStartTime() time.Time

func (*MockHistory) GetValidatorIndex

func (h *MockHistory) GetValidatorIndex() string

func (*MockHistory) GetValidatorPubkey

func (h *MockHistory) GetValidatorPubkey() types.ValidatorPubkey

func (*MockHistory) SetWithdrawals

func (h *MockHistory) SetWithdrawals(mockBeaconClient *MockBeaconClient)

type MockMinipool

type MockMinipool struct {
	Address            common.Address
	Pubkey             types.ValidatorPubkey
	Status             types.MinipoolStatus
	StatusBlock        *big.Int
	StatusTime         time.Time
	Finalised          bool
	NodeFee            *big.Int
	NodeDepositBalance *big.Int
	NodeAddress        common.Address

	LastBondReductionTime        time.Time
	LastBondReductionPrevValue   *big.Int
	LastBondReductionPrevNodeFee *big.Int

	ValidatorIndex string

	// Withdrawal amount to add to the minipool during its SP period
	SPWithdrawals *big.Int

	// Withdrawal amount to add to the minipool during its regular period
	OptedOutWithdrawals *big.Int

	// The epoch after which the minipool is withdrawable.
	// Defaults to FAR_FUTURE_EPOCH.
	WithdrawableEpoch uint64

	Notes []string
}

type MockNode

type MockNode struct {
	Address                          common.Address
	RegistrationTime                 time.Time
	RplStake                         *big.Int
	SmoothingPoolRegistrationState   bool
	SmoothingPoolRegistrationChanged time.Time

	IsOdao       bool
	JoinedOdaoAt time.Time

	Minipools []*MockMinipool

	Notes string
	Class string
	// contains filtered or unexported fields
}

func (*MockNode) AddMinipool

func (n *MockNode) AddMinipool(minipool *MockMinipool)

type MockRocketPool

type MockRocketPool struct {
	RewardsIndex *big.Int
	// contains filtered or unexported fields
}

MockRocketPool is a EC mock specifically for testing treegen. At a high level our approach is to provide two options to the tester: 1) Use a recording of request/response data from production to emulate a canonical tree 2) Allow for full response customization.

The former is useful for ensuring that no regressions arise during refactors that should otherwise be nonfunction, ie, not impact the merkle root.

The latter is useful to probe specific behaviors such as opt-in/opt-out eligibility timing, node weight, smoothing pool status, etc.

Because recording responses ties the test to a specific version of the contracts and therefor the client-side code, the interface we need to mock should be as minimized as possible, and the recorded data should tightly match that interface. That is, no recorded response should encode something like the contract address data are being requested from, but instead the high-level function name and arguments.

func NewMockRocketPool

func NewMockRocketPool(t *testing.T, index uint64) *MockRocketPool

func (*MockRocketPool) Client

func (mock *MockRocketPool) Client() *rocketpool.RocketPool

func (*MockRocketPool) GetNetworkEnabled

func (mock *MockRocketPool) GetNetworkEnabled(networkId *big.Int, opts *bind.CallOpts) (bool, error)

func (*MockRocketPool) GetRewardIndex

func (mock *MockRocketPool) GetRewardIndex(opts *bind.CallOpts) (*big.Int, error)

func (*MockRocketPool) GetRewardSnapshotEvent

func (mock *MockRocketPool) GetRewardSnapshotEvent(previousRewardsPoolAddresses []common.Address, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error)

func (*MockRocketPool) GetRewardsEvent

func (mock *MockRocketPool) GetRewardsEvent(index uint64, _ []common.Address, opts *bind.CallOpts) (bool, rewards.RewardsEvent, error)

func (*MockRocketPool) HeaderByNumber

func (mock *MockRocketPool) HeaderByNumber(_ context.Context, number *big.Int) (*types.Header, error)

func (*MockRocketPool) SetHeaderByNumber

func (mock *MockRocketPool) SetHeaderByNumber(number *big.Int, header *types.Header)

func (*MockRocketPool) SetRewardSnapshotEvent

func (mock *MockRocketPool) SetRewardSnapshotEvent(event rewards.RewardsEvent)

type NewMockNodeParams

type NewMockNodeParams struct {
	SmoothingPool       bool
	EightEthMinipools   int
	SixteenEthMinipools int
	CollateralRpl       int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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