refactor(sims)!: Remove Baseapp from sims (#21039)

This commit is contained in:
Alexander Peters
2024-07-24 12:40:01 +00:00
committed by GitHub
parent b536d11532
commit 1f0ce2f5b5
36 changed files with 140 additions and 255 deletions
+16 -6
View File
@@ -1,15 +1,18 @@
package simulation
import (
"context"
"encoding/json"
"math/rand"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/types"
"cosmossdk.io/core/address"
stakingtypes "cosmossdk.io/x/staking/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/simulation"
)
@@ -125,13 +128,20 @@ func NewSimLegacyParamChange(subspace, key string, simVal simulation.SimValFn) s
// WeightedProposalMsg defines a common struct for proposal msgs defined by external modules (i.e outside gov)
type WeightedProposalMsg struct {
appParamsKey string // key used to retrieve the value of the weight from the simulation application params
defaultWeight int // default weight
msgSimulatorFn simulation.MsgSimulatorFn // msg simulator function
appParamsKey string // key used to retrieve the value of the weight from the simulation application params
defaultWeight int // default weight
msgSimulatorFnX simulation.MsgSimulatorFnX // msg simulator function
}
// Deprecated: use NewWeightedProposalMsgX instead
func NewWeightedProposalMsg(appParamsKey string, defaultWeight int, msgSimulatorFn simulation.MsgSimulatorFn) simulation.WeightedProposalMsg {
return &WeightedProposalMsg{appParamsKey: appParamsKey, defaultWeight: defaultWeight, msgSimulatorFn: msgSimulatorFn}
return NewWeightedProposalMsgX(appParamsKey, defaultWeight, func(_ context.Context, r *rand.Rand, accs []simulation.Account, cdc address.Codec) (sdk.Msg, error) {
return msgSimulatorFn(r, accs, cdc)
})
}
func NewWeightedProposalMsgX(appParamsKey string, defaultWeight int, msgSimulatorFn simulation.MsgSimulatorFnX) simulation.WeightedProposalMsg {
return &WeightedProposalMsg{appParamsKey: appParamsKey, defaultWeight: defaultWeight, msgSimulatorFnX: msgSimulatorFn}
}
func (w WeightedProposalMsg) AppParamsKey() string {
@@ -142,8 +152,8 @@ func (w WeightedProposalMsg) DefaultWeight() int {
return w.defaultWeight
}
func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFn {
return w.msgSimulatorFn
func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFnX {
return w.msgSimulatorFnX
}
// Legacy Proposal Content
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"math/rand"
"testing"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
@@ -65,7 +64,7 @@ func mustMarshalJSONIndent(o interface{}) []byte {
// OperationInput is a struct that holds all the needed values to generate a tx and deliver it
type OperationInput struct {
R *rand.Rand
App *baseapp.BaseApp
App simtypes.AppEntrypoint
TxGen client.TxConfig
Cdc *codec.ProtoCodec
Msg sdk.Msg