Skip to content

Commit

Permalink
tests: update simulation randfees calc
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Dec 6, 2023
1 parent 743f059 commit 47a0019
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions types/simulation/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {

Check warning

Code scanning / CodeQL

Directly using the bech32 constants Warning

Directly using the bech32 constants instead of the configuration values
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
}
Expand Down

0 comments on commit 47a0019

Please sign in to comment.