refactor!: MsgSimulatorFn clean up (#19792)
This commit is contained in:
parent
3ed9f7fc69
commit
0c2decd7cd
@ -101,8 +101,8 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (types) [#19792](https://github.com/cosmos/cosmos-sdk/pull/19792) In `MsgSimulatorFn` `sdk.Context` argument is replaced for an `address.Codec`. It also returns an error.
|
||||
* (types) [#19742](https://github.com/cosmos/cosmos-sdk/pull/19742) Removes the use of `Accounts.String`
|
||||
* `MsgSimulatorFn` now takes an `address.Codec` as argument and also returns an error.
|
||||
* `SimulationState` now has address and validator codecs as fields.
|
||||
* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument.
|
||||
* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`).
|
||||
|
||||
@ -147,12 +147,12 @@ If you were depending on `cosmossdk.io/api/tendermint`, please use the buf gener
|
||||
|
||||
##### Simulation
|
||||
|
||||
As an effort to remove the use of the global config, `sdk.Address.String` method must be removed. As a consequence, `MsgSimulatorFn` has been updated to return an error and use an `address.Codec` to set
|
||||
`staking.MsgUpdateParams.Authority`.
|
||||
`MsgSimulatorFn` has been updated to return an error. Its context argument has been removed, and an address.Codec has
|
||||
been added to avoid the use of the Accounts.String() method.
|
||||
|
||||
```diff
|
||||
-type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg
|
||||
+type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account, cdc address.Codec) (sdk.Msg, error)
|
||||
+type MsgSimulatorFn func(r *rand.Rand, accs []Account, cdc address.Codec) (sdk.Msg, error)
|
||||
```
|
||||
|
||||
##### Core API
|
||||
|
||||
@ -2,12 +2,13 @@ package root
|
||||
|
||||
import (
|
||||
corestore "cosmossdk.io/core/store"
|
||||
|
||||
"cosmossdk.io/store/v2"
|
||||
)
|
||||
|
||||
var _ corestore.Reader = (*Reader)(nil)
|
||||
var _ corestore.ReaderMap = (*ReaderMap)(nil)
|
||||
var (
|
||||
_ corestore.Reader = (*Reader)(nil)
|
||||
_ corestore.ReaderMap = (*ReaderMap)(nil)
|
||||
)
|
||||
|
||||
// ReaderMap defines an adapter around a RootStore that only exposes read-only
|
||||
// operations. This is useful for exposing a read-only view of the RootStore at
|
||||
|
||||
@ -56,7 +56,7 @@ func (m MockWeightedProposals) DefaultWeight() int {
|
||||
}
|
||||
|
||||
func (m MockWeightedProposals) MsgSimulatorFn() simtypes.MsgSimulatorFn {
|
||||
return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ address.Codec) (sdk.Msg, error) {
|
||||
return func(r *rand.Rand, _ []simtypes.Account, _ address.Codec) (sdk.Msg, error) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ type WeightedProposalMsg interface {
|
||||
MsgSimulatorFn() MsgSimulatorFn // msg simulator function
|
||||
}
|
||||
|
||||
type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account, cdc address.Codec) (sdk.Msg, error)
|
||||
type MsgSimulatorFn func(r *rand.Rand, accs []Account, cdc address.Codec) (sdk.Msg, error)
|
||||
|
||||
type SimValFn func(r *rand.Rand) string
|
||||
|
||||
|
||||
@ -5,8 +5,9 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
)
|
||||
|
||||
func UnpackAnyRaw(m *codectypes.Any) (proto.Message, error) {
|
||||
|
||||
@ -31,7 +31,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -33,7 +32,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -31,7 +31,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -33,7 +32,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -32,7 +32,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -34,7 +33,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -155,7 +155,7 @@ func SimulateMsgSubmitProposal(
|
||||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
||||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
||||
msgs := []sdk.Msg{}
|
||||
proposalMsg, err := msgSim(r, ctx, accs, ak.AddressCodec())
|
||||
proposalMsg, err := msgSim(r, accs, ak.AddressCodec())
|
||||
if err != nil {
|
||||
return simtypes.OperationMsg{}, nil, err
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
|
||||
// SimulateTextProposal returns a random text proposal content.
|
||||
// A text proposal is a proposal that contains no msgs.
|
||||
func SimulateTextProposal(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateTextProposal(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -31,7 +30,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightSubmitTextProposal, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, msg == nil)
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -34,7 +33,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -28,7 +28,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
}
|
||||
|
||||
func SimulateMsgCommunityPoolSpend(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgCommunityPoolSpend(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -33,7 +32,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgCommunityPoolSpend, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgCommunityPoolSpend, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgCommunityPoolSpend, ok := msg.(*pooltypes.MsgCommunityPoolSpend)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -33,7 +33,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
|
||||
// execute ProposalMsgs function
|
||||
@ -35,7 +34,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
@ -33,7 +33,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg {
|
||||
}
|
||||
|
||||
// SimulateMsgUpdateParams returns a random MsgUpdateParams
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account, addressCodec coreaddress.Codec) (sdk.Msg, error) {
|
||||
func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, addressCodec coreaddress.Codec) (sdk.Msg, error) {
|
||||
// use the default gov module account address as authority
|
||||
var authority sdk.AccAddress = address.Module("gov")
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"cosmossdk.io/x/staking/types"
|
||||
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
)
|
||||
@ -22,7 +21,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
ctx := sdk.NewContext(nil, true, nil)
|
||||
accounts := simtypes.RandomAccounts(r, 3)
|
||||
addressCodec := codectestutil.CodecOptions{}.GetAddressCodec()
|
||||
// execute ProposalMsgs function
|
||||
@ -35,7 +33,7 @@ func TestProposalMsgs(t *testing.T) {
|
||||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
|
||||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
|
||||
|
||||
msg, err := w0.MsgSimulatorFn()(r, ctx, accounts, addressCodec)
|
||||
msg, err := w0.MsgSimulatorFn()(r, accounts, addressCodec)
|
||||
assert.NilError(t, err)
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user