From f1d816038878831237eda89570ddf0e74771d6fa Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sun, 16 Apr 2023 15:54:50 +0200 Subject: [PATCH 1/6] remove global bech32 from vesting and crisis --- x/auth/vesting/client/cli/tx.go | 21 +++++++++++---------- x/auth/vesting/client/cli/tx_test.go | 7 ++++--- x/auth/vesting/module.go | 13 ++++++++----- x/auth/vesting/msg_server.go | 12 ++++++------ x/crisis/keeper/genesis_test.go | 3 ++- x/crisis/keeper/keeper.go | 7 ++++++- x/crisis/keeper/keeper_test.go | 7 ++++--- x/crisis/keeper/msg_server.go | 2 +- x/crisis/keeper/msg_server_test.go | 13 +++++++------ x/crisis/module.go | 5 ++++- 10 files changed, 53 insertions(+), 37 deletions(-) diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index 0b057d1f04d6..0ce6708fd5e6 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -7,6 +7,7 @@ import ( "os" "strconv" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" @@ -22,7 +23,7 @@ const ( ) // GetTxCmd returns vesting module's transaction commands. -func GetTxCmd() *cobra.Command { +func GetTxCmd(ac address.Codec) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Vesting transaction subcommands", @@ -32,9 +33,9 @@ func GetTxCmd() *cobra.Command { } txCmd.AddCommand( - NewMsgCreateVestingAccountCmd(), - NewMsgCreatePermanentLockedAccountCmd(), - NewMsgCreatePeriodicVestingAccountCmd(), + NewMsgCreateVestingAccountCmd(ac), + NewMsgCreatePermanentLockedAccountCmd(ac), + NewMsgCreatePeriodicVestingAccountCmd(ac), ) return txCmd @@ -42,7 +43,7 @@ func GetTxCmd() *cobra.Command { // NewMsgCreateVestingAccountCmd returns a CLI command handler for creating a // MsgCreateVestingAccount transaction. -func NewMsgCreateVestingAccountCmd() *cobra.Command { +func NewMsgCreateVestingAccountCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "create-vesting-account [to_address] [amount] [end_time]", Short: "Create a new vesting account funded with an allocation of tokens.", @@ -57,7 +58,7 @@ timestamp.`, if err != nil { return err } - toAddr, err := sdk.AccAddressFromBech32(args[0]) + toAddr, err := ac.StringToBytes(args[0]) if err != nil { return err } @@ -91,7 +92,7 @@ timestamp.`, // NewMsgCreatePermanentLockedAccountCmd returns a CLI command handler for creating a // MsgCreatePermanentLockedAccount transaction. -func NewMsgCreatePermanentLockedAccountCmd() *cobra.Command { +func NewMsgCreatePermanentLockedAccountCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "create-permanent-locked-account [to_address] [amount]", Short: "Create a new permanently locked account funded with an allocation of tokens.", @@ -104,7 +105,7 @@ tokens.`, if err != nil { return err } - toAddr, err := sdk.AccAddressFromBech32(args[0]) + toAddr, err := ac.StringToBytes(args[0]) if err != nil { return err } @@ -140,7 +141,7 @@ type InputPeriod struct { // NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a // MsgCreatePeriodicVestingAccountCmd transaction. -func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command { +func NewMsgCreatePeriodicVestingAccountCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "create-periodic-vesting-account [to_address] [periods_json_file]", Short: "Create a new vesting account funded with an allocation of tokens.", @@ -168,7 +169,7 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command { return err } - toAddr, err := sdk.AccAddressFromBech32(args[0]) + toAddr, err := ac.StringToBytes(args[0]) if err != nil { return err } diff --git a/x/auth/vesting/client/cli/tx_test.go b/x/auth/vesting/client/cli/tx_test.go index f0205d20a36d..f2591446034d 100644 --- a/x/auth/vesting/client/cli/tx_test.go +++ b/x/auth/vesting/client/cli/tx_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" @@ -49,7 +50,7 @@ func (s *CLITestSuite) SetupSuite() { func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.NewMsgCreateVestingAccountCmd() + cmd := cli.NewMsgCreateVestingAccountCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) extraArgs := []string{ @@ -138,7 +139,7 @@ func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() { func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.NewMsgCreatePermanentLockedAccountCmd() + cmd := cli.NewMsgCreatePermanentLockedAccountCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) extraArgs := []string{ @@ -217,7 +218,7 @@ func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() { func (s *CLITestSuite) TestNewMsgCreatePeriodicVestingAccountCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.NewMsgCreatePeriodicVestingAccountCmd() + cmd := cli.NewMsgCreatePeriodicVestingAccountCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) extraArgs := []string{ diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 62a56ebbdf31..4b16397fa2ed 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" modulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -32,7 +33,9 @@ var ( // AppModuleBasic defines the basic application module used by the sub-vesting // module. The module itself contain no special logic or state other than message // handling. -type AppModuleBasic struct{} +type AppModuleBasic struct { + ac address.Codec +} // Name returns the module's name. func (AppModuleBasic) Name() string { @@ -62,11 +65,11 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConf // RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this // is a no-op. -func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {} +func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {} // GetTxCmd returns the root tx command for the auth module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() +func (ab AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd(ab.ac) } // GetQueryCmd returns the module's root query command. Currently, this is a no-op. @@ -85,7 +88,7 @@ type AppModule struct { func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, + AppModuleBasic: AppModuleBasic{ac: ak}, accountKeeper: ak, bankKeeper: bk, } diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index 5a68ffefe79d..5664266dfd46 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -29,12 +29,12 @@ func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServ var _ types.MsgServer = msgServer{} func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCreateVestingAccount) (*types.MsgCreateVestingAccountResponse, error) { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) + from, err := s.AccountKeeper.StringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err) } - to, err := sdk.AccAddressFromBech32(msg.ToAddress) + to, err := s.AccountKeeper.StringToBytes(msg.ToAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err) } @@ -95,12 +95,12 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre } func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *types.MsgCreatePermanentLockedAccount) (*types.MsgCreatePermanentLockedAccountResponse, error) { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) + from, err := s.AccountKeeper.StringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err) } - to, err := sdk.AccAddressFromBech32(msg.ToAddress) + to, err := s.AccountKeeper.StringToBytes(msg.ToAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err) } @@ -150,12 +150,12 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type } func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *types.MsgCreatePeriodicVestingAccount) (*types.MsgCreatePeriodicVestingAccountResponse, error) { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) + from, err := s.AccountKeeper.StringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err) } - to, err := sdk.AccAddressFromBech32(msg.ToAddress) + to, err := s.AccountKeeper.StringToBytes(msg.ToAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err) } diff --git a/x/crisis/keeper/genesis_test.go b/x/crisis/keeper/genesis_test.go index 3ae7fb0438d5..475e712f2629 100644 --- a/x/crisis/keeper/genesis_test.go +++ b/x/crisis/keeper/genesis_test.go @@ -10,6 +10,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -43,7 +44,7 @@ func (s *GenesisTestSuite) SetupTest() { supplyKeeper := crisistestutil.NewMockSupplyKeeper(ctrl) - s.keeper = *keeper.NewKeeper(s.cdc, key, 5, supplyKeeper, "", "") + s.keeper = *keeper.NewKeeper(s.cdc, key, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) } func (s *GenesisTestSuite) TestImportExportGenesis() { diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index 35268e2c65e2..ba0890e46d03 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "cosmossdk.io/core/address" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -27,13 +28,16 @@ type Keeper struct { supplyKeeper types.SupplyKeeper feeCollectorName string // name of the FeeCollector ModuleAccount + + addressCodec address.Codec } // NewKeeper creates a new Keeper object func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, invCheckPeriod uint, - supplyKeeper types.SupplyKeeper, feeCollectorName, authority string, + supplyKeeper types.SupplyKeeper, feeCollectorName, authority string, ac address.Codec, ) *Keeper { + return &Keeper{ storeKey: storeKey, cdc: cdc, @@ -42,6 +46,7 @@ func NewKeeper( supplyKeeper: supplyKeeper, feeCollectorName: feeCollectorName, authority: authority, + addressCodec: ac, } } diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index 1cbd6cb8422d..1a1eaa38cda6 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( storetypes "cosmossdk.io/store/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -24,7 +25,7 @@ func TestLogger(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) - keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName), @@ -37,7 +38,7 @@ func TestInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) - keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, keeper.InvCheckPeriod(), uint(5)) orgInvRoutes := keeper.Routes() @@ -53,7 +54,7 @@ func TestAssertInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) - keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "") + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) keeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false }) require.NotPanics(t, func() { keeper.AssertInvariants(testCtx.Ctx) }) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 79fa138e1a06..c13da8d644e9 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -16,7 +16,7 @@ var _ types.MsgServer = &Keeper{} // VerifyInvariant implements MsgServer.VerifyInvariant method. // It defines a method to verify a particular invariant. func (k *Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) { - sender, err := sdk.AccAddressFromBech32(msg.Sender) + sender, err := k.addressCodec.StringToBytes(msg.Sender) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err) } diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 7a2b5d614daf..a36c219b39d2 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -9,6 +9,7 @@ import ( sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -21,9 +22,9 @@ import ( type KeeperTestSuite struct { suite.Suite - ctx sdk.Context - authKeeper *crisistestutil.MockSupplyKeeper - keeper *keeper.Keeper + ctx sdk.Context + supplyKeeper *crisistestutil.MockSupplyKeeper + keeper *keeper.Keeper } func (s *KeeperTestSuite) SetupTest() { @@ -34,11 +35,11 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) - keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String()) + keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String(), addresscodec.NewBech32Codec("cosmos")) s.ctx = testCtx.Ctx s.keeper = keeper - s.authKeeper = supplyKeeper + s.supplyKeeper = supplyKeeper } func (s *KeeperTestSuite) TestMsgVerifyInvariant() { @@ -49,7 +50,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { sender := sdk.AccAddress([]byte("addr1_______________")) - s.authKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) + s.supplyKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) s.keeper.RegisterRoute("bank", "total-supply", func(sdk.Context) (string, bool) { return "", false }) testCases := []struct { diff --git a/x/crisis/module.go b/x/crisis/module.go index 1fec0487e938..a19419ee7b7e 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -199,7 +200,8 @@ type ModuleInputs struct { Cdc codec.Codec AppOpts servertypes.AppOptions `optional:"true"` - BankKeeper types.SupplyKeeper + BankKeeper types.SupplyKeeper + AddressCodec address.Codec // LegacySubspace is used solely for migration of x/params managed parameters LegacySubspace exported.Subspace @@ -236,6 +238,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.BankKeeper, feeCollectorName, authority.String(), + in.AddressCodec, ) var skipGenesisInvariants bool From 76f70c36c83f96df7b351c4b9623292bdc4aa42d Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sun, 16 Apr 2023 15:55:31 +0200 Subject: [PATCH 2/6] fix lint --- x/crisis/keeper/keeper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index ba0890e46d03..e987f813e660 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -37,7 +37,6 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, invCheckPeriod uint, supplyKeeper types.SupplyKeeper, feeCollectorName, authority string, ac address.Codec, ) *Keeper { - return &Keeper{ storeKey: storeKey, cdc: cdc, From 89b41ff515adcc4cc4c04511cc7a6df0de8a9d23 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 17 Apr 2023 11:07:53 +0200 Subject: [PATCH 3/6] fix build --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index 5f939f2c87ba..0a34c622dd77 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -311,7 +311,7 @@ func NewSimApp( invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)) app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, keys[crisistypes.StoreKey], invCheckPeriod, - app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountKeeper.GetAddressCodec()) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), app.AccountKeeper) From 67e57e6b220dff77be55d5fe5f8e91912064ae97 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 17 Apr 2023 14:36:28 +0200 Subject: [PATCH 4/6] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f787a08fab..5511af42a9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,6 +160,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `InterfaceRegistry` is now a private interface and implements `protodesc.Resolver` plus the `RangeFiles` method All implementations of `InterfaceRegistry` by other users must now embed the official implementation. * `AminoCodec` is marked as deprecated. +* (x/crisis) [#15852](https://github.com/cosmos/cosmos-sdk/pull/15852) Crisis keeper now takes a instance of the address codec to be able to decode user addresses ### Client Breaking Changes From 3816248815ee9a0d7e44c757b53d939c081a7cd0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 18 Apr 2023 10:37:18 +0200 Subject: [PATCH 5/6] fix tests --- x/crisis/keeper/msg_server.go | 3 +++ x/crisis/keeper/msg_server_test.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index c13da8d644e9..c0db5a46e167 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -16,6 +16,9 @@ var _ types.MsgServer = &Keeper{} // VerifyInvariant implements MsgServer.VerifyInvariant method. // It defines a method to verify a particular invariant. func (k *Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) { + if msg.Sender == "" { + return nil, sdkerrors.ErrInvalidAddress.Wrap("empty address string is not allowed") + } sender, err := k.addressCodec.StringToBytes(msg.Sender) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index a36c219b39d2..195516e84b65 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -10,7 +10,9 @@ import ( storetypes "cosmossdk.io/store/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" + sdktestutil "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -48,7 +50,11 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { err := s.keeper.SetConstantFee(s.ctx, constantFee) s.Require().NoError(err) - sender := sdk.AccAddress([]byte("addr1_______________")) + encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) + kr := keyring.NewInMemory(encCfg.Codec) + sdktestutil.CreateKeyringAccounts(s.T(), kr, 1) + + sender := sdktestutil.CreateKeyringAccounts(s.T(), kr, 1)[0] s.supplyKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) s.keeper.RegisterRoute("bank", "total-supply", func(sdk.Context) (string, bool) { return "", false }) @@ -82,7 +88,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { { name: "unregistered invariant route", input: &types.MsgVerifyInvariant{ - Sender: sender.String(), + Sender: sender.Address.String(), InvariantModuleName: "module", InvariantRoute: "invalidroute", }, @@ -92,7 +98,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { { name: "valid invariant", input: &types.MsgVerifyInvariant{ - Sender: sender.String(), + Sender: sender.Address.String(), InvariantModuleName: "bank", InvariantRoute: "total-supply", }, From 8efb1a2b054f183e1b9449f001776991eee4f8ce Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 18 Apr 2023 12:30:50 +0200 Subject: [PATCH 6/6] lint --- x/crisis/keeper/msg_server_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 195516e84b65..1bcedd606367 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -12,7 +12,6 @@ import ( addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" - sdktestutil "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -52,9 +51,9 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}) kr := keyring.NewInMemory(encCfg.Codec) - sdktestutil.CreateKeyringAccounts(s.T(), kr, 1) + testutil.CreateKeyringAccounts(s.T(), kr, 1) - sender := sdktestutil.CreateKeyringAccounts(s.T(), kr, 1)[0] + sender := testutil.CreateKeyringAccounts(s.T(), kr, 1)[0] s.supplyKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) s.keeper.RegisterRoute("bank", "total-supply", func(sdk.Context) (string, bool) { return "", false })