Skip to content

Commit

Permalink
Move x/feegrant/types to x/feegrant (#9273)
Browse files Browse the repository at this point in the history
* Move x/feegrant/types to x/feegrant

* Update spec

* Use feegrantmodule
  • Loading branch information
blushi committed May 7, 2021
1 parent 59810f3 commit 3582cce
Show file tree
Hide file tree
Showing 53 changed files with 533 additions and 541 deletions.
2 changes: 1 addition & 1 deletion proto/cosmos/feegrant/v1beta1/feegrant.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types";
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant";

// BasicAllowance implements Allowance with a one-time grant of tokens
// that optionally expires. The grantee can use up to SpendLimit to cover fees.
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/feegrant/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package cosmos.feegrant.v1beta1;
import "gogoproto/gogo.proto";
import "cosmos/feegrant/v1beta1/feegrant.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types";
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant";

// GenesisState contains a set of fee allowances, persisted from the store
message GenesisState {
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/feegrant/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "cosmos/feegrant/v1beta1/feegrant.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types";
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant";

// Query defines the gRPC querier service.
service Query {
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/feegrant/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types";
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant";

// Msg defines the feegrant msg service.
service Msg {
Expand Down
16 changes: 8 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
feegrant "github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
feegranttypes "github.com/cosmos/cosmos-sdk/x/feegrant/types"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
Expand Down Expand Up @@ -112,7 +112,7 @@ var (
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrant.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
authz_m.AppModuleBasic{},
Expand Down Expand Up @@ -205,7 +205,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegranttypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey,
)
Expand Down Expand Up @@ -255,7 +255,7 @@ func NewSimApp(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegranttypes.StoreKey], app.AccountKeeper)
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

// register the staking hooks
Expand Down Expand Up @@ -308,7 +308,7 @@ func NewSimApp(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
feegrant.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down Expand Up @@ -339,7 +339,7 @@ func NewSimApp(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegranttypes.ModuleName,
feegrant.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand All @@ -358,7 +358,7 @@ func NewSimApp(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrant.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
feegrant "github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestRunMigrations(t *testing.T) {
"params": params.AppModule{}.ConsensusVersion(),
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
"vesting": vesting.AppModule{}.ConsensusVersion(),
"feegrant": feegrant.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"params": params.AppModule{}.ConsensusVersion(),
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
"vesting": vesting.AppModule{}.ConsensusVersion(),
"feegrant": feegrant.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
Expand Down
4 changes: 2 additions & 2 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ const (
DefaultWeightParamChangeProposal int = 5

// feegrant
DefaultWeightGrantFeeAllowance int = 100
DefaultWeightRevokeFeeAllowance int = 100
DefaultWeightGrantAllowance int = 100
DefaultWeightRevokeAllowance int = 100
)
6 changes: 3 additions & 3 deletions x/auth/ante/feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
)

func (suite *AnteTestSuite) TestDeductFeesNoDelegation() {
Expand Down Expand Up @@ -54,13 +54,13 @@ func (suite *AnteTestSuite) TestDeductFeesNoDelegation() {
suite.Require().NoError(err)

// grant fee allowance from `addr2` to `addr3` (plenty to pay)
err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr3, &types.BasicAllowance{
err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr3, &feegrant.BasicAllowance{
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)),
})
suite.Require().NoError(err)

// grant low fee allowance (20atom), to check the tx requesting more than allowed.
err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr4, &types.BasicAllowance{
err = app.FeeGrantKeeper.GrantAllowance(ctx, addr2, addr4, &feegrant.BasicAllowance{
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 20)),
})
suite.Require().NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions x/feegrant/types/basic_fee.go → x/feegrant/basic_fee.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types
package feegrant

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,7 +16,7 @@ var _ FeeAllowanceI = (*BasicAllowance)(nil)
// and will be saved again after an acceptance.
//
// If remove is true (regardless of the error), the FeeAllowance will be deleted from storage
// (eg. when it is used up). (See call to RevokeFeeAllowance in Keeper.UseGrantedFees)
// (eg. when it is used up). (See call to RevokeAllowance in Keeper.UseGrantedFees)
func (a *BasicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bool, error) {
if a.Expiration != nil && a.Expiration.Before(ctx.BlockTime()) {
return true, sdkerrors.Wrap(ErrFeeLimitExpired, "basic allowance")
Expand Down
26 changes: 13 additions & 13 deletions x/feegrant/types/basic_fee_test.go → x/feegrant/basic_fee_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types_test
package feegrant_test

import (
"testing"
Expand All @@ -10,15 +10,15 @@ import (

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
)

func TestBasicFeeValidAllow(t *testing.T) {
app := simapp.Setup(false)

ctx := app.BaseApp.NewContext(false, tmproto.Header{})
badTime := ctx.BlockTime().AddDate(0, 0, -1)
allowace := &types.BasicAllowance{
allowace := &feegrant.BasicAllowance{
Expiration: &badTime,
}
require.Error(t, allowace.ValidateBasic())
Expand All @@ -35,7 +35,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
oneHour := now.Add(1 * time.Hour)

cases := map[string]struct {
allowance *types.BasicAllowance
allowance *feegrant.BasicAllowance
// all other checks are ignored if valid=false
fee sdk.Coins
blockTime time.Time
Expand All @@ -45,11 +45,11 @@ func TestBasicFeeValidAllow(t *testing.T) {
remains sdk.Coins
}{
"empty": {
allowance: &types.BasicAllowance{},
allowance: &feegrant.BasicAllowance{},
accept: true,
},
"small fee without expire": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: atom,
},
fee: smallAtom,
Expand All @@ -58,22 +58,22 @@ func TestBasicFeeValidAllow(t *testing.T) {
remains: leftAtom,
},
"all fee without expire": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: smallAtom,
},
fee: smallAtom,
accept: true,
remove: true,
},
"wrong fee": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: smallAtom,
},
fee: eth,
accept: false,
},
"non-expired": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: atom,
Expiration: &oneHour,
},
Expand All @@ -85,7 +85,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
remains: leftAtom,
},
"expired": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: atom,
Expiration: &now,
},
Expand All @@ -96,7 +96,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
remove: true,
},
"fee more than allowed": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
SpendLimit: atom,
Expiration: &oneHour,
},
Expand All @@ -106,7 +106,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
accept: false,
},
"with out spend limit": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
Expiration: &oneHour,
},
valid: true,
Expand All @@ -115,7 +115,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
accept: true,
},
"expired no spend limit": {
allowance: &types.BasicAllowance{
allowance: &feegrant.BasicAllowance{
Expiration: &now,
},
valid: true,
Expand Down
12 changes: 6 additions & 6 deletions x/feegrant/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/feegrant/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd() *cobra.Command {
feegrantQueryCmd := &cobra.Command{
Use: types.ModuleName,
Use: feegrant.ModuleName,
Short: "Querying commands for the feegrant module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
Expand Down Expand Up @@ -47,7 +47,7 @@ $ %s query feegrant grant [granter] [grantee]
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
queryClient := feegrant.NewQueryClient(clientCtx)

granterAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
Expand All @@ -61,7 +61,7 @@ $ %s query feegrant grant [granter] [grantee]

res, err := queryClient.Allowance(
cmd.Context(),
&types.QueryAllowanceRequest{
&feegrant.QueryAllowanceRequest{
Granter: granterAddr.String(),
Grantee: granteeAddr.String(),
},
Expand Down Expand Up @@ -95,7 +95,7 @@ $ %s query feegrant grants [grantee]
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
queryClient := feegrant.NewQueryClient(clientCtx)

granteeAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
Expand All @@ -109,7 +109,7 @@ $ %s query feegrant grants [grantee]

res, err := queryClient.Allowances(
cmd.Context(),
&types.QueryAllowancesRequest{
&feegrant.QueryAllowancesRequest{
Grantee: granteeAddr.String(),
Pagination: pageReq,
},
Expand Down
Loading

0 comments on commit 3582cce

Please sign in to comment.