wasmd/x/wasm/simulation/sim_utils.go

53 lines
1.9 KiB
Go

package simulation
import (
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
// GenAndDeliverTxWithRandFees generates a transaction with a random fee and delivers it.
func GenAndDeliverTxWithRandFees(txCtx simulation.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 = simtypes.RandomFees(txCtx.R, txCtx.Context, 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 simulation.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
}