diff --git a/x/authz/client/cli/service_msg_client.go b/simapp/helpers/service_msg_client.go similarity index 67% rename from x/authz/client/cli/service_msg_client.go rename to simapp/helpers/service_msg_client.go index 001b37fa4d38..d13761e663a0 100644 --- a/x/authz/client/cli/service_msg_client.go +++ b/simapp/helpers/service_msg_client.go @@ -1,4 +1,4 @@ -package cli +package helpers import ( "context" @@ -10,16 +10,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ gogogrpc.ClientConn = &serviceMsgClientConn{} +var _ gogogrpc.ClientConn = &ServiceMsgClientConn{} -// serviceMsgClientConn is an instance of grpc.ClientConn that is used to test building +// ServiceMsgClientConn is an instance of grpc.ClientConn that is used to test building // transactions with MsgClient's. It is intended to be replaced by the work in // https://github.com/cosmos/cosmos-sdk/issues/7541 when that is ready. -type serviceMsgClientConn struct { - msgs []sdk.Msg +type ServiceMsgClientConn struct { + Msgs []sdk.Msg } -func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc.CallOption) error { +func (t *ServiceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc.CallOption) error { req, ok := args.(sdk.MsgRequest) if !ok { return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil)) @@ -30,7 +30,7 @@ func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ return err } - t.msgs = append(t.msgs, sdk.ServiceMsg{ + t.Msgs = append(t.Msgs, sdk.ServiceMsg{ MethodName: method, Request: req, }) @@ -38,6 +38,6 @@ func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ return nil } -func (t *serviceMsgClientConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { +func (t *ServiceMsgClientConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { return nil, fmt.Errorf("not supported") } diff --git a/types/simulation/types.go b/types/simulation/types.go index f541b1d764de..7274fdefd61f 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -3,6 +3,7 @@ package simulation import ( "encoding/json" "math/rand" + "reflect" "time" "github.com/cosmos/cosmos-sdk/baseapp" @@ -75,7 +76,16 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper } // NewOperationMsg - create a new operation message from sdk.Msg -func NewOperationMsg(msg sdk.Msg, ok bool, comment string) OperationMsg { +func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg { + if reflect.TypeOf(msg) == reflect.TypeOf(sdk.ServiceMsg{}) { + srvMsg, ok := msg.(sdk.ServiceMsg) + if !ok { + panic("failed: type assert") + } + bz := cdc.MustMarshalJSON(srvMsg.Request) + + return NewOperationMsgBasic(srvMsg.MethodName, srvMsg.MethodName, comment, ok, bz) + } return NewOperationMsgBasic(msg.Route(), msg.Type(), comment, ok, msg.GetSignBytes()) } diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 97dbf6453040..cef6a2943423 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -87,14 +88,14 @@ Examples: return err } - svcMsgClientConn := &serviceMsgClientConn{} + svcMsgClientConn := &helpers.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.GrantAuthorization(context.Background(), msg) if err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...) }, } @@ -131,14 +132,14 @@ Example: msg := types.NewMsgRevokeAuthorization(granter, grantee, msgAuthorized) - svcMsgClientConn := &serviceMsgClientConn{} + svcMsgClientConn := &helpers.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.RevokeAuthorization(context.Background(), &msg) if err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...) }, } flags.AddTxFlagsToCmd(cmd) @@ -180,14 +181,14 @@ Example: } msg := types.NewMsgExecAuthorized(grantee, serviceMsgs) - svcMsgClientConn := &serviceMsgClientConn{} + svcMsgClientConn := &helpers.ServiceMsgClientConn{} authzMsgClient := types.NewMsgClient(svcMsgClientConn) _, err = authzMsgClient.ExecAuthorized(context.Background(), &msg) if err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.Msgs...) }, } diff --git a/x/authz/simulation/decoder.go b/x/authz/simulation/decoder.go index cfae11cae411..c87f7a70c13a 100644 --- a/x/authz/simulation/decoder.go +++ b/x/authz/simulation/decoder.go @@ -18,7 +18,6 @@ func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { var grantA, grantB types.AuthorizationGrant cdc.MustUnmarshalBinaryBare(kvA.Value, &grantA) cdc.MustUnmarshalBinaryBare(kvB.Value, &grantB) - fmt.Println(grantA) return fmt.Sprintf("%v\n%v", grantA, grantB) default: panic(fmt.Sprintf("invalid authz key %X", kvA.Key)) diff --git a/x/authz/simulation/genesis.go b/x/authz/simulation/genesis.go new file mode 100644 index 000000000000..6e5a5b7bc68b --- /dev/null +++ b/x/authz/simulation/genesis.go @@ -0,0 +1,38 @@ +package simulation + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/types" +) + +// Simulation parameter constant. +const authz = "authz" + +// GenAuthorizationGrant returns an empty slice of authorization grants. +func GenAuthorizationGrant(_ *rand.Rand, _ []simtypes.Account) []types.MsgGrantAuthorization { + return []types.MsgGrantAuthorization{} +} + +// RandomizedGenState generates a random GenesisState for authz. +func RandomizedGenState(simState *module.SimulationState) { + var grants []types.MsgGrantAuthorization + + simState.AppParams.GetOrGenerate( + simState.Cdc, authz, &grants, simState.Rand, + func(r *rand.Rand) { grants = GenAuthorizationGrant(r, simState.Accounts) }, + ) + authzGrantsGenesis := types.NewGenesisState(grants) + + bz, err := json.MarshalIndent(&authzGrantsGenesis, "", " ") + if err != nil { + panic(err) + } + + fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(authzGrantsGenesis) +} diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go new file mode 100644 index 000000000000..4672d195ec0a --- /dev/null +++ b/x/authz/simulation/genesis_test.go @@ -0,0 +1,40 @@ +package simulation_test + +import ( + "encoding/json" + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/types" +) + +func TestRandomizedGenState(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + + s := rand.NewSource(1) + r := rand.New(s) + + simState := module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + NumBonded: 3, + Accounts: simtypes.RandomAccounts(r, 3), + InitialStake: 1000, + GenState: make(map[string]json.RawMessage), + } + + simulation.RandomizedGenState(&simState) + var authzGenesis types.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &authzGenesis) + + require.Len(t, authzGenesis.Authorization, 0) +} diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 5ed76706c98b..fb52baf52730 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -1,266 +1,292 @@ package simulation -// import ( -// "math/rand" -// "strings" -// "time" - -// "github.com/cosmos/cosmos-sdk/baseapp" -// "github.com/cosmos/cosmos-sdk/codec" -// cdctypes "github.com/cosmos/cosmos-sdk/codec/types" -// "github.com/cosmos/cosmos-sdk/simapp/helpers" -// simappparams "github.com/cosmos/cosmos-sdk/simapp/params" -// sdk "github.com/cosmos/cosmos-sdk/types" -// simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -// "github.com/cosmos/cosmos-sdk/x/authz/keeper" -// "github.com/cosmos/cosmos-sdk/x/authz/types" -// banktype "github.com/cosmos/cosmos-sdk/x/bank/types" -// "github.com/cosmos/cosmos-sdk/x/simulation" -// ) - -// // Simulation operation weights constants -// const ( -// OpWeightMsgGrantAuthorization = "op_weight_msg_grant_authorization" -// OpWeightRevokeAuthorization = "op_weight_msg_revoke_authorization" -// OpWeightExecAuthorized = "op_weight_msg_execute_authorized" -// ) - -// // WeightedOperations returns all the operations from the module with their respective weights -// func WeightedOperations( -// appParams simtypes.AppParams, cdc codec.JSONMarshaler, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker) simulation.WeightedOperations { - -// var ( -// weightMsgGrantAuthorization int -// weightRevokeAuthorization int -// weightExecAuthorized int -// ) - -// appParams.GetOrGenerate(cdc, OpWeightMsgGrantAuthorization, &weightMsgGrantAuthorization, nil, -// func(_ *rand.Rand) { -// weightMsgGrantAuthorization = simappparams.DefaultWeightMsgDelegate -// }, -// ) - -// appParams.GetOrGenerate(cdc, OpWeightRevokeAuthorization, &weightRevokeAuthorization, nil, -// func(_ *rand.Rand) { -// weightRevokeAuthorization = simappparams.DefaultWeightMsgUndelegate -// }, -// ) - -// appParams.GetOrGenerate(cdc, OpWeightExecAuthorized, &weightExecAuthorized, nil, -// func(_ *rand.Rand) { -// weightExecAuthorized = simappparams.DefaultWeightMsgSend -// }, -// ) - -// return simulation.WeightedOperations{ -// simulation.NewWeightedOperation( -// weightMsgGrantAuthorization, -// SimulateMsgGrantAuthorization(ak, bk, k), -// ), -// simulation.NewWeightedOperation( -// weightRevokeAuthorization, -// SimulateMsgRevokeAuthorization(ak, bk, k), -// ), -// simulation.NewWeightedOperation( -// weightExecAuthorized, -// SimulateMsgExecuteAuthorized(ak, bk, k, appCdc), -// ), -// } -// } - -// // SimulateMsgGrantAuthorization generates a MsgGrantAuthorization with random values. -// // nolint: funlen -// func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { -// return func( -// r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, -// ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - -// granter, _ := simtypes.RandomAcc(r, accs) -// grantee, _ := simtypes.RandomAcc(r, accs) - -// account := ak.GetAccount(ctx, granter.Address) - -// spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) -// fees, err := simtypes.RandomFees(r, ctx, spendableCoins) -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgGrantAuthorization, err.Error()), nil, err -// } - -// msg, err := types.NewMsgGrantAuthorization(granter.Address, grantee.Address, -// types.NewSendAuthorization(spendableCoins.Sub(fees)), ctx.BlockTime().Add(30*time.Hour)) - -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgGrantAuthorization, err.Error()), nil, err -// } -// txGen := simappparams.MakeTestEncodingConfig().TxConfig -// tx, err := helpers.GenTx( -// txGen, -// []sdk.Msg{msg}, -// fees, -// helpers.DefaultGenTxGas, -// chainID, -// []uint64{account.GetAccountNumber()}, -// []uint64{account.GetSequence()}, -// granter.PrivKey, -// ) - -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgGrantAuthorization, "unable to generate mock tx"), nil, err -// } - -// _, _, err = app.Deliver(txGen.TxEncoder(), tx) -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err -// } -// return simtypes.NewOperationMsg(msg, true, ""), nil, err -// } -// } - -// // SimulateMsgRevokeAuthorization generates a MsgRevokeAuthorization with random values. -// // nolint: funlen -// func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { -// return func( -// r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, -// ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - -// hasGrant := false -// var targetGrant types.AuthorizationGrant -// var granterAddr sdk.AccAddress -// var granteeAddr sdk.AccAddress -// k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { -// targetGrant = grant -// granterAddr = granter -// granteeAddr = grantee -// hasGrant = true -// return true -// }) - -// if !hasGrant { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRevokeAuthorization, "no grants"), nil, nil -// } - -// granter, ok := simtypes.FindAccount(accs, granterAddr) -// if !ok { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRevokeAuthorization, "Account not found"), nil, nil -// } -// account := ak.GetAccount(ctx, granter.Address) - -// spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) -// fees, err := simtypes.RandomFees(r, ctx, spendableCoins) -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRevokeAuthorization, "fee error"), nil, err -// } -// auth := targetGrant.GetAuthorizationGrant() -// msg := types.NewMsgRevokeAuthorization(granterAddr, granteeAddr, auth.MethodName()) - -// txGen := simappparams.MakeTestEncodingConfig().TxConfig -// tx, err := helpers.GenTx( -// txGen, -// []sdk.Msg{&msg}, -// fees, -// helpers.DefaultGenTxGas, -// chainID, -// []uint64{account.GetAccountNumber()}, -// []uint64{account.GetSequence()}, -// granter.PrivKey, -// ) - -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRevokeAuthorization, err.Error()), nil, err -// } - -// _, _, err = app.Deliver(txGen.TxEncoder(), tx) -// return simtypes.NewOperationMsg(&msg, true, ""), nil, err -// } -// } - -// // SimulateMsgExecuteAuthorized generates a MsgExecuteAuthorized with random values. -// // nolint: funlen -// func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker) simtypes.Operation { -// return func( -// r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, -// ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - -// hasGrant := false -// var targetGrant types.AuthorizationGrant -// var granterAddr sdk.AccAddress -// var granteeAddr sdk.AccAddress -// k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { -// targetGrant = grant -// granterAddr = granter -// granteeAddr = grantee -// hasGrant = true -// return true -// }) - -// if !hasGrant { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "Not found"), nil, nil -// } - -// grantee, _ := simtypes.FindAccount(accs, granteeAddr) -// granterAccount := ak.GetAccount(ctx, granterAddr) -// granteeAccount := ak.GetAccount(ctx, granteeAddr) - -// granterspendableCoins := bk.SpendableCoins(ctx, granterAccount.GetAddress()) -// if granterspendableCoins.Empty() { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "no coins"), nil, nil -// } - -// if targetGrant.Expiration < ctx.BlockHeader().Time.Unix() { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "grant expired"), nil, nil -// } - -// granteespendableCoins := bk.SpendableCoins(ctx, granteeAccount.GetAddress()) -// fees, err := simtypes.RandomFees(r, ctx, granteespendableCoins) -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "fee error"), nil, err -// } -// sendCoins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10))) - -// execMsg := sdk.ServiceMsg{ -// MethodName: types.SendAuthorization{}.MethodName(), -// Request: banktype.NewMsgSend( -// granterAddr, -// granteeAddr, -// sendCoins, -// ), -// } - -// msg := types.NewMsgExecAuthorized(grantee.Address, []sdk.ServiceMsg{execMsg}) -// sendGrant := targetGrant.Authorization.GetCachedValue().(*types.SendAuthorization) -// allow, _, _ := sendGrant.Accept(execMsg, ctx.BlockHeader()) -// if !allow { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "not allowed"), nil, nil -// } - -// txGen := simappparams.MakeTestEncodingConfig().TxConfig -// tx, err := helpers.GenTx( -// txGen, -// []sdk.Msg{&msg}, -// fees, -// helpers.DefaultGenTxGas, -// chainID, -// []uint64{granteeAccount.GetAccountNumber()}, -// []uint64{granteeAccount.GetSequence()}, -// grantee.PrivKey, -// ) - -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, err.Error()), nil, err -// } -// _, _, err = app.Deliver(txGen.TxEncoder(), tx) -// if err != nil { -// if strings.Contains(err.Error(), "insufficient fee") { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "insufficient fee"), nil, nil -// } -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, err.Error()), nil, err -// } -// msg.UnpackInterfaces(cdc) -// _, err = msg.GetServiceMsgs() -// if err != nil { -// return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgExecDelegated, "unmarshal error"), nil, err -// } -// return simtypes.NewOperationMsg(&msg, true, "success"), nil, nil -// } -// } +import ( + "context" + "math/rand" + "strings" + "time" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/simapp/helpers" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/keeper" + "github.com/cosmos/cosmos-sdk/x/authz/types" + banktype "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/simulation" +) + +// authz message types +const ( + TypeMsgGrantAuthorization = "/cosmos.authz.v1beta1.Msg/GrantAuthorization" + TypeMsgRevokeAuthorization = "/cosmos.authz.v1beta1.Msg/RevokeAuthorization" + TypeMsgExecDelegated = "/cosmos.authz.v1beta1.Msg/ExecAuthorized" +) + +// Simulation operation weights constants +const ( + OpWeightMsgGrantAuthorization = "op_weight_msg_grant_authorization" + OpWeightRevokeAuthorization = "op_weight_msg_revoke_authorization" + OpWeightExecAuthorized = "op_weight_msg_execute_authorized" +) + +// WeightedOperations returns all the operations from the module with their respective weights +func WeightedOperations( + appParams simtypes.AppParams, cdc codec.JSONMarshaler, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simulation.WeightedOperations { + + var ( + weightMsgGrantAuthorization int + weightRevokeAuthorization int + weightExecAuthorized int + ) + + appParams.GetOrGenerate(cdc, OpWeightMsgGrantAuthorization, &weightMsgGrantAuthorization, nil, + func(_ *rand.Rand) { + weightMsgGrantAuthorization = simappparams.DefaultWeightMsgDelegate + }, + ) + + appParams.GetOrGenerate(cdc, OpWeightRevokeAuthorization, &weightRevokeAuthorization, nil, + func(_ *rand.Rand) { + weightRevokeAuthorization = simappparams.DefaultWeightMsgUndelegate + }, + ) + + appParams.GetOrGenerate(cdc, OpWeightExecAuthorized, &weightExecAuthorized, nil, + func(_ *rand.Rand) { + weightExecAuthorized = simappparams.DefaultWeightMsgSend + }, + ) + + return simulation.WeightedOperations{ + simulation.NewWeightedOperation( + weightMsgGrantAuthorization, + SimulateMsgGrantAuthorization(ak, bk, k, time.Now().Add(100*time.Hour), protoCdc), + ), + simulation.NewWeightedOperation( + weightRevokeAuthorization, + SimulateMsgRevokeAuthorization(ak, bk, k, protoCdc), + ), + simulation.NewWeightedOperation( + weightExecAuthorized, + SimulateMsgExecuteAuthorized(ak, bk, k, appCdc, protoCdc), + ), + } +} + +// SimulateMsgGrantAuthorization generates a MsgGrantAuthorization with random values. +// nolint: funlen +func SimulateMsgGrantAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, + t time.Time, protoCdc *codec.ProtoCodec) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + + granter, _ := simtypes.RandomAcc(r, accs) + grantee, _ := simtypes.RandomAcc(r, accs) + + account := ak.GetAccount(ctx, granter.Address) + + spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) + fees, err := simtypes.RandomFees(r, ctx, spendableCoins) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + } + + msg, err := types.NewMsgGrantAuthorization(granter.Address, grantee.Address, + types.NewSendAuthorization(spendableCoins.Sub(fees)), t) + + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + } + txGen := simappparams.MakeTestEncodingConfig().TxConfig + svcMsgClientConn := &helpers.ServiceMsgClientConn{} + authzMsgClient := types.NewMsgClient(svcMsgClientConn) + _, err = authzMsgClient.GrantAuthorization(context.Background(), msg) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, err.Error()), nil, err + } + tx, err := helpers.GenTx( + txGen, + svcMsgClientConn.Msgs, + fees, + helpers.DefaultGenTxGas, + chainID, + []uint64{account.GetAccountNumber()}, + []uint64{account.GetSequence()}, + granter.PrivKey, + ) + + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgGrantAuthorization, "unable to generate mock tx"), nil, err + } + + _, _, err = app.Deliver(txGen.TxEncoder(), tx) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, svcMsgClientConn.Msgs[0].Type(), "unable to deliver tx"), nil, err + } + return simtypes.NewOperationMsg(svcMsgClientConn.Msgs[0], true, "", protoCdc), nil, err + } +} + +// SimulateMsgRevokeAuthorization generates a MsgRevokeAuthorization with random values. +// nolint: funlen +func SimulateMsgRevokeAuthorization(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + + hasGrant := false + var targetGrant types.AuthorizationGrant + var granterAddr sdk.AccAddress + var granteeAddr sdk.AccAddress + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + targetGrant = grant + granterAddr = granter + granteeAddr = grantee + hasGrant = true + return true + }) + + if !hasGrant { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "no grants"), nil, nil + } + + granter, ok := simtypes.FindAccount(accs, granterAddr) + if !ok { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "Account not found"), nil, nil + } + account := ak.GetAccount(ctx, granter.Address) + + spendableCoins := bk.SpendableCoins(ctx, account.GetAddress()) + fees, err := simtypes.RandomFees(r, ctx, spendableCoins) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, "fee error"), nil, err + } + auth := targetGrant.GetAuthorizationGrant() + msg := types.NewMsgRevokeAuthorization(granterAddr, granteeAddr, auth.MethodName()) + + txGen := simappparams.MakeTestEncodingConfig().TxConfig + svcMsgClientConn := &helpers.ServiceMsgClientConn{} + authzMsgClient := types.NewMsgClient(svcMsgClientConn) + _, err = authzMsgClient.RevokeAuthorization(context.Background(), &msg) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err + } + tx, err := helpers.GenTx( + txGen, + svcMsgClientConn.Msgs, + fees, + helpers.DefaultGenTxGas, + chainID, + []uint64{account.GetAccountNumber()}, + []uint64{account.GetSequence()}, + granter.PrivKey, + ) + + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRevokeAuthorization, err.Error()), nil, err + } + + _, _, err = app.Deliver(txGen.TxEncoder(), tx) + return simtypes.NewOperationMsg(svcMsgClientConn.Msgs[0], true, "", protoCdc), nil, err + } +} + +// SimulateMsgExecuteAuthorized generates a MsgExecuteAuthorized with random values. +// nolint: funlen +func SimulateMsgExecuteAuthorized(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + + hasGrant := false + var targetGrant types.AuthorizationGrant + var granterAddr sdk.AccAddress + var granteeAddr sdk.AccAddress + k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant types.AuthorizationGrant) bool { + targetGrant = grant + granterAddr = granter + granteeAddr = grantee + hasGrant = true + return true + }) + + if !hasGrant { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "Not found"), nil, nil + } + + grantee, _ := simtypes.FindAccount(accs, granteeAddr) + granterAccount := ak.GetAccount(ctx, granterAddr) + granteeAccount := ak.GetAccount(ctx, granteeAddr) + + granterspendableCoins := bk.SpendableCoins(ctx, granterAccount.GetAddress()) + if granterspendableCoins.Empty() { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "no coins"), nil, nil + } + + if targetGrant.Expiration < ctx.BlockHeader().Time.Unix() { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "grant expired"), nil, nil + } + + granteespendableCoins := bk.SpendableCoins(ctx, granteeAccount.GetAddress()) + fees, err := simtypes.RandomFees(r, ctx, granteespendableCoins) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "fee error"), nil, err + } + sendCoins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10))) + + execMsg := sdk.ServiceMsg{ + MethodName: types.SendAuthorization{}.MethodName(), + Request: banktype.NewMsgSend( + granterAddr, + granteeAddr, + sendCoins, + ), + } + + msg := types.NewMsgExecAuthorized(grantee.Address, []sdk.ServiceMsg{execMsg}) + sendGrant := targetGrant.Authorization.GetCachedValue().(*types.SendAuthorization) + allow, _, _ := sendGrant.Accept(execMsg, ctx.BlockHeader()) + if !allow { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "not allowed"), nil, nil + } + + txGen := simappparams.MakeTestEncodingConfig().TxConfig + svcMsgClientConn := &helpers.ServiceMsgClientConn{} + authzMsgClient := types.NewMsgClient(svcMsgClientConn) + _, err = authzMsgClient.ExecAuthorized(context.Background(), &msg) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + } + tx, err := helpers.GenTx( + txGen, + svcMsgClientConn.Msgs, + fees, + helpers.DefaultGenTxGas, + chainID, + []uint64{granteeAccount.GetAccountNumber()}, + []uint64{granteeAccount.GetSequence()}, + grantee.PrivKey, + ) + + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + } + _, _, err = app.Deliver(txGen.TxEncoder(), tx) + if err != nil { + if strings.Contains(err.Error(), "insufficient fee") { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "insufficient fee"), nil, nil + } + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, err.Error()), nil, err + } + msg.UnpackInterfaces(cdc) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgExecDelegated, "unmarshal error"), nil, err + } + return simtypes.NewOperationMsg(svcMsgClientConn.Msgs[0], true, "success", protoCdc), nil, nil + } +} diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 1e829e161ac1..f614e2a501c5 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -1,160 +1,195 @@ package simulation_test -// import ( -// "math/rand" -// "testing" -// "time" - -// "github.com/stretchr/testify/suite" - -// abci "github.com/tendermint/tendermint/abci/types" -// tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - -// "github.com/cosmos/cosmos-sdk/simapp" -// simappparams "github.com/cosmos/cosmos-sdk/simapp/params" -// sdk "github.com/cosmos/cosmos-sdk/types" -// simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -// "github.com/cosmos/cosmos-sdk/x/authz/simulation" -// "github.com/cosmos/cosmos-sdk/x/authz/types" -// ) - -// type SimTestSuite struct { -// suite.Suite - -// ctx sdk.Context -// app *simapp.SimApp -// } - -// func (suite *SimTestSuite) SetupTest() { -// checkTx := false -// app := simapp.Setup(checkTx) -// suite.app = app -// suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) -// } - -// func (suite *SimTestSuite) TestWeightedOperations() { -// cdc := suite.app.AppCodec() -// appParams := make(simtypes.AppParams) - -// weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, -// suite.app.BankKeeper, suite.app.MsgAuthKeeper, cdc, -// ) - -// // setup 3 accounts -// s := rand.NewSource(1) -// r := rand.New(s) -// accs := suite.getTestingAccounts(r, 3) - -// expected := []struct { -// weight int -// opMsgRoute string -// opMsgName string -// }{ -// {simappparams.DefaultWeightMsgDelegate, types.ModuleName, types.TypeMsgGrantAuthorization}, -// {simappparams.DefaultWeightMsgUndelegate, types.ModuleName, types.TypeMsgRevokeAuthorization}, -// {simappparams.DefaultWeightMsgSend, types.ModuleName, types.TypeMsgExecDelegated}, -// } - -// for i, w := range weightesOps { -// operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") -// // the following checks are very much dependent from the ordering of the output given -// // by WeightedOperations. if the ordering in WeightedOperations changes some tests -// // will fail -// suite.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same") -// suite.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") -// suite.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") -// } -// } - -// func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { -// accounts := simtypes.RandomAccounts(r, n) - -// initAmt := sdk.TokensFromConsensusPower(200000) -// initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) - -// // add coins to the accounts -// for _, account := range accounts { -// acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, account.Address) -// suite.app.AccountKeeper.SetAccount(suite.ctx, acc) -// err := suite.app.BankKeeper.SetBalances(suite.ctx, account.Address, initCoins) -// suite.Require().NoError(err) -// } - -// return accounts -// } - -// func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { -// // setup 3 accounts -// s := rand.NewSource(1) -// r := rand.New(s) -// accounts := suite.getTestingAccounts(r, 3) - -// // begin a new block -// suite.app.BeginBlock(abci.RequestBeginBlock{ -// Header: tmproto.Header{ -// Height: suite.app.LastBlockHeight() + 1, -// AppHash: suite.app.LastCommitID().Hash, -// }}) - -// initAmt := sdk.TokensFromConsensusPower(200000) -// initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) - -// granter := accounts[0] -// grantee := accounts[1] -// authorization := types.NewSendAuthorization(initCoins) - -// err := suite.app.MsgAuthKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) -// suite.Require().NoError(err) - -// // execute operation -// op := simulation.SimulateMsgRevokeAuthorization(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.MsgAuthKeeper) -// operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") -// suite.Require().NoError(err) - -// var msg types.MsgRevokeAuthorization -// types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) - -// suite.Require().True(operationMsg.OK) -// suite.Require().Equal(granter.Address.String(), msg.Granter) -// suite.Require().Equal(grantee.Address.String(), msg.Grantee) -// suite.Require().Equal(types.SendAuthorization{}.MethodName(), msg.AuthorizationMsgType) -// suite.Require().Len(futureOperations, 0) - -// } - -// func (suite *SimTestSuite) TestSimulateExecAuthorization() { -// // setup 3 accounts -// s := rand.NewSource(1) -// r := rand.New(s) -// accounts := suite.getTestingAccounts(r, 3) - -// // begin a new block -// suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}}) - -// initAmt := sdk.TokensFromConsensusPower(200000) -// initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) - -// granter := accounts[0] -// grantee := accounts[1] -// authorization := types.NewSendAuthorization(initCoins) - -// err := suite.app.MsgAuthKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) -// suite.Require().NoError(err) - -// // execute operation -// op := simulation.SimulateMsgExecuteAuthorized(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.MsgAuthKeeper, suite.app.AppCodec()) -// operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") -// suite.Require().NoError(err) - -// var msg types.MsgExecAuthorized -// types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) - -// suite.Require().True(operationMsg.OK) -// suite.Require().Equal(grantee.Address.String(), msg.Grantee) -// suite.Require().Len(futureOperations, 0) - -// } - -// func TestSimTestSuite(t *testing.T) { -// suite.Run(t, new(SimTestSuite)) -// } +import ( + "math/rand" + "testing" + "time" + + "github.com/stretchr/testify/suite" + + abci "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/simapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/types" +) + +type SimTestSuite struct { + suite.Suite + + ctx sdk.Context + app *simapp.SimApp + protoCdc *codec.ProtoCodec +} + +func (suite *SimTestSuite) SetupTest() { + checkTx := false + app := simapp.Setup(checkTx) + suite.app = app + suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) + suite.protoCdc = codec.NewProtoCodec(suite.app.InterfaceRegistry()) +} + +func (suite *SimTestSuite) TestWeightedOperations() { + cdc := suite.app.AppCodec() + appParams := make(simtypes.AppParams) + + weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, + suite.app.BankKeeper, suite.app.MsgAuthKeeper, cdc, suite.protoCdc, + ) + + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accs := suite.getTestingAccounts(r, 3) + + expected := []struct { + weight int + opMsgRoute string + opMsgName string + }{ + {simappparams.DefaultWeightMsgDelegate, types.ModuleName, simulation.TypeMsgGrantAuthorization}, + {simappparams.DefaultWeightMsgUndelegate, types.ModuleName, simulation.TypeMsgRevokeAuthorization}, + {simappparams.DefaultWeightMsgSend, types.ModuleName, simulation.TypeMsgExecDelegated}, + } + + for i, w := range weightesOps { + operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + // the following checks are very much dependent from the ordering of the output given + // by WeightedOperations. if the ordering in WeightedOperations changes some tests + // will fail + suite.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same") + suite.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") + suite.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") + } +} + +func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { + accounts := simtypes.RandomAccounts(r, n) + + initAmt := sdk.TokensFromConsensusPower(200000) + initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) + + // add coins to the accounts + for _, account := range accounts { + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, account.Address) + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + err := suite.app.BankKeeper.SetBalances(suite.ctx, account.Address, initCoins) + suite.Require().NoError(err) + } + + return accounts +} + +func (suite *SimTestSuite) TestSimulateGrantAuthorization() { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 2) + + // begin a new block + suite.app.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: suite.app.LastBlockHeight() + 1, + AppHash: suite.app.LastCommitID().Hash, + }, + }) + + granter := accounts[0] + grantee := accounts[1] + + // execute operation + op := simulation.SimulateMsgGrantAuthorization(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.MsgAuthKeeper, time.Now().Add(30*time.Hour), suite.protoCdc) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgGrantAuthorization + suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) + suite.Require().True(operationMsg.OK) + suite.Require().Equal(granter.Address.String(), msg.Granter) + suite.Require().Equal(grantee.Address.String(), msg.Grantee) + suite.Require().Len(futureOperations, 0) + +} + +func (suite *SimTestSuite) TestSimulateRevokeAuthorization() { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + // begin a new block + suite.app.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: suite.app.LastBlockHeight() + 1, + AppHash: suite.app.LastCommitID().Hash, + }}) + + initAmt := sdk.TokensFromConsensusPower(200000) + initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) + + granter := accounts[0] + grantee := accounts[1] + authorization := types.NewSendAuthorization(initCoins) + + err := suite.app.MsgAuthKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + suite.Require().NoError(err) + + // execute operation + op := simulation.SimulateMsgRevokeAuthorization(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.MsgAuthKeeper, suite.protoCdc) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgRevokeAuthorization + suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) + + suite.Require().True(operationMsg.OK) + suite.Require().Equal(granter.Address.String(), msg.Granter) + suite.Require().Equal(grantee.Address.String(), msg.Grantee) + suite.Require().Equal(types.SendAuthorization{}.MethodName(), msg.AuthorizationMsgType) + suite.Require().Len(futureOperations, 0) + +} + +func (suite *SimTestSuite) TestSimulateExecAuthorization() { + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 3) + + // begin a new block + suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}}) + + initAmt := sdk.TokensFromConsensusPower(200000) + initCoins := sdk.NewCoins(sdk.NewCoin("foo", initAmt)) + + granter := accounts[0] + grantee := accounts[1] + authorization := types.NewSendAuthorization(initCoins) + + err := suite.app.MsgAuthKeeper.Grant(suite.ctx, grantee.Address, granter.Address, authorization, time.Now().Add(30*time.Hour)) + suite.Require().NoError(err) + + // execute operation + op := simulation.SimulateMsgExecuteAuthorized(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.MsgAuthKeeper, suite.app.AppCodec(), suite.protoCdc) + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().NoError(err) + + var msg types.MsgExecAuthorized + + suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg) + + suite.Require().True(operationMsg.OK) + suite.Require().Equal(grantee.Address.String(), msg.Grantee) + suite.Require().Len(futureOperations, 0) + +} + +func TestSimTestSuite(t *testing.T) { + suite.Run(t, new(SimTestSuite)) +} diff --git a/x/authz/types/msgs.go b/x/authz/types/msgs.go index 8913ce342e3a..4abd1b0b02dc 100644 --- a/x/authz/types/msgs.go +++ b/x/authz/types/msgs.go @@ -11,13 +11,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// authz message types -const ( - TypeMsgGrantAuthorization = "grant_authorization" - TypeMsgRevokeAuthorization = "revoke_authorization" - TypeMsgExecDelegated = "exec_delegated" -) - var ( _ sdk.MsgRequest = &MsgGrantAuthorization{} _ sdk.MsgRequest = &MsgRevokeAuthorization{} diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 9fcc80f0fe45..40be2feeb4a0 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -76,7 +76,7 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -217,7 +217,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 09090d1f64d6..b83e6f8a4e4b 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -120,7 +120,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -172,7 +172,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -227,7 +227,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -282,6 +282,6 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 2ea89ca97bb1..d90ca07d5ccc 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -162,7 +162,7 @@ func SimulateMsgSubmitProposal( return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - opMsg := simtypes.NewOperationMsg(msg, true, "") + opMsg := simtypes.NewOperationMsg(msg, true, "", nil) // get the submitted proposal ID proposalID, err := k.GetProposalID(ctx) @@ -248,7 +248,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -311,7 +311,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 20acc9e91a88..1c49775cc193 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -115,23 +115,23 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) { if res != nil && err == nil { if info.Tombstoned { - return simtypes.NewOperationMsg(msg, true, ""), nil, errors.New("validator should not have been unjailed if validator tombstoned") + return simtypes.NewOperationMsg(msg, true, "", nil), nil, errors.New("validator should not have been unjailed if validator tombstoned") } if ctx.BlockHeader().Time.Before(info.JailedUntil) { - return simtypes.NewOperationMsg(msg, true, ""), nil, errors.New("validator unjailed while validator still in jail period") + return simtypes.NewOperationMsg(msg, true, "", nil), nil, errors.New("validator unjailed while validator still in jail period") } if validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) { - return simtypes.NewOperationMsg(msg, true, ""), nil, errors.New("validator unjailed even though self-delegation too low") + return simtypes.NewOperationMsg(msg, true, "", nil), nil, errors.New("validator unjailed even though self-delegation too low") } } // msg failed as expected - return simtypes.NewOperationMsg(msg, false, ""), nil, nil + return simtypes.NewOperationMsg(msg, false, "", nil), nil, nil } if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, errors.New(res.Log) } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 0bcb274ed717..d9621bc7321c 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -173,7 +173,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -244,7 +244,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -317,7 +317,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -407,7 +407,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } @@ -520,6 +520,6 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } }