From d316013f77eb9c4f72e54fbd097b806815ee89d3 Mon Sep 17 00:00:00 2001 From: likhita809 <74715594+likhita809@users.noreply.github.com> Date: Tue, 29 Dec 2020 21:38:07 +0530 Subject: [PATCH] Update randomfees selection of non-zero coins (#8209) * Update randomfees selection of non-zero coins * fix randomfees * fixing account test * fix broadcast.go * fixing * Revert "fixing" This reverts commit b6eaa8d281977451d95e3f5e17792bef642ff65c. * Revert "fix broadcast.go" This reverts commit 2275ea1303b3f5f8c61774a42f17d8a539c3c00a. * Revert "fixing account test" This reverts commit d0d4aa7d5d9421b810bd6582db33ea7dda66a008. * fix randomfees * fix randomfees * remove commented code Co-authored-by: Likhita Polavarapu Co-authored-by: Anil Kumar Kammari --- types/simulation/account.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/types/simulation/account.go b/types/simulation/account.go index e031b5a9eb..5bc5bfe14d 100644 --- a/types/simulation/account.go +++ b/types/simulation/account.go @@ -1,6 +1,7 @@ package simulation import ( + "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -70,11 +71,17 @@ func RandomFees(r *rand.Rand, ctx sdk.Context, spendableCoins sdk.Coins) (sdk.Co return nil, nil } - denomIndex := r.Intn(len(spendableCoins)) - randCoin := spendableCoins[denomIndex] + perm := r.Perm(len(spendableCoins)) + var randCoin sdk.Coin + for _, index := range perm { + randCoin = spendableCoins[index] + if !randCoin.Amount.IsZero() { + break + } + } if randCoin.Amount.IsZero() { - return nil, nil + return nil, fmt.Errorf("no coins found for random fees") } amt, err := RandPositiveInt(r, randCoin.Amount)