Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(feegrant): remove bech32 global #15347

Merged
merged 34 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
539b6fe
feegrant bech32 removal
tac0turtle Mar 10, 2023
683e1f2
remove some global bech32 items in feegrant
tac0turtle Mar 10, 2023
e72f015
few more changes
tac0turtle Mar 10, 2023
d31093a
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 14, 2023
fb97ad9
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 17, 2023
1144aef
remove global codec
tac0turtle Mar 17, 2023
90e0cac
remove usage of accaddressfrombech32
tac0turtle Mar 17, 2023
2d56e2a
remove failing tests
tac0turtle Mar 17, 2023
cde3607
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 17, 2023
f16b0fd
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 20, 2023
4285a67
address feedback
tac0turtle Mar 20, 2023
979697e
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 20, 2023
523c839
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 21, 2023
11f2150
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 21, 2023
232c6f4
move to address/codec
tac0turtle Mar 21, 2023
ca828f5
depend on core
tac0turtle Mar 21, 2023
5063def
remove types codec
tac0turtle Mar 21, 2023
96b3845
fix imports
tac0turtle Mar 21, 2023
c9fdbdb
fix imports
tac0turtle Mar 21, 2023
8cea31f
move bech32 back to auth and wrap methods
tac0turtle Mar 21, 2023
600915c
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 22, 2023
6a0784e
changelog
tac0turtle Mar 22, 2023
d09177a
fix build
tac0turtle Mar 22, 2023
536d268
mock expect
tac0turtle Mar 22, 2023
aece29f
stuck
tac0turtle Mar 22, 2023
c50474d
Merge branch 'main' into marko/bech32_global_feegrant
tac0turtle Mar 24, 2023
698ec45
fix tests
tac0turtle Mar 24, 2023
dc2ebf1
some fixes
tac0turtle Mar 24, 2023
f41cb66
move higher
tac0turtle Mar 24, 2023
028444b
fix genesis test
julienrbrt Mar 24, 2023
4f7a171
fix all tests
julienrbrt Mar 24, 2023
6d297e1
Merge branch 'main' into marko/bech32_global_feegrant
julienrbrt Mar 24, 2023
0176e31
go mod tidy
julienrbrt Mar 24, 2023
764bd17
remove replace
julienrbrt Mar 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper, app.AccountKeeper.GetAddressCodec())
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -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),
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)),
Expand Down
27 changes: 14 additions & 13 deletions tests/e2e/feegrant/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
Expand All @@ -694,7 +695,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 {
Expand Down Expand Up @@ -743,7 +744,7 @@ func (s *E2ETestSuite) TestTxWithFeeGrant() {
commonFlags...,
)

cmd := cli.NewCmdFeeGrant()
cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec())

_, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
s.Require().NoError(err)
Expand Down Expand Up @@ -878,7 +879,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 {
Expand All @@ -900,7 +901,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)

Expand Down Expand Up @@ -963,7 +964,7 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() {
},
commonFlags...,
)
cmd := cli.NewCmdFeeGrant()
cmd := cli.NewCmdFeeGrant(testutil.NewBech32Codec())
return clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
},
&sdk.TxResponse{},
Expand Down
48 changes: 48 additions & 0 deletions testutil/bech32_codec.go
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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 {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
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
}
34 changes: 16 additions & 18 deletions x/feegrant/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
Expand All @@ -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 {
Expand All @@ -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),
Expand All @@ -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
}
Expand All @@ -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,
},
)
Expand All @@ -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),
Expand All @@ -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
}
Expand All @@ -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,
},
)
Expand Down
7 changes: 4 additions & 3 deletions x/feegrant/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrant() {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrant()
cmd := cli.GetCmdQueryFeeGrant(testutil.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)

if tc.expectErr {
Expand Down Expand Up @@ -94,7 +95,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGrantee() {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrantsByGrantee()
cmd := cli.GetCmdQueryFeeGrantsByGrantee(testutil.NewBech32Codec("cosmos"))

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

Expand Down Expand Up @@ -141,7 +142,7 @@ func (s *CLITestSuite) TestCmdGetFeeGrantsByGranter() {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrantsByGranter()
cmd := cli.GetCmdQueryFeeGrantsByGranter(testutil.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.expectErr {
Expand Down
15 changes: 8 additions & 7 deletions x/feegrant/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -69,7 +70,7 @@ Examples:
return err
}

grantee, err := sdk.AccAddressFromBech32(args[1])
grantee, err := ac.StringToBytes(args[1])
if err != nil {
return err
}
Expand Down Expand Up @@ -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",
Expand All @@ -200,7 +201,7 @@ Example:
return err
}

grantee, err := sdk.AccAddressFromBech32(args[1])
grantee, err := ac.StringToBytes(args[1])
if err != nil {
return err
}
Expand Down
Loading