-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure only
sdk.DefaultBondDenom
is used for fees in our modu…
…les simulation (#743) * init `rand` seed in non-determinism simulation * add random fee function to `sample` * fix simulation for `msgParticipate` * use custom `GenAndDeliverTxWithRandFees`
- Loading branch information
Showing
17 changed files
with
323 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package simulation | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/simapp/helpers" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
sdksimulation "github.com/cosmos/cosmos-sdk/x/simulation" | ||
|
||
"github.com/tendermint/spn/testutil/sample" | ||
) | ||
|
||
// GenAndDeliverTxWithRandFees generates a transaction with a random fee and delivers it. | ||
func GenAndDeliverTxWithRandFees(txCtx sdksimulation.OperationInput, gas uint64) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
account := txCtx.AccountKeeper.GetAccount(txCtx.Context, txCtx.SimAccount.Address) | ||
spendable := txCtx.Bankkeeper.SpendableCoins(txCtx.Context, account.GetAddress()) | ||
|
||
var fees sdk.Coins | ||
var err error | ||
|
||
coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg) | ||
if hasNeg { | ||
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err | ||
} | ||
|
||
fees, err = sample.Fees(txCtx.R, coins) | ||
if err != nil { | ||
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate fees"), nil, err | ||
} | ||
return GenAndDeliverTx(txCtx, fees, gas) | ||
} | ||
|
||
// GenAndDeliverTx generates a transactions and delivers it. | ||
func GenAndDeliverTx(txCtx sdksimulation.OperationInput, fees sdk.Coins, gas uint64) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
account := txCtx.AccountKeeper.GetAccount(txCtx.Context, txCtx.SimAccount.Address) | ||
tx, err := helpers.GenTx( | ||
txCtx.TxGen, | ||
[]sdk.Msg{txCtx.Msg}, | ||
fees, | ||
gas, | ||
txCtx.Context.ChainID(), | ||
[]uint64{account.GetAccountNumber()}, | ||
[]uint64{account.GetSequence()}, | ||
txCtx.SimAccount.PrivKey, | ||
) | ||
|
||
if err != nil { | ||
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate mock tx"), nil, err | ||
} | ||
|
||
_, _, err = txCtx.App.Deliver(txCtx.TxGen.TxEncoder(), tx) | ||
if err != nil { | ||
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to deliver tx"), nil, err | ||
} | ||
|
||
return simtypes.NewOperationMsg(txCtx.Msg, true, "", txCtx.Cdc), nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.