From 47a0019ca4b5b284d0d6ca5863496d6ce18cd619 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Wed, 6 Dec 2023 15:09:19 +0100 Subject: [PATCH] tests: update simulation randfees calc --- types/simulation/account.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/types/simulation/account.go b/types/simulation/account.go index b9f69ffa6116..6bd3f7692937 100644 --- a/types/simulation/account.go +++ b/types/simulation/account.go @@ -3,6 +3,7 @@ package simulation import ( "fmt" "math/rand" + "strings" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -66,14 +67,23 @@ func FindAccount(accs []Account, address sdk.Address) (Account, bool) { // amount from the account's available balance. If the user doesn't have enough // funds for paying fees, it returns empty coins. func RandomFees(r *rand.Rand, ctx sdk.Context, spendableCoins sdk.Coins) (sdk.Coins, error) { - if spendableCoins.Empty() { + spendable := sdk.NewCoins() + // remove liquid staking denoms from spendable coins since fees cannot be paid in those denoms + for _, coin := range spendableCoins { + if strings.Contains(coin.Denom, sdk.Bech32PrefixValAddr) { + continue + } + spendable = append(spendable, coin) + } + + if spendable.Empty() { return nil, nil } - perm := r.Perm(len(spendableCoins)) + perm := r.Perm(len(spendable)) var randCoin sdk.Coin for _, index := range perm { - randCoin = spendableCoins[index] + randCoin = spendable[index] if !randCoin.Amount.IsZero() { break }