Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: handle liquid staked coins in sim; update sim ops #21

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 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 @@ -67,14 +68,24 @@ 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
valoperPrefix := fmt.Sprintf("%s%s%s", sdk.Bech32MainPrefix, sdk.PrefixValidator, sdk.PrefixOperator)
sampocs marked this conversation as resolved.
Show resolved Hide resolved
for _, coin := range spendableCoins {
if strings.Contains(coin.Denom, valoperPrefix) {
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
3 changes: 3 additions & 0 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@ func SimulateMsgTokenizeShares(ak types.AccountKeeper, bk types.BankKeeper, k ke
// check that tokenization would not exceed global cap
params := k.GetParams(ctx)
totalStaked := k.TotalBondedTokens(ctx).ToDec()
if totalStaked.IsZero() {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgTokenizeShares, "cannot happend - no validators bonded if stake is 0.0"), nil, nil // skip
}
totalLiquidStaked := k.GetTotalLiquidStakedTokens(ctx).Add(tokenizeShareAmt).ToDec()
liquidStakedPercent := totalLiquidStaked.Quo(totalStaked)
if liquidStakedPercent.GT(params.GlobalLiquidStakingCap) {
Expand Down