testepoching

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

README

testepoching

The code under this directory provides infrastructure for testing the epoching module, such as mocking staking module messages, parsing Tenderming/Cosmos validators, etc.. The code is adapted from https://github.com/cosmos/cosmos-sdk/tree/v0.45.5/x/staking/teststaking

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateValHash

func CalculateValHash(valSet []stakingtypes.Validator) []byte

calculate validator hash and new header (adapted from https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/test_helpers.go#L156-L163)

func GenTmValidatorSet

func GenTmValidatorSet(numVals int) (*tmtypes.ValidatorSet, error)

GenTmValidatorSet generates a set with `numVals` Tendermint validators

func GetTmConsPubKey

func GetTmConsPubKey(v stakingtypes.Validator) (tmcrypto.PubKey, error)

GetTmConsPubKey gets the validator's public key as a tmcrypto.PubKey.

func Min

func Min(a, b uint64) uint64

func NewValidator

func NewValidator(t testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey) stakingtypes.Validator

NewValidator is a testing helper method to create validators in tests

func ToTmValidator

func ToTmValidator(v stakingtypes.Validator, r math.Int) (*tmtypes.Validator, error)

ToTmValidator casts an SDK validator to a tendermint type Validator.

func ToTmValidators

func ToTmValidators(v stakingtypes.Validators, r math.Int) ([]*tmtypes.Validator, error)

ToTmValidators casts all validators to the corresponding tendermint type.

func ZeroCommission

func ZeroCommission() stakingtypes.CommissionRates

ZeroCommission constructs a commission rates with all zeros.

Types

type Helper

type Helper struct {
	Ctx            sdk.Context
	App            *app.BabylonApp
	EpochingKeeper *keeper.Keeper
	MsgSrvr        types.MsgServer
	QueryClient    types.QueryClient
	StakingKeeper  *stakingkeeper.Keeper

	GenAccs        []authtypes.GenesisAccount
	ValBlsPrivKeys []ValidatorInfo
	// contains filtered or unexported fields
}

Helper is a structure which wraps the entire app and exposes functionalities for testing the epoching module

func NewHelper

func NewHelper(t *testing.T) *Helper

NewHelper creates the helper for testing the epoching module

func NewHelperWithValSet

func NewHelperWithValSet(t *testing.T) *Helper

NewHelperWithValSet is same as NewHelper, except that it creates a set of validators

func (*Helper) BeginBlock

func (h *Helper) BeginBlock(r *rand.Rand) sdk.Context

func (*Helper) CheckDelegator

func (h *Helper) CheckDelegator(delegator sdk.AccAddress, val sdk.ValAddress, found bool)

CheckDelegator asserts that a delegator exists

func (*Helper) CheckValidator

func (h *Helper) CheckValidator(addr sdk.ValAddress, status stakingtypes.BondStatus, jailed bool) stakingtypes.Validator

CheckValidator asserts that a validor exists and has a given status (if status!="") and if has a right jailed flag.

func (*Helper) EndBlock

func (h *Helper) EndBlock() sdk.Context

func (*Helper) GenAndApplyEmptyBlock

func (h *Helper) GenAndApplyEmptyBlock(r *rand.Rand) sdk.Context

GenAndApplyEmptyBlock generates a new empty block and appends it to the current blockchain

func (*Helper) Handle

func (h *Helper) Handle(action func(sdk.Context) (proto.Message, error)) *sdk.Result

Handle executes an action function with the Helper's context, wraps the result into an SDK service result, and performs two assertions before returning it

func (*Helper) WrappedBeginRedelegate

func (h *Helper) WrappedBeginRedelegate(delegator sdk.AccAddress, srcVal sdk.ValAddress, dstVal sdk.ValAddress, amount math.Int) *sdk.Result

WrappedBeginRedelegate calls handler to redelegate some stake from a validator to another

func (*Helper) WrappedDelegate

func (h *Helper) WrappedDelegate(delegator sdk.AccAddress, val sdk.ValAddress, amount math.Int) *sdk.Result

WrappedDelegate calls handler to delegate stake for a validator

func (*Helper) WrappedDelegateWithPower

func (h *Helper) WrappedDelegateWithPower(delegator sdk.AccAddress, val sdk.ValAddress, power int64) *sdk.Result

WrappedDelegateWithPower calls handler to delegate stake for a validator

func (*Helper) WrappedUndelegate

func (h *Helper) WrappedUndelegate(delegator sdk.AccAddress, val sdk.ValAddress, amount math.Int) *sdk.Result

WrappedUndelegate calls handler to unbound some stake from a validator.

type ValidatorInfo

type ValidatorInfo struct {
	BlsKey  bls12381.PrivateKey
	Address sdk.ValAddress
}

Jump to

Keyboard shortcuts

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