From 539b6fee919c376b2fe38aeaebd6b86b24d2db8b Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 Mar 2023 13:01:01 +0100 Subject: [PATCH 01/24] feegrant bech32 removal --- testutil/bech32_codec.go | 48 +++++++++++++++++++++++++++++++ x/feegrant/expected_keepers.go | 7 +++++ x/feegrant/keeper/genesis_test.go | 2 +- x/feegrant/keeper/grpc_query.go | 15 +++++----- x/feegrant/keeper/keeper.go | 16 ++++++----- x/feegrant/keeper/keeper_test.go | 2 +- x/feegrant/keeper/msg_server.go | 8 +++--- x/feegrant/key.go | 4 +-- x/feegrant/module/module.go | 3 +- 9 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 testutil/bech32_codec.go diff --git a/testutil/bech32_codec.go b/testutil/bech32_codec.go new file mode 100644 index 000000000000..276b1853b2d9 --- /dev/null +++ b/testutil/bech32_codec.go @@ -0,0 +1,48 @@ +package testutil + +import ( + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/types/bech32" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +type bech32Codec struct { + bech32Prefix string +} + +var _ address.Codec = &bech32Codec{} + +func NewBech32Codec() address.Codec { + return bech32Codec{"cosmos"} +} + +// StringToBytes encodes text to bytes +func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { + hrp, bz, err := bech32.DecodeAndConvert(text) + if err != nil { + return nil, err + } + + if hrp != bc.bech32Prefix { + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix") + } + + if err := sdk.VerifyAddressFormat(bz); err != nil { + return nil, err + } + + return bz, nil +} + +// BytesToString decodes bytes to text +func (bc bech32Codec) BytesToString(bz []byte) (string, error) { + text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz) + if err != nil { + return "", err + } + + return text, nil +} diff --git a/x/feegrant/expected_keepers.go b/x/feegrant/expected_keepers.go index 39e7ca223495..55d8e795d690 100644 --- a/x/feegrant/expected_keepers.go +++ b/x/feegrant/expected_keepers.go @@ -19,3 +19,10 @@ type BankKeeper interface { SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } + +type AddressCodec interface { + // StringToBytes decodes text to bytes + StringToBytes(text string) ([]byte, error) + // BytesToString encodes bytes to text + BytesToString(bz []byte) (string, error) +} diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index d5484acbc133..00c3699224a3 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -36,7 +36,7 @@ func (suite *GenesisTestSuite) SetupTest() { accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec()) suite.ctx = testCtx.Ctx } diff --git a/x/feegrant/keeper/grpc_query.go b/x/feegrant/keeper/grpc_query.go index 22490b884e40..2cbd971b0c65 100644 --- a/x/feegrant/keeper/grpc_query.go +++ b/x/feegrant/keeper/grpc_query.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "context" "github.com/cosmos/gogoproto/proto" @@ -23,12 +24,12 @@ func (q Keeper) Allowance(c context.Context, req *feegrant.QueryAllowanceRequest return nil, status.Error(codes.InvalidArgument, "invalid request") } - granterAddr, err := sdk.AccAddressFromBech32(req.Granter) + granterAddr, err := q.addressCodec.StringToBytes(req.Granter) if err != nil { return nil, err } - granteeAddr, err := sdk.AccAddressFromBech32(req.Grantee) + granteeAddr, err := q.addressCodec.StringToBytes(req.Grantee) if err != nil { return nil, err } @@ -52,8 +53,8 @@ func (q Keeper) Allowance(c context.Context, req *feegrant.QueryAllowanceRequest return &feegrant.QueryAllowanceResponse{ Allowance: &feegrant.Grant{ - Granter: granterAddr.String(), - Grantee: granteeAddr.String(), + Granter: req.Granter, + Grantee: req.Grantee, Allowance: feeAllowanceAny, }, }, nil @@ -65,7 +66,7 @@ func (q Keeper) Allowances(c context.Context, req *feegrant.QueryAllowancesReque return nil, status.Error(codes.InvalidArgument, "invalid request") } - granteeAddr, err := sdk.AccAddressFromBech32(req.Grantee) + granteeAddr, err := q.addressCodec.StringToBytes(req.Grantee) if err != nil { return nil, err } @@ -100,7 +101,7 @@ func (q Keeper) AllowancesByGranter(c context.Context, req *feegrant.QueryAllowa return nil, status.Error(codes.InvalidArgument, "invalid request") } - granterAddr, err := sdk.AccAddressFromBech32(req.Granter) + granterAddr, err := q.addressCodec.StringToBytes(req.Granter) if err != nil { return nil, err } @@ -112,7 +113,7 @@ func (q Keeper) AllowancesByGranter(c context.Context, req *feegrant.QueryAllowa grants, pageRes, err := query.GenericFilteredPaginate(q.cdc, prefixStore, req.Pagination, func(key []byte, grant *feegrant.Grant) (*feegrant.Grant, error) { // ParseAddressesFromFeeAllowanceKey expects the full key including the prefix. granter, _ := feegrant.ParseAddressesFromFeeAllowanceKey(append(feegrant.FeeAllowanceKeyPrefix, key...)) - if !granter.Equals(granterAddr) { + if !bytes.Equal(granter, granterAddr) { return nil, nil } diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 582c997eb968..d72659abfa38 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -18,19 +18,21 @@ import ( // Keeper manages state of all fee grants, as well as calculating approval. // It must have a codec with all available allowances registered. type Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - authKeeper feegrant.AccountKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + authKeeper feegrant.AccountKeeper + addressCodec feegrant.AddressCodec } var _ ante.FeegrantKeeper = &Keeper{} // NewKeeper creates a fee grant Keeper -func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.AccountKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.AccountKeeper, addressCodec feegrant.AddressCodec) Keeper { return Keeper{ - cdc: cdc, - storeKey: storeKey, - authKeeper: ak, + cdc: cdc, + storeKey: storeKey, + authKeeper: ak, + addressCodec: addressCodec, } } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 53b86199a2a0..895354c8a8fc 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, testutil.NewBech32Codec()) suite.ctx = testCtx.Ctx suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper) suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(555))) diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index 78b9e7fca958..2cafc9fd9fae 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -26,12 +26,12 @@ var _ feegrant.MsgServer = msgServer{} func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantAllowance) (*feegrant.MsgGrantAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - grantee, err := sdk.AccAddressFromBech32(msg.Grantee) + grantee, err := k.addressCodec.StringToBytes(msg.Grantee) if err != nil { return nil, err } - granter, err := sdk.AccAddressFromBech32(msg.Granter) + granter, err := k.addressCodec.StringToBytes(msg.Granter) if err != nil { return nil, err } @@ -53,12 +53,12 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevokeAllowance) (*feegrant.MsgRevokeAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - grantee, err := sdk.AccAddressFromBech32(msg.Grantee) + grantee, err := k.addressCodec.StringToBytes(msg.Grantee) if err != nil { return nil, err } - granter, err := sdk.AccAddressFromBech32(msg.Granter) + granter, err := k.addressCodec.StringToBytes(msg.Granter) if err != nil { return nil, err } diff --git a/x/feegrant/key.go b/x/feegrant/key.go index 9cf0e4437481..8b519053a0fc 100644 --- a/x/feegrant/key.go +++ b/x/feegrant/key.go @@ -67,7 +67,7 @@ func AllowanceByExpTimeKey(exp *time.Time) []byte { } // ParseAddressesFromFeeAllowanceKey extracts and returns the granter, grantee from the given key. -func ParseAddressesFromFeeAllowanceKey(key []byte) (granter, grantee sdk.AccAddress) { +func ParseAddressesFromFeeAllowanceKey(key []byte) (granter, grantee []byte) { // key is of format: // 0x00 granterAddrLen, granterAddrLenEndIndex := sdk.ParseLengthPrefixedBytes(key, 1, 1) // ignore key[0] since it is a prefix key @@ -80,7 +80,7 @@ func ParseAddressesFromFeeAllowanceKey(key []byte) (granter, grantee sdk.AccAddr } // ParseAddressesFromFeeAllowanceQueueKey extracts and returns the granter, grantee from the given key. -func ParseAddressesFromFeeAllowanceQueueKey(key []byte) (granter, grantee sdk.AccAddress) { +func ParseAddressesFromFeeAllowanceQueueKey(key []byte) (granter, grantee []byte) { lenTime := len(sdk.FormatTimeBytes(time.Now())) // key is of format: diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index db0f97134a5b..3dc0cc387d37 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -191,12 +191,13 @@ type FeegrantInputs struct { Key *store.KVStoreKey Cdc codec.Codec AccountKeeper feegrant.AccountKeeper + AddressCodec feegrant.AddressCodec BankKeeper feegrant.BankKeeper Registry cdctypes.InterfaceRegistry } func ProvideModule(in FeegrantInputs) (keeper.Keeper, appmodule.AppModule) { - k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper) + k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper, in.AddressCodec) m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) return k, m } From 683e1f2378b86b1b55b312cc3c11e1687da9a5ae Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 Mar 2023 13:04:50 +0100 Subject: [PATCH 02/24] remove some global bech32 items in feegrant --- x/feegrant/keeper/msg_server_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index d59d996ee799..a312e4beb19c 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -4,8 +4,9 @@ import ( "time" "cosmossdk.io/x/feegrant" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/golang/mock/gomock" ) @@ -15,6 +16,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { oneYear := ctx.BlockTime().AddDate(1, 0, 0) yesterday := ctx.BlockTime().AddDate(0, 0, -1) + addressCodec := testutil.NewBech32Codec() + testCases := []struct { name string req func() *feegrant.MsgGrantAllowance @@ -53,7 +56,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { "valid: grantee account doesn't exist", func() *feegrant.MsgGrantAllowance { grantee := "cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5" - granteeAccAddr := types.MustAccAddressFromBech32(grantee) + granteeAccAddr, err := addressCodec.StringToBytes(grantee) + suite.Require().NoError(err) any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{ SpendLimit: suite.atom, Expiration: &oneYear, @@ -62,7 +66,10 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAccAddr).Return(nil).AnyTimes() acc := authtypes.NewBaseAccountWithAddress(granteeAccAddr) - suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), types.MustAccAddressFromBech32(grantee)).Return(acc).AnyTimes() + add, err := addressCodec.StringToBytes(grantee) + suite.Require().NoError(err) + + suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), add).Return(acc).AnyTimes() suite.accountKeeper.EXPECT().SetAccount(gomock.Any(), acc).Return() suite.Require().NoError(err) From e72f0151a6e0c54ced3b2e1efd689fcd67e5128e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 10 Mar 2023 13:29:14 +0100 Subject: [PATCH 03/24] few more changes --- x/feegrant/client/cli/tx_test.go | 8 +++++--- x/feegrant/grant_test.go | 5 +++-- x/feegrant/key_test.go | 17 ++++++++++------- x/feegrant/module/abci_test.go | 2 +- x/feegrant/msgs_test.go | 6 ++++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index 776e8c12bac9..f4493da0d71c 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -436,10 +436,12 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), } + addressCodec := testutil.NewBech32Codec() // Create new fee grant specifically to test amino. - aminoGrantee, err := sdk.AccAddressFromBech32("cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00") + encodedGrantee := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00" + aminoGrantee, err := addressCodec.StringToBytes(encodedGrantee) s.Require().NoError(err) - s.createGrant(granter, aminoGrantee) + s.createGrant(granter, sdk.AccAddress(aminoGrantee)) testCases := []struct { name string @@ -489,7 +491,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { append( []string{ granter.String(), - aminoGrantee.String(), + encodedGrantee, fmt.Sprintf("--%s=%s", flags.FlagFrom, granter), fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index eff034d1650c..2916d81ad505 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -16,15 +16,16 @@ import ( ) func TestGrant(t *testing.T) { + addressCodec := testutil.NewBech32Codec() key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) - addr, err := sdk.AccAddressFromBech32("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") + addr, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) - addr2, err := sdk.AccAddressFromBech32("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") + addr2, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") require.NoError(t, err) atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) now := ctx.BlockTime() diff --git a/x/feegrant/key_test.go b/x/feegrant/key_test.go index c0589279d447..2be0cd035cb7 100644 --- a/x/feegrant/key_test.go +++ b/x/feegrant/key_test.go @@ -7,18 +7,20 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/x/feegrant" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { - grantee, err := sdk.AccAddressFromBech32("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") + addressCodec := testutil.NewBech32Codec() + grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) - granter, err := sdk.AccAddressFromBech32("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") + granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") require.NoError(t, err) key := feegrant.FeeAllowanceKey(granter, grantee) - require.Len(t, key, len(grantee.Bytes())+len(granter.Bytes())+3) - require.Equal(t, feegrant.FeeAllowancePrefixByGrantee(grantee), key[:len(grantee.Bytes())+2]) + require.Len(t, key, len(grantee)+len(granter)+3) + require.Equal(t, feegrant.FeeAllowancePrefixByGrantee(grantee), key[:len(grantee)+2]) g1, g2 := feegrant.ParseAddressesFromFeeAllowanceKey(key) require.Equal(t, granter, g1) @@ -26,16 +28,17 @@ func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { } func TestMarshalAndUnmarshalFeegrantKeyQueueKey(t *testing.T) { - grantee, err := sdk.AccAddressFromBech32("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") + addressCodec := testutil.NewBech32Codec() + grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) - granter, err := sdk.AccAddressFromBech32("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") + granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") require.NoError(t, err) exp := time.Now() expBytes := sdk.FormatTimeBytes(exp) key := feegrant.FeeAllowancePrefixQueue(&exp, feegrant.FeeAllowanceKey(granter, grantee)[1:]) - require.Len(t, key, len(grantee.Bytes())+len(granter.Bytes())+3+len(expBytes)) + require.Len(t, key, len(grantee)+len(granter)+3+len(expBytes)) granter1, grantee1 := feegrant.ParseAddressesFromFeeAllowanceQueueKey(key) require.Equal(t, granter, granter1) diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 5ba572164690..23905862df01 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -40,7 +40,7 @@ func TestFeegrantPruning(t *testing.T) { accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() - feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper) + feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec()) feegrantKeeper.GrantAllowance( testCtx.Ctx, diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index 7f28554fbe99..27c6eb62479b 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -9,14 +9,16 @@ import ( "cosmossdk.io/x/feegrant" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) func TestMsgGrantAllowance(t *testing.T) { cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") - addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") + addressCodec := testutil.NewBech32Codec() + addr, _ := addressCodec.StringToBytes("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") + addr2, _ := addressCodec.StringToBytes("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) threeHours := time.Now().Add(3 * time.Hour) basic := &feegrant.BasicAllowance{ From 1144aefdb571fab9e0db8b484042c155f89486ee Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 17 Mar 2023 14:44:22 +0100 Subject: [PATCH 04/24] remove global codec --- tests/e2e/feegrant/suite.go | 20 +++++++------- x/feegrant/client/cli/query.go | 34 +++++++++++------------- x/feegrant/client/cli/query_test.go | 7 ++--- x/feegrant/client/cli/tx.go | 15 ++++++----- x/feegrant/client/cli/tx_test.go | 12 ++++----- x/feegrant/keeper/keeper.go | 4 +-- x/feegrant/keeper/keeper_test.go | 5 ++-- x/feegrant/keeper/msg_server.go | 14 ++++++++++ x/feegrant/module/module.go | 30 +++++++++++---------- x/feegrant/msgs.go | 25 +---------------- x/feegrant/simulation/operations.go | 16 ++++++++--- x/feegrant/simulation/operations_test.go | 5 ++-- 12 files changed, 95 insertions(+), 92 deletions(-) diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index 4b11c2ca110a..781c4d0ee4ea 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -97,7 +97,7 @@ func (s *E2ETestSuite) createGrant(granter, grantee sdk.Address) { commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -171,7 +171,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrant() + cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -237,7 +237,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrantsByGrantee() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGrantee() + cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -294,7 +294,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrantsByGranter() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGranter() + cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -587,7 +587,7 @@ func (s *E2ETestSuite) TestNewCmdFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -694,7 +694,7 @@ func (s *E2ETestSuite) TestNewCmdRevokeFeegrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeFeegrant() + cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -743,7 +743,7 @@ func (s *E2ETestSuite) TestTxWithFeeGrant() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -878,7 +878,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -900,7 +900,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { } // get filtered fee allowance and check info - cmd := cli.GetCmdQueryFeeGrant() + cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -963,7 +963,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { }, commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) }, &sdk.TxResponse{}, diff --git a/x/feegrant/client/cli/query.go b/x/feegrant/client/cli/query.go index 9c01fbe43517..adb68b7aa339 100644 --- a/x/feegrant/client/cli/query.go +++ b/x/feegrant/client/cli/query.go @@ -9,12 +9,12 @@ import ( "cosmossdk.io/x/feegrant" "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/types/address" "github.com/cosmos/cosmos-sdk/version" ) // GetQueryCmd returns the cli query commands for this module -func GetQueryCmd() *cobra.Command { +func GetQueryCmd(ac address.Codec) *cobra.Command { feegrantQueryCmd := &cobra.Command{ Use: feegrant.ModuleName, Short: "Querying commands for the feegrant module", @@ -24,16 +24,16 @@ func GetQueryCmd() *cobra.Command { } feegrantQueryCmd.AddCommand( - GetCmdQueryFeeGrant(), - GetCmdQueryFeeGrantsByGrantee(), - GetCmdQueryFeeGrantsByGranter(), + GetCmdQueryFeeGrant(ac), + GetCmdQueryFeeGrantsByGrantee(ac), + GetCmdQueryFeeGrantsByGranter(ac), ) return feegrantQueryCmd } // GetCmdQueryFeeGrant returns cmd to query for a grant between granter and grantee. -func GetCmdQueryFeeGrant() *cobra.Command { +func GetCmdQueryFeeGrant(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "grant [granter] [grantee]", Args: cobra.ExactArgs(2), @@ -50,21 +50,19 @@ $ %s query feegrant grant [granter] [grantee] clientCtx := client.GetClientContextFromCmd(cmd) queryClient := feegrant.NewQueryClient(clientCtx) - granterAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { + if _, err := ac.StringToBytes(args[0]); err != nil { return err } - granteeAddr, err := sdk.AccAddressFromBech32(args[1]) - if err != nil { + if _, err := ac.StringToBytes(args[1]); err != nil { return err } res, err := queryClient.Allowance( cmd.Context(), &feegrant.QueryAllowanceRequest{ - Granter: granterAddr.String(), - Grantee: granteeAddr.String(), + Granter: args[0], + Grantee: args[1], }, ) if err != nil { @@ -81,7 +79,7 @@ $ %s query feegrant grant [granter] [grantee] } // GetCmdQueryFeeGrantsByGrantee returns cmd to query for all grants for a grantee. -func GetCmdQueryFeeGrantsByGrantee() *cobra.Command { +func GetCmdQueryFeeGrantsByGrantee(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "grants-by-grantee [grantee]", Args: cobra.ExactArgs(1), @@ -97,7 +95,7 @@ $ %s query feegrant grants-by-grantee [grantee] clientCtx := client.GetClientContextFromCmd(cmd) queryClient := feegrant.NewQueryClient(clientCtx) - granteeAddr, err := sdk.AccAddressFromBech32(args[0]) + _, err := ac.StringToBytes(args[0]) if err != nil { return err } @@ -110,7 +108,7 @@ $ %s query feegrant grants-by-grantee [grantee] res, err := queryClient.Allowances( cmd.Context(), &feegrant.QueryAllowancesRequest{ - Grantee: granteeAddr.String(), + Grantee: args[0], Pagination: pageReq, }, ) @@ -129,7 +127,7 @@ $ %s query feegrant grants-by-grantee [grantee] } // GetCmdQueryFeeGrantsByGranter returns cmd to query for all grants by a granter. -func GetCmdQueryFeeGrantsByGranter() *cobra.Command { +func GetCmdQueryFeeGrantsByGranter(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "grants-by-granter [granter]", Args: cobra.ExactArgs(1), @@ -145,7 +143,7 @@ $ %s query feegrant grants-by-granter [granter] clientCtx := client.GetClientContextFromCmd(cmd) queryClient := feegrant.NewQueryClient(clientCtx) - granterAddr, err := sdk.AccAddressFromBech32(args[0]) + _, err := ac.StringToBytes(args[0]) if err != nil { return err } @@ -158,7 +156,7 @@ $ %s query feegrant grants-by-granter [granter] res, err := queryClient.AllowancesByGranter( cmd.Context(), &feegrant.QueryAllowancesByGranterRequest{ - Granter: granterAddr.String(), + Granter: args[0], Pagination: pageReq, }, ) diff --git a/x/feegrant/client/cli/query_test.go b/x/feegrant/client/cli/query_test.go index eddc817aef54..eaf013f1ecf0 100644 --- a/x/feegrant/client/cli/query_test.go +++ b/x/feegrant/client/cli/query_test.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/client/cli" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" ) @@ -47,7 +48,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrant() + cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) if tc.expectErr { @@ -94,7 +95,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGrantee() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGrantee() + cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -141,7 +142,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGranter() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGranter() + cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index 2f3abbe8b07b..5069fe7df38a 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/version" ) @@ -25,7 +26,7 @@ const ( ) // GetTxCmd returns the transaction commands for this module -func GetTxCmd() *cobra.Command { +func GetTxCmd(ac address.Codec) *cobra.Command { feegrantTxCmd := &cobra.Command{ Use: feegrant.ModuleName, Short: "Feegrant transactions subcommands", @@ -36,15 +37,15 @@ func GetTxCmd() *cobra.Command { } feegrantTxCmd.AddCommand( - NewCmdFeeGrant(), - NewCmdRevokeFeegrant(), + NewCmdFeeGrant(ac), + NewCmdRevokeFeegrant(ac), ) return feegrantTxCmd } // NewCmdFeeGrant returns a CLI command handler for creating a MsgGrantAllowance transaction. -func NewCmdFeeGrant() *cobra.Command { +func NewCmdFeeGrant(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "grant [granter_key_or_address] [grantee]", Short: "Grant Fee allowance to an address", @@ -69,7 +70,7 @@ Examples: return err } - grantee, err := sdk.AccAddressFromBech32(args[1]) + grantee, err := ac.StringToBytes(args[1]) if err != nil { return err } @@ -180,7 +181,7 @@ Examples: } // NewCmdRevokeFeegrant returns a CLI command handler for creating a MsgRevokeAllowance transaction. -func NewCmdRevokeFeegrant() *cobra.Command { +func NewCmdRevokeFeegrant(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "revoke [granter] [grantee]", Short: "revoke fee-grant", @@ -200,7 +201,7 @@ Example: return err } - grantee, err := sdk.AccAddressFromBech32(args[1]) + grantee, err := ac.StringToBytes(args[1]) if err != nil { return err } diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index f4493da0d71c..d5af0790259a 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -125,7 +125,7 @@ func (s *CLITestSuite) createGrant(granter, grantee sdk.Address) { commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args) s.Require().NoError(err) @@ -412,7 +412,7 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -505,7 +505,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeFeegrant() + cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -550,7 +550,7 @@ func (s *CLITestSuite) TestTxWithFeeGrant() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) var res sdk.TxResponse out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) @@ -707,7 +707,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -762,7 +762,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant() + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &sdk.TxResponse{}), out.String()) diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index d72659abfa38..9022e5f8d570 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -250,11 +250,11 @@ func emitUseGrantEvent(ctx sdk.Context, granter, grantee string) { // InitGenesis will initialize the keeper from a *previously validated* GenesisState func (k Keeper) InitGenesis(ctx sdk.Context, data *feegrant.GenesisState) error { for _, f := range data.Allowances { - granter, err := sdk.AccAddressFromBech32(f.Granter) + granter, err := k.addressCodec.StringToBytes(f.Granter) if err != nil { return err } - grantee, err := sdk.AccAddressFromBech32(f.Grantee) + grantee, err := k.addressCodec.StringToBytes(f.Grantee) if err != nil { return err } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 895354c8a8fc..2de38e517dd9 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -165,7 +165,8 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { suite.Equal(tc.allowance, allow) }) } - accAddr, err := sdk.AccAddressFromBech32("cosmos1rxr4mq58w3gtnx5tsc438mwjjafv3mja7k5pnu") + address := "cosmos1rxr4mq58w3gtnx5tsc438mwjjafv3mja7k5pnu" + accAddr, err := testutil.NewBech32Codec().StringToBytes(address) suite.Require().NoError(err) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() @@ -176,7 +177,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { _, err = suite.feegrantKeeper.GetAllowance(suite.ctx, suite.addrs[3], accAddr) suite.Require().NoError(err) - _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[3].String(), Grantee: accAddr.String()}) + _, err = suite.msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{Granter: suite.addrs[3].String(), Grantee: address}) suite.Require().NoError(err) } diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index 2cafc9fd9fae..486938fcb078 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -4,7 +4,9 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/feegrant" ) @@ -36,11 +38,19 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA return nil, err } + if msg.Grantee == msg.Granter { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot self-grant fee authorization") + } + allowance, err := msg.GetFeeAllowanceI() if err != nil { return nil, err } + if err := allowance.ValidateBasic(); err != nil { + return nil, err + } + err = k.Keeper.GrantAllowance(ctx, granter, grantee, allowance) if err != nil { return nil, err @@ -68,5 +78,9 @@ func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevok return nil, err } + if msg.Grantee == msg.Granter { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "addresses must be different") + } + return &feegrant.MsgRevokeAllowanceResponse{}, nil } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index eaf2b742078c..fe2b5a05f4fe 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -9,6 +9,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/errors" @@ -43,10 +44,11 @@ var ( // AppModuleBasic defines the basic application module used by the feegrant module. type AppModuleBasic struct { cdc codec.Codec + ac address.Codec } // Name returns the feegrant module's name. -func (AppModuleBasic) Name() string { +func (ab AppModuleBasic) Name() string { return feegrant.ModuleName } @@ -63,23 +65,23 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // RegisterLegacyAminoCodec registers the feegrant module's types for the given codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +func (ab AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { feegrant.RegisterLegacyAminoCodec(cdc) } // RegisterInterfaces registers the feegrant module's interface types -func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { +func (ab AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { feegrant.RegisterInterfaces(registry) } // DefaultGenesis returns default genesis state as raw bytes for the feegrant // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { +func (ab AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(feegrant.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the feegrant module. -func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { +func (ab AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { var data feegrant.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return errors.Wrapf(err, "failed to unmarshal %s genesis state", feegrant.ModuleName) @@ -89,20 +91,20 @@ func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.Tx } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the feegrant module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) { +func (ab AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) { if err := feegrant.RegisterQueryHandlerClient(context.Background(), mux, feegrant.NewQueryClient(clientCtx)); err != nil { panic(err) } } // GetTxCmd returns the root tx command for the feegrant module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() +func (ab AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd(ab.ac) } // GetQueryCmd returns no root query command for the feegrant module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() +func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(ab.ac) } // ---------------------------------------------------------------------------- @@ -119,9 +121,9 @@ type AppModule struct { } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule { +func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry, ac address.Codec) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, + AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ac}, keeper: keeper, accountKeeper: ak, bankKeeper: bk, @@ -195,7 +197,7 @@ type FeegrantInputs struct { func ProvideModule(in FeegrantInputs) (keeper.Keeper, appmodule.AppModule) { k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper, in.AddressCodec) - m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) + m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry, in.AddressCodec) return k, m } @@ -214,6 +216,6 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { // WeightedOperations returns all the feegrant module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( - am.registry, simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, + am.registry, simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, am.ac, ) } diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 050feb8c7cd5..c3120b587a99 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -41,21 +41,7 @@ func NewMsgGrantAllowance(feeAllowance FeeAllowanceI, granter, grantee sdk.AccAd // ValidateBasic implements the sdk.Msg interface. func (msg MsgGrantAllowance) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Granter); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid granter address: %s", err) - } - if _, err := sdk.AccAddressFromBech32(msg.Grantee); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid grantee address: %s", err) - } - if msg.Grantee == msg.Granter { - return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot self-grant fee authorization") - } - allowance, err := msg.GetFeeAllowanceI() - if err != nil { - return err - } - - return allowance.ValidateBasic() + return nil } // GetSigners gets the granter account associated with an allowance @@ -95,15 +81,6 @@ func NewMsgRevokeAllowance(granter sdk.AccAddress, grantee sdk.AccAddress) MsgRe // ValidateBasic implements the sdk.Msg interface. func (msg MsgRevokeAllowance) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Granter); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid granter address: %s", err) - } - if _, err := sdk.AccAddressFromBech32(msg.Grantee); err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid grantee address: %s", err) - } - if msg.Grantee == msg.Granter { - return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "addresses must be different") - } return nil } diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 147bcb9263f2..474c164be531 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -36,6 +37,7 @@ func WeightedOperations( ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, + ac address.Codec, ) simulation.WeightedOperations { var ( weightMsgGrantAllowance int @@ -61,7 +63,7 @@ func WeightedOperations( ), simulation.NewWeightedOperation( weightMsgRevokeAllowance, - SimulateMsgRevokeAllowance(codec.NewProtoCodec(registry), ak, bk, k), + SimulateMsgRevokeAllowance(codec.NewProtoCodec(registry), ak, bk, k, ac), ), } } @@ -116,7 +118,7 @@ func SimulateMsgGrantAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper, } // SimulateMsgRevokeAllowance generates a MsgRevokeAllowance with random values. -func SimulateMsgRevokeAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgRevokeAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, ac address.Codec) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -124,8 +126,14 @@ func SimulateMsgRevokeAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress k.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool { - granter := sdk.MustAccAddressFromBech32(grant.Granter) - grantee := sdk.MustAccAddressFromBech32(grant.Grantee) + granter, err := ac.StringToBytes(grant.Granter) + if err != nil { + panic(err) + } + grantee, err := ac.StringToBytes(grant.Grantee) + if err != nil { + panic(err) + } granterAddr = granter granteeAddr = grantee hasGrant = true diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 354b1bd80a0d..df24eca0746a 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + sdktestutil "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -75,7 +76,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { weightedOps := simulation.WeightedOperations( suite.interfaceRegistry, appParams, suite.cdc, suite.accountKeeper, - suite.bankKeeper, suite.feegrantKeeper, + suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec(), ) s := rand.NewSource(1) @@ -166,7 +167,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper) + op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec()) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) From 90e0caca78746b9515fb8ab7feff7cac894ce61f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 17 Mar 2023 14:46:35 +0100 Subject: [PATCH 05/24] remove usage of accaddressfrombech32 --- tests/e2e/feegrant/suite.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index 781c4d0ee4ea..6509e9facce4 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -615,10 +615,11 @@ func (s *E2ETestSuite) TestNewCmdRevokeFeegrant() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), } + address := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00" // Create new fee grant specifically to test amino. - aminoGrantee, err := sdk.AccAddressFromBech32("cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00") + aminoGrantee, err := testutil.NewBech32Codec().StringToBytes(address) s.Require().NoError(err) - s.createGrant(granter, aminoGrantee) + s.createGrant(granter, sdk.AccAddress(aminoGrantee)) testCases := []struct { name string @@ -680,7 +681,7 @@ func (s *E2ETestSuite) TestNewCmdRevokeFeegrant() { append( []string{ granter.String(), - aminoGrantee.String(), + address, fmt.Sprintf("--%s=%s", flags.FlagFrom, granter), fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, From 2d56e2a35e1c6717139d0b7d3fe4b8609ba8ea7b Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 17 Mar 2023 14:49:15 +0100 Subject: [PATCH 06/24] remove failing tests --- x/feegrant/msgs_test.go | 125 ---------------------------------------- 1 file changed, 125 deletions(-) diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index 27c6eb62479b..5e33f131dae1 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -2,140 +2,15 @@ package feegrant_test import ( "testing" - "time" "github.com/stretchr/testify/require" "cosmossdk.io/x/feegrant" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -func TestMsgGrantAllowance(t *testing.T) { - cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - addressCodec := testutil.NewBech32Codec() - addr, _ := addressCodec.StringToBytes("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") - addr2, _ := addressCodec.StringToBytes("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") - atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) - threeHours := time.Now().Add(3 * time.Hour) - basic := &feegrant.BasicAllowance{ - SpendLimit: atom, - Expiration: &threeHours, - } - - cases := map[string]struct { - grantee sdk.AccAddress - granter sdk.AccAddress - grant *feegrant.BasicAllowance - valid bool - }{ - "valid": { - grantee: addr, - granter: addr2, - grant: basic, - valid: true, - }, - "no grantee": { - granter: addr2, - grantee: sdk.AccAddress{}, - grant: basic, - valid: false, - }, - "no granter": { - granter: sdk.AccAddress{}, - grantee: addr, - grant: basic, - valid: false, - }, - "grantee == granter": { - grantee: addr, - granter: addr, - grant: basic, - valid: false, - }, - } - - for _, tc := range cases { - msg, err := feegrant.NewMsgGrantAllowance(tc.grant, tc.granter, tc.grantee) - require.NoError(t, err) - err = msg.ValidateBasic() - - if tc.valid { - require.NoError(t, err) - - addrSlice := msg.GetSigners() - require.True(t, tc.granter.Equals(addrSlice[0])) - - allowance, err := msg.GetFeeAllowanceI() - require.NoError(t, err) - require.Equal(t, tc.grant, allowance) - - err = msg.UnpackInterfaces(cdc) - require.NoError(t, err) - } else { - require.Error(t, err) - } - } -} - -func TestMsgRevokeAllowance(t *testing.T) { - addr, _ := sdk.AccAddressFromBech32("cosmos1aeuqja06474dfrj7uqsvukm6rael982kk89mqr") - addr2, _ := sdk.AccAddressFromBech32("cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl") - atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555)) - threeHours := time.Now().Add(3 * time.Hour) - - basic := &feegrant.BasicAllowance{ - SpendLimit: atom, - Expiration: &threeHours, - } - cases := map[string]struct { - grantee sdk.AccAddress - granter sdk.AccAddress - grant *feegrant.BasicAllowance - valid bool - }{ - "valid": { - grantee: addr, - granter: addr2, - grant: basic, - valid: true, - }, - "no grantee": { - granter: addr2, - grantee: sdk.AccAddress{}, - grant: basic, - valid: false, - }, - "no granter": { - granter: sdk.AccAddress{}, - grantee: addr, - grant: basic, - valid: false, - }, - "grantee == granter": { - grantee: addr, - granter: addr, - grant: basic, - valid: false, - }, - } - - for _, tc := range cases { - msg := feegrant.NewMsgRevokeAllowance(tc.granter, tc.grantee) - err := msg.ValidateBasic() - if tc.valid { - require.NoError(t, err) - addrSlice := msg.GetSigners() - require.True(t, tc.granter.Equals(addrSlice[0])) - } else { - require.Error(t, err) - } - } -} - func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} var msg legacytx.LegacyMsg From 4285a6749f58f94e4a48a941145dd3c7d1239902 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 20 Mar 2023 11:50:04 +0100 Subject: [PATCH 07/24] address feedback --- simapp/app.go | 4 ++-- testutil/bech32_codec.go | 4 ++-- x/feegrant/client/cli/query_test.go | 6 +++--- x/feegrant/client/cli/tx_test.go | 14 +++++++------- x/feegrant/grant_test.go | 2 +- x/feegrant/keeper/genesis_test.go | 2 +- x/feegrant/keeper/keeper_test.go | 4 ++-- x/feegrant/keeper/msg_server_test.go | 2 +- x/feegrant/key_test.go | 4 ++-- x/feegrant/module/abci_test.go | 2 +- x/feegrant/simulation/operations_test.go | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index ba037dd41bb7..4a1bd4a16f16 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -311,7 +311,7 @@ func NewSimApp( app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, keys[crisistypes.StoreKey], invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper, app.AccountKeeper.GetAddressCodec()) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks @@ -390,7 +390,7 @@ func NewSimApp( vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), - feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry, app.AccountKeeper.GetAddressCodec()), gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), diff --git a/testutil/bech32_codec.go b/testutil/bech32_codec.go index 276b1853b2d9..e0fcdb3d4165 100644 --- a/testutil/bech32_codec.go +++ b/testutil/bech32_codec.go @@ -15,8 +15,8 @@ type bech32Codec struct { var _ address.Codec = &bech32Codec{} -func NewBech32Codec() address.Codec { - return bech32Codec{"cosmos"} +func NewBech32Codec(hrp string) address.Codec { + return bech32Codec{hrp} } // StringToBytes encodes text to bytes diff --git a/x/feegrant/client/cli/query_test.go b/x/feegrant/client/cli/query_test.go index eaf013f1ecf0..ff9fd78ef1eb 100644 --- a/x/feegrant/client/cli/query_test.go +++ b/x/feegrant/client/cli/query_test.go @@ -48,7 +48,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) if tc.expectErr { @@ -95,7 +95,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGrantee() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -142,7 +142,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGranter() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index d5af0790259a..c3e7fab3414c 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -125,7 +125,7 @@ func (s *CLITestSuite) createGrant(granter, grantee sdk.Address) { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args) s.Require().NoError(err) @@ -412,7 +412,7 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -436,7 +436,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), } - addressCodec := testutil.NewBech32Codec() + addressCodec := testutil.NewBech32Codec("cosmos") // Create new fee grant specifically to test amino. encodedGrantee := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00" aminoGrantee, err := addressCodec.StringToBytes(encodedGrantee) @@ -505,7 +505,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -550,7 +550,7 @@ func (s *CLITestSuite) TestTxWithFeeGrant() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) var res sdk.TxResponse out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) @@ -707,7 +707,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -762,7 +762,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &sdk.TxResponse{}), out.String()) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index 2916d81ad505..d19982eb9ff9 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -16,7 +16,7 @@ import ( ) func TestGrant(t *testing.T) { - addressCodec := testutil.NewBech32Codec() + addressCodec := testutil.NewBech32Codec("cosmos") key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 00c3699224a3..aed497ad7377 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -36,7 +36,7 @@ func (suite *GenesisTestSuite) SetupTest() { accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec()) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec("cosmos")) suite.ctx = testCtx.Ctx } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 2de38e517dd9..c3bb4fb77542 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, testutil.NewBech32Codec()) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, testutil.NewBech32Codec("cosmos")) suite.ctx = testCtx.Ctx suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper) suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(555))) @@ -166,7 +166,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { }) } address := "cosmos1rxr4mq58w3gtnx5tsc438mwjjafv3mja7k5pnu" - accAddr, err := testutil.NewBech32Codec().StringToBytes(address) + accAddr, err := testutil.NewBech32Codec("cosmos").StringToBytes(address) suite.Require().NoError(err) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index a312e4beb19c..ce89060b2276 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -16,7 +16,7 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { oneYear := ctx.BlockTime().AddDate(1, 0, 0) yesterday := ctx.BlockTime().AddDate(0, 0, -1) - addressCodec := testutil.NewBech32Codec() + addressCodec := testutil.NewBech32Codec("cosmos") testCases := []struct { name string diff --git a/x/feegrant/key_test.go b/x/feegrant/key_test.go index 2be0cd035cb7..b931cf2e8369 100644 --- a/x/feegrant/key_test.go +++ b/x/feegrant/key_test.go @@ -12,7 +12,7 @@ import ( ) func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { - addressCodec := testutil.NewBech32Codec() + addressCodec := testutil.NewBech32Codec("cosmos") grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") @@ -28,7 +28,7 @@ func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { } func TestMarshalAndUnmarshalFeegrantKeyQueueKey(t *testing.T) { - addressCodec := testutil.NewBech32Codec() + addressCodec := testutil.NewBech32Codec("cosmos") grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 23905862df01..458334c91871 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -40,7 +40,7 @@ func TestFeegrantPruning(t *testing.T) { accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() - feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec()) + feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec("cosmos")) feegrantKeeper.GrantAllowance( testCtx.Ctx, diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index df24eca0746a..7a091739306e 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -76,7 +76,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { weightedOps := simulation.WeightedOperations( suite.interfaceRegistry, appParams, suite.cdc, suite.accountKeeper, - suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec(), + suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec("cosmos"), ) s := rand.NewSource(1) @@ -167,7 +167,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec()) + op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec("cosmos")) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) From 232c6f4a8a8bf385a5acec00b26770bfeed7104f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 17:56:35 +0100 Subject: [PATCH 08/24] move to address/codec --- .../keeper => codec/address}/bech32_codec.go | 18 +++---- tests/e2e/feegrant/suite.go | 23 ++++----- testutil/bech32_codec.go | 48 ------------------- x/auth/keeper/keeper.go | 7 +-- x/auth/module.go | 3 +- x/feegrant/client/cli/query_test.go | 8 ++-- x/feegrant/client/cli/tx_test.go | 15 +++--- x/feegrant/grant_test.go | 3 +- x/feegrant/keeper/genesis_test.go | 3 +- x/feegrant/keeper/keeper_test.go | 5 +- x/feegrant/keeper/msg_server_test.go | 4 +- x/feegrant/key_test.go | 6 +-- x/feegrant/module/abci_test.go | 3 +- x/feegrant/simulation/operations_test.go | 6 +-- 14 files changed, 56 insertions(+), 96 deletions(-) rename {x/auth/keeper => codec/address}/bech32_codec.go (67%) delete mode 100644 testutil/bech32_codec.go diff --git a/x/auth/keeper/bech32_codec.go b/codec/address/bech32_codec.go similarity index 67% rename from x/auth/keeper/bech32_codec.go rename to codec/address/bech32_codec.go index 2a28dcc426b1..9182af2d0bd3 100644 --- a/x/auth/keeper/bech32_codec.go +++ b/codec/address/bech32_codec.go @@ -1,4 +1,4 @@ -package keeper +package address import ( errorsmod "cosmossdk.io/errors" @@ -9,24 +9,24 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -type bech32Codec struct { - bech32Prefix string +type Bech32Codec struct { + Bech32Prefix string } -var _ address.Codec = &bech32Codec{} +var _ address.Codec = &Bech32Codec{} func NewBech32Codec(prefix string) address.Codec { - return bech32Codec{prefix} + return Bech32Codec{prefix} } // StringToBytes encodes text to bytes -func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { +func (bc Bech32Codec) StringToBytes(text string) ([]byte, error) { hrp, bz, err := bech32.DecodeAndConvert(text) if err != nil { return nil, err } - if hrp != bc.bech32Prefix { + if hrp != bc.Bech32Prefix { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix") } @@ -38,8 +38,8 @@ func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { } // BytesToString decodes bytes to text -func (bc bech32Codec) BytesToString(bz []byte) (string, error) { - text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz) +func (bc Bech32Codec) BytesToString(bz []byte) (string, error) { + text, err := bech32.ConvertAndEncode(bc.Bech32Prefix, bz) if err != nil { return "", err } diff --git a/tests/e2e/feegrant/suite.go b/tests/e2e/feegrant/suite.go index 6509e9facce4..ab9ca482a450 100644 --- a/tests/e2e/feegrant/suite.go +++ b/tests/e2e/feegrant/suite.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/x/feegrant/client/cli" "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/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -97,7 +98,7 @@ func (s *E2ETestSuite) createGrant(granter, grantee sdk.Address) { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -171,7 +172,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -237,7 +238,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrantsByGrantee() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrantsByGrantee(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -294,7 +295,7 @@ func (s *E2ETestSuite) TestCmdGetFeeGrantsByGranter() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrantsByGranter(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -587,7 +588,7 @@ func (s *E2ETestSuite) TestNewCmdFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -617,7 +618,7 @@ func (s *E2ETestSuite) TestNewCmdRevokeFeegrant() { address := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00" // Create new fee grant specifically to test amino. - aminoGrantee, err := testutil.NewBech32Codec().StringToBytes(address) + aminoGrantee, err := codecaddress.NewBech32Codec("cosmos").StringToBytes(address) s.Require().NoError(err) s.createGrant(granter, sdk.AccAddress(aminoGrantee)) @@ -695,7 +696,7 @@ func (s *E2ETestSuite) TestNewCmdRevokeFeegrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdRevokeFeegrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -744,7 +745,7 @@ func (s *E2ETestSuite) TestTxWithFeeGrant() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -879,7 +880,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -901,7 +902,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { } // get filtered fee allowance and check info - cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec()) + cmd := cli.GetCmdQueryFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) @@ -964,7 +965,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() { }, commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec()) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) return clitestutil.ExecTestCLICmd(clientCtx, cmd, args) }, &sdk.TxResponse{}, diff --git a/testutil/bech32_codec.go b/testutil/bech32_codec.go deleted file mode 100644 index e0fcdb3d4165..000000000000 --- a/testutil/bech32_codec.go +++ /dev/null @@ -1,48 +0,0 @@ -package testutil - -import ( - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - "github.com/cosmos/cosmos-sdk/types/bech32" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -type bech32Codec struct { - bech32Prefix string -} - -var _ address.Codec = &bech32Codec{} - -func NewBech32Codec(hrp string) address.Codec { - return bech32Codec{hrp} -} - -// StringToBytes encodes text to bytes -func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { - hrp, bz, err := bech32.DecodeAndConvert(text) - if err != nil { - return nil, err - } - - if hrp != bc.bech32Prefix { - return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix") - } - - if err := sdk.VerifyAddressFormat(bz); err != nil { - return nil, err - } - - return bz, nil -} - -// BytesToString decodes bytes to text -func (bc bech32Codec) BytesToString(bz []byte) (string, error) { - text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz) - if err != nil { - return "", err - } - - return text, nil -} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 2d3a65c9e337..7351f40a0aff 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -10,6 +10,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" @@ -86,7 +87,7 @@ func NewAccountKeeper( permAddrs[name] = types.NewPermissionsForAddress(name, perms) } - bech32Codec := NewBech32Codec(bech32Prefix) + bech32Codec := codecaddress.NewBech32Codec(bech32Prefix) return AccountKeeper{ storeKey: storeKey, @@ -262,10 +263,10 @@ func (ak AccountKeeper) GetCodec() codec.BinaryCodec { return ak.cdc } // add getter for bech32Prefix func (ak AccountKeeper) getBech32Prefix() (string, error) { - bech32Codec, ok := ak.addressCdc.(bech32Codec) + bech32Codec, ok := ak.addressCdc.(codecaddress.Bech32Codec) if !ok { return "", fmt.Errorf("unable cast addressCdc to bech32Codec; expected %T got %T", bech32Codec, ak.addressCdc) } - return bech32Codec.bech32Prefix, nil + return bech32Codec.Bech32Prefix, nil } diff --git a/x/auth/module.go b/x/auth/module.go index e0ecddac85b7..6929e03b5979 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -20,6 +20,7 @@ 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" @@ -206,7 +207,7 @@ func init() { // 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 keeper.NewBech32Codec(config.Bech32Prefix) + return codecaddress.NewBech32Codec(config.Bech32Prefix) } //nolint:revive diff --git a/x/feegrant/client/cli/query_test.go b/x/feegrant/client/cli/query_test.go index ff9fd78ef1eb..b066af7309e5 100644 --- a/x/feegrant/client/cli/query_test.go +++ b/x/feegrant/client/cli/query_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/client/cli" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/testutil" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" ) @@ -48,7 +48,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.GetCmdQueryFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args) if tc.expectErr { @@ -95,7 +95,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGrantee() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec("cosmos")) + cmd := cli.GetCmdQueryFeeGrantsByGrantee(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) @@ -142,7 +142,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGranter() { tc := tc s.Run(tc.name, func() { - cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec("cosmos")) + cmd := cli.GetCmdQueryFeeGrantsByGranter(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index c3e7fab3414c..40866b47cc8b 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -125,7 +126,7 @@ func (s *CLITestSuite) createGrant(granter, grantee sdk.Address) { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, args) s.Require().NoError(err) @@ -412,7 +413,7 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -436,7 +437,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), } - addressCodec := testutil.NewBech32Codec("cosmos") + addressCodec := codecaddress.NewBech32Codec("cosmos") // Create new fee grant specifically to test amino. encodedGrantee := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00" aminoGrantee, err := addressCodec.StringToBytes(encodedGrantee) @@ -505,7 +506,7 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdRevokeFeegrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdRevokeFeegrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -550,7 +551,7 @@ func (s *CLITestSuite) TestTxWithFeeGrant() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) var res sdk.TxResponse out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) @@ -707,7 +708,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { tc := tc s.Run(tc.name, func() { - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -762,7 +763,7 @@ func (s *CLITestSuite) TestFilteredFeeAllowance() { commonFlags..., ) - cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec("cosmos")) + cmd := cli.NewCmdFeeGrant(codecaddress.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &sdk.TxResponse{}), out.String()) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index d19982eb9ff9..83da814c9196 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -10,13 +10,14 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/module" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestGrant(t *testing.T) { - addressCodec := testutil.NewBech32Codec("cosmos") + addressCodec := codecaddress.NewBech32Codec("cosmos") key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index aed497ad7377..51362a200cce 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/module" feegranttestutil "cosmossdk.io/x/feegrant/testutil" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" @@ -36,7 +37,7 @@ func (suite *GenesisTestSuite) SetupTest() { accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec("cosmos")) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, codecaddress.NewBech32Codec("cosmos")) suite.ctx = testCtx.Ctx } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index c3bb4fb77542..484c6c8fdb02 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/module" feegranttestutil "cosmossdk.io/x/feegrant/testutil" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -48,7 +49,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, testutil.NewBech32Codec("cosmos")) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, codecaddress.NewBech32Codec("cosmos")) suite.ctx = testCtx.Ctx suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper) suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(555))) @@ -166,7 +167,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { }) } address := "cosmos1rxr4mq58w3gtnx5tsc438mwjjafv3mja7k5pnu" - accAddr, err := testutil.NewBech32Codec("cosmos").StringToBytes(address) + accAddr, err := codecaddress.NewBech32Codec("cosmos").StringToBytes(address) suite.Require().NoError(err) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index ce89060b2276..7ae318aa34e7 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -5,8 +5,8 @@ import ( "cosmossdk.io/x/feegrant" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/golang/mock/gomock" ) @@ -16,7 +16,7 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { oneYear := ctx.BlockTime().AddDate(1, 0, 0) yesterday := ctx.BlockTime().AddDate(0, 0, -1) - addressCodec := testutil.NewBech32Codec("cosmos") + addressCodec := codecaddress.NewBech32Codec("cosmos") testCases := []struct { name string diff --git a/x/feegrant/key_test.go b/x/feegrant/key_test.go index b931cf2e8369..67b382d87817 100644 --- a/x/feegrant/key_test.go +++ b/x/feegrant/key_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/x/feegrant" - "github.com/cosmos/cosmos-sdk/testutil" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" sdk "github.com/cosmos/cosmos-sdk/types" ) func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { - addressCodec := testutil.NewBech32Codec("cosmos") + addressCodec := codecaddress.NewBech32Codec("cosmos") grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") @@ -28,7 +28,7 @@ func TestMarshalAndUnmarshalFeegrantKey(t *testing.T) { } func TestMarshalAndUnmarshalFeegrantKeyQueueKey(t *testing.T) { - addressCodec := testutil.NewBech32Codec("cosmos") + addressCodec := codecaddress.NewBech32Codec("cosmos") grantee, err := addressCodec.StringToBytes("cosmos1qk93t4j0yyzgqgt6k5qf8deh8fq6smpn3ntu3x") require.NoError(t, err) granter, err := addressCodec.StringToBytes("cosmos1p9qh4ldfd6n0qehujsal4k7g0e37kel90rc4ts") diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 458334c91871..3de1840d480c 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/baseapp" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -40,7 +41,7 @@ func TestFeegrantPruning(t *testing.T) { accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() - feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, testutil.NewBech32Codec("cosmos")) + feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, codecaddress.NewBech32Codec("cosmos")) feegrantKeeper.GrantAllowance( testCtx.Ctx, diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 7a091739306e..b1c37384493a 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -12,9 +12,9 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" - sdktestutil "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -76,7 +76,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { weightedOps := simulation.WeightedOperations( suite.interfaceRegistry, appParams, suite.cdc, suite.accountKeeper, - suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec("cosmos"), + suite.bankKeeper, suite.feegrantKeeper, codecaddress.NewBech32Codec("cosmos"), ) s := rand.NewSource(1) @@ -167,7 +167,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, sdktestutil.NewBech32Codec("cosmos")) + op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, codecaddress.NewBech32Codec("cosmos")) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) From ca828f537e12a14d44e644b6d66db54d0c5acd75 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 17:57:23 +0100 Subject: [PATCH 09/24] depend on core --- codec/address/bech32_codec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/address/bech32_codec.go b/codec/address/bech32_codec.go index 9182af2d0bd3..d1daf93703f6 100644 --- a/codec/address/bech32_codec.go +++ b/codec/address/bech32_codec.go @@ -1,10 +1,10 @@ package address import ( + "cosmossdk.io/core/address" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/bech32" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) From 5063def162cd681d0f9fd59f199723dd49606c8a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 17:59:12 +0100 Subject: [PATCH 10/24] remove types codec --- types/address/codec.go | 9 --------- x/auth/keeper/deterministic_test.go | 3 +-- x/auth/keeper/keeper.go | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 types/address/codec.go diff --git a/types/address/codec.go b/types/address/codec.go deleted file mode 100644 index 5f20690cbcc7..000000000000 --- a/types/address/codec.go +++ /dev/null @@ -1,9 +0,0 @@ -package address - -// Codec defines an interface to convert addresses from and to string/bytes. -type Codec interface { - // StringToBytes decodes text to bytes - StringToBytes(text string) ([]byte, error) - // BytesToString encodes bytes to text - BytesToString(bz []byte) (string, error) -} diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index e756f6075fda..829d28286fc7 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -5,12 +5,11 @@ import ( "sort" "testing" + storetypes "cosmossdk.io/store/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" "pgregory.net/rapid" - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 7351f40a0aff..cb6c08006ad7 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/log" gogotypes "github.com/cosmos/gogoproto/types" + "cosmossdk.io/core/address" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -13,7 +14,6 @@ import ( codecaddress "github.com/cosmos/cosmos-sdk/codec/address" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" ) From 96b3845bfed1597ae528f9dc24bbd7954c420392 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 18:03:12 +0100 Subject: [PATCH 11/24] fix imports --- x/auth/module.go | 2 +- x/feegrant/client/cli/query.go | 2 +- x/feegrant/client/cli/tx.go | 5 +++-- x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 2 ++ x/feegrant/simulation/operations.go | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/x/auth/module.go b/x/auth/module.go index 6929e03b5979..b2fff09f8a17 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -11,8 +11,8 @@ import ( "cosmossdk.io/depinject" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" - "github.com/cosmos/cosmos-sdk/types/address" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" diff --git a/x/feegrant/client/cli/query.go b/x/feegrant/client/cli/query.go index adb68b7aa339..8702f19dabbd 100644 --- a/x/feegrant/client/cli/query.go +++ b/x/feegrant/client/cli/query.go @@ -4,12 +4,12 @@ import ( "fmt" "strings" + "cosmosdk.io/core/address" "github.com/spf13/cobra" "cosmossdk.io/x/feegrant" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/version" ) diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index 5069fe7df38a..c32369599fac 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -7,13 +7,14 @@ import ( "github.com/spf13/cobra" - "cosmossdk.io/x/feegrant" + "cosmosdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/version" + + "cosmossdk.io/x/feegrant" ) // flag for feegrant module diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 4020c2203a54..7d6aca3e1b4e 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( cosmossdk.io/api v0.3.1 - cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba + cosmossdk.io/core v0.6.1 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/log v0.1.0 diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 2514409a4d4d..cb18da6f4f29 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -41,6 +41,8 @@ cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba h1:S4PYij/tX3Op/hwen cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba/go.mod h1:lpS+G8bGC2anqzWdndTzjnQnuMO/qAcgZUkGJp4i3rc= cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba h1:kSnaDzbwMInpQYwz8ESgvi6ceUQWcXAJdEVZW454dX0= cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba/go.mod h1:WiFk9ZQbFVBHk9AqQIkLFqyj30NPQB6C45CIeAZxDcw= +cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= +cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 474c164be531..c89c08e04921 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -3,13 +3,13 @@ package simulation import ( "math/rand" + "cosmosdk.io/core/address" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/cosmos/cosmos-sdk/x/simulation" From c9fdbdbe80a466ccfab86372d4b53929ded328af Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 18:10:35 +0100 Subject: [PATCH 12/24] fix imports --- x/feegrant/client/cli/query.go | 2 +- x/feegrant/client/cli/tx.go | 2 +- x/feegrant/go.mod | 7 ++---- x/feegrant/go.sum | 38 +++++++++++------------------ x/feegrant/simulation/operations.go | 2 +- 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/x/feegrant/client/cli/query.go b/x/feegrant/client/cli/query.go index 8702f19dabbd..d2808f5f5dff 100644 --- a/x/feegrant/client/cli/query.go +++ b/x/feegrant/client/cli/query.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "cosmosdk.io/core/address" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "cosmossdk.io/x/feegrant" diff --git a/x/feegrant/client/cli/tx.go b/x/feegrant/client/cli/tx.go index c32369599fac..635249da0e18 100644 --- a/x/feegrant/client/cli/tx.go +++ b/x/feegrant/client/cli/tx.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" - "cosmosdk.io/core/address" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 7d6aca3e1b4e..bb6c71b8e489 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/feegrant go 1.20 require ( - cosmossdk.io/api v0.3.1 + cosmossdk.io/api v0.3.2-0.20230313131911-55bf5d4efbe7 cosmossdk.io/core v0.6.1 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/errors v1.0.0-beta.7 @@ -154,7 +154,4 @@ require ( sigs.k8s.io/yaml v1.3.0 // indirect ) -// Below are the long-lived replace of the Cosmos SDK -// Fix upstream GHSA-h395-qcrw-5vmq vulnerability. -// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 -replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 +replace github.com/cosmos/cosmos-sdk => ../../. diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index cb18da6f4f29..c9233fed028a 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -35,12 +35,10 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= -cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= +cosmossdk.io/api v0.3.2-0.20230313131911-55bf5d4efbe7 h1:4LrWK+uGP5IxznxtHHsHD+ZBs2+oZRH2loYOGjHLzZM= +cosmossdk.io/api v0.3.2-0.20230313131911-55bf5d4efbe7/go.mod h1:yVns7mKgcsG+hZW/3C5FdJtC6QYWdFIcRlKb9+5HV5g= cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba h1:S4PYij/tX3Op/hwenVEN9D+M27JRcwSwVqE3UA0BnwM= cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba/go.mod h1:lpS+G8bGC2anqzWdndTzjnQnuMO/qAcgZUkGJp4i3rc= -cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba h1:kSnaDzbwMInpQYwz8ESgvi6ceUQWcXAJdEVZW454dX0= -cosmossdk.io/core v0.6.1-0.20230309163709-87da587416ba/go.mod h1:WiFk9ZQbFVBHk9AqQIkLFqyj30NPQB6C45CIeAZxDcw= cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= @@ -188,8 +186,6 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230314215525-ba8de97d1af8 h1:aWCQzeF9Hw8LR2v5FkRG5WnE/9lBXUzGQ14AQ/DRUH4= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230314215525-ba8de97d1af8/go.mod h1:8aa+u5OVfJ28TEHc3CpZDBbfUR7cOqIBVJ3sE+BvpcY= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -281,10 +277,12 @@ github.com/getsentry/sentry-go v0.12.0/go.mod h1:NSap0JBYWzHND8oMbyi0+XZhUalc1TB github.com/getsentry/sentry-go v0.19.0 h1:BcCH3CN5tXt5aML+gwmbFwVptLLQA+eT866fCO9wVOM= github.com/getsentry/sentry-go v0.19.0/go.mod h1:y3+lGEFEFexZtpbG1GUE2WD/f9zGyKYwpEqryTOC/nE= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= +github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -306,11 +304,11 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -321,7 +319,6 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= @@ -521,7 +518,6 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -550,7 +546,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -560,8 +555,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= @@ -586,6 +581,7 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -624,7 +620,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= @@ -681,7 +676,6 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= @@ -742,7 +736,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -828,13 +821,12 @@ github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= -github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= @@ -900,7 +892,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= @@ -1082,7 +1073,6 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1305,7 +1295,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= @@ -1315,11 +1304,12 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index c89c08e04921..173a6478f9e7 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -3,7 +3,7 @@ package simulation import ( "math/rand" - "cosmosdk.io/core/address" + "cosmossdk.io/core/address" "cosmossdk.io/x/feegrant" "cosmossdk.io/x/feegrant/keeper" "github.com/cosmos/cosmos-sdk/baseapp" From 8cea31f3f7f0cc2f4ec7cbc137407f731b4c8a1a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 21 Mar 2023 18:54:13 +0100 Subject: [PATCH 13/24] move bech32 back to auth and wrap methods --- simapp/app.go | 4 +- x/auth/keeper/bech32_codec.go | 48 +++++++++++++++++++ x/auth/keeper/grpc_query.go | 12 +++++ x/auth/keeper/keeper.go | 7 ++- x/feegrant/expected_keepers.go | 12 ++--- x/feegrant/keeper/grpc_query.go | 8 ++-- x/feegrant/keeper/keeper.go | 20 ++++---- x/feegrant/keeper/msg_server.go | 8 ++-- x/feegrant/module/abci_test.go | 3 +- x/feegrant/module/module.go | 9 ++-- x/feegrant/testutil/expected_keepers_mocks.go | 30 ++++++++++++ 11 files changed, 122 insertions(+), 39 deletions(-) create mode 100644 x/auth/keeper/bech32_codec.go diff --git a/simapp/app.go b/simapp/app.go index 207bfbfcfb40..1f6447054ce4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -313,7 +313,7 @@ func NewSimApp( app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, keys[crisistypes.StoreKey], invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper, app.AccountKeeper.GetAddressCodec()) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks @@ -392,7 +392,7 @@ func NewSimApp( vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), - feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry, app.AccountKeeper.GetAddressCodec()), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), diff --git a/x/auth/keeper/bech32_codec.go b/x/auth/keeper/bech32_codec.go new file mode 100644 index 000000000000..fa0734efeba5 --- /dev/null +++ b/x/auth/keeper/bech32_codec.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "cosmossdk.io/core/address" + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +type bech32Codec struct { + bech32Prefix string +} + +var _ address.Codec = &bech32Codec{} + +func NewBech32Codec(prefix string) address.Codec { + return bech32Codec{prefix} +} + +// StringToBytes encodes text to bytes +func (bc bech32Codec) StringToBytes(text string) ([]byte, error) { + hrp, bz, err := bech32.DecodeAndConvert(text) + if err != nil { + return nil, err + } + + if hrp != bc.bech32Prefix { + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "hrp does not match bech32Prefix") + } + + if err := sdk.VerifyAddressFormat(bz); err != nil { + return nil, err + } + + return bz, nil +} + +// BytesToString decodes bytes to text +func (bc bech32Codec) BytesToString(bz []byte) (string, error) { + text, err := bech32.ConvertAndEncode(bc.bech32Prefix, bz) + if err != nil { + return "", err + } + + return text, nil +} diff --git a/x/auth/keeper/grpc_query.go b/x/auth/keeper/grpc_query.go index 4ba3d4e86d9f..f8e51411eca1 100644 --- a/x/auth/keeper/grpc_query.go +++ b/x/auth/keeper/grpc_query.go @@ -246,3 +246,15 @@ func (ak AccountKeeper) AccountInfo(goCtx context.Context, req *types.QueryAccou }, }, nil } + +// BytesToString converts an address from bytes to string, using the +// keeper's bech32 prefix. +func (ak AccountKeeper) BytesToString(address []byte) (string, error) { + return ak.addressCdc.BytesToString(address) +} + +// StringToBytes converts an address from string to bytes, using the +// keeper's bech32 prefix. +func (ak AccountKeeper) StringToBytes(address string) ([]byte, error) { + return ak.addressCdc.StringToBytes(address) +} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index cb6c08006ad7..d3b862e7cfee 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -11,7 +11,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - codecaddress "github.com/cosmos/cosmos-sdk/codec/address" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -87,7 +86,7 @@ func NewAccountKeeper( permAddrs[name] = types.NewPermissionsForAddress(name, perms) } - bech32Codec := codecaddress.NewBech32Codec(bech32Prefix) + bech32Codec := NewBech32Codec(bech32Prefix) return AccountKeeper{ storeKey: storeKey, @@ -263,10 +262,10 @@ func (ak AccountKeeper) GetCodec() codec.BinaryCodec { return ak.cdc } // add getter for bech32Prefix func (ak AccountKeeper) getBech32Prefix() (string, error) { - bech32Codec, ok := ak.addressCdc.(codecaddress.Bech32Codec) + bech32Codec, ok := ak.addressCdc.(bech32Codec) if !ok { return "", fmt.Errorf("unable cast addressCdc to bech32Codec; expected %T got %T", bech32Codec, ak.addressCdc) } - return bech32Codec.Bech32Prefix, nil + return bech32Codec.bech32Prefix, nil } diff --git a/x/feegrant/expected_keepers.go b/x/feegrant/expected_keepers.go index 55d8e795d690..1ec0ddeff2eb 100644 --- a/x/feegrant/expected_keepers.go +++ b/x/feegrant/expected_keepers.go @@ -12,6 +12,11 @@ type AccountKeeper interface { NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) sdk.AccountI GetAccount(ctx sdk.Context, addr sdk.AccAddress) sdk.AccountI SetAccount(ctx sdk.Context, acc sdk.AccountI) + + // StringToBytes decodes text to bytes + StringToBytes(text string) ([]byte, error) + // BytesToString encodes bytes to text + BytesToString(bz []byte) (string, error) } // BankKeeper defines the expected supply Keeper (noalias) @@ -19,10 +24,3 @@ type BankKeeper interface { SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } - -type AddressCodec interface { - // StringToBytes decodes text to bytes - StringToBytes(text string) ([]byte, error) - // BytesToString encodes bytes to text - BytesToString(bz []byte) (string, error) -} diff --git a/x/feegrant/keeper/grpc_query.go b/x/feegrant/keeper/grpc_query.go index 2cbd971b0c65..ffa061e7ce53 100644 --- a/x/feegrant/keeper/grpc_query.go +++ b/x/feegrant/keeper/grpc_query.go @@ -24,12 +24,12 @@ func (q Keeper) Allowance(c context.Context, req *feegrant.QueryAllowanceRequest return nil, status.Error(codes.InvalidArgument, "invalid request") } - granterAddr, err := q.addressCodec.StringToBytes(req.Granter) + granterAddr, err := q.authKeeper.StringToBytes(req.Granter) if err != nil { return nil, err } - granteeAddr, err := q.addressCodec.StringToBytes(req.Grantee) + granteeAddr, err := q.authKeeper.StringToBytes(req.Grantee) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (q Keeper) Allowances(c context.Context, req *feegrant.QueryAllowancesReque return nil, status.Error(codes.InvalidArgument, "invalid request") } - granteeAddr, err := q.addressCodec.StringToBytes(req.Grantee) + granteeAddr, err := q.authKeeper.StringToBytes(req.Grantee) if err != nil { return nil, err } @@ -101,7 +101,7 @@ func (q Keeper) AllowancesByGranter(c context.Context, req *feegrant.QueryAllowa return nil, status.Error(codes.InvalidArgument, "invalid request") } - granterAddr, err := q.addressCodec.StringToBytes(req.Granter) + granterAddr, err := q.authKeeper.StringToBytes(req.Granter) if err != nil { return nil, err } diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 9022e5f8d570..b2f1ede2776a 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -18,21 +18,19 @@ import ( // Keeper manages state of all fee grants, as well as calculating approval. // It must have a codec with all available allowances registered. type Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - authKeeper feegrant.AccountKeeper - addressCodec feegrant.AddressCodec + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + authKeeper feegrant.AccountKeeper } var _ ante.FeegrantKeeper = &Keeper{} // NewKeeper creates a fee grant Keeper -func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.AccountKeeper, addressCodec feegrant.AddressCodec) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.AccountKeeper) Keeper { return Keeper{ - cdc: cdc, - storeKey: storeKey, - authKeeper: ak, - addressCodec: addressCodec, + cdc: cdc, + storeKey: storeKey, + authKeeper: ak, } } @@ -250,11 +248,11 @@ func emitUseGrantEvent(ctx sdk.Context, granter, grantee string) { // InitGenesis will initialize the keeper from a *previously validated* GenesisState func (k Keeper) InitGenesis(ctx sdk.Context, data *feegrant.GenesisState) error { for _, f := range data.Allowances { - granter, err := k.addressCodec.StringToBytes(f.Granter) + granter, err := k.authKeeper.StringToBytes(f.Granter) if err != nil { return err } - grantee, err := k.addressCodec.StringToBytes(f.Grantee) + grantee, err := k.authKeeper.StringToBytes(f.Grantee) if err != nil { return err } diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index 486938fcb078..d45a5098c656 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -28,12 +28,12 @@ var _ feegrant.MsgServer = msgServer{} func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantAllowance) (*feegrant.MsgGrantAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - grantee, err := k.addressCodec.StringToBytes(msg.Grantee) + grantee, err := k.authKeeper.StringToBytes(msg.Grantee) if err != nil { return nil, err } - granter, err := k.addressCodec.StringToBytes(msg.Granter) + granter, err := k.authKeeper.StringToBytes(msg.Granter) if err != nil { return nil, err } @@ -63,12 +63,12 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevokeAllowance) (*feegrant.MsgRevokeAllowanceResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - grantee, err := k.addressCodec.StringToBytes(msg.Grantee) + grantee, err := k.authKeeper.StringToBytes(msg.Grantee) if err != nil { return nil, err } - granter, err := k.addressCodec.StringToBytes(msg.Granter) + granter, err := k.authKeeper.StringToBytes(msg.Granter) if err != nil { return nil, err } diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 3de1840d480c..5ba572164690 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/baseapp" - codecaddress "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -41,7 +40,7 @@ func TestFeegrantPruning(t *testing.T) { accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() - feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper, codecaddress.NewBech32Codec("cosmos")) + feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper) feegrantKeeper.GrantAllowance( testCtx.Ctx, diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index fe2b5a05f4fe..800855025d42 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -121,9 +121,9 @@ type AppModule struct { } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry, ac address.Codec) AppModule { +func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ac}, + AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak}, keeper: keeper, accountKeeper: ak, bankKeeper: bk, @@ -190,14 +190,13 @@ type FeegrantInputs struct { Key *store.KVStoreKey Cdc codec.Codec AccountKeeper feegrant.AccountKeeper - AddressCodec feegrant.AddressCodec BankKeeper feegrant.BankKeeper Registry cdctypes.InterfaceRegistry } func ProvideModule(in FeegrantInputs) (keeper.Keeper, appmodule.AppModule) { - k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper, in.AddressCodec) - m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry, in.AddressCodec) + k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper) + m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) return k, m } diff --git a/x/feegrant/testutil/expected_keepers_mocks.go b/x/feegrant/testutil/expected_keepers_mocks.go index c49fc0ae9577..5145192c17fa 100644 --- a/x/feegrant/testutil/expected_keepers_mocks.go +++ b/x/feegrant/testutil/expected_keepers_mocks.go @@ -34,6 +34,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 types.Context, addr types.AccAddress) types.AccountI { m.ctrl.T.Helper() @@ -102,6 +117,21 @@ func (mr *MockAccountKeeperMockRecorder) SetAccount(ctx, acc interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), ctx, acc) } +// 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) +} + // MockBankKeeper is a mock of BankKeeper interface. type MockBankKeeper struct { ctrl *gomock.Controller From 6a0784ee59969fc0a0d74cd243a57476af1d91ef Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 22 Mar 2023 13:52:53 +0100 Subject: [PATCH 14/24] changelog --- x/feegrant/CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x/feegrant/CHANGELOG.md b/x/feegrant/CHANGELOG.md index c0fe3529547c..6d0461d712cd 100644 --- a/x/feegrant/CHANGELOG.md +++ b/x/feegrant/CHANGELOG.md @@ -27,4 +27,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* (x/feegrant) [14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module. \ No newline at end of file +* (x/feegrant) [14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module. + +### Api Breaking Changes + +* (keeper) [15347](https://github.com/cosmos/cosmos-sdk/pull/15347) Remove global bech32 usage in keeper. +* (keeper) [15347](https://github.com/cosmos/cosmos-sdk/pull/15347) `ValidateBasic` is treated as a no op now with with acceptance of RFC001 From d09177adeb30edb7931851a6578afce1f1178821 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 22 Mar 2023 15:58:59 +0100 Subject: [PATCH 15/24] fix build --- x/feegrant/keeper/genesis_test.go | 3 +-- x/feegrant/keeper/keeper_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 51362a200cce..d5484acbc133 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -12,7 +12,6 @@ import ( "cosmossdk.io/x/feegrant/module" feegranttestutil "cosmossdk.io/x/feegrant/testutil" - codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" @@ -37,7 +36,7 @@ func (suite *GenesisTestSuite) SetupTest() { accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper, codecaddress.NewBech32Codec("cosmos")) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper) suite.ctx = testCtx.Ctx } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 484c6c8fdb02..640913327569 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -49,7 +49,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper, codecaddress.NewBech32Codec("cosmos")) + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper) suite.ctx = testCtx.Ctx suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper) suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(555))) From 536d268ebe2e4223c95e1771de4a903603e5c832 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 22 Mar 2023 16:44:30 +0100 Subject: [PATCH 16/24] mock expect --- x/feegrant/keeper/keeper_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 640913327569..efe3bfa31658 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -49,6 +49,16 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[0]).Address).Return(suite.addrs[0], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[1]).Address).Return(suite.addrs[1], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[2]).Address).Return(suite.addrs[2], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[3]).Address).Return(suite.addrs[3], nil).AnyTimes() + + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[0]).Address, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[1]).Address, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2]).Address, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3]).Address, nil).AnyTimes() + suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper) suite.ctx = testCtx.Ctx suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper) From aece29f28016bb40d52a3b02be5652144cc1913a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 22 Mar 2023 17:57:02 +0100 Subject: [PATCH 17/24] stuck --- x/feegrant/keeper/keeper_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index efe3bfa31658..7dddb3e33c3a 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -49,15 +49,15 @@ func (suite *KeeperTestSuite) SetupTest() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes() suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes() - suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[0]).Address).Return(suite.addrs[0], nil).AnyTimes() - suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[1]).Address).Return(suite.addrs[1], nil).AnyTimes() - suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[2]).Address).Return(suite.addrs[2], nil).AnyTimes() - suite.accountKeeper.EXPECT().StringToBytes(authtypes.NewBaseAccountWithAddress(suite.addrs[3]).Address).Return(suite.addrs[3], nil).AnyTimes() - - suite.accountKeeper.EXPECT().BytesToString(suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[0]).Address, nil).AnyTimes() - suite.accountKeeper.EXPECT().BytesToString(suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[1]).Address, nil).AnyTimes() - suite.accountKeeper.EXPECT().BytesToString(suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2]).Address, nil).AnyTimes() - suite.accountKeeper.EXPECT().BytesToString(suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3]).Address, nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(suite.addrs[0].String()).Return(suite.addrs[0], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(suite.addrs[1].String()).Return(suite.addrs[1], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(suite.addrs[2].String()).Return(suite.addrs[2], nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(suite.addrs[3].String()).Return(suite.addrs[3], nil).AnyTimes() + + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[0]).Return(suite.addrs[0].String(), nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[1]).Return(suite.addrs[1].String(), nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[2]).Return(suite.addrs[2].String(), nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(suite.addrs[3]).Return(suite.addrs[3].String(), nil).AnyTimes() suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper) suite.ctx = testCtx.Ctx From 698ec45c2fbc5c2538b9f84353fdc3947b223893 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 24 Mar 2023 10:14:32 +0100 Subject: [PATCH 18/24] fix tests --- x/feegrant/keeper/keeper_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 7dddb3e33c3a..c9e033a446e8 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -180,6 +180,8 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { accAddr, err := codecaddress.NewBech32Codec("cosmos").StringToBytes(address) suite.Require().NoError(err) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(address).Return(accAddr, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(accAddr).Return(address, nil).AnyTimes() // let's grant and revoke authorization to non existing account err = suite.feegrantKeeper.GrantAllowance(suite.ctx, suite.addrs[3], accAddr, basic2) From dc2ebf173a06e4c50b5ebdfe3f20e17c7ba8395d Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 24 Mar 2023 11:43:51 +0100 Subject: [PATCH 19/24] some fixes --- testutil/context.go | 3 +- x/feegrant/keeper/grpc_query_test.go | 20 ++++++++++--- x/feegrant/keeper/msg_server.go | 6 +++- x/feegrant/keeper/msg_server_test.go | 44 +++++++++++++--------------- x/feegrant/module/abci_test.go | 10 +++++++ 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/testutil/context.go b/testutil/context.go index a00625933bbd..47753a773b36 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -2,6 +2,7 @@ package testutil import ( "testing" + "time" "cosmossdk.io/log" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -44,7 +45,7 @@ func DefaultContextWithDB(t *testing.T, key storetypes.StoreKey, tkey storetypes err := cms.LoadLatestVersion() assert.NoError(t, err) - ctx := sdk.NewContext(cms, cmtproto.Header{}, false, log.NewNopLogger()) + ctx := sdk.NewContext(cms, cmtproto.Header{Time: time.Now()}, false, log.NewNopLogger()) return TestContext{ctx, db, cms} } diff --git a/x/feegrant/keeper/grpc_query_test.go b/x/feegrant/keeper/grpc_query_test.go index a5915d4e9c70..358a2812fe57 100644 --- a/x/feegrant/keeper/grpc_query_test.go +++ b/x/feegrant/keeper/grpc_query_test.go @@ -1,11 +1,21 @@ package keeper_test import ( + "errors" + "cosmossdk.io/x/feegrant" sdk "github.com/cosmos/cosmos-sdk/types" ) +const ( + invalidGrantee = "invalid-grantee" + invalidGranter = "invalid-granter" +) + func (suite *KeeperTestSuite) TestFeeAllowance() { + suite.accountKeeper.EXPECT().StringToBytes(invalidGranter).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(invalidGrantee).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + testCases := []struct { name string req *feegrant.QueryAllowanceRequest @@ -23,7 +33,7 @@ func (suite *KeeperTestSuite) TestFeeAllowance() { { "fail: invalid granter", &feegrant.QueryAllowanceRequest{ - Granter: "invalid_granter", + Granter: invalidGranter, Grantee: suite.addrs[0].String(), }, true, @@ -34,7 +44,7 @@ func (suite *KeeperTestSuite) TestFeeAllowance() { "fail: invalid grantee", &feegrant.QueryAllowanceRequest{ Granter: suite.addrs[0].String(), - Grantee: "invalid_grantee", + Grantee: invalidGrantee, }, true, func() {}, @@ -82,6 +92,7 @@ func (suite *KeeperTestSuite) TestFeeAllowance() { } func (suite *KeeperTestSuite) TestFeeAllowances() { + suite.accountKeeper.EXPECT().StringToBytes(invalidGrantee).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() testCases := []struct { name string req *feegrant.QueryAllowancesRequest @@ -99,7 +110,7 @@ func (suite *KeeperTestSuite) TestFeeAllowances() { { "fail: invalid grantee", &feegrant.QueryAllowancesRequest{ - Grantee: "invalid_grantee", + Grantee: invalidGrantee, }, true, func() {}, @@ -148,6 +159,7 @@ func (suite *KeeperTestSuite) TestFeeAllowances() { } func (suite *KeeperTestSuite) TestFeeAllowancesByGranter() { + suite.accountKeeper.EXPECT().StringToBytes(invalidGrantee).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() testCases := []struct { name string req *feegrant.QueryAllowancesByGranterRequest @@ -165,7 +177,7 @@ func (suite *KeeperTestSuite) TestFeeAllowancesByGranter() { { "fail: invalid grantee", &feegrant.QueryAllowancesByGranterRequest{ - Granter: "invalid_grantee", + Granter: invalidGrantee, }, true, func() {}, diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index d45a5098c656..b8c9bc7a0e34 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -3,10 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/feegrant" ) @@ -42,6 +42,10 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot self-grant fee authorization") } + if f, _ := k.GetAllowance(ctx, granter, grantee); f != nil { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fee allowance already exists") + } + allowance, err := msg.GetFeeAllowanceI() if err != nil { return nil, err diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index 7ae318aa34e7..6b394a627c57 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "errors" "time" "cosmossdk.io/x/feegrant" @@ -29,8 +30,11 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { func() *feegrant.MsgGrantAllowance { any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{}) suite.Require().NoError(err) + invalid := "invalid-granter" + suite.accountKeeper.EXPECT().StringToBytes(invalid).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + return &feegrant.MsgGrantAllowance{ - Granter: "invalid-granter", + Granter: invalid, Grantee: suite.addrs[1].String(), Allowance: any, } @@ -43,9 +47,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { func() *feegrant.MsgGrantAllowance { any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{}) suite.Require().NoError(err) + invalid := "invalid-grantee" + suite.accountKeeper.EXPECT().StringToBytes(invalid).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + return &feegrant.MsgGrantAllowance{ Granter: suite.addrs[0].String(), - Grantee: "invalid-grantee", + Grantee: invalid, Allowance: any, } }, @@ -64,6 +71,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { }) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAccAddr).Return(nil).AnyTimes() + suite.accountKeeper.EXPECT().StringToBytes(grantee).Return(granteeAccAddr, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(granteeAccAddr).Return(grantee, nil).AnyTimes() acc := authtypes.NewBaseAccountWithAddress(granteeAccAddr) add, err := addressCodec.StringToBytes(grantee) @@ -71,6 +80,8 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), add).Return(acc).AnyTimes() suite.accountKeeper.EXPECT().SetAccount(gomock.Any(), acc).Return() + suite.accountKeeper.EXPECT().StringToBytes(grantee).Return(granteeAccAddr, nil).AnyTimes() + suite.accountKeeper.EXPECT().BytesToString(granteeAccAddr).Return(grantee, nil).AnyTimes() suite.Require().NoError(err) return &feegrant.MsgGrantAllowance{ @@ -152,25 +163,6 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { false, "", }, - { - "error: fee allowance exists", - func() *feegrant.MsgGrantAllowance { - any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ - Basic: feegrant.BasicAllowance{ - SpendLimit: suite.atom, - Expiration: &oneYear, - }, - }) - suite.Require().NoError(err) - return &feegrant.MsgGrantAllowance{ - Granter: suite.addrs[1].String(), - Grantee: suite.addrs[2].String(), - Allowance: any, - } - }, - true, - "fee allowance already exists", - }, } for _, tc := range testCases { suite.Run(tc.name, func() { @@ -186,6 +178,12 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { func (suite *KeeperTestSuite) TestRevokeAllowance() { oneYear := suite.ctx.BlockTime().AddDate(1, 0, 0) + invalidGranter := "invalid-granter" + suite.accountKeeper.EXPECT().StringToBytes(invalidGranter).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + + invalidGrantee := "invalid-grantee" + suite.accountKeeper.EXPECT().StringToBytes(invalidGrantee).Return(nil, errors.New("decoding bech32 failed")).AnyTimes() + testCases := []struct { name string request *feegrant.MsgRevokeAllowance @@ -196,7 +194,7 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() { { "error: invalid granter", &feegrant.MsgRevokeAllowance{ - Granter: "invalid-granter", + Granter: invalidGranter, Grantee: suite.addrs[1].String(), }, func() {}, @@ -207,7 +205,7 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() { "error: invalid grantee", &feegrant.MsgRevokeAllowance{ Granter: suite.addrs[0].String(), - Grantee: "invalid-grantee", + Grantee: invalidGrantee, }, func() {}, true, diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 5ba572164690..b0def7d5ff16 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -40,6 +40,16 @@ func TestFeegrantPruning(t *testing.T) { accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() + accountKeeper.EXPECT().StringToBytes(grantee.String()).Return(grantee.Bytes(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(granter1.String()).Return(granter1.Bytes(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(granter2.String()).Return(granter2.Bytes(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(granter3.String()).Return(granter3.Bytes(), nil).AnyTimes() + + accountKeeper.EXPECT().BytesToString(grantee.Bytes()).Return(grantee.String(), nil).AnyTimes() + accountKeeper.EXPECT().BytesToString(granter1.Bytes()).Return(granter1.String(), nil).AnyTimes() + accountKeeper.EXPECT().BytesToString(granter2.Bytes()).Return(granter2.String(), nil).AnyTimes() + accountKeeper.EXPECT().BytesToString(granter3.Bytes()).Return(granter3.String(), nil).AnyTimes() + feegrantKeeper := keeper.NewKeeper(encCfg.Codec, key, accountKeeper) feegrantKeeper.GrantAllowance( From f41cb666c34459fa1ab1d24da8b8ce3598f75910 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 24 Mar 2023 12:05:59 +0100 Subject: [PATCH 20/24] move higher --- x/feegrant/keeper/msg_server.go | 16 ++++++++-------- x/feegrant/keeper/msg_server_test.go | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/x/feegrant/keeper/msg_server.go b/x/feegrant/keeper/msg_server.go index b8c9bc7a0e34..e6d735602e11 100644 --- a/x/feegrant/keeper/msg_server.go +++ b/x/feegrant/keeper/msg_server.go @@ -26,6 +26,10 @@ var _ feegrant.MsgServer = msgServer{} // GrantAllowance grants an allowance from the granter's funds to be used by the grantee. func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantAllowance) (*feegrant.MsgGrantAllowanceResponse, error) { + if msg.Grantee == msg.Granter { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot self-grant fee authorization") + } + ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := k.authKeeper.StringToBytes(msg.Grantee) @@ -38,10 +42,6 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA return nil, err } - if msg.Grantee == msg.Granter { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "cannot self-grant fee authorization") - } - if f, _ := k.GetAllowance(ctx, granter, grantee); f != nil { return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fee allowance already exists") } @@ -65,6 +65,10 @@ func (k msgServer) GrantAllowance(goCtx context.Context, msg *feegrant.MsgGrantA // RevokeAllowance revokes a fee allowance between a granter and grantee. func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevokeAllowance) (*feegrant.MsgRevokeAllowanceResponse, error) { + if msg.Grantee == msg.Granter { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "addresses must be different") + } + ctx := sdk.UnwrapSDKContext(goCtx) grantee, err := k.authKeeper.StringToBytes(msg.Grantee) @@ -82,9 +86,5 @@ func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevok return nil, err } - if msg.Grantee == msg.Granter { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "addresses must be different") - } - return &feegrant.MsgRevokeAllowanceResponse{}, nil } diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index 6b394a627c57..55b93a5e62d5 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -8,6 +8,7 @@ import ( codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/golang/mock/gomock" ) @@ -233,9 +234,11 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() { Granter: suite.addrs[0].String(), Grantee: suite.addrs[1].String(), }) + + atom := sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(6000000))) any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ Basic: feegrant.BasicAllowance{ - SpendLimit: suite.atom, + SpendLimit: atom, Expiration: &oneYear, }, }) From 028444b58f68b6882c2f07ad0188eb2774033048 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 24 Mar 2023 14:31:34 +0100 Subject: [PATCH 21/24] fix genesis test --- x/feegrant/keeper/genesis_test.go | 101 ++++++++++++++++++------------ 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index d5484acbc133..374c859632f0 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -1,10 +1,11 @@ package keeper_test import ( + "errors" "testing" "github.com/golang/mock/gomock" - "github.com/stretchr/testify/suite" + "gotest.tools/v3/assert" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/feegrant" @@ -21,66 +22,76 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -type GenesisTestSuite struct { - suite.Suite +var ( + granteePub = secp256k1.GenPrivKey().PubKey() + granterPub = secp256k1.GenPrivKey().PubKey() + granteeAddr = sdk.AccAddress(granteePub.Address()) + granterAddr = sdk.AccAddress(granterPub.Address()) +) + +type genesisFixture struct { ctx sdk.Context feegrantKeeper keeper.Keeper + accountKeeper *feegranttestutil.MockAccountKeeper } -func (suite *GenesisTestSuite) SetupTest() { +func initFixture(t *testing.T) *genesisFixture { key := storetypes.NewKVStoreKey(feegrant.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) - ctrl := gomock.NewController(suite.T()) + ctrl := gomock.NewController(t) accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() - - suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, accountKeeper) - suite.ctx = testCtx.Ctx + return &genesisFixture{ + ctx: testCtx.Ctx, + feegrantKeeper: keeper.NewKeeper(encCfg.Codec, key, accountKeeper), + accountKeeper: accountKeeper, + } } -var ( - granteePub = secp256k1.GenPrivKey().PubKey() - granterPub = secp256k1.GenPrivKey().PubKey() - granteeAddr = sdk.AccAddress(granteePub.Address()) - granterAddr = sdk.AccAddress(granterPub.Address()) -) +func TestImportExportGenesis(t *testing.T) { + f := initFixture(t) + + f.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() + f.accountKeeper.EXPECT().StringToBytes(granteeAddr.String()).Return(granteeAddr, nil).AnyTimes() + f.accountKeeper.EXPECT().StringToBytes(granterAddr.String()).Return(granterAddr, nil).AnyTimes() -func (suite *GenesisTestSuite) TestImportExportGenesis() { coins := sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1_000))) - now := suite.ctx.BlockHeader().Time + now := f.ctx.BlockHeader().Time oneYear := now.AddDate(1, 0, 0) - msgSrvr := keeper.NewMsgServerImpl(suite.feegrantKeeper) + msgSrvr := keeper.NewMsgServerImpl(f.feegrantKeeper) allowance := &feegrant.BasicAllowance{SpendLimit: coins, Expiration: &oneYear} - err := suite.feegrantKeeper.GrantAllowance(suite.ctx, granterAddr, granteeAddr, allowance) - suite.Require().NoError(err) + err := f.feegrantKeeper.GrantAllowance(f.ctx, granterAddr, granteeAddr, allowance) + assert.NilError(t, err) + + genesis, err := f.feegrantKeeper.ExportGenesis(f.ctx) + assert.NilError(t, err) - genesis, err := suite.feegrantKeeper.ExportGenesis(suite.ctx) - suite.Require().NoError(err) // revoke fee allowance - _, err = msgSrvr.RevokeAllowance(suite.ctx, &feegrant.MsgRevokeAllowance{ + _, err = msgSrvr.RevokeAllowance(f.ctx, &feegrant.MsgRevokeAllowance{ Granter: granterAddr.String(), Grantee: granteeAddr.String(), }) - suite.Require().NoError(err) - err = suite.feegrantKeeper.InitGenesis(suite.ctx, genesis) - suite.Require().NoError(err) + assert.NilError(t, err) + + err = f.feegrantKeeper.InitGenesis(f.ctx, genesis) + assert.NilError(t, err) - newGenesis, err := suite.feegrantKeeper.ExportGenesis(suite.ctx) - suite.Require().NoError(err) - suite.Require().Equal(genesis, newGenesis) + newGenesis, err := f.feegrantKeeper.ExportGenesis(f.ctx) + assert.NilError(t, err) + assert.DeepEqual(t, genesis, newGenesis) } -func (suite *GenesisTestSuite) TestInitGenesis() { +func TestInitGenesis(t *testing.T) { any, err := codectypes.NewAnyWithValue(&testdata.Dog{}) - suite.Require().NoError(err) + assert.NilError(t, err) testCases := []struct { name string feeAllowances []feegrant.Grant + invalidAddr bool }{ { "invalid granter", @@ -90,6 +101,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() { Grantee: granteeAddr.String(), }, }, + true, }, { "invalid grantee", @@ -99,6 +111,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() { Grantee: "invalid grantee", }, }, + true, }, { "invalid allowance", @@ -109,18 +122,28 @@ func (suite *GenesisTestSuite) TestInitGenesis() { Allowance: any, }, }, + false, }, } for _, tc := range testCases { tc := tc - suite.Run(tc.name, func() { - err := suite.feegrantKeeper.InitGenesis(suite.ctx, &feegrant.GenesisState{Allowances: tc.feeAllowances}) - suite.Require().Error(err) + t.Run(tc.name, func(t *testing.T) { + f := initFixture(t) + if !tc.invalidAddr { + f.accountKeeper.EXPECT().StringToBytes(tc.feeAllowances[0].Grantee).Return(granteeAddr, nil).AnyTimes() + f.accountKeeper.EXPECT().StringToBytes(tc.feeAllowances[0].Granter).Return(granterAddr, nil).AnyTimes() + + err := f.feegrantKeeper.InitGenesis(f.ctx, &feegrant.GenesisState{Allowances: tc.feeAllowances}) + assert.ErrorContains(t, err, "failed to get allowance: no allowance") + } else { + expectedErr := errors.New("errors") + f.accountKeeper.EXPECT().StringToBytes(tc.feeAllowances[0].Grantee).Return(nil, expectedErr).AnyTimes() + f.accountKeeper.EXPECT().StringToBytes(tc.feeAllowances[0].Granter).Return(nil, expectedErr).AnyTimes() + + err := f.feegrantKeeper.InitGenesis(f.ctx, &feegrant.GenesisState{Allowances: tc.feeAllowances}) + assert.ErrorContains(t, err, expectedErr.Error()) + } }) } } - -func TestGenesisTestSuite(t *testing.T) { - suite.Run(t, new(GenesisTestSuite)) -} From 4f7a1716458d6614ab5ce76a32d92fdf2456fd23 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 24 Mar 2023 18:04:58 +0100 Subject: [PATCH 22/24] fix all tests --- x/feegrant/CHANGELOG.md | 8 ++++---- x/feegrant/client/cli/tx_test.go | 4 +--- x/feegrant/keeper/msg_server_test.go | 27 ++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/x/feegrant/CHANGELOG.md b/x/feegrant/CHANGELOG.md index 6d0461d712cd..8202db4de60e 100644 --- a/x/feegrant/CHANGELOG.md +++ b/x/feegrant/CHANGELOG.md @@ -27,9 +27,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* (x/feegrant) [14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module. +* [#14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module. -### Api Breaking Changes +### API Breaking Changes -* (keeper) [15347](https://github.com/cosmos/cosmos-sdk/pull/15347) Remove global bech32 usage in keeper. -* (keeper) [15347](https://github.com/cosmos/cosmos-sdk/pull/15347) `ValidateBasic` is treated as a no op now with with acceptance of RFC001 +* [#15347](https://github.com/cosmos/cosmos-sdk/pull/15347) Remove global bech32 usage in keeper. +* [#15347](https://github.com/cosmos/cosmos-sdk/pull/15347) `ValidateBasic` is treated as a no op now with with acceptance of RFC001 diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index 40866b47cc8b..c62febd7a3a7 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -18,12 +18,12 @@ import ( "cosmossdk.io/x/feegrant/module" "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/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - codecaddress "github.com/cosmos/cosmos-sdk/codec/address" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -520,8 +520,6 @@ func (s *CLITestSuite) TestNewCmdRevokeFeegrant() { } func (s *CLITestSuite) TestTxWithFeeGrant() { - // s.T().Skip() // TODO to re-enable in #12274 - clientCtx := s.clientCtx granter := s.addedGranter diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index 55b93a5e62d5..dac0bbdefddb 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -8,7 +8,6 @@ import ( codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/golang/mock/gomock" ) @@ -70,6 +69,7 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { SpendLimit: suite.atom, Expiration: &oneYear, }) + suite.Require().NoError(err) suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAccAddr).Return(nil).AnyTimes() suite.accountKeeper.EXPECT().StringToBytes(grantee).Return(granteeAccAddr, nil).AnyTimes() @@ -153,6 +153,7 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { SpendLimit: suite.atom, Expiration: &oneYear, }, + PeriodSpendLimit: suite.atom, }) suite.Require().NoError(err) return &feegrant.MsgGrantAllowance{ @@ -164,6 +165,26 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { false, "", }, + { + "error: fee allowance exists", + func() *feegrant.MsgGrantAllowance { + any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ + Basic: feegrant.BasicAllowance{ + SpendLimit: suite.atom, + Expiration: &oneYear, + }, + PeriodSpendLimit: suite.atom, + }) + suite.Require().NoError(err) + return &feegrant.MsgGrantAllowance{ + Granter: suite.addrs[1].String(), + Grantee: suite.addrs[2].String(), + Allowance: any, + } + }, + true, + "fee allowance already exists", + }, } for _, tc := range testCases { suite.Run(tc.name, func() { @@ -235,12 +256,12 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() { Grantee: suite.addrs[1].String(), }) - atom := sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(6000000))) any, err := codectypes.NewAnyWithValue(&feegrant.PeriodicAllowance{ Basic: feegrant.BasicAllowance{ - SpendLimit: atom, + SpendLimit: suite.atom, Expiration: &oneYear, }, + PeriodSpendLimit: suite.atom, }) suite.Require().NoError(err) req := &feegrant.MsgGrantAllowance{ From 0176e313261d3612781a93d1d4015eed0bfe77cf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 24 Mar 2023 18:10:29 +0100 Subject: [PATCH 23/24] go mod tidy --- x/feegrant/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 7909e7a1cb70..b3e24b0a2e8d 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -22,6 +22,7 @@ require ( google.golang.org/genproto v0.0.0-20230320184635-7606e756e683 google.golang.org/grpc v1.54.0 google.golang.org/protobuf v1.30.0 + gotest.tools/v3 v3.4.0 ) require ( @@ -148,7 +149,6 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gotest.tools/v3 v3.4.0 // indirect nhooyr.io/websocket v1.8.6 // indirect pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect From 764bd17211a5a4c9a99d57d4c2e829831291e287 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 24 Mar 2023 18:25:15 +0100 Subject: [PATCH 24/24] remove replace --- simapp/go.mod | 2 +- tests/go.mod | 2 +- x/feegrant/go.mod | 4 +--- x/feegrant/go.sum | 2 ++ 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/simapp/go.mod b/simapp/go.mod index 52fcb02851a8..4236763ed2a9 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -19,7 +19,7 @@ require ( github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 // this version is not used as it is always replaced by the latest Cosmos SDK version - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230321173237-fe77d4bca302 + github.com/cosmos/cosmos-sdk v0.48.0 github.com/cosmos/gogoproto v1.4.6 github.com/golang/mock v1.6.0 github.com/spf13/cast v1.5.0 diff --git a/tests/go.mod b/tests/go.mod index 56012a416450..f1e354256a81 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -19,7 +19,7 @@ require ( github.com/cosmos/cosmos-db v1.0.0-rc.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 // this version is not used as it is always replaced by the latest Cosmos SDK version - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230321173237-fe77d4bca302 + github.com/cosmos/cosmos-sdk v0.48.0 github.com/cosmos/gogoproto v1.4.6 github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index b3e24b0a2e8d..6cf8f6b20be6 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -12,7 +12,7 @@ require ( cosmossdk.io/store v0.1.0-alpha.1 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230321173237-fe77d4bca302 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230324171029-0176e313261d github.com/cosmos/gogoproto v1.4.6 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 @@ -153,5 +153,3 @@ require ( pgregory.net/rapid v0.5.5 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) - -replace github.com/cosmos/cosmos-sdk => ../../. diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index 004094e4daa6..67eed43ad41d 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -186,6 +186,8 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9 github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230324171029-0176e313261d h1:FmHvrGoLwiF/4UviweBbWtpEXcNo6IOjnZMgNHcP4mU= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230324171029-0176e313261d/go.mod h1:X5eCGsQaPQWvFwRzAbneZZaLjnZcral+yoLqAN2QTRI= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=