Skip to content

Commit

Permalink
refactor: remove unused context argument from types/simulation.Random…
Browse files Browse the repository at this point in the history
…Fees
  • Loading branch information
elias-orijtech committed Sep 13, 2023
1 parent d4f874d commit f61d679
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (types/simulation) [#17737](https://github.com/cosmos/cosmos-sdk/pull/17737) Remove unused parameter from `RandomFees`
* (x/staking) [#17486](https://github.com/cosmos/cosmos-sdk/pull/17486) Use collections for `RedelegationQueueKey`:
* remove from `types`: `GetRedelegationTimeKey`
* remove from `Keeper`: `RedelegationQueueIterator`
Expand Down
2 changes: 1 addition & 1 deletion types/simulation/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func FindAccount(accs []Account, address sdk.Address) (Account, bool) {
// RandomFees returns a random fee by selecting a random coin denomination and
// 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) {
func RandomFees(r *rand.Rand, spendableCoins sdk.Coins) (sdk.Coins, error) {
if spendableCoins.Empty() {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion types/simulation/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestRandomFees(t *testing.T) {
tt := tt

t.Run(tt.name, func(t *testing.T) {
got, err := simulation.RandomFees(r, sdk.Context{}, tt.spendableCoins)
got, err := simulation.RandomFees(r, tt.spendableCoins)
if (err != nil) != tt.wantErr {
t.Errorf("RandomFees() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
6 changes: 3 additions & 3 deletions x/authz/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func SimulateMsgGrant(

granterAcc := ak.GetAccount(ctx, granter.Address)
spendableCoins := bk.SpendableCoins(ctx, granter.Address)
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func SimulateMsgRevoke(
}

spendableCoins := bk.SpendableCoins(ctx, granterAddr)
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevoke, "fee error"), nil, err
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func SimulateMsgExec(

msgExec := authz.NewMsgExec(granteeAddr, msg)
granteeSpendableCoins := bk.SpendableCoins(ctx, granteeAddr)
fees, err := simtypes.RandomFees(r, ctx, granteeSpendableCoins)
fees, err := simtypes.RandomFees(r, granteeSpendableCoins)
if err != nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "fee error"), nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func sendMsgSend(

coins, hasNeg := spendable.SafeSub(msg.Amount...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return err
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func sendMsgMultiSend(
spendable := bk.SpendableCoins(ctx, feePayer.GetAddress())
coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep

coins, hasNeg := spendable.SafeSub(fundAmount...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "unable to generate fees"), nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func SimulateMsgDeposit(
var fees sdk.Coins
coins, hasNeg := spendable.SafeSub(deposit...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err
}
Expand Down
28 changes: 14 additions & 14 deletions x/group/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func SimulateMsgCreateGroup(
accAddr := acc.Address.String()

spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroup, "fee error"), nil, err
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func SimulateMsgCreateGroupWithPolicy(
accAddr := acc.Address.String()

spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroup, "fee error"), nil, err
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func SimulateMsgCreateGroupPolicy(
groupID := groupInfo.Id

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, "fee error"), nil, err
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func SimulateMsgSubmitProposal(
}

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "fee error"), nil, err
}
Expand Down Expand Up @@ -494,7 +494,7 @@ func SimulateMsgUpdateGroupAdmin(
groupID := groupInfo.Id

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, "fee error"), nil, err
}
Expand Down Expand Up @@ -559,7 +559,7 @@ func SimulateMsgUpdateGroupMetadata(
groupID := groupInfo.Id

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, "fee error"), nil, err
}
Expand Down Expand Up @@ -615,7 +615,7 @@ func SimulateMsgUpdateGroupMembers(
groupID := groupInfo.Id

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, "fee error"), nil, err
}
Expand Down Expand Up @@ -698,7 +698,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(
groupPolicyAddr := groupPolicy.Address

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, "fee error"), nil, err
}
Expand Down Expand Up @@ -763,7 +763,7 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(
groupPolicyAddr := groupPolicy.Address

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, "fee error"), nil, err
}
Expand Down Expand Up @@ -827,7 +827,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(
groupPolicyAddr := groupPolicy.Address

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "fee error"), nil, err
}
Expand Down Expand Up @@ -932,7 +932,7 @@ func SimulateMsgWithdrawProposal(
proposerAcc := ak.GetAccount(sdkCtx, proposer.Address)

spendableCoins := bk.SpendableCoins(sdkCtx, proposer.Address)
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "fee error"), nil, err
}
Expand Down Expand Up @@ -1003,7 +1003,7 @@ func SimulateMsgVote(
}

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "fee error"), nil, err
}
Expand Down Expand Up @@ -1099,7 +1099,7 @@ func SimulateMsgExec(
groupPolicyAddr := groupPolicy.Address

spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "fee error"), nil, err
}
Expand Down Expand Up @@ -1188,7 +1188,7 @@ func SimulateMsgLeaveGroup(
}

spendableCoins := bk.SpendableCoins(sdkCtx, acc.Address)
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, "fee error"), nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/nft/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func SimulateMsgSend(

senderAcc := ak.GetAccount(ctx, sender.Address)
spendableCoins := bk.SpendableCoins(ctx, sender.Address)
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
fees, err := simtypes.RandomFees(r, spendableCoins)
if err != nil {
return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, err.Error()), nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/simulation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [
return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "message doesn't leave room for fees"), nil, err
}

fees, err = simtypes.RandomFees(txCtx.R, txCtx.Context, coins)
fees, err = simtypes.RandomFees(txCtx.R, coins)
if err != nil {
return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to generate fees"), nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func SimulateMsgUnjail(
account := ak.GetAccount(ctx, sdk.AccAddress(bz))
spendable := bk.SpendableCoins(ctx, account.GetAddress())

fees, err := simtypes.RandomFees(r, ctx, spendable)
fees, err := simtypes.RandomFees(r, spendable)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func SimulateMsgCreateValidator(

coins, hasNeg := spendable.SafeSub(selfDelegation)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func SimulateMsgDelegate(

coins, hasNeg := spendable.SafeSub(bondAmt)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
fees, err = simtypes.RandomFees(r, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err
}
Expand Down

0 comments on commit f61d679

Please sign in to comment.