simtypes

package
v0.0.0-...-018c514 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAccount

func AddAccount(acc simulation.Account, accs []simulation.Account) []simulation.Account

func FindAccount

func FindAccount(address sdk.Address, accs []simulation.Account) (simulation.Account, bool)

FindAccount iterates over all the simulation accounts to find the one that matches the given address TODO: Benchmark time in here, we should probably just make a hashmap indexing this.

func GetRandSubsetOfKDenoms

func GetRandSubsetOfKDenoms(ctx sdk.Context, r *rand.Rand, acc simulation.Account, k int, bk BankKeeper) (sdk.Coins, bool)

GetRandSubsetOfKDenoms returns a random subset of coins of k unique denoms from the provided account TODO: Write unit test.

func RandCoin

func RandCoin(r *rand.Rand, coins sdk.Coins) sdk.Coins

func RandCoinSubsetFromBalance

func RandCoinSubsetFromBalance(ctx sdk.Context, r *rand.Rand, addr sdk.AccAddress, denoms []string, bk BankKeeper) (sdk.Coins, error)

func RandExponentialCoin

func RandExponentialCoin(r *rand.Rand, coin sdk.Coin) sdk.Coin

RandExponentialCoin uniformly samples a denom from the addr's balances. Then it samples an Exponentially distributed amount of the addr's coins, with rate = 10. (Meaning that on average it samples 10% of the chosen balance) Pre-condition: Addr must have a spendable balance.

func RandExponentialCoinFromBalance

func RandExponentialCoinFromBalance(ctx sdk.Context, r *rand.Rand, addr sdk.AccAddress, bk BankKeeper) sdk.Coin

RandExponentialCoinFromBalance uniformly samples a denom from the addr's balances. Then it samples an Exponentially distributed amount of the addr's coins, with rate = 10. (Meaning that on average it samples 10% of the chosen balance) Pre-condition: Addr must have a spendable balance.

func RandIntBetween

func RandIntBetween(r *rand.Rand, min, max int) int

RandIntBetween returns a random int between two numbers inclusively.

func RandLTBound

func RandLTBound[T constraints.Integer](r *rand.Rand, upperbound T) T

func RandLTEBound

func RandLTEBound[T constraints.Integer](r *rand.Rand, upperbound T) T

func RandPositiveInt

func RandPositiveInt(r *rand.Rand, max sdkmath.Int) (sdkmath.Int, error)

RandPositiveInt get a rand positive sdk.Int.

func RandSelect

func RandSelect[T interface{}](r *rand.Rand, args ...T) T

func RandStringOfLength

func RandStringOfLength(r *rand.Rand, n int) string

RandStringOfLength generates a random string of a particular length.

func RandSubsetCoins

func RandSubsetCoins(r *rand.Rand, coins sdk.Coins) sdk.Coins

RandSubsetCoins returns random subset of the provided coins will return at least one coin unless coins argument is empty or malformed i.e. 0 amt in coins.

func RandTimestamp

func RandTimestamp(r *rand.Rand) time.Time

RandTimestamp generates a random timestamp.

func RandomAmount

func RandomAmount(r *rand.Rand, max sdkmath.Int) sdkmath.Int

RandomAmount generates a random amount. Note: The range of RandomAmount includes max, and is, in fact, biased to return max as well as 0.

func RandomDecAmount

func RandomDecAmount(r *rand.Rand, max sdk.Dec) sdk.Dec

RandomDecAmount generates a random decimal amount Note: The range of RandomDecAmount includes max, and is, in fact, biased to return max as well as 0.

func RandomExistingAddress

func RandomExistingAddress(r *rand.Rand, accs []simulation.Account) sdk.AccAddress

func RandomFees

func RandomFees(r *rand.Rand, spendableCoins sdk.Coins) (sdk.Coins, error)

RandomFees returns a random fee by selecting a random coin denomination and amount from the account's available balance. If the user doesn't have enough funds for paying fees, it returns empty coins.

func RandomSimAccount

func RandomSimAccount(r *rand.Rand, accs []simulation.Account) simulation.Account

func RandomSimAccountWithBalance

func RandomSimAccountWithBalance(ctx sdk.Context, r *rand.Rand, accs []simulation.Account, bk BankKeeper) (simulation.Account, error)

func RandomSimAccountWithConstraint

func RandomSimAccountWithConstraint(r *rand.Rand, f SimAccountConstraint, accs []simulation.Account) (simulation.Account, bool)

returns acc, accExists := sim.RandomSimAccountWithConstraint(f) where acc is a uniformly sampled account from all accounts satisfying the constraint f a constraint is satisfied for an account `acc` if f(acc) = true accExists is false, if there is no such account.

func RandomSimAccountWithKDenoms

func RandomSimAccountWithKDenoms(ctx sdk.Context, r *rand.Rand, accs []simulation.Account, k int, bk BankKeeper) (simulation.Account, bool)

RandomSimAccountWithKDenoms returns an account that possesses k unique denoms.

func RandomSimAccountWithMinCoins

func RandomSimAccountWithMinCoins(ctx sdk.Context, r *rand.Rand, accs []simulation.Account, coins sdk.Coins, bk BankKeeper) (simulation.Account, error)

func RemoveIndex

func RemoveIndex(s sdk.Coins, index int) sdk.Coins

func SelAddrWithDenom

func SelAddrWithDenom(ctx sdk.Context, r *rand.Rand, accs []simulation.Account, denom string, bk BankKeeper) (simulation.Account, sdk.Coin, bool)

SelAddrWithDenom attempts to find an address with the provided denom. This function returns (account, randSubsetCoins, found), so if found = false, then no such address exists. randSubsetCoins is a random subset of the provided denoms, if the account is found. TODO: Write unit test.

func SelAddrWithDenoms

func SelAddrWithDenoms(ctx sdk.Context, r *rand.Rand, accs []simulation.Account, denoms []string, bk BankKeeper) (simulation.Account, sdk.Coins, bool)

Returns (account, randSubsetCoins, found), so if found = false, then no such address exists. randSubsetCoins is a random subset of the provided denoms, if the account is found. TODO: Write unit test.

Types

type AccountKeeper

type AccountKeeper interface {
	GetModuleAddress(name string) sdk.AccAddress
	HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool

	// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
	SetModuleAccount(sdk.Context, types.ModuleAccountI)
	GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI
}

AccountKeeper defines the contract required for account APIs.

type BankKeeper

type BankKeeper interface {
	GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
	MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
	BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
	SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
}

BankKeeper defines the contract needed to be fulfilled for banking and supply dependencies.

type DistrKeeper

type DistrKeeper interface {
	FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
}

DistrKeeper defines the contract needed to be fulfilled for distribution keeper.

type SimAccountConstraint

type SimAccountConstraint = func(account simulation.Account) bool

Jump to

Keyboard shortcuts

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