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

Limit simulation fee token to only sdk.DefaultBondDenom #42

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,17 @@ func (coins Coins) GetDenomByIndex(i int) string {
return coins[i].Denom
}

// FilterDenoms returns the coins with only the passed in denoms
func (coins Coins) FilterDenoms(denoms []string) Coins {
filteredCoins := NewCoins()

for _, denom := range denoms {
filteredCoins.Add(NewCoin(denom, coins.AmountOf(denom)))
}

return filteredCoins
}

// IsAllPositive returns true if there is at least one coin and all currencies
// have a positive value.
func (coins Coins) IsAllPositive() bool {
Expand Down
6 changes: 4 additions & 2 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func sendMsgSend(

coins, hasNeg := spendable.SafeSub(msg.Amount)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return err
}
Expand Down Expand Up @@ -255,7 +256,8 @@ func sendMsgMultiSend(

coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions x/distribution/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper,
account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSetWithdrawAddress, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -145,7 +146,8 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee
account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawDelegatorReward, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -200,7 +202,8 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban
account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -255,7 +258,8 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k

coins, hasNeg := spendable.SafeSub(fundAmount)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgFundCommunityPool, "unable to generate fees"), nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func SimulateMsgSubmitProposal(
var fees sdk.Coins
coins, hasNeg := spendable.SafeSub(deposit)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -223,7 +224,8 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
var fees sdk.Coins
coins, hasNeg := spendable.SafeSub(deposit)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -286,7 +288,8 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee
account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee
account := ak.GetAccount(ctx, sdk.AccAddress(validator.GetOperator()))
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to generate fees"), nil, err
}
Expand Down
16 changes: 11 additions & 5 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k

coins, hasNeg := spendable.SafeSub(sdk.Coins{selfDelegation})
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fmt.Println(feeCoins.String())
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -207,7 +209,8 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee
account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -286,7 +289,8 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K

coins, hasNeg := spendable.SafeSub(sdk.Coins{bondAmt})
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
feeCoins := coins.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err = simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -378,7 +382,8 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper
account := ak.GetAccount(ctx, delAddr)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -485,7 +490,8 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k
account := ak.GetAccount(ctx, delAddr)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
feeCoins := spendable.FilterDenoms([]string{sdk.DefaultBondDenom})
fees, err := simtypes.RandomFees(r, ctx, feeCoins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to generate fees"), nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions x/staking/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func TestSimulateMsgCreateValidator(t *testing.T) {
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "0.080000000000000000", msg.Commission.MaxChangeRate.String())
require.Equal(t, "0.080000000000000000", msg.Commission.MaxRate.String())
require.Equal(t, "0.019527679037870745", msg.Commission.Rate.String())
require.Equal(t, "0.249094493096653750", msg.Commission.MaxChangeRate.String())
require.Equal(t, "0.470000000000000000", msg.Commission.MaxRate.String())
require.Equal(t, "0.398173207580023280", msg.Commission.Rate.String())
require.Equal(t, types.TypeMsgCreateValidator, msg.Type())
require.Equal(t, []byte{0xa, 0x20, 0x51, 0xde, 0xbd, 0xe8, 0xfa, 0xdf, 0x4e, 0xfc, 0x33, 0xa5, 0x16, 0x94, 0xf6, 0xee, 0xd3, 0x69, 0x7a, 0x7a, 0x1c, 0x2d, 0x50, 0xb6, 0x2, 0xf7, 0x16, 0x4e, 0x66, 0x9f, 0xff, 0x38, 0x91, 0x9b}, msg.Pubkey.Value)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress)
Expand Down Expand Up @@ -120,10 +120,10 @@ func TestSimulateMsgEditValidator(t *testing.T) {

require.True(t, operationMsg.OK)
require.Equal(t, "0.280623462081924936", msg.CommissionRate.String())
require.Equal(t, "rBqDOTtGTO", msg.Description.Moniker)
require.Equal(t, "BSpYuLyYgg", msg.Description.Identity)
require.Equal(t, "wNbeHVIkPZ", msg.Description.Website)
require.Equal(t, "MOXcnQfyze", msg.Description.SecurityContact)
require.Equal(t, "xKGLwQvuyN", msg.Description.Moniker)
require.Equal(t, "SlcxgdXhhu", msg.Description.Identity)
require.Equal(t, "WeLrQKjLxz", msg.Description.Website)
require.Equal(t, "rBqDOTtGTO", msg.Description.SecurityContact)
require.Equal(t, types.TypeMsgEditValidator, msg.Type())
require.Equal(t, "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress)
require.Len(t, futureOperations, 0)
Expand Down