util

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainID = "test-app"
)

Variables

View Source
var (
	// ModuleBasics is a mock module basic manager for testing
	ModuleBasics = app.ModuleBasics
	// TestingStakeParams is a set of staking params for testing
	TestingStakeParams = stakingtypes.Params{
		UnbondingTime:     100,
		MaxValidators:     10,
		MaxEntries:        10,
		HistoricalEntries: 10000,
		BondDenom:         "stake",
		MinCommissionRate: sdk.NewDecWithPrec(0, 0),
	}

	// ConsPrivKeys generate ed25519 ConsPrivKeys to be used for validator operator keys
	ConsPrivKeys = []ccrypto.PrivKey{
		ed25519.GenPrivKey(),
		ed25519.GenPrivKey(),
		ed25519.GenPrivKey(),
		ed25519.GenPrivKey(),
		ed25519.GenPrivKey(),
	}

	// ConsPubKeys holds the consensus public keys to be used for validator operator keys
	ConsPubKeys = []ccrypto.PubKey{
		ConsPrivKeys[0].PubKey(),
		ConsPrivKeys[1].PubKey(),
		ConsPrivKeys[2].PubKey(),
		ConsPrivKeys[3].PubKey(),
		ConsPrivKeys[4].PubKey(),
	}

	// AccPrivKeys generate secp256k1 pubkeys to be used for account pub keys
	AccPrivKeys = []ccrypto.PrivKey{
		secp256k1.GenPrivKey(),
		secp256k1.GenPrivKey(),
		secp256k1.GenPrivKey(),
		secp256k1.GenPrivKey(),
		secp256k1.GenPrivKey(),
	}

	// AccPubKeys holds the pub keys for the account keys
	AccPubKeys = []ccrypto.PubKey{
		AccPrivKeys[0].PubKey(),
		AccPrivKeys[1].PubKey(),
		AccPrivKeys[2].PubKey(),
		AccPrivKeys[3].PubKey(),
		AccPrivKeys[4].PubKey(),
	}

	// AccAddrs holds the sdk.AccAddresses
	AccAddrs = []sdk.AccAddress{
		sdk.AccAddress(AccPubKeys[0].Address()),
		sdk.AccAddress(AccPubKeys[1].Address()),
		sdk.AccAddress(AccPubKeys[2].Address()),
		sdk.AccAddress(AccPubKeys[3].Address()),
		sdk.AccAddress(AccPubKeys[4].Address()),
	}

	// ValAddrs holds the sdk.ValAddresses
	ValAddrs = []sdk.ValAddress{
		sdk.ValAddress(AccPubKeys[0].Address()),
		sdk.ValAddress(AccPubKeys[1].Address()),
		sdk.ValAddress(AccPubKeys[2].Address()),
		sdk.ValAddress(AccPubKeys[3].Address()),
		sdk.ValAddress(AccPubKeys[4].Address()),
	}

	// EVMAddrs holds etheruem addresses
	EVMAddrs = initEVMAddrs(100)

	// InitTokens holds the number of tokens to initialize an account with
	InitTokens = sdk.TokensFromConsensusPower(110, sdk.DefaultPowerReduction)

	// InitCoins holds the number of coins to initialize an account with
	InitCoins = sdk.NewCoins(sdk.NewCoin(TestingStakeParams.BondDenom, InitTokens))

	// StakingAmount holds the staking power to start a validator with
	StakingAmount = sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
)

Functions

func AddDeterministicValidatorToGenesis added in v1.12.0

func AddDeterministicValidatorToGenesis(g *genesis.Genesis) error

AddDeterministicValidatorToGenesis adds a single deterministic validator to the genesis.

func AddGenesisAccount

func AddGenesisAccount(addr sdk.AccAddress, appState app.GenesisState, cdc codec.Codec) (map[string]json.RawMessage, error)

AddGenesisAccount mimics the cli addGenesisAccount command, providing an account with an allocation of to "token" and "tia" tokens in the genesis state

func CreateValidator

func CreateValidator(
	t *testing.T,
	input TestInput,
	accAddr sdk.AccAddress,
	accPubKey ccrypto.PubKey,
	accountNumber uint64,
	valAddr sdk.ValAddress,
	consPubKey ccrypto.PubKey,
	stakingAmount cosmosmath.Int,
)

func DirectQueryAccount

func DirectQueryAccount(app *app.App, addr sdk.AccAddress) authtypes.AccountI

func ExecuteQGBHeights

func ExecuteQGBHeights(ctx sdk.Context, qgbKeeper keeper.Keeper, beginHeight int64, endHeight int64) sdk.Context

ExecuteQGBHeights executes the end exclusive range of heights specified by beginHeight and endHeight along with the QGB abci.EndBlocker on each one of them. Returns the updated context with block height advanced to endHeight.

func ExecuteQGBHeightsWithTime

func ExecuteQGBHeightsWithTime(ctx sdk.Context, qgbKeeper keeper.Keeper, beginHeight int64, endHeight int64, blockInterval time.Duration) sdk.Context

ExecuteQGBHeightsWithTime executes the end exclusive range of heights specified by beginHeight and endHeight along with the QGB abci.EndBlocker on each one of them. Uses the interval to calculate the block header time.

func GenesisStateWithSingleValidator

func GenesisStateWithSingleValidator(testApp *app.App, genAccounts ...string) (app.GenesisState, *tmtypes.ValidatorSet, keyring.Keyring)

GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts that also act as delegators.

func MakeTestCodec

func MakeTestCodec() *codec.LegacyAmino

MakeTestCodec creates a legacy amino codec for testing

func MakeTestMarshaler

func MakeTestMarshaler() codec.Codec

MakeTestMarshaler creates a proto codec for use in testing

func NewDefaultGenesisState

func NewDefaultGenesisState(cdc codec.JSONCodec) app.GenesisState

NewDefaultGenesisState generates the default state for the application.

func NewTestApp added in v1.12.0

func NewTestApp() *app.App

NewTestApp initializes a new app with a no-op logger and in-memory database.

func NewTestMsgCreateValidator

func NewTestMsgCreateValidator(
	address sdk.ValAddress,
	pubKey ccrypto.PubKey,
	amt cosmosmath.Int,
) *stakingtypes.MsgCreateValidator

func NewTestMsgUnDelegateValidator

func NewTestMsgUnDelegateValidator(address sdk.ValAddress, amt cosmosmath.Int) *stakingtypes.MsgUndelegate

func RandBlobTxsWithAccounts

func RandBlobTxsWithAccounts(
	_ *testing.T,
	capp *app.App,
	_ sdk.TxEncoder,
	kr keyring.Keyring,
	size int,
	blobCount int,
	randSize bool,
	chainid string,
	accounts []string,
	extraOpts ...blobtypes.TxBuilderOption,
) []coretypes.Tx

RandBlobTxsWithAccounts will create random blob transactions using the provided configuration. The account info is queried directly from the application. One blob transaction is generated per account provided.

func RandBlobTxsWithManualSequence

func RandBlobTxsWithManualSequence(
	t *testing.T,
	_ sdk.TxEncoder,
	kr keyring.Keyring,
	size int,
	blobCount int,
	randSize bool,
	chainid string,
	accounts []string,
	sequence, accountNum uint64,
	invalidSignature bool,
) []coretypes.Tx

RandBlobTxsWithManualSequence will create random blob transactions using the provided configuration. One blob transaction is generated per account provided. The sequence and account numbers are set manually using the provided values.

func RegisterEVMAddress

func RegisterEVMAddress(
	t *testing.T,
	input TestInput,
	valAddr sdk.ValAddress,
	evmAddr gethcommon.Address,
)

func SendTxWithManualSequence

func SendTxWithManualSequence(
	t *testing.T,
	_ sdk.TxEncoder,
	kr keyring.Keyring,
	fromAcc, toAcc string,
	amount uint64,
	chainid string,
	sequence, accountNum uint64,
	opts ...blobtypes.TxBuilderOption,
) coretypes.Tx

SendTxsWithAccounts will create a send transaction per account provided. The account info must be provided.

func SendTxsWithAccounts

func SendTxsWithAccounts(
	t *testing.T,
	capp *app.App,
	enc sdk.TxEncoder,
	kr keyring.Keyring,
	amount uint64,
	toAccount string,
	accounts []string,
	chainid string,
	extraOpts ...blobtypes.TxBuilderOption,
) []coretypes.Tx

SendTxsWithAccounts will create a send transaction per account provided, and send all funds to the "toAccount". The account info is queried directly from the application.

func SetupDeterministicGenesisState added in v1.12.0

func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubKey, balance int64, cparams *tmproto.ConsensusParams) (keyring.Keyring, []genesis.Account, error)

SetupDeterministicGenesisState sets genesis on initialized testApp with the provided arguments.

func SetupTestAppWithGenesisValSet

func SetupTestAppWithGenesisValSet(cparams *tmproto.ConsensusParams, genAccounts ...string) (*app.App, keyring.Keyring)

SetupTestAppWithGenesisValSet initializes a new app with a validator set and genesis accounts that also act as delegators. For simplicity, each validator is bonded with a delegation of one consensus engine unit in the default token of the app from first genesis account. A no-op logger is set in app.

Types

type EmptyAppOptions added in v1.12.0

type EmptyAppOptions struct{}

func (EmptyAppOptions) Get added in v1.12.0

func (ao EmptyAppOptions) Get(_ string) interface{}

Get implements AppOptions

type TestInput

type TestInput struct {
	QgbKeeper      keeper.Keeper
	AccountKeeper  authkeeper.AccountKeeper
	StakingKeeper  stakingkeeper.Keeper
	SlashingKeeper slashingkeeper.Keeper
	DistKeeper     distrkeeper.Keeper
	BankKeeper     bankkeeper.BaseKeeper
	Context        sdk.Context
	Marshaler      codec.Codec
	LegacyAmino    *codec.LegacyAmino
}

TestInput stores the various keepers required to test the QGB

func CreateTestEnv

func CreateTestEnv(t *testing.T) TestInput

CreateTestEnv creates the keeper testing environment for QGB

func CreateTestEnvWithoutQGBKeysInit

func CreateTestEnvWithoutQGBKeysInit(t *testing.T) TestInput

CreateTestEnvWithoutQGBKeysInit creates the keeper testing environment for the QGB

func SetupFiveValChain

func SetupFiveValChain(t *testing.T) (TestInput, sdk.Context)

SetupFiveValChain does all the initialization for a 5 Validator chain using the keys here

func SetupTestChain

func SetupTestChain(t *testing.T, weights []uint64) (TestInput, sdk.Context)

SetupTestChain sets up a test environment with the provided validator voting weights

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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