From 339bb30fad57c7047cc325a369d91a793ea4ce40 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 28 Mar 2023 10:50:04 +0200 Subject: [PATCH 01/19] migrate bank bech32 encoding --- testutil/cli/cmd.go | 9 ++++--- x/bank/client/cli/query.go | 16 ++++++------ x/bank/client/cli/query_test.go | 6 ++--- x/bank/client/cli/tx.go | 15 ++++++------ x/bank/client/cli/tx_test.go | 5 ++-- x/bank/exported/exported.go | 3 ++- x/bank/keeper/genesis.go | 5 +++- x/bank/keeper/grpc_query.go | 8 +++--- x/bank/keeper/keeper.go | 15 +++++++++++- x/bank/keeper/msg_server.go | 9 ++++--- x/bank/keeper/send.go | 6 ++--- x/bank/module.go | 11 +++++---- x/bank/simulation/genesis_test.go | 2 +- x/bank/testutil/expected_keepers_mocks.go | 30 +++++++++++++++++++++++ x/bank/types/balance.go | 5 ++-- x/bank/types/balance_test.go | 15 +++++++++--- x/bank/types/expected_keepers.go | 5 ++++ x/genutil/types/genesis_state_test.go | 2 +- x/gov/testutil/expected_keepers_mocks.go | 30 +++++++++++++++++++++++ 19 files changed, 148 insertions(+), 49 deletions(-) diff --git a/testutil/cli/cmd.go b/testutil/cli/cmd.go index e571ce78454b..f4385aea30ac 100644 --- a/testutil/cli/cmd.go +++ b/testutil/cli/cmd.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "cosmossdk.io/core/address" cli2 "github.com/cometbft/cometbft/libs/cli" "github.com/spf13/cobra" @@ -29,16 +30,16 @@ func ExecTestCLICmd(clientCtx client.Context, cmd *cobra.Command, extraArgs []st return out, nil } -func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) { +func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) { args := []string{from.String(), to.String(), amount.String()} args = append(args, extraArgs...) - return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(), args) + return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(ac), args) } -func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) { +func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) { args := []string{address.String(), fmt.Sprintf("--%s=json", cli2.OutputFlag)} args = append(args, extraArgs...) - return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(), args) + return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(ac), args) } diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 7c1a0f7ae53f..23facd68ff09 100644 --- a/x/bank/client/cli/query.go +++ b/x/bank/client/cli/query.go @@ -4,11 +4,11 @@ import ( "fmt" "strings" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -21,7 +21,7 @@ const ( // GetQueryCmd returns the parent command for all x/bank CLi query commands. The // provided clientCtx should have, at a minimum, a verifier, CometBFT RPC client, // and marshaler set. -func GetQueryCmd() *cobra.Command { +func GetQueryCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Querying commands for the bank module", @@ -31,8 +31,8 @@ func GetQueryCmd() *cobra.Command { } cmd.AddCommand( - GetBalancesCmd(), - GetSpendableBalancesCmd(), + GetBalancesCmd(ac), + GetSpendableBalancesCmd(ac), GetCmdQueryTotalSupply(), GetCmdDenomsMetadata(), GetCmdQuerySendEnabled(), @@ -41,7 +41,7 @@ func GetQueryCmd() *cobra.Command { return cmd } -func GetBalancesCmd() *cobra.Command { +func GetBalancesCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "balances [address]", Short: "Query for account balances by address", @@ -70,7 +70,7 @@ Example: queryClient := types.NewQueryClient(clientCtx) - addr, err := sdk.AccAddressFromBech32(args[0]) + addr, err := ac.StringToBytes(args[0]) if err != nil { return err } @@ -117,7 +117,7 @@ Example: return cmd } -func GetSpendableBalancesCmd() *cobra.Command { +func GetSpendableBalancesCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "spendable-balances [address]", Short: "Query for account spendable balances by address", @@ -136,7 +136,7 @@ func GetSpendableBalancesCmd() *cobra.Command { queryClient := types.NewQueryClient(clientCtx) - addr, err := sdk.AccAddressFromBech32(args[0]) + addr, err := ac.StringToBytes(args[0]) if err != nil { return err } diff --git a/x/bank/client/cli/query_test.go b/x/bank/client/cli/query_test.go index 2708a9063625..92aac17703f3 100644 --- a/x/bank/client/cli/query_test.go +++ b/x/bank/client/cli/query_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -21,8 +22,7 @@ import ( func (s *CLITestSuite) TestGetBalancesCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - - cmd := cli.GetBalancesCmd() + cmd := cli.GetBalancesCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) testCases := []struct { @@ -123,7 +123,7 @@ func (s *CLITestSuite) TestGetBalancesCmd() { func (s *CLITestSuite) TestGetSpendableBalancesCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.GetSpendableBalancesCmd() + cmd := cli.GetSpendableBalancesCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) testCases := []struct { diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 8161fa902118..5126407d2b8b 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "fmt" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" @@ -15,7 +16,7 @@ import ( var FlagSplit = "split" // NewTxCmd returns a root CLI command handler for all x/bank transaction commands. -func NewTxCmd() *cobra.Command { +func NewTxCmd(ac address.Codec) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Bank transaction subcommands", @@ -25,15 +26,15 @@ func NewTxCmd() *cobra.Command { } txCmd.AddCommand( - NewSendTxCmd(), - NewMultiSendTxCmd(), + NewSendTxCmd(ac), + NewMultiSendTxCmd(ac), ) return txCmd } // NewSendTxCmd returns a CLI command handler for creating a MsgSend transaction. -func NewSendTxCmd() *cobra.Command { +func NewSendTxCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "send [from_key_or_address] [to_address] [amount]", Short: "Send funds from one account to another.", @@ -49,7 +50,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. return err } - toAddr, err := sdk.AccAddressFromBech32(args[1]) + toAddr, err := ac.StringToBytes(args[1]) if err != nil { return err } @@ -72,7 +73,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. // NewMultiSendTxCmd returns a CLI command handler for creating a MsgMultiSend transaction. // For a better UX this command is limited to send funds from one account to two or more accounts. -func NewMultiSendTxCmd() *cobra.Command { +func NewMultiSendTxCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "multi-send [from_key_or_address] [to_address_1, to_address_2, ...] [amount]", Short: "Send funds from one account to two or more accounts.", @@ -113,7 +114,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. var output []types.Output for _, arg := range args[1 : len(args)-1] { - toAddr, err := sdk.AccAddressFromBech32(arg) + toAddr, err := ac.StringToBytes(arg) if err != nil { return err } diff --git a/x/bank/client/cli/tx_test.go b/x/bank/client/cli/tx_test.go index 7f3fe4b565be..be16d2a39b77 100644 --- a/x/bank/client/cli/tx_test.go +++ b/x/bank/client/cli/tx_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,7 +16,7 @@ import ( func (s *CLITestSuite) TestSendTxCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.NewSendTxCmd() + cmd := cli.NewSendTxCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) extraArgs := []string{ @@ -98,7 +99,7 @@ func (s *CLITestSuite) TestSendTxCmd() { func (s *CLITestSuite) TestMultiSendTxCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 3) - cmd := cli.NewMultiSendTxCmd() + cmd := cli.NewMultiSendTxCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) extraArgs := []string{ diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 7ab9136e896d..5ca0ae784662 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -1,6 +1,7 @@ package exported import ( + "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -8,7 +9,7 @@ import ( // GenesisBalance defines a genesis balance interface that allows for account // address and balance retrieval. type GenesisBalance interface { - GetAddress() sdk.AccAddress + GetAddress(address.Codec) ([]byte, error) GetCoins() sdk.Coins } diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index e214570e5035..10168029a0f4 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -22,7 +22,10 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { genState.Balances = types.SanitizeGenesisBalances(genState.Balances) for _, balance := range genState.Balances { - addr := balance.GetAddress() + addr, err := balance.GetAddress(k.ak) + if err != nil { + panic(fmt.Errorf("error on setting balances %w", err)) + } if err := k.initBalances(ctx, addr, balance.Coins); err != nil { panic(fmt.Errorf("error on setting balances %w", err)) diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index 49fa628090c7..873ff91877eb 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -27,7 +27,7 @@ func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) } sdkCtx := sdk.UnwrapSDKContext(ctx) - address, err := sdk.AccAddressFromBech32(req.Address) + address, err := k.ak.StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -43,7 +43,7 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := sdk.AccAddressFromBech32(req.Address) + addr, err := k.ak.StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -85,7 +85,7 @@ func (k BaseKeeper) SpendableBalances(ctx context.Context, req *types.QuerySpend return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := sdk.AccAddressFromBech32(req.Address) + addr, err := k.ak.StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -121,7 +121,7 @@ func (k BaseKeeper) SpendableBalanceByDenom(ctx context.Context, req *types.Quer return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := sdk.AccAddressFromBech32(req.Address) + addr, err := k.ak.StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index d767ae5f31bb..adff3f602c13 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -48,6 +48,11 @@ type Keeper interface { DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error + // StringToBytes decodes text to bytes + StringToBytes(text string) ([]byte, error) + // BytesToString encodes bytes to text + BytesToString(bz []byte) (string, error) + types.QueryServer } @@ -90,7 +95,7 @@ func NewBaseKeeper( blockedAddrs map[string]bool, authority string, ) BaseKeeper { - if _, err := sdk.AccAddressFromBech32(authority); err != nil { + if _, err := ak.StringToBytes(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) } @@ -467,3 +472,11 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bo return cb(sdk.NewCoin(s, m)) }) } + +func (k BaseKeeper) StringToBytes(s string) ([]byte, error) { + return k.ak.StringToBytes(s) +} + +func (k BaseKeeper) BytesToString(s []byte) (string, error) { + return k.ak.BytesToString(s) +} diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 77d58eefd1a5..469fde78f681 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -33,11 +33,11 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe return nil, err } - from, err := sdk.AccAddressFromBech32(msg.FromAddress) + from, err := k.StringToBytes(msg.FromAddress) if err != nil { return nil, err } - to, err := sdk.AccAddressFromBech32(msg.ToAddress) + to, err := k.StringToBytes(msg.ToAddress) if err != nil { return nil, err } @@ -77,7 +77,10 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t } for _, out := range msg.Outputs { - accAddr := sdk.MustAccAddressFromBech32(out.Address) + accAddr, err := k.StringToBytes(out.Address) + if err != nil { + return nil, err + } if k.BlockedAddr(accAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 3903cf482f05..b6732f4fa572 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -69,7 +69,7 @@ func NewBaseSendKeeper( blockedAddrs map[string]bool, authority string, ) BaseSendKeeper { - if _, err := sdk.AccAddressFromBech32(authority); err != nil { + if _, err := ak.StringToBytes(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) } @@ -120,7 +120,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, out return err } - inAddress, err := sdk.AccAddressFromBech32(input.Address) + inAddress, err := k.ak.StringToBytes(input.Address) if err != nil { return err } @@ -138,7 +138,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, out ) for _, out := range outputs { - outAddress, err := sdk.AccAddressFromBech32(out.Address) + outAddress, err := k.ak.StringToBytes(out.Address) if err != nil { return err } diff --git a/x/bank/module.go b/x/bank/module.go index 63d6319ff479..f5c13eb8a69d 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -44,6 +44,7 @@ var ( // AppModuleBasic defines the basic application module used by the bank module. type AppModuleBasic struct { cdc codec.Codec + ak types.AccountKeeper } // Name returns the bank module's name. @@ -78,13 +79,13 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } // GetTxCmd returns the root tx command for the bank module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() +func (ab AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd(ab.ak) } // GetQueryCmd returns no root query command for the bank module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() +func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(ab.ak) } // RegisterInterfaces registers interfaces and implementations of the bank module. @@ -136,7 +137,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, ss exported.Subspace) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, + AppModuleBasic: AppModuleBasic{cdc: cdc, ak: accountKeeper}, keeper: keeper, accountKeeper: accountKeeper, legacySubspace: ss, diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 76be7256f84d..91b2119399ec 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -45,7 +45,7 @@ func TestRandomizedGenState(t *testing.T) { assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled") assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck if assert.Len(t, bankGenesis.Balances, 3) { - assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].GetAddress().String(), "Balances[2] address") + assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2], "Balances[2] address") assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins") } assert.Equal(t, "6000stake", bankGenesis.Supply.String(), "Supply") diff --git a/x/bank/testutil/expected_keepers_mocks.go b/x/bank/testutil/expected_keepers_mocks.go index 3b5668228444..4d0ba2ac2380 100644 --- a/x/bank/testutil/expected_keepers_mocks.go +++ b/x/bank/testutil/expected_keepers_mocks.go @@ -36,6 +36,21 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { return m.recorder } +// BytesToString mocks base method. +func (m *MockAccountKeeper) BytesToString(bz []byte) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BytesToString", bz) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BytesToString indicates an expected call of BytesToString. +func (mr *MockAccountKeeperMockRecorder) BytesToString(bz interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesToString", reflect.TypeOf((*MockAccountKeeper)(nil).BytesToString), bz) +} + // GetAccount mocks base method. func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { m.ctrl.T.Helper() @@ -214,6 +229,21 @@ func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(ctx, macc interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), ctx, macc) } +// StringToBytes mocks base method. +func (m *MockAccountKeeper) StringToBytes(text string) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StringToBytes", text) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StringToBytes indicates an expected call of StringToBytes. +func (mr *MockAccountKeeperMockRecorder) StringToBytes(text interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringToBytes", reflect.TypeOf((*MockAccountKeeper)(nil).StringToBytes), text) +} + // ValidatePermissions mocks base method. func (m *MockAccountKeeper) ValidatePermissions(macc types.ModuleAccountI) error { m.ctrl.T.Helper() diff --git a/x/bank/types/balance.go b/x/bank/types/balance.go index 3b0decadbea0..e829d38c366f 100644 --- a/x/bank/types/balance.go +++ b/x/bank/types/balance.go @@ -5,6 +5,7 @@ import ( "encoding/json" "sort" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" @@ -13,8 +14,8 @@ import ( var _ exported.GenesisBalance = (*Balance)(nil) // GetAddress returns the account address of the Balance object. -func (b Balance) GetAddress() sdk.AccAddress { - return sdk.MustAccAddressFromBech32(b.Address) +func (b Balance) GetAddress(ac address.Codec) ([]byte, error) { + return ac.StringToBytes(b.Address) } // GetCoins returns the account coins of the Balance object. diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index a69cf48268bf..443d28bf4b87 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" bank "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -128,12 +129,14 @@ func TestBalance_GetAddress(t *testing.T) { } for _, tt := range tests { tt := tt + ac := address.NewBech32Codec("cosmos") t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} if tt.wantPanic { - require.Panics(t, func() { b.GetAddress() }) + require.Panics(t, func() { b.GetAddress(ac) }) } else { - require.False(t, b.GetAddress().Empty()) + _, err := b.GetAddress(ac) + require.Error(t, err) } }) } @@ -165,7 +168,13 @@ func TestSanitizeBalances(t *testing.T) { for j := i + 1; j < len(sorted); j++ { aj := sorted[j] - if got := bytes.Compare(ai.GetAddress(), aj.GetAddress()); got > 0 { + ac := address.NewBech32Codec("cosmos") + + aiAddr, err := ai.GetAddress(ac) + require.NoError(t, err) + ajAddr, err := aj.GetAddress(ac) + require.NoError(t, err) + if got := bytes.Compare(aiAddr, ajAddr); got > 0 { t.Errorf("Balance(%d) > Balance(%d)", i, j) } } diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index c1a8911107c6..f0acb8bdd748 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -28,4 +28,9 @@ type AccountKeeper interface { GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI) GetModulePermissions() map[string]types.PermissionsForAddress + + // StringToBytes decodes text to bytes + StringToBytes(text string) ([]byte, error) + // BytesToString encodes bytes to text + BytesToString(bz []byte) (string, error) } diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index a589f5a4f953..5ef4b0c1dded 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -88,7 +88,7 @@ func TestGenesisStateFromGenFile(t *testing.T) { require.True(t, bankGenesis.Params.DefaultSendEnabled) require.Equal(t, "1000nametoken,100000000stake", bankGenesis.Balances[0].GetCoins().String()) - require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0].GetAddress().String()) + require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0]) require.Equal(t, "The native staking token of the Cosmos Hub.", bankGenesis.DenomMetadata[0].GetDescription()) require.Equal(t, "uatom", bankGenesis.DenomMetadata[0].GetBase()) require.Equal(t, "matom", bankGenesis.DenomMetadata[0].GetDenomUnits()[1].GetDenom()) diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index e59d2a5656ce..59904e4ebaa8 100644 --- a/x/gov/testutil/expected_keepers_mocks.go +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -187,6 +187,21 @@ func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) } +// BytesToString mocks base method. +func (m *MockBankKeeper) BytesToString(bz []byte) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BytesToString", bz) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BytesToString indicates an expected call of BytesToString. +func (mr *MockBankKeeperMockRecorder) BytesToString(bz interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesToString", reflect.TypeOf((*MockBankKeeper)(nil).BytesToString), bz) +} + // DelegateCoins mocks base method. func (m *MockBankKeeper) DelegateCoins(ctx types.Context, delegatorAddr, moduleAccAddr types.AccAddress, amt types.Coins) error { m.ctrl.T.Helper() @@ -860,6 +875,21 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) } +// StringToBytes mocks base method. +func (m *MockBankKeeper) StringToBytes(text string) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StringToBytes", text) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StringToBytes indicates an expected call of StringToBytes. +func (mr *MockBankKeeperMockRecorder) StringToBytes(text interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringToBytes", reflect.TypeOf((*MockBankKeeper)(nil).StringToBytes), text) +} + // SupplyOf mocks base method. func (m *MockBankKeeper) SupplyOf(arg0 context.Context, arg1 *types0.QuerySupplyOfRequest) (*types0.QuerySupplyOfResponse, error) { m.ctrl.T.Helper() From 763c11cd887a79722465c5df76d9675622ecf715 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 28 Mar 2023 11:04:56 +0200 Subject: [PATCH 02/19] fix module tests --- x/auth/client/cli/suite_test.go | 15 +++++++++++++-- x/authz/client/cli/tx_test.go | 11 ++++++++++- x/group/client/cli/tx_test.go | 3 ++- x/nft/client/cli/tx_test.go | 8 +++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index 29bb0a2f05f5..755d1f6f02a0 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "cosmossdk.io/core/address" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" @@ -15,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -46,6 +48,8 @@ type CLITestSuite struct { clientCtx client.Context val sdk.AccAddress val1 sdk.AccAddress + + ac address.Codec } func TestCLITestSuite(t *testing.T) { @@ -99,6 +103,8 @@ func (s *CLITestSuite) SetupSuite() { multi := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{pub1, pub2}) _, err = kb.SaveMultisig("multi", multi) s.Require().NoError(err) + + s.ac = addresscodec.NewBech32Codec("cosmos") } func (s *CLITestSuite) TestCLIValidateSignatures() { @@ -456,6 +462,7 @@ func (s *CLITestSuite) TestCLIMultisignInsufficientCosigners() { sdk.NewCoins( sdk.NewInt64Coin("stake", 5), ), + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -544,6 +551,7 @@ func (s *CLITestSuite) TestCLIMultisignSortSignatures() { sdk.NewCoins( sdk.NewInt64Coin("stake", 5), ), + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -617,6 +625,7 @@ func (s *CLITestSuite) TestSignWithMultisig() { sdk.NewCoins( sdk.NewInt64Coin("stake", 5), ), + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -658,6 +667,7 @@ func (s *CLITestSuite) TestCLIMultisign() { sdk.NewCoins( sdk.NewInt64Coin("stake", 5), ), + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -731,6 +741,7 @@ func (s *CLITestSuite) TestSignBatchMultisig() { sdk.NewCoins( sdk.NewCoin("stake", sdk.NewInt(1)), ), + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -1266,7 +1277,7 @@ func (s *CLITestSuite) TestAuxToFeeWithTips() { } func (s *CLITestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int { - resp, err := clitestutil.QueryBalancesExec(clientCtx, addr) + resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, s.ac) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse @@ -1285,5 +1296,5 @@ func (s *CLITestSuite) createBankMsg(clientCtx client.Context, toAddr sdk.AccAdd } flags = append(flags, extraFlags...) - return clitestutil.MsgSendExec(clientCtx, s.val, toAddr, amount, flags...) + return clitestutil.MsgSendExec(clientCtx, s.val, toAddr, amount, s.ac, flags...) } diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 969129489fa4..de1ad6f6fb2d 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -12,8 +12,10 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -46,6 +48,8 @@ type CLITestSuite struct { clientCtx client.Context grantee []sdk.AccAddress addrs []sdk.AccAddress + + ac address.Codec } func TestCLITestSuite(t *testing.T) { @@ -152,6 +156,8 @@ func (s *CLITestSuite) SetupSuite() { s.Require().NoError(err) s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) + + s.ac = addresscodec.NewBech32Codec("cosmos") } func (s *CLITestSuite) createAccount(uid string) sdk.AccAddress { @@ -172,7 +178,7 @@ func (s *CLITestSuite) msgSendExec(grantee sdk.AccAddress) { s.clientCtx, val[0].Address, grantee, - sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))), s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), ) @@ -738,6 +744,7 @@ func (s *CLITestSuite) TestNewExecGrantAuthorized() { val[0].Address, grantee, tokens, + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -835,6 +842,7 @@ func (s *CLITestSuite) TestExecSendAuthzWithAllowList() { val[0].Address, allowedAddr, tokens, + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), @@ -849,6 +857,7 @@ func (s *CLITestSuite) TestExecSendAuthzWithAllowList() { val[0].Address, notAllowedAddr, tokens, + s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 46f35b137c80..ab5015a54e22 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -17,6 +17,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/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" @@ -91,7 +92,7 @@ func (s *CLITestSuite) SetupSuite() { s.clientCtx, val.Address, account, - sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), address.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), ) diff --git a/x/nft/client/cli/tx_test.go b/x/nft/client/cli/tx_test.go index 5d78c89d699f..8351363c7aa6 100644 --- a/x/nft/client/cli/tx_test.go +++ b/x/nft/client/cli/tx_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codecaddress "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" @@ -21,6 +22,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" + "cosmossdk.io/core/address" "cosmossdk.io/x/nft" "cosmossdk.io/x/nft/client/cli" nftmodule "cosmossdk.io/x/nft/module" @@ -75,6 +77,8 @@ type CLITestSuite struct { ctx context.Context owner sdk.AccAddress + + ac address.Codec } func TestCLITestSuite(t *testing.T) { @@ -120,6 +124,8 @@ func (s *CLITestSuite) SetupSuite() { s.Require().NoError(err) genesisState[nft.ModuleName] = nftDataBz + s.ac = codecaddress.NewBech32Codec("cosmos") + s.initAccount() } @@ -229,6 +235,6 @@ func (s *CLITestSuite) initAccount() { s.Require().NoError(err) amount := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))) - _, err = clitestutil.MsgSendExec(ctx, accounts[0].Address, s.owner, amount, args...) + _, err = clitestutil.MsgSendExec(ctx, accounts[0].Address, s.owner, amount, s.ac, args...) s.Require().NoError(err) } From 36a20785fbd6c2e06d23b87f8c9aded9c9cc8151 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 29 Mar 2023 23:59:13 +0200 Subject: [PATCH 03/19] fixing --- tests/e2e/auth/suite.go | 29 ++++++++++++-------- tests/e2e/authz/tx.go | 6 +++- tests/e2e/bank/suite.go | 12 ++++---- tests/e2e/distribution/withdraw_all_suite.go | 3 +- tests/e2e/gov/tx.go | 5 ++-- tests/e2e/group/tx.go | 6 ++-- tests/e2e/nft/tx.go | 3 +- tests/e2e/staking/suite.go | 7 +++-- tests/e2e/tx/service_test.go | 5 ++++ 9 files changed, 50 insertions(+), 26 deletions(-) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 7097851bad74..193342883165 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -143,7 +144,7 @@ func (s *E2ETestSuite) TestCLISignGenOnly() { fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), } - generatedStd, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args) + generatedStd, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(addresscodec.NewBech32Codec("cosmos")), args) s.Require().NoError(err) opFile := testutil.WriteToNewTempFile(s.T(), generatedStd.String()) defer opFile.Close() @@ -689,7 +690,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().NoError(err) s.Require().Equal(0, len(sigs)) - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address) + resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse @@ -754,7 +755,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().NoError(s.network.WaitForNextBlock()) // Ensure foo has right amount of funds - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address) + resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) @@ -776,7 +777,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { // Ensure destiny account state err = s.network.RetryForBlocks(func() error { - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) return err }, 3) s.Require().NoError(err) @@ -786,7 +787,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) // Ensure origin account state - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address) + resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) @@ -824,6 +825,7 @@ func (s *E2ETestSuite) TestCLIMultisignInsufficientCosigners() { sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 5), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -907,7 +909,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { addr, err := multisigRecord.GetAddress() s.Require().NoError(err) - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse @@ -925,7 +927,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) @@ -941,6 +943,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 5), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -1018,6 +1021,7 @@ func (s *E2ETestSuite) TestSignWithMultisig() { sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 5), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -1065,7 +1069,7 @@ func (s *E2ETestSuite) TestCLIMultisign() { var balRes banktypes.QueryAllBalancesResponse err = s.network.RetryForBlocks(func() error { - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr) + resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) if err != nil { return err } @@ -1082,6 +1086,7 @@ func (s *E2ETestSuite) TestCLIMultisign() { sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 5), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -1175,6 +1180,7 @@ func (s *E2ETestSuite) TestSignBatchMultisig() { sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -1240,6 +1246,7 @@ func (s *E2ETestSuite) TestMultisignBatch() { sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -1616,7 +1623,7 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { require.Equal(uint32(0), txRes.Code, txRes.RawLog) // Make sure the addr1's balance got funded. - queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1) + queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1, addresscodec.NewBech32Codec("cosmos")) require.NoError(err) var queryRes banktypes.QueryAllBalancesResponse err = val0.ClientCtx.Codec.UnmarshalJSON(queryResJSON.Bytes(), &queryRes) @@ -1948,11 +1955,11 @@ func (s *E2ETestSuite) createBankMsg(val *network.Validator, toAddr sdk.AccAddre } flags = append(flags, extraFlags...) - return clitestutil.MsgSendExec(val.ClientCtx, val.Address, toAddr, amount, flags...) + return clitestutil.MsgSendExec(val.ClientCtx, val.Address, toAddr, amount, addresscodec.NewBech32Codec("cosmos"), flags...) } func (s *E2ETestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int { - resp, err := clitestutil.QueryBalancesExec(clientCtx, addr) + resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse diff --git a/tests/e2e/authz/tx.go b/tests/e2e/authz/tx.go index 613b959b4c75..f3bf0baffd51 100644 --- a/tests/e2e/authz/tx.go +++ b/tests/e2e/authz/tx.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -146,7 +147,7 @@ func (s *E2ETestSuite) msgSendExec(grantee sdk.AccAddress) { val.ClientCtx, val.Address, grantee, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -858,6 +859,7 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() { val.Address, grantee, tokens, + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -972,6 +974,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() { val.Address, allowedAddr, tokens, + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -986,6 +989,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() { val.Address, notAllowedAddr, tokens, + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), diff --git a/tests/e2e/bank/suite.go b/tests/e2e/bank/suite.go index 961aca4474a6..501f54994cd8 100644 --- a/tests/e2e/bank/suite.go +++ b/tests/e2e/bank/suite.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -152,7 +153,8 @@ func (s *E2ETestSuite) TestGetBalancesCmd() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetBalancesCmd() + + cmd := cli.GetBalancesCmd(addresscodec.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args) if tc.expectErr { @@ -383,7 +385,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() { fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), } - bz, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...) + bz, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, addresscodec.NewBech32Codec("cosmos"), args...) s.Require().NoError(err) tx, err := s.cfg.TxConfig.TxJSONDecoder()(bz.Bytes()) s.Require().NoError(err) @@ -412,7 +414,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdDryRun() { r, w, _ := os.Pipe() os.Stderr = w - _, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...) + _, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, addresscodec.NewBech32Codec("cosmos"), args...) s.Require().NoError(err) w.Close() @@ -510,7 +512,7 @@ func (s *E2ETestSuite) TestNewSendTxCmd() { s.Run(tc.name, func() { clientCtx := val.ClientCtx - bz, err := clitestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...) + bz, err := clitestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, addresscodec.NewBech32Codec("cosmos"), tc.args...) if tc.expectErr { s.Require().Error(err) } else { @@ -673,5 +675,5 @@ func MsgMultiSendExec(clientCtx client.Context, from sdk.AccAddress, to []sdk.Ac args = append(args, amount.String()) args = append(args, extraArgs...) - return clitestutil.ExecTestCLICmd(clientCtx, cli.NewMultiSendTxCmd(), args) + return clitestutil.ExecTestCLICmd(clientCtx, cli.NewMultiSendTxCmd(addresscodec.NewBech32Codec("cosmos")), args) } diff --git a/tests/e2e/distribution/withdraw_all_suite.go b/tests/e2e/distribution/withdraw_all_suite.go index 25a431d54c1f..803d92c0cf1e 100644 --- a/tests/e2e/distribution/withdraw_all_suite.go +++ b/tests/e2e/distribution/withdraw_all_suite.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -63,7 +64,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() { val.ClientCtx, val.Address, newAddr, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) diff --git a/tests/e2e/gov/tx.go b/tests/e2e/gov/tx.go index a8e06691133a..15258f569797 100644 --- a/tests/e2e/gov/tx.go +++ b/tests/e2e/gov/tx.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -351,7 +352,7 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() { var balRes banktypes.QueryAllBalancesResponse var newBalance banktypes.QueryAllBalancesResponse if !tc.expectErr && tc.expectedCode == 0 { - resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address) + resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) s.Require().NoError(err) @@ -367,7 +368,7 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() { s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode)) if !tc.expectErr && tc.expectedCode == 0 { - resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address) + resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &newBalance) s.Require().NoError(err) diff --git a/tests/e2e/group/tx.go b/tests/e2e/group/tx.go index 6b6265c6c73b..40c1cd503cf1 100644 --- a/tests/e2e/group/tx.go +++ b/tests/e2e/group/tx.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -75,7 +76,7 @@ func (s *E2ETestSuite) SetupSuite() { val.ClientCtx, val.Address, account, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -2564,7 +2565,7 @@ func (s *E2ETestSuite) createAccounts(quantity int) []string { val.ClientCtx, val.Address, account, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -2638,6 +2639,7 @@ func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, group s.Require().NoError(err) _, err = clitestutil.MsgSendExec(clientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(tokens))), + addresscodec.NewBech32Codec("cosmos"), s.commonFlags..., ) s.Require().NoError(err) diff --git a/tests/e2e/nft/tx.go b/tests/e2e/nft/tx.go index 2c1423b71a07..7db9cd14fe5b 100644 --- a/tests/e2e/nft/tx.go +++ b/tests/e2e/nft/tx.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/x/nft" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -157,6 +158,6 @@ func (s *E2ETestSuite) initAccount() { s.Require().NoError(err) amount := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))) - _, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, args...) + _, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, addresscodec.NewBech32Codec("cosmos"), args...) s.Require().NoError(err) } diff --git a/tests/e2e/staking/suite.go b/tests/e2e/staking/suite.go index ee291910b81c..ee036aaa9783 100644 --- a/tests/e2e/staking/suite.go +++ b/tests/e2e/staking/suite.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -107,7 +108,7 @@ func (s *E2ETestSuite) TestNewCreateValidatorCmd() { val.ClientCtx, val.Address, newAddr, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -1115,7 +1116,7 @@ func (s *E2ETestSuite) TestNewDelegateCmd() { val.ClientCtx, val.Address, newAddr, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -1477,7 +1478,7 @@ func (s *E2ETestSuite) TestBlockResults() { val.ClientCtx, val.Address, newAddr, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 30b8142479cd..3ed53bcd207b 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clienttx "github.com/cosmos/cosmos-sdk/client/tx" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -74,6 +75,7 @@ func (s *E2ETestSuite) SetupSuite() { sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -91,6 +93,7 @@ func (s *E2ETestSuite) SetupSuite() { sdk.NewCoins( sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=0", flags.FlagAccountNumber), @@ -597,6 +600,7 @@ func (s *E2ETestSuite) TestSimMultiSigTx() { val1.Address, addr, sdk.NewCoins(coins), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), @@ -617,6 +621,7 @@ func (s *E2ETestSuite) TestSimMultiSigTx() { sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 5), ), + addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), From 8b91ae90a67c17b9b39a75d3ef1b524cbedf2992 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 31 Mar 2023 16:31:43 +0200 Subject: [PATCH 04/19] remove extra provide --- x/auth/module.go | 9 --------- x/bank/keeper/keeper_test.go | 8 ++++++-- x/bank/types/balance_test.go | 11 ++++++----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/x/auth/module.go b/x/auth/module.go index 00bbb2607016..5b92c476a5a0 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -11,7 +11,6 @@ import ( "cosmossdk.io/depinject" - "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -20,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -199,17 +197,10 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideAddressCodec), appmodule.Provide(ProvideModule), ) } -// ProvideAddressCodec provides an address.Codec to the container for any -// modules that want to do address string <> bytes conversion. -func ProvideAddressCodec(config *modulev1.Module) address.Codec { - return codecaddress.NewBech32Codec(config.Bech32Prefix) -} - type ModuleInputs struct { depinject.In diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 28bf17fe8093..ae031f623856 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -130,7 +130,8 @@ func (suite *KeeperTestSuite) SetupTest() { // gomock initializations ctrl := gomock.NewController(suite.T()) authKeeper := banktestutil.NewMockAccountKeeper(ctrl) - + authKeeper.EXPECT().StringToBytes(authtypes.NewModuleAddress(govtypes.ModuleName).String()).Return(authtypes.NewModuleAddress(govtypes.ModuleName), nil).AnyTimes() + authKeeper.EXPECT().BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)).Return(authtypes.NewModuleAddress(govtypes.ModuleName).String(), nil).AnyTimes() suite.ctx = ctx suite.authKeeper = authKeeper suite.bankKeeper = keeper.NewBaseKeeper( @@ -233,11 +234,14 @@ func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx sdk.Context, acc, mAcc sdk } func (suite *KeeperTestSuite) TestGetAuthority() { + suite.authKeeper.EXPECT().StringToBytes(authtypes.NewModuleAddress(minttypes.ModuleName).String()).Return(authtypes.NewModuleAddress(minttypes.ModuleName), nil).AnyTimes() + suite.authKeeper.EXPECT().StringToBytes("cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5").Return([]byte("8953EB4F1B47C7982A698DEB7C557D6E4F4CD923"), nil).AnyTimes() + NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper { return keeper.NewBaseKeeper( moduletestutil.MakeTestEncodingConfig().Codec, storetypes.NewKVStoreKey(banktypes.StoreKey), - nil, + suite.authKeeper, nil, authority, ) diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index 443d28bf4b87..676a26eae115 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -119,9 +119,9 @@ func TestBalanceValidate(t *testing.T) { func TestBalance_GetAddress(t *testing.T) { tests := []struct { - name string - Address string - wantPanic bool + name string + Address string + err bool }{ {"empty address", "", true}, {"malformed address", "invalid", true}, @@ -132,8 +132,9 @@ func TestBalance_GetAddress(t *testing.T) { ac := address.NewBech32Codec("cosmos") t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} - if tt.wantPanic { - require.Panics(t, func() { b.GetAddress(ac) }) + if !tt.err { + _, err := b.GetAddress(ac) + require.NoError(t, err) } else { _, err := b.GetAddress(ac) require.Error(t, err) From 9b0278408ce4be82a251beae280e2c0c9c9fab62 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 7 Apr 2023 11:55:18 +0200 Subject: [PATCH 05/19] early feedback --- simapp/simd/cmd/root.go | 11 ++++++----- testutil/network/util.go | 5 +++-- x/genutil/client/cli/collect.go | 5 +++-- x/genutil/client/cli/commands.go | 15 ++++++++------- x/genutil/client/cli/gentx.go | 5 +++-- x/genutil/collect.go | 29 ++++++++++++++++++++++++----- x/genutil/collect_test.go | 3 ++- x/genutil/gentx.go | 11 ++++++++--- 8 files changed, 57 insertions(+), 27 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 23e4707be0c5..13aced86e8e6 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -5,6 +5,7 @@ import ( "io" "os" + "cosmossdk.io/core/address" "cosmossdk.io/log" cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" @@ -108,7 +109,7 @@ func NewRootCmd() *cobra.Command { }, } - initRootCmd(rootCmd, encodingConfig) + initRootCmd(rootCmd, encodingConfig, tempApp.AccountKeeper.GetAddressCodec()) if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil { panic(err) @@ -186,7 +187,7 @@ lru_size = 0` return customAppTemplate, customAppConfig } -func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { +func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, ac address.Codec) { cfg := sdk.GetConfig() cfg.Seal() @@ -203,7 +204,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { // add keybase, auxiliary RPC, query, genesis, and tx child commands rootCmd.AddCommand( rpc.StatusCommand(), - genesisCommand(encodingConfig), + genesisCommand(encodingConfig, ac), queryCommand(), txCommand(), keys.Commands(simapp.DefaultNodeHome), @@ -218,8 +219,8 @@ func addModuleInitFlags(startCmd *cobra.Command) { } // genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter -func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { - cmd := genutilcli.Commands(encodingConfig.TxConfig, simapp.ModuleBasics, simapp.DefaultNodeHome) +func genesisCommand(encodingConfig params.EncodingConfig, ac address.Codec, cmds ...*cobra.Command) *cobra.Command { + cmd := genutilcli.Commands(encodingConfig.TxConfig, simapp.ModuleBasics, simapp.DefaultNodeHome, ac) for _, subCmd := range cmds { cmd.AddCommand(subCmd) diff --git a/testutil/network/util.go b/testutil/network/util.go index 6b049bfe23c5..baa0b85171f3 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" + "cosmossdk.io/core/address" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" pvm "github.com/cometbft/cometbft/privval" @@ -118,7 +119,7 @@ func startInProcess(cfg Config, val *Validator) error { return nil } -func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { +func collectGenFiles(cfg Config, vals []*Validator, outputDir string, ac address.Codec) error { genTime := cmttime.Now() for i := 0; i < cfg.NumValidators; i++ { @@ -139,7 +140,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, - cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator) + cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, ac) if err != nil { return err } diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index fc001d391fdd..275db954a0c1 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -4,6 +4,7 @@ import ( "encoding/json" "path/filepath" + "cosmossdk.io/core/address" "cosmossdk.io/errors" "github.com/spf13/cobra" @@ -17,7 +18,7 @@ import ( const flagGenTxDir = "gentx-dir" // CollectGenTxsCmd - return the cobra command to collect genesis transactions -func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, validator types.MessageValidator) *cobra.Command { +func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, validator types.MessageValidator, ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "collect-gentxs", Short: "Collect genesis txs and output a genesis.json file", @@ -49,7 +50,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator) + appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator, ac) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/client/cli/commands.go b/x/genutil/client/cli/commands.go index 22d69dc6d17b..369ef4643f45 100644 --- a/x/genutil/client/cli/commands.go +++ b/x/genutil/client/cli/commands.go @@ -1,6 +1,7 @@ package cli import ( + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/module" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -12,18 +13,18 @@ import ( // GenesisCoreCommand adds core sdk's sub-commands into genesis command. // Deprecated: use Commands instead. -func GenesisCoreCommand(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string) *cobra.Command { - return Commands(txConfig, moduleBasics, defaultNodeHome) +func GenesisCoreCommand(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, ac address.Codec) *cobra.Command { + return Commands(txConfig, moduleBasics, defaultNodeHome, ac) } // Commands adds core sdk's sub-commands into genesis command. -func Commands(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string) *cobra.Command { - return CommandsWithCustomMigrationMap(txConfig, moduleBasics, defaultNodeHome, MigrationMap) +func Commands(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, ac address.Codec) *cobra.Command { + return CommandsWithCustomMigrationMap(txConfig, moduleBasics, defaultNodeHome, MigrationMap, ac) } // CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map. // This custom migration map can be used by the application to add its own migration map. -func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, migrationMap genutiltypes.MigrationMap) *cobra.Command { +func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, migrationMap genutiltypes.MigrationMap, ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "genesis", Short: "Application's genesis-related subcommands", @@ -34,9 +35,9 @@ func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics modul gentxModule := moduleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) cmd.AddCommand( - GenTxCmd(moduleBasics, txConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome), + GenTxCmd(moduleBasics, txConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome, ac), MigrateGenesisCmd(migrationMap), - CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator), + CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator, ac), ValidateGenesisCmd(moduleBasics), AddGenesisAccountCmd(defaultNodeHome), ) diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index e73fce8a125d..ab60379d0c23 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + "cosmossdk.io/core/address" "cosmossdk.io/errors" "github.com/spf13/cobra" @@ -27,7 +28,7 @@ import ( ) // GenTxCmd builds the application's gentx command. -func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command { +func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, ac address.Codec) *cobra.Command { ipDefault, _ := server.ExternalIP() fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault) @@ -122,7 +123,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o if err != nil { return err } - err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, addr, coins, cdc) + err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, addr, coins, cdc, ac) if err != nil { return errors.Wrap(err, "failed to validate account in genesis") } diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 9d99559375c2..2e02ece18e60 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -10,6 +10,7 @@ import ( "sort" "strings" + "cosmossdk.io/core/address" cfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/client" @@ -23,11 +24,11 @@ import ( // GenAppStateFromConfig gets the genesis app state from the config func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, config *cfg.Config, initCfg types.InitConfig, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, - validator types.MessageValidator, + validator types.MessageValidator, ac address.Codec, ) (appState json.RawMessage, err error) { // process genesis transactions, else create default genesis.json appGenTxs, persistentPeers, err := CollectTxs( - cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genesis, genBalIterator, validator) + cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genesis, genBalIterator, validator, ac) if err != nil { return appState, err } @@ -66,7 +67,7 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi // the list of appGenTxs, and persistent peers required to generate genesis.json. func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, - validator types.MessageValidator, + validator types.MessageValidator, ac address.Codec, ) (appGenTxs []sdk.Tx, persistentPeers string, err error) { // prepare a map of all balances in genesis state to then validate // against the validators addresses @@ -86,7 +87,15 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx genBalIterator.IterateGenesisBalances( cdc, appState, func(balance bankexported.GenesisBalance) (stop bool) { - balancesMap[balance.GetAddress().String()] = balance + addr, err := balance.GetAddress(ac) + if err != nil { + return true + } + addrSt, err := ac.BytesToString(addr) // this is ugly, we should avoid going to bytes and back + if err != nil { + return true + } + balancesMap[addrSt] = balance return false }, ) @@ -159,9 +168,19 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx } if delBal.GetCoins().AmountOf(msg.Value.Denom).LT(msg.Value.Amount) { + + addr, err := delBal.GetAddress(ac) + if err != nil { + return appGenTxs, persistentPeers, err + } + + addrSt, err := ac.BytesToString(addr) + if err != nil { + return appGenTxs, persistentPeers, err + } return appGenTxs, persistentPeers, fmt.Errorf( "insufficient fund for delegation %v: %v < %v", - delBal.GetAddress().String(), delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount, + addrSt, delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount, ) } diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index 3f0a32a07915..7c7b229b80b1 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -59,7 +60,7 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { balItr := new(doNothingIterator) dnc := &doNothingUnmarshalJSON{cdc} - if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, genesis, balItr, types.DefaultMessageValidator); err != nil { + if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, genesis, balItr, types.DefaultMessageValidator, address.NewBech32Codec("cosmos")); err != nil { t.Fatal(err) } } diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 49eb5349bb7e..6f78bec45d39 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -1,9 +1,11 @@ package genutil import ( + "bytes" "encoding/json" "fmt" + "cosmossdk.io/core/address" abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" @@ -38,7 +40,7 @@ func SetGenTxsInAppGenesisState( // balance in the set of genesis accounts. func ValidateAccountInGenesis( appGenesisState map[string]json.RawMessage, genBalIterator types.GenesisBalancesIterator, - addr sdk.Address, coins sdk.Coins, cdc codec.JSONCodec, + addr sdk.Address, coins sdk.Coins, cdc codec.JSONCodec, ac address.Codec, ) error { var stakingData stakingtypes.GenesisState cdc.MustUnmarshalJSON(appGenesisState[stakingtypes.ModuleName], &stakingData) @@ -50,11 +52,14 @@ func ValidateAccountInGenesis( genBalIterator.IterateGenesisBalances(cdc, appGenesisState, func(bal bankexported.GenesisBalance) (stop bool) { - accAddress := bal.GetAddress() + accAddress, err := bal.GetAddress(ac) + if err != nil { + return false + } accCoins := bal.GetCoins() // ensure that account is in genesis - if accAddress.Equals(addr) { + if bytes.Equal(accAddress, addr.Bytes()) { // ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) { err = fmt.Errorf( From 3a467e2093ea82c14156997b835f7533e8ac490c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 24 Apr 2023 11:56:00 +0200 Subject: [PATCH 06/19] revert some changes --- testutil/network/util.go | 5 ++--- x/bank/exported/exported.go | 3 +-- x/bank/types/balance.go | 3 +-- x/bank/types/balance_test.go | 13 ++++--------- x/genutil/client/cli/collect.go | 2 +- x/genutil/client/cli/gentx.go | 2 +- x/genutil/collect.go | 11 +++++------ x/genutil/gentx.go | 5 ++--- 8 files changed, 17 insertions(+), 27 deletions(-) diff --git a/testutil/network/util.go b/testutil/network/util.go index baa0b85171f3..6b049bfe23c5 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" - "cosmossdk.io/core/address" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" pvm "github.com/cometbft/cometbft/privval" @@ -119,7 +118,7 @@ func startInProcess(cfg Config, val *Validator) error { return nil } -func collectGenFiles(cfg Config, vals []*Validator, outputDir string, ac address.Codec) error { +func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { genTime := cmttime.Now() for i := 0; i < cfg.NumValidators; i++ { @@ -140,7 +139,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string, ac address } appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, - cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator, ac) + cmtCfg, initCfg, appGenesis, banktypes.GenesisBalancesIterator{}, genutiltypes.DefaultMessageValidator) if err != nil { return err } diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 5ca0ae784662..3736427b2567 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -1,7 +1,6 @@ package exported import ( - "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -9,7 +8,7 @@ import ( // GenesisBalance defines a genesis balance interface that allows for account // address and balance retrieval. type GenesisBalance interface { - GetAddress(address.Codec) ([]byte, error) + GetAddress() ([]byte, error) GetCoins() sdk.Coins } diff --git a/x/bank/types/balance.go b/x/bank/types/balance.go index e829d38c366f..167f5aa2d4a9 100644 --- a/x/bank/types/balance.go +++ b/x/bank/types/balance.go @@ -5,7 +5,6 @@ import ( "encoding/json" "sort" - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" @@ -14,7 +13,7 @@ import ( var _ exported.GenesisBalance = (*Balance)(nil) // GetAddress returns the account address of the Balance object. -func (b Balance) GetAddress(ac address.Codec) ([]byte, error) { +func (b Balance) GetAddress() ([]byte, error) { return ac.StringToBytes(b.Address) } diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index 9075a2fe293c..b51eda8db795 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" bank "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -129,14 +128,13 @@ func TestBalance_GetAddress(t *testing.T) { } for _, tt := range tests { tt := tt - ac := address.NewBech32Codec("cosmos") t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} if !tt.err { - _, err := b.GetAddress(ac) + _, err := b.GetAddress() require.NoError(t, err) } else { - _, err := b.GetAddress(ac) + _, err := b.GetAddress() require.Error(t, err) } }) @@ -168,12 +166,9 @@ func TestSanitizeBalances(t *testing.T) { // Ensure that every single value that comes after i is less than it. for j := i + 1; j < len(sorted); j++ { aj := sorted[j] - - ac := address.NewBech32Codec("cosmos") - - aiAddr, err := ai.GetAddress(ac) + aiAddr, err := ai.GetAddress() require.NoError(t, err) - ajAddr, err := aj.GetAddress(ac) + ajAddr, err := aj.GetAddress() require.NoError(t, err) if got := bytes.Compare(aiAddr, ajAddr); got > 0 { t.Errorf("Balance(%d) > Balance(%d)", i, j) diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index 275db954a0c1..a36c696a6de9 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -50,7 +50,7 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH toPrint := newPrintInfo(config.Moniker, appGenesis.ChainID, nodeID, genTxsDir, json.RawMessage("")) initCfg := types.NewInitConfig(appGenesis.ChainID, genTxsDir, nodeID, valPubKey) - appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator, ac) + appMessage, err := genutil.GenAppStateFromConfig(cdc, clientCtx.TxConfig, config, initCfg, appGenesis, genBalIterator, validator) if err != nil { return errors.Wrap(err, "failed to get genesis app state from config") } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index ab60379d0c23..68980144dea5 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -123,7 +123,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o if err != nil { return err } - err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, addr, coins, cdc, ac) + err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, addr, coins, cdc) if err != nil { return errors.Wrap(err, "failed to validate account in genesis") } diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 2e02ece18e60..5ff17c42ea69 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -10,7 +10,6 @@ import ( "sort" "strings" - "cosmossdk.io/core/address" cfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/client" @@ -24,11 +23,11 @@ import ( // GenAppStateFromConfig gets the genesis app state from the config func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig, config *cfg.Config, initCfg types.InitConfig, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, - validator types.MessageValidator, ac address.Codec, + validator types.MessageValidator, ) (appState json.RawMessage, err error) { // process genesis transactions, else create default genesis.json appGenTxs, persistentPeers, err := CollectTxs( - cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genesis, genBalIterator, validator, ac) + cdc, txEncodingConfig.TxJSONDecoder(), config.Moniker, initCfg.GenTxsDir, genesis, genBalIterator, validator) if err != nil { return appState, err } @@ -67,7 +66,7 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi // the list of appGenTxs, and persistent peers required to generate genesis.json. func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator, - validator types.MessageValidator, ac address.Codec, + validator types.MessageValidator, ) (appGenTxs []sdk.Tx, persistentPeers string, err error) { // prepare a map of all balances in genesis state to then validate // against the validators addresses @@ -87,7 +86,7 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx genBalIterator.IterateGenesisBalances( cdc, appState, func(balance bankexported.GenesisBalance) (stop bool) { - addr, err := balance.GetAddress(ac) + addr, err := balance.GetAddress() if err != nil { return true } @@ -169,7 +168,7 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx if delBal.GetCoins().AmountOf(msg.Value.Denom).LT(msg.Value.Amount) { - addr, err := delBal.GetAddress(ac) + addr, err := delBal.GetAddress() if err != nil { return appGenTxs, persistentPeers, err } diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 6f78bec45d39..fa5d13723a82 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "cosmossdk.io/core/address" abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" @@ -40,7 +39,7 @@ func SetGenTxsInAppGenesisState( // balance in the set of genesis accounts. func ValidateAccountInGenesis( appGenesisState map[string]json.RawMessage, genBalIterator types.GenesisBalancesIterator, - addr sdk.Address, coins sdk.Coins, cdc codec.JSONCodec, ac address.Codec, + addr sdk.Address, coins sdk.Coins, cdc codec.JSONCodec, ) error { var stakingData stakingtypes.GenesisState cdc.MustUnmarshalJSON(appGenesisState[stakingtypes.ModuleName], &stakingData) @@ -52,7 +51,7 @@ func ValidateAccountInGenesis( genBalIterator.IterateGenesisBalances(cdc, appGenesisState, func(bal bankexported.GenesisBalance) (stop bool) { - accAddress, err := bal.GetAddress(ac) + accAddress, err := bal.GetAddress() if err != nil { return false } From 777e22955e8480d598512b40bdb026002fcaaf1c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 1 May 2023 13:09:22 +0200 Subject: [PATCH 07/19] revert some changes and return string on getBalances --- simapp/simd/cmd/root.go | 10 ++++------ x/authz/client/cli/tx_test.go | 4 ---- x/bank/exported/exported.go | 2 +- x/bank/keeper/genesis.go | 5 +---- x/bank/keeper/keeper.go | 8 +++----- x/bank/types/balance.go | 4 ++-- x/bank/types/balance_test.go | 14 ++++---------- x/genutil/client/cli/gentx_test.go | 2 ++ x/genutil/collect.go | 23 +++-------------------- x/genutil/collect_test.go | 3 +-- x/genutil/gentx.go | 9 +++------ x/group/client/cli/tx_test.go | 6 ------ 12 files changed, 24 insertions(+), 66 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 59d8fe1ec43b..c0553d3123a6 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -6,17 +6,13 @@ import ( "os" "cosmossdk.io/core/address" - "cosmossdk.io/log" - cmtcfg "github.com/cometbft/cometbft/config" - dbm "github.com/cosmos/cosmos-db" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "cosmossdk.io/log" "cosmossdk.io/simapp" "cosmossdk.io/simapp/params" confixcmd "cosmossdk.io/tools/confix/cmd" rosettaCmd "cosmossdk.io/tools/rosetta/cmd" + cmtcfg "github.com/cometbft/cometbft/config" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" @@ -37,6 +33,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + "github.com/spf13/cobra" + "github.com/spf13/viper" ) // NewRootCmd creates a new root command for simd. It is called once in the diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 6c94b8b7cc08..2513c80b7bd0 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -11,14 +11,10 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" -<<<<<<< HEAD "cosmossdk.io/core/address" -||||||| 67c1c788b2 -======= sdkmath "cosmossdk.io/math" _ "cosmossdk.io/api/cosmos/authz/v1beta1" ->>>>>>> main "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 3736427b2567..60e6872e12c5 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -8,7 +8,7 @@ import ( // GenesisBalance defines a genesis balance interface that allows for account // address and balance retrieval. type GenesisBalance interface { - GetAddress() ([]byte, error) + GetAddress() string GetCoins() sdk.Coins } diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index 86fc97abbc20..eaee07c4843d 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -25,10 +25,7 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat genState.Balances = types.SanitizeGenesisBalances(genState.Balances) for _, balance := range genState.Balances { - addr, err := balance.GetAddress(k.ak) - if err != nil { - panic(fmt.Errorf("error on setting balances %w", err)) - } + addr := balance.GetAddress() for _, coin := range balance.Coins { err := k.Balances.Set(ctx, collections.Join(addr, coin.Denom), coin.Amount) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index fc9a2e7045e0..d3c74a485946 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "cosmossdk.io/core/address" "cosmossdk.io/core/store" "cosmossdk.io/log" "cosmossdk.io/math" @@ -23,6 +24,8 @@ var _ Keeper = (*BaseKeeper)(nil) // Keeper defines a module interface that facilitates the transfer of coins // between accounts. type Keeper interface { + address.Codec + SendKeeper WithMintCoinsRestriction(MintingRestrictionFn) BaseKeeper @@ -50,11 +53,6 @@ type Keeper interface { DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error - // StringToBytes decodes text to bytes - StringToBytes(text string) ([]byte, error) - // BytesToString encodes bytes to text - BytesToString(bz []byte) (string, error) - types.QueryServer } diff --git a/x/bank/types/balance.go b/x/bank/types/balance.go index 167f5aa2d4a9..b1988ed50d78 100644 --- a/x/bank/types/balance.go +++ b/x/bank/types/balance.go @@ -13,8 +13,8 @@ import ( var _ exported.GenesisBalance = (*Balance)(nil) // GetAddress returns the account address of the Balance object. -func (b Balance) GetAddress() ([]byte, error) { - return ac.StringToBytes(b.Address) +func (b Balance) GetAddress() string { + return b.Address } // GetCoins returns the account coins of the Balance object. diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index b51eda8db795..9718755b1dc5 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -1,7 +1,7 @@ package types_test import ( - "bytes" + "strings" "testing" "cosmossdk.io/math" @@ -131,11 +131,9 @@ func TestBalance_GetAddress(t *testing.T) { t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} if !tt.err { - _, err := b.GetAddress() - require.NoError(t, err) + require.Panics(t, func() { b.GetAddress() }) } else { - _, err := b.GetAddress() - require.Error(t, err) + require.False(t, len(b.GetAddress()) == 0) } }) } @@ -166,11 +164,7 @@ func TestSanitizeBalances(t *testing.T) { // Ensure that every single value that comes after i is less than it. for j := i + 1; j < len(sorted); j++ { aj := sorted[j] - aiAddr, err := ai.GetAddress() - require.NoError(t, err) - ajAddr, err := aj.GetAddress() - require.NoError(t, err) - if got := bytes.Compare(aiAddr, ajAddr); got > 0 { + if got := strings.Compare(ai.GetAddress(), aj.GetAddress()); got > 0 { t.Errorf("Balance(%d) > Balance(%d)", i, j) } } diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index c3fa2e63d68f..f9c20897f263 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -126,6 +127,7 @@ func (s *CLITestSuite) TestGenTxCmd() { clientCtx.TxConfig, banktypes.GenesisBalancesIterator{}, clientCtx.HomeDir, + addresscodec.NewBech32Codec("cosmos"), ) cmd.SetContext(ctx) cmd.SetArgs(tc.args) diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 5ff17c42ea69..d7fbf38dcdbb 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -86,15 +86,8 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx genBalIterator.IterateGenesisBalances( cdc, appState, func(balance bankexported.GenesisBalance) (stop bool) { - addr, err := balance.GetAddress() - if err != nil { - return true - } - addrSt, err := ac.BytesToString(addr) // this is ugly, we should avoid going to bytes and back - if err != nil { - return true - } - balancesMap[addrSt] = balance + addr := balance.GetAddress() + balancesMap[addr] = balance return false }, ) @@ -167,19 +160,9 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx } if delBal.GetCoins().AmountOf(msg.Value.Denom).LT(msg.Value.Amount) { - - addr, err := delBal.GetAddress() - if err != nil { - return appGenTxs, persistentPeers, err - } - - addrSt, err := ac.BytesToString(addr) - if err != nil { - return appGenTxs, persistentPeers, err - } return appGenTxs, persistentPeers, fmt.Errorf( "insufficient fund for delegation %v: %v < %v", - addrSt, delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount, + delBal.GetAddress(), delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount, ) } diff --git a/x/genutil/collect_test.go b/x/genutil/collect_test.go index 7c7b229b80b1..3f0a32a07915 100644 --- a/x/genutil/collect_test.go +++ b/x/genutil/collect_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/address" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -60,7 +59,7 @@ func TestCollectTxsHandlesDirectories(t *testing.T) { balItr := new(doNothingIterator) dnc := &doNothingUnmarshalJSON{cdc} - if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, genesis, balItr, types.DefaultMessageValidator, address.NewBech32Codec("cosmos")); err != nil { + if _, _, err := genutil.CollectTxs(dnc, txDecoder, "foo", testDir, genesis, balItr, types.DefaultMessageValidator); err != nil { t.Fatal(err) } } diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index fa5d13723a82..bfc33b0758b6 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -1,9 +1,9 @@ package genutil import ( - "bytes" "encoding/json" "fmt" + "strings" abci "github.com/cometbft/cometbft/abci/types" @@ -51,14 +51,11 @@ func ValidateAccountInGenesis( genBalIterator.IterateGenesisBalances(cdc, appGenesisState, func(bal bankexported.GenesisBalance) (stop bool) { - accAddress, err := bal.GetAddress() - if err != nil { - return false - } + accAddress := bal.GetAddress() accCoins := bal.GetCoins() // ensure that account is in genesis - if bytes.Equal(accAddress, addr.Bytes()) { + if strings.Compare(accAddress, addr.String()) == 1 { // ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) { err = fmt.Errorf( diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 1a843098ed1f..23b9aa5d6b71 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -89,13 +89,7 @@ func (s *CLITestSuite) SetupSuite() { s.clientCtx, val.Address, account, -<<<<<<< HEAD sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), address.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), -||||||| 67c1c788b2 - sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), -======= - sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), ->>>>>>> main fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), ) From 35559301cbc253542f70eec46102c2a4754f1df6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 1 May 2023 13:16:37 +0200 Subject: [PATCH 08/19] minor cleanup --- x/auth/module.go | 1 + x/bank/keeper/keeper.go | 7 ++----- x/bank/keeper/msg_server.go | 12 ++++++------ x/bank/types/expected_keepers.go | 8 +++----- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/x/auth/module.go b/x/auth/module.go index 7878e37c90e1..84ef5489b2f4 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -200,6 +200,7 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, + appmodule.Provide(ProvideAddressCodec), appmodule.Provide(ProvideModule), ) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index d3c74a485946..3452f5f3e15e 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "cosmossdk.io/core/address" "cosmossdk.io/core/store" "cosmossdk.io/log" "cosmossdk.io/math" @@ -24,8 +23,6 @@ var _ Keeper = (*BaseKeeper)(nil) // Keeper defines a module interface that facilitates the transfer of coins // between accounts. type Keeper interface { - address.Codec - SendKeeper WithMintCoinsRestriction(MintingRestrictionFn) BaseKeeper @@ -482,10 +479,10 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin }) } -func (k BaseKeeper) StringToBytes(s string) ([]byte, error) { +func (k BaseKeeper) stringToBytes(s string) ([]byte, error) { return k.ak.StringToBytes(s) } -func (k BaseKeeper) BytesToString(s []byte) (string, error) { +func (k BaseKeeper) bytesToString(s []byte) (string, error) { return k.ak.BytesToString(s) } diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 2791ecfd0d5e..916f3e9672f1 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -15,24 +15,24 @@ import ( ) type msgServer struct { - Keeper + BaseKeeper } var _ types.MsgServer = msgServer{} // NewMsgServerImpl returns an implementation of the bank MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} +func NewMsgServerImpl(keeper BaseKeeper) types.MsgServer { + return &msgServer{BaseKeeper: keeper} } func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) { - from, err := k.StringToBytes(msg.FromAddress) + from, err := k.stringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err) } - to, err := k.StringToBytes(msg.ToAddress) + to, err := k.stringToBytes(msg.ToAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err) } @@ -101,7 +101,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t } for _, out := range msg.Outputs { - accAddr, err := k.StringToBytes(out.Address) + accAddr, err := k.stringToBytes(out.Address) if err != nil { return nil, err } diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index f0acb8bdd748..3b7cc09f6cac 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -3,6 +3,7 @@ package types import ( context "context" + "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -10,6 +11,8 @@ import ( // AccountKeeper defines the account contract that must be fulfilled when // creating a x/bank keeper. type AccountKeeper interface { + address.Codec + NewAccount(context.Context, sdk.AccountI) sdk.AccountI NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI @@ -28,9 +31,4 @@ type AccountKeeper interface { GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI) GetModulePermissions() map[string]types.PermissionsForAddress - - // StringToBytes decodes text to bytes - StringToBytes(text string) ([]byte, error) - // BytesToString encodes bytes to text - BytesToString(bz []byte) (string, error) } From 9b985f268e8ab6144ca752f1ede161b9e5e304db Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 1 May 2023 13:20:46 +0200 Subject: [PATCH 09/19] add some changelog entries --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ff4790c48b..6fd427c1bbb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -179,6 +179,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`. * The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments. * The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`. +* (x/bank) [#15567](https://github.com/cosmos/cosmos-sdk/pull/15567) `GenesisBalance.GetAddress` now returns a string instead of `sdk.AccAddress` + * `MsgSendExec` test helper function now takes a address.Codec +* (x/genutil) [#15567](https://github.com/cosmos/cosmos-sdk/pull/15567) `CollectGenTxsCmd` & `GenTxCmd` takes a address.Codec to be able to decode addresses + ### Client Breaking Changes From b7f5e8e199fcbce4b74686c27ee27c4602a9e630 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 2 May 2023 08:17:15 +0200 Subject: [PATCH 10/19] fix type tests --- x/bank/keeper/genesis.go | 6 +++++- x/bank/keeper/msg_server.go | 7 +++---- x/bank/types/balance_test.go | 7 +++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index eaee07c4843d..9a440a0eb582 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -26,9 +26,13 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat for _, balance := range genState.Balances { addr := balance.GetAddress() + bz, err := k.stringToBytes(addr) + if err != nil { + panic(err) + } for _, coin := range balance.Coins { - err := k.Balances.Set(ctx, collections.Join(addr, coin.Denom), coin.Amount) + err := k.Balances.Set(ctx, collections.Join(sdk.AccAddress(bz), coin.Denom), coin.Amount) if err != nil { panic(err) } diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 916f3e9672f1..ebd46ad64ef0 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -15,19 +15,18 @@ import ( ) type msgServer struct { - BaseKeeper + Keeper } var _ types.MsgServer = msgServer{} // NewMsgServerImpl returns an implementation of the bank MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper BaseKeeper) types.MsgServer { - return &msgServer{BaseKeeper: keeper} +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} } func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) { - from, err := k.stringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err) diff --git a/x/bank/types/balance_test.go b/x/bank/types/balance_test.go index 9718755b1dc5..0be898e2b9cf 100644 --- a/x/bank/types/balance_test.go +++ b/x/bank/types/balance_test.go @@ -1,7 +1,6 @@ package types_test import ( - "strings" "testing" "cosmossdk.io/math" @@ -131,9 +130,9 @@ func TestBalance_GetAddress(t *testing.T) { t.Run(tt.name, func(t *testing.T) { b := bank.Balance{Address: tt.Address} if !tt.err { - require.Panics(t, func() { b.GetAddress() }) + require.Equal(t, b.GetAddress(), tt.Address) } else { - require.False(t, len(b.GetAddress()) == 0) + require.False(t, len(b.GetAddress()) != 0 && b.GetAddress() != tt.Address) } }) } @@ -164,7 +163,7 @@ func TestSanitizeBalances(t *testing.T) { // Ensure that every single value that comes after i is less than it. for j := i + 1; j < len(sorted); j++ { aj := sorted[j] - if got := strings.Compare(ai.GetAddress(), aj.GetAddress()); got > 0 { + if ai.GetAddress() == aj.GetAddress() { t.Errorf("Balance(%d) > Balance(%d)", i, j) } } From 8804d3dcd6b1cc97d244bb79a9cdf8a7fd830a2e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 2 May 2023 12:37:27 +0200 Subject: [PATCH 11/19] use account keeper --- x/bank/keeper/genesis.go | 2 +- x/bank/keeper/keeper.go | 8 -------- x/bank/keeper/msg_server.go | 35 ++++++++++++++++++++++------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index 9a440a0eb582..d9a9a5acf13b 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -26,7 +26,7 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat for _, balance := range genState.Balances { addr := balance.GetAddress() - bz, err := k.stringToBytes(addr) + bz, err := k.ak.StringToBytes(addr) if err != nil { panic(err) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 3452f5f3e15e..b4fd40db63e2 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -478,11 +478,3 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin return cb(sdk.NewCoin(s, m)) }) } - -func (k BaseKeeper) stringToBytes(s string) ([]byte, error) { - return k.ak.StringToBytes(s) -} - -func (k BaseKeeper) bytesToString(s []byte) (string, error) { - return k.ak.BytesToString(s) -} diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index ebd46ad64ef0..28a871ccd964 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -27,13 +27,20 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { } func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) { - from, err := k.stringToBytes(msg.FromAddress) - if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err) - } - to, err := k.stringToBytes(msg.ToAddress) - if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err) + var ( + from, to []byte + err error + ) + + if base, ok := k.Keeper.(BaseKeeper); ok { + from, err = base.ak.StringToBytes(msg.FromAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err) + } + to, err = base.ak.StringToBytes(msg.ToAddress) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err) + } } if !msg.Amount.IsValid() { @@ -100,13 +107,15 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t } for _, out := range msg.Outputs { - accAddr, err := k.stringToBytes(out.Address) - if err != nil { - return nil, err - } + if base, ok := k.Keeper.(BaseKeeper); ok { + accAddr, err := base.ak.StringToBytes(out.Address) + if err != nil { + return nil, err + } - if k.BlockedAddr(accAddr) { - return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address) + if k.BlockedAddr(accAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address) + } } } From 6ed34e71f2680f542d2b7f6e8579d4b3941b6c1f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 13:42:48 +0200 Subject: [PATCH 12/19] use AddressCodec --- x/bank/keeper/genesis.go | 2 +- x/bank/keeper/grpc_query.go | 8 +++--- x/bank/keeper/keeper.go | 2 +- x/bank/keeper/keeper_test.go | 7 ++--- x/bank/keeper/msg_server.go | 6 ++--- x/bank/keeper/send.go | 6 ++--- x/bank/module.go | 9 ++++--- x/bank/testutil/expected_keepers_mocks.go | 33 +++++++---------------- x/bank/types/expected_keepers.go | 2 +- x/gov/testutil/expected_keepers_mocks.go | 30 --------------------- 10 files changed, 29 insertions(+), 76 deletions(-) diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index a26bf528f569..cb208b22d33b 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -26,7 +26,7 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat for _, balance := range genState.Balances { addr := balance.GetAddress() - bz, err := k.ak.StringToBytes(addr) + bz, err := k.ak.AddressCodec().StringToBytes(addr) if err != nil { panic(err) } diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index a60cb80e4e09..ae2e6782766b 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -37,7 +37,7 @@ func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) } sdkCtx := sdk.UnwrapSDKContext(ctx) - address, err := k.ak.StringToBytes(req.Address) + address, err := k.ak.AddressCodec().StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -53,7 +53,7 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := k.ak.StringToBytes(req.Address) + addr, err := k.ak.AddressCodec().StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -86,7 +86,7 @@ func (k BaseKeeper) SpendableBalances(ctx context.Context, req *types.QuerySpend return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := k.ak.StringToBytes(req.Address) + addr, err := k.ak.AddressCodec().StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } @@ -121,7 +121,7 @@ func (k BaseKeeper) SpendableBalanceByDenom(ctx context.Context, req *types.Quer return nil, status.Error(codes.InvalidArgument, "empty request") } - addr, err := k.ak.StringToBytes(req.Address) + addr, err := k.ak.AddressCodec().StringToBytes(req.Address) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 2e22d7525fbd..008e08e9a9cc 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -97,7 +97,7 @@ func NewBaseKeeper( authority string, logger log.Logger, ) BaseKeeper { - if _, err := ak.StringToBytes(authority); err != nil { + if _, err := ak.AddressCodec().StringToBytes(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index cd8cc18b799e..f28346ea2925 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -20,6 +20,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -135,8 +136,7 @@ func (suite *KeeperTestSuite) SetupTest() { // gomock initializations ctrl := gomock.NewController(suite.T()) authKeeper := banktestutil.NewMockAccountKeeper(ctrl) - authKeeper.EXPECT().StringToBytes(authtypes.NewModuleAddress(govtypes.ModuleName).String()).Return(authtypes.NewModuleAddress(govtypes.ModuleName), nil).AnyTimes() - authKeeper.EXPECT().BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)).Return(authtypes.NewModuleAddress(govtypes.ModuleName).String(), nil).AnyTimes() + authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() suite.ctx = ctx suite.authKeeper = authKeeper suite.bankKeeper = keeper.NewBaseKeeper( @@ -240,9 +240,6 @@ func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx context.Context, acc, mAcc } func (suite *KeeperTestSuite) TestGetAuthority() { - suite.authKeeper.EXPECT().StringToBytes(authtypes.NewModuleAddress(minttypes.ModuleName).String()).Return(authtypes.NewModuleAddress(minttypes.ModuleName), nil).AnyTimes() - suite.authKeeper.EXPECT().StringToBytes("cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5").Return([]byte("8953EB4F1B47C7982A698DEB7C557D6E4F4CD923"), nil).AnyTimes() - storeService := runtime.NewKVStoreService(storetypes.NewKVStoreKey(banktypes.StoreKey)) NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper { return keeper.NewBaseKeeper( diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 28a871ccd964..1cc43eb9af46 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -33,11 +33,11 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe ) if base, ok := k.Keeper.(BaseKeeper); ok { - from, err = base.ak.StringToBytes(msg.FromAddress) + from, err = base.ak.AddressCodec().StringToBytes(msg.FromAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err) } - to, err = base.ak.StringToBytes(msg.ToAddress) + to, err = base.ak.AddressCodec().StringToBytes(msg.ToAddress) if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err) } @@ -108,7 +108,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t for _, out := range msg.Outputs { if base, ok := k.Keeper.(BaseKeeper); ok { - accAddr, err := base.ak.StringToBytes(out.Address) + accAddr, err := base.ak.AddressCodec().StringToBytes(out.Address) if err != nil { return nil, err } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index c8aab56947ba..5219d2513553 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -73,7 +73,7 @@ func NewBaseSendKeeper( authority string, logger log.Logger, ) BaseSendKeeper { - if _, err := ak.StringToBytes(authority); err != nil { + if _, err := ak.AddressCodec().StringToBytes(authority); err != nil { panic(fmt.Errorf("invalid bank authority address: %w", err)) } @@ -125,7 +125,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, return err } - inAddress, err := k.ak.StringToBytes(input.Address) + inAddress, err := k.ak.AddressCodec().StringToBytes(input.Address) if err != nil { return err } @@ -144,7 +144,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, ) for _, out := range outputs { - outAddress, err := k.ak.StringToBytes(out.Address) + outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address) if err != nil { return err } diff --git a/x/bank/module.go b/x/bank/module.go index 8672b33f192e..ca201365d034 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -7,6 +7,7 @@ import ( "time" modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" "cosmossdk.io/log" @@ -45,7 +46,7 @@ var ( // AppModuleBasic defines the basic application module used by the bank module. type AppModuleBasic struct { cdc codec.Codec - ak types.AccountKeeper + ac address.Codec } // Name returns the bank module's name. @@ -81,12 +82,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g // GetTxCmd returns the root tx command for the bank module. func (ab AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd(ab.ak) + return cli.NewTxCmd(ab.ac) } // GetQueryCmd returns no root query command for the bank module. func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(ab.ak) + return cli.GetQueryCmd(ab.ac) } // RegisterInterfaces registers interfaces and implementations of the bank module. @@ -138,7 +139,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, ss exported.Subspace) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc, ak: accountKeeper}, + AppModuleBasic: AppModuleBasic{cdc: cdc, ac: accountKeeper.AddressCodec()}, keeper: keeper, accountKeeper: accountKeeper, legacySubspace: ss, diff --git a/x/bank/testutil/expected_keepers_mocks.go b/x/bank/testutil/expected_keepers_mocks.go index 4d0ba2ac2380..fcdfd8a472e6 100644 --- a/x/bank/testutil/expected_keepers_mocks.go +++ b/x/bank/testutil/expected_keepers_mocks.go @@ -8,6 +8,7 @@ import ( context "context" reflect "reflect" + address "cosmossdk.io/core/address" types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/auth/types" gomock "github.com/golang/mock/gomock" @@ -36,19 +37,18 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { return m.recorder } -// BytesToString mocks base method. -func (m *MockAccountKeeper) BytesToString(bz []byte) (string, error) { +// AddressCodec mocks base method. +func (m *MockAccountKeeper) AddressCodec() address.Codec { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BytesToString", bz) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret := m.ctrl.Call(m, "AddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 } -// BytesToString indicates an expected call of BytesToString. -func (mr *MockAccountKeeperMockRecorder) BytesToString(bz interface{}) *gomock.Call { +// AddressCodec indicates an expected call of AddressCodec. +func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesToString", reflect.TypeOf((*MockAccountKeeper)(nil).BytesToString), bz) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec)) } // GetAccount mocks base method. @@ -229,21 +229,6 @@ func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(ctx, macc interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), ctx, macc) } -// StringToBytes mocks base method. -func (m *MockAccountKeeper) StringToBytes(text string) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StringToBytes", text) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// StringToBytes indicates an expected call of StringToBytes. -func (mr *MockAccountKeeperMockRecorder) StringToBytes(text interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringToBytes", reflect.TypeOf((*MockAccountKeeper)(nil).StringToBytes), text) -} - // ValidatePermissions mocks base method. func (m *MockAccountKeeper) ValidatePermissions(macc types.ModuleAccountI) error { m.ctrl.T.Helper() diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index 3b7cc09f6cac..8e6e32301cd3 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -11,7 +11,7 @@ import ( // AccountKeeper defines the account contract that must be fulfilled when // creating a x/bank keeper. type AccountKeeper interface { - address.Codec + AddressCodec() address.Codec NewAccount(context.Context, sdk.AccountI) sdk.AccountI NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index 1a37a77a00bd..92c8a5574130 100644 --- a/x/gov/testutil/expected_keepers_mocks.go +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -202,21 +202,6 @@ func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) } -// BytesToString mocks base method. -func (m *MockBankKeeper) BytesToString(bz []byte) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BytesToString", bz) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BytesToString indicates an expected call of BytesToString. -func (mr *MockBankKeeperMockRecorder) BytesToString(bz interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesToString", reflect.TypeOf((*MockBankKeeper)(nil).BytesToString), bz) -} - // DelegateCoins mocks base method. func (m *MockBankKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr types.AccAddress, amt types.Coins) error { m.ctrl.T.Helper() @@ -890,21 +875,6 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) } -// StringToBytes mocks base method. -func (m *MockBankKeeper) StringToBytes(text string) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StringToBytes", text) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// StringToBytes indicates an expected call of StringToBytes. -func (mr *MockBankKeeperMockRecorder) StringToBytes(text interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringToBytes", reflect.TypeOf((*MockBankKeeper)(nil).StringToBytes), text) -} - // SupplyOf mocks base method. func (m *MockBankKeeper) SupplyOf(arg0 context.Context, arg1 *types0.QuerySupplyOfRequest) (*types0.QuerySupplyOfResponse, error) { m.ctrl.T.Helper() From 558f179909a07c55922cd886694cd753c7458683 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 13:46:51 +0200 Subject: [PATCH 13/19] fix build --- simapp/simd/cmd/root.go | 8 +++++++- x/genutil/client/cli/collect.go | 3 +-- x/genutil/client/cli/commands.go | 15 +++++++-------- x/genutil/client/cli/gentx.go | 3 +-- x/genutil/client/cli/gentx_test.go | 2 -- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 6154a1d4352d..b8f5dadd357b 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/snapshot" @@ -199,7 +200,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b rootCmd.AddCommand( rpc.StatusCommand(), genesisCommand(encodingConfig, basicManager), - rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))) + txCommand(), + queryCommand(), + keys.Commands(simapp.DefaultNodeHome), + ) + + rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)) } func addModuleInitFlags(startCmd *cobra.Command) { diff --git a/x/genutil/client/cli/collect.go b/x/genutil/client/cli/collect.go index a36c696a6de9..fc001d391fdd 100644 --- a/x/genutil/client/cli/collect.go +++ b/x/genutil/client/cli/collect.go @@ -4,7 +4,6 @@ import ( "encoding/json" "path/filepath" - "cosmossdk.io/core/address" "cosmossdk.io/errors" "github.com/spf13/cobra" @@ -18,7 +17,7 @@ import ( const flagGenTxDir = "gentx-dir" // CollectGenTxsCmd - return the cobra command to collect genesis transactions -func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, validator types.MessageValidator, ac address.Codec) *cobra.Command { +func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, validator types.MessageValidator) *cobra.Command { cmd := &cobra.Command{ Use: "collect-gentxs", Short: "Collect genesis txs and output a genesis.json file", diff --git a/x/genutil/client/cli/commands.go b/x/genutil/client/cli/commands.go index 369ef4643f45..22d69dc6d17b 100644 --- a/x/genutil/client/cli/commands.go +++ b/x/genutil/client/cli/commands.go @@ -1,7 +1,6 @@ package cli import ( - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/module" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -13,18 +12,18 @@ import ( // GenesisCoreCommand adds core sdk's sub-commands into genesis command. // Deprecated: use Commands instead. -func GenesisCoreCommand(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, ac address.Codec) *cobra.Command { - return Commands(txConfig, moduleBasics, defaultNodeHome, ac) +func GenesisCoreCommand(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string) *cobra.Command { + return Commands(txConfig, moduleBasics, defaultNodeHome) } // Commands adds core sdk's sub-commands into genesis command. -func Commands(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, ac address.Codec) *cobra.Command { - return CommandsWithCustomMigrationMap(txConfig, moduleBasics, defaultNodeHome, MigrationMap, ac) +func Commands(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string) *cobra.Command { + return CommandsWithCustomMigrationMap(txConfig, moduleBasics, defaultNodeHome, MigrationMap) } // CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map. // This custom migration map can be used by the application to add its own migration map. -func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, migrationMap genutiltypes.MigrationMap, ac address.Codec) *cobra.Command { +func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics module.BasicManager, defaultNodeHome string, migrationMap genutiltypes.MigrationMap) *cobra.Command { cmd := &cobra.Command{ Use: "genesis", Short: "Application's genesis-related subcommands", @@ -35,9 +34,9 @@ func CommandsWithCustomMigrationMap(txConfig client.TxConfig, moduleBasics modul gentxModule := moduleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) cmd.AddCommand( - GenTxCmd(moduleBasics, txConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome, ac), + GenTxCmd(moduleBasics, txConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome), MigrateGenesisCmd(migrationMap), - CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator, ac), + CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator), ValidateGenesisCmd(moduleBasics), AddGenesisAccountCmd(defaultNodeHome), ) diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 0bfe0da4a6fd..ed7c659ad1c4 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" - "cosmossdk.io/core/address" "cosmossdk.io/errors" "github.com/spf13/cobra" @@ -28,7 +27,7 @@ import ( ) // GenTxCmd builds the application's gentx command. -func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, ac address.Codec) *cobra.Command { +func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command { ipDefault, _ := server.ExternalIP() fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault) diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index f9c20897f263..c3fa2e63d68f 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -127,7 +126,6 @@ func (s *CLITestSuite) TestGenTxCmd() { clientCtx.TxConfig, banktypes.GenesisBalancesIterator{}, clientCtx.HomeDir, - addresscodec.NewBech32Codec("cosmos"), ) cmd.SetContext(ctx) cmd.SetArgs(tc.args) From 2933b6e372b4a543ee84d762282f4f8e5639f438 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 13:56:39 +0200 Subject: [PATCH 14/19] fix tests --- x/genutil/gentx.go | 3 +-- x/genutil/types/genesis_state_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index f68ebec196ec..5b8481ad5665 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -54,9 +54,8 @@ func ValidateAccountInGenesis( func(bal bankexported.GenesisBalance) (stop bool) { accAddress := bal.GetAddress() accCoins := bal.GetCoins() - // ensure that account is in genesis - if strings.Compare(accAddress, addr.String()) == 1 { + if strings.Compare(accAddress, addr.String()) == 0 { // ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) { err = fmt.Errorf( diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index 2c6dc8ab0b11..dc8b469732df 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -87,7 +87,7 @@ func TestGenesisStateFromGenFile(t *testing.T) { require.True(t, bankGenesis.Params.DefaultSendEnabled) require.Equal(t, "1000nametoken,100000000stake", bankGenesis.Balances[0].GetCoins().String()) - require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0]) + require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0].Address) require.Equal(t, "The native staking token of the Cosmos Hub.", bankGenesis.DenomMetadata[0].GetDescription()) require.Equal(t, "uatom", bankGenesis.DenomMetadata[0].GetBase()) require.Equal(t, "matom", bankGenesis.DenomMetadata[0].GetDenomUnits()[1].GetDenom()) From 035e8a1e071e499c47d9ebb08f16d677279e302a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 15:15:05 +0200 Subject: [PATCH 15/19] fix some tests --- tests/e2e/group/suite.go | 2 ++ x/authz/client/cli/tx_test.go | 9 ++++++--- x/bank/client/cli/tx.go | 2 +- x/bank/simulation/genesis_test.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/e2e/group/suite.go b/tests/e2e/group/suite.go index 54bf6aa4f9b9..8a65452d75ff 100644 --- a/tests/e2e/group/suite.go +++ b/tests/e2e/group/suite.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -280,6 +281,7 @@ func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, group _, err = clitestutil.MsgSendExec(clientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(tokens))), s.commonFlags..., + address.NewBech32Codec("cosmos"), ) s.Require().NoError(err) return groupPolicyAddress diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 2513c80b7bd0..3124167d28c0 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -70,6 +70,8 @@ func (s *CLITestSuite) SetupSuite() { WithOutput(io.Discard). WithChainID("test-chain") + s.ac = addresscodec.NewBech32Codec("cosmos") + ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ @@ -156,8 +158,6 @@ func (s *CLITestSuite) SetupSuite() { ) s.Require().NoError(err) s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) - - s.ac = addresscodec.NewBech32Codec("cosmos") } func (s *CLITestSuite) createAccount(uid string) sdk.AccAddress { @@ -174,11 +174,14 @@ func (s *CLITestSuite) createAccount(uid string) sdk.AccAddress { func (s *CLITestSuite) msgSendExec(grantee sdk.AccAddress) { val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) // Send some funds to the new account. + s.ac.StringToBytes("cosmos16zex22087zs656t0vedytv5wqhm6axxd5679ry") out, err := clitestutil.MsgSendExec( s.clientCtx, val[0].Address, grantee, - sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))), s.ac, fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))), + s.ac, + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()), ) diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 86f5379716a2..7bc38eaac197 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -50,7 +50,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. if err != nil { return err } - + fmt.Println(args[1]) toAddr, err := ac.StringToBytes(args[1]) if err != nil { return err diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 245cc6fae7f5..3de14ad2c82b 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -45,7 +45,7 @@ func TestRandomizedGenState(t *testing.T) { assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled") assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing deprecated code here if assert.Len(t, bankGenesis.Balances, 3) { - assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2], "Balances[2] address") + assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].Address, "Balances[2] address") assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins") } assert.Equal(t, "6000stake", bankGenesis.Supply.String(), "Supply") From 1376a562408717fc41036ca2efbf43aa573210ca Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 15:19:45 +0200 Subject: [PATCH 16/19] fix linting --- tests/e2e/auth/suite.go | 5 ++--- tests/e2e/authz/tx.go | 3 +-- tests/e2e/bank/suite.go | 1 - tests/e2e/group/suite.go | 8 +++++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index a51846112131..bc77fe91805e 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -1261,7 +1260,7 @@ func (s *E2ETestSuite) TestMultisignBatch() { defer filename.Close() val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) - queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr, address.NewBech32Codec("cosmos")) + queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) s.Require().NoError(err) var account sdk.AccountI s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account)) @@ -1329,7 +1328,7 @@ func (s *E2ETestSuite) TestGetAccountCmd() { s.Run(tc.name, func() { clientCtx := val.ClientCtx - out, err := authclitestutil.QueryAccountExec(clientCtx, tc.address, address.NewBech32Codec("cosmos")) + out, err := authclitestutil.QueryAccountExec(clientCtx, tc.address, addresscodec.NewBech32Codec("cosmos")) if tc.expectErr { s.Require().Error(err) s.Require().NotEqual("internal", err.Error()) diff --git a/tests/e2e/authz/tx.go b/tests/e2e/authz/tx.go index 4b7f10e46f3c..cb4e7671553b 100644 --- a/tests/e2e/authz/tx.go +++ b/tests/e2e/authz/tx.go @@ -10,7 +10,6 @@ import ( // without this import amino json encoding will fail when resolving any types _ "cosmossdk.io/api/cosmos/authz/v1beta1" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -309,7 +308,7 @@ func (s *E2ETestSuite) TestCmdRevokeAuthorizations() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeAuthorization(address.NewBech32Codec("cosmos")) + cmd := cli.NewCmdRevokeAuthorization(addresscodec.NewBech32Codec("cosmos")) clientCtx := val.ClientCtx out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) diff --git a/tests/e2e/bank/suite.go b/tests/e2e/bank/suite.go index d3eb80e59d2e..d319676fdb71 100644 --- a/tests/e2e/bank/suite.go +++ b/tests/e2e/bank/suite.go @@ -154,7 +154,6 @@ func (s *E2ETestSuite) TestGetBalancesCmd() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetBalancesCmd(addresscodec.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args) diff --git a/tests/e2e/group/suite.go b/tests/e2e/group/suite.go index 8a65452d75ff..1de710d17463 100644 --- a/tests/e2e/group/suite.go +++ b/tests/e2e/group/suite.go @@ -12,10 +12,10 @@ import ( _ "cosmossdk.io/api/cosmos/group/v1" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" @@ -72,7 +72,9 @@ func (s *E2ETestSuite) SetupSuite() { val.ClientCtx, val.Address, account, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), + address.NewBech32Codec("cosmos"), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), ) @@ -280,8 +282,8 @@ func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, group s.Require().NoError(err) _, err = clitestutil.MsgSendExec(clientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(tokens))), - s.commonFlags..., address.NewBech32Codec("cosmos"), + s.commonFlags..., ) s.Require().NoError(err) return groupPolicyAddress From fc0e83160921accf2a8cfe0e3102ee61d557de63 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 17:10:53 +0200 Subject: [PATCH 17/19] remove prints --- x/bank/client/cli/tx.go | 1 - x/bank/simulation/proposals_test.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 7bc38eaac197..022cbbcf03ea 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -50,7 +50,6 @@ When using '--dry-run' a key name cannot be used, only a bech32 address. if err != nil { return err } - fmt.Println(args[1]) toAddr, err := ac.StringToBytes(args[1]) if err != nil { return err diff --git a/x/bank/simulation/proposals_test.go b/x/bank/simulation/proposals_test.go index 5365a4fbf6b3..0dcc42b02c95 100644 --- a/x/bank/simulation/proposals_test.go +++ b/x/bank/simulation/proposals_test.go @@ -1,7 +1,6 @@ package simulation_test import ( - "fmt" "math/rand" "testing" @@ -37,7 +36,6 @@ func TestProposalMsgs(t *testing.T) { msgUpdateParams, ok := msg.(*types.MsgUpdateParams) assert.Assert(t, ok) - fmt.Println(msgUpdateParams) assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing deprecated code here assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled) From c739d39bfc1f5d26b579e1f34f796121a9cd2f96 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 22 May 2023 17:15:23 +0200 Subject: [PATCH 18/19] address comments --- testutil/cli/cmd.go | 4 ++-- x/bank/keeper/msg_server.go | 4 ++++ x/genutil/gentx.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/testutil/cli/cmd.go b/testutil/cli/cmd.go index f4385aea30ac..6e36bc2c6622 100644 --- a/testutil/cli/cmd.go +++ b/testutil/cli/cmd.go @@ -5,10 +5,10 @@ import ( "fmt" "cosmossdk.io/core/address" - cli2 "github.com/cometbft/cometbft/libs/cli" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) @@ -38,7 +38,7 @@ func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, ac add } func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) { - args := []string{address.String(), fmt.Sprintf("--%s=json", cli2.OutputFlag)} + args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)} args = append(args, extraArgs...) return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(ac), args) diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 1cc43eb9af46..c6fbedf8369b 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -41,6 +41,8 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe if err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err) } + } else { + return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid keeper type: %T", k.Keeper) } if !msg.Amount.IsValid() { @@ -116,6 +118,8 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t if k.BlockedAddr(accAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address) } + } else { + return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid keeper type: %T", k.Keeper) } } diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 5b8481ad5665..296dc57c4bb4 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -55,7 +55,7 @@ func ValidateAccountInGenesis( accAddress := bal.GetAddress() accCoins := bal.GetCoins() // ensure that account is in genesis - if strings.Compare(accAddress, addr.String()) == 0 { + if !strings.EqualFold(accAddress, addr.String()) { // ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) { err = fmt.Errorf( From 6189a36ac131b799b8599085967186267dbe7a9c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 23 May 2023 09:49:16 +0200 Subject: [PATCH 19/19] fix equalfold --- x/genutil/gentx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 296dc57c4bb4..c5021e0b709c 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -55,7 +55,7 @@ func ValidateAccountInGenesis( accAddress := bal.GetAddress() accCoins := bal.GetCoins() // ensure that account is in genesis - if !strings.EqualFold(accAddress, addr.String()) { + if strings.EqualFold(accAddress, addr.String()) { // ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) { err = fmt.Errorf(