Skip to content

Commit

Permalink
feat: add transfer to app config and wire up, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Apr 29, 2024
1 parent a8403f7 commit e7c2eae
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 40 deletions.
24 changes: 17 additions & 7 deletions modules/apps/transfer/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ type ModuleInputs struct {
Cdc codec.Codec
Key *storetypes.KVStoreKey

Ics4Wrapper porttypes.ICS4Wrapper
ChannelKeeper types.ChannelKeeper
Ics4Wrapper porttypes.ICS4Wrapper
PortKeeper types.PortKeeper

AuthKeeper types.AccountKeeper
BankKeeper types.BankKeeper
ScopedKeeper capabilitykeeper.ScopedKeeper
AuthKeeper types.AccountKeeper
BankKeeper types.BankKeeper
CapabilityKeeper *capabilitykeeper.Keeper

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace paramtypes.Subspace `optional:"true"`
Expand All @@ -53,8 +53,10 @@ type ModuleInputs struct {
type ModuleOutputs struct {
depinject.Out

TransferKeeper *keeper.Keeper
ScopedKeeper types.ScopedTransferKeeper
TransferKeeper keeper.Keeper
Module appmodule.AppModule
IBCModuleRoute porttypes.IBCModuleRoute
}

// ProvideModule returns the transfer module outputs for dependency injection
Expand All @@ -65,6 +67,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

scopedKeeper := in.CapabilityKeeper.ScopeToModule(types.ModuleName)
transferKeeper := keeper.NewKeeper(
in.Cdc,
in.Key,
Expand All @@ -74,10 +77,17 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.PortKeeper,
in.AuthKeeper,
in.BankKeeper,
in.ScopedKeeper,
scopedKeeper,
authority.String(),
)

m := NewAppModule(transferKeeper)
ibcModule := NewIBCModule(transferKeeper)

return ModuleOutputs{TransferKeeper: &transferKeeper, Module: m}
return ModuleOutputs{
ScopedKeeper: types.ScopedTransferKeeper{ScopedKeeper: scopedKeeper},
TransferKeeper: transferKeeper,
Module: m,
IBCModuleRoute: porttypes.IBCModuleRoute{Name: types.ModuleName, IBCModule: ibcModule},
}
}
6 changes: 4 additions & 2 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand Down Expand Up @@ -62,7 +64,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AccountKeeper,
suite.chainA.GetSimApp().BankKeeper,
suite.chainA.GetSimApp().ScopedTransferKeeper,
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
}, true},
{"failure: transfer module account does not exist", func() {
Expand All @@ -76,7 +78,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
authkeeper.AccountKeeper{}, // empty account keeper
suite.chainA.GetSimApp().BankKeeper,
suite.chainA.GetSimApp().ScopedTransferKeeper,
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
}, false},
{"failure: empty authority", func() {
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down Expand Up @@ -61,3 +62,6 @@ type PortKeeper interface {
type ParamSubspace interface {
GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet)
}

// ScopedTranferKeeper embeds x/capability's ScopedKeeper used for depinject module outputs.
type ScopedTransferKeeper struct{ capabilitykeeper.ScopedKeeper }
13 changes: 12 additions & 1 deletion modules/core/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
modulev1 "github.com/cosmos/ibc-go/api/ibc/core/module/v1"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
portkeeper "github.com/cosmos/ibc-go/v8/modules/core/05-port/keeper"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -57,6 +59,9 @@ type ModuleOutputs struct {

IBCKeeper *ibckeeper.Keeper
ScopedIBCKeeper types.ScopedIBCKeeper

ChannelKeeper *channelkeeper.Keeper
PortKeeper *portkeeper.Keeper
}

// ProvideModule defines a depinject provider function to supply the module dependencies and return its outputs.
Expand All @@ -80,7 +85,13 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
)
m := NewAppModule(keeper)

return ModuleOutputs{Module: m, IBCKeeper: keeper, ScopedIBCKeeper: types.ScopedIBCKeeper(scopedKeeper)}
return ModuleOutputs{
Module: m,
IBCKeeper: keeper,
ChannelKeeper: keeper.ChannelKeeper,
PortKeeper: keeper.PortKeeper,
ScopedIBCKeeper: types.ScopedIBCKeeper{ScopedKeeper: scopedKeeper},
}
}

// InvokeAddAppRoutes defines a depinject Invoker for registering ibc application modules on the core ibc application router.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {

consensusHost = ibctm.NewConsensusHost(suite.chainA.GetSimApp().StakingKeeper)
upgradeKeeper = suite.chainA.GetSimApp().UpgradeKeeper
scopedKeeper = suite.chainA.GetSimApp().ScopedIBCKeeper
scopedKeeper = suite.chainA.GetSimApp().GetScopedIBCKeeper()

tc.malleate()

Expand Down
4 changes: 2 additions & 2 deletions modules/core/types/expected_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ type ParamSubspace interface {
GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet)
}

// ScopedIBCKeeper is a type alias of x/capability's ScopedKeeper used for depinject module outputs.
type ScopedIBCKeeper capabilitykeeper.ScopedKeeper
// ScopedIBCKeeper embeds x/capability's ScopedKeeper used for depinject module outputs.
type ScopedIBCKeeper struct{ capabilitykeeper.ScopedKeeper }
6 changes: 3 additions & 3 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
cmttypes "github.com/cometbft/cometbft/types"
cmtversion "github.com/cometbft/cometbft/version"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand All @@ -37,6 +36,7 @@ import (
"github.com/cosmos/ibc-go/v8/modules/core/types"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"github.com/cosmos/ibc-go/v8/testing/simapp"
testingtypes "github.com/cosmos/ibc-go/v8/testing/types"
)

var MaxAccounts = 10
Expand Down Expand Up @@ -560,7 +560,7 @@ func MakeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) cmttypes.B
// already exist. This function will fail testing on any resulting error.
// NOTE: only creation of a capability for a transfer or mock port is supported
// Other applications must bind to the port in InitGenesis or modify this code.
func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID string) {
func (chain *TestChain) CreatePortCapability(scopedKeeper testingtypes.ScopedKeeper, portID string) {
// check if the portId is already binded, if not bind it
_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID))
if !ok {
Expand Down Expand Up @@ -588,7 +588,7 @@ func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capabi
// CreateChannelCapability binds and claims a capability for the given portID and channelID
// if it does not already exist. This function will fail testing on any resulting error. The
// scoped keeper passed in will claim the new capability.
func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID, channelID string) {
func (chain *TestChain) CreateChannelCapability(scopedKeeper testingtypes.ScopedKeeper, portID, channelID string) {
capName := host.ChannelCapabilityPath(portID, channelID)
// check if the portId is already binded, if not bind it
_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), capName)
Expand Down
2 changes: 1 addition & 1 deletion testing/mock/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
Module: m,
IBCModule: ibcModule,
IBCModuleRoute: porttypes.IBCModuleRoute{Name: ModuleName, IBCModule: ibcModule},
ScopedKeeper: ScopedMockKeeper(scopedKeeper),
ScopedKeeper: ScopedMockKeeper{ScopedKeeper: scopedKeeper},
}
}
4 changes: 2 additions & 2 deletions testing/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type PortKeeper interface {
IsBound(ctx sdk.Context, portID string) bool
}

// ScopedMockKeeper is a type alias of x/capability's ScopedKeeper used for depinject module outputs.
type ScopedMockKeeper capabilitykeeper.ScopedKeeper
// ScopedMockKeeper embeds x/capability's ScopedKeeper used for depinject module outputs.
type ScopedMockKeeper struct{ capabilitykeeper.ScopedKeeper }

var _ exported.Acknowledgement = (*EmptyAcknowledgement)(nil)

Expand Down
46 changes: 28 additions & 18 deletions testing/simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import (

"google.golang.org/protobuf/types/known/durationpb"

_ "cosmossdk.io/x/circuit" // import for side-effects
_ "cosmossdk.io/x/evidence" // import for side-effects
_ "cosmossdk.io/x/feegrant/module" // import for side-effects
_ "cosmossdk.io/x/upgrade" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
_ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects
_ "github.com/cosmos/ibc-go/v8/modules/core" // import for side-effects
_ "cosmossdk.io/x/circuit" // import for side-effects
_ "cosmossdk.io/x/evidence" // import for side-effects
_ "cosmossdk.io/x/feegrant/module" // import for side-effects
_ "cosmossdk.io/x/upgrade" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
_ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects
_ "github.com/cosmos/ibc-go/v8/modules/apps/transfer" // import for side-effects
_ "github.com/cosmos/ibc-go/v8/modules/core" // import for side-effects

runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
Expand Down Expand Up @@ -74,11 +75,14 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

capabilitymodulev1 "github.com/cosmos/ibc-go/api/capability/module/v1"
ibctransfermodulev1 "github.com/cosmos/ibc-go/api/ibc/applications/transfer/module/v1"
ibcmodulev1 "github.com/cosmos/ibc-go/api/ibc/core/module/v1"
solomachinemodulev1 "github.com/cosmos/ibc-go/api/ibc/lightclients/solomachine/module/v1"
ibctmmodulev1 "github.com/cosmos/ibc-go/api/ibc/lightclients/tendermint/module/v1"
ibcmockmodulev1 "github.com/cosmos/ibc-go/api/mock/module/v1"

Check failure on line 83 in testing/simapp/app_config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 83 in testing/simapp/app_config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
Expand All @@ -94,6 +98,7 @@ var (
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: ibctransfertypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
}

// blocked account addresses
Expand Down Expand Up @@ -171,6 +176,7 @@ var (
circuittypes.ModuleName,
ibcexported.ModuleName,
ibcmock.ModuleName,
ibctransfertypes.ModuleName,
},
// When ExportGenesis is not specified, the export genesis module order
// is equal to the init genesis order
Expand Down Expand Up @@ -291,6 +297,10 @@ var (
Name: ibcmock.ModuleName,
Config: appconfig.WrapAny(&ibcmockmodulev1.Module{}),
},
{
Name: ibctransfertypes.ModuleName,
Config: appconfig.WrapAny(&ibctransfermodulev1.Module{}),
},
},
}),
depinject.Supply(
Expand Down
7 changes: 5 additions & 2 deletions testing/simapp/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctypes "github.com/cosmos/ibc-go/v8/modules/core/types"
ibcmock "github.com/cosmos/ibc-go/v8/testing/mock"
Expand Down Expand Up @@ -96,7 +97,7 @@ type SimApp struct {
CapabilityKeeper *capabilitykeeper.Keeper
ScopedIBCKeeper ibctypes.ScopedIBCKeeper
ScopedIBCMockKeeper ibcmock.ScopedMockKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper ibctransfertypes.ScopedTransferKeeper
ScopedFeeMockKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -220,6 +221,8 @@ func NewSimApp(
&app.ScopedIBCKeeper,
&app.IBCMockModule,
&app.ScopedIBCMockKeeper,
&app.TransferKeeper,
&app.ScopedTransferKeeper,
); err != nil {
panic(err)
}
Expand Down Expand Up @@ -446,7 +449,7 @@ func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper {

// GetScopedIBCKeeper implements the TestingApp interface.
func (app *SimApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return capabilitykeeper.ScopedKeeper(app.ScopedIBCKeeper)
return app.ScopedIBCKeeper.ScopedKeeper
}

// GetTxConfig implements the TestingApp interface.
Expand Down
3 changes: 2 additions & 1 deletion testing/testing_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package ibctesting_test
import (
"testing"

ibctesting "github.com/cosmos/ibc-go/v8/testing"
"github.com/stretchr/testify/require"

ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

// TODO: Remove this before merging.
Expand Down
8 changes: 8 additions & 0 deletions testing/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ package types
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
)

// StakingKeeper defines the expected staking keeper interface used in the
// IBC testing package
type StakingKeeper interface {
GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error)
}

type ScopedKeeper interface {
ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error
GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool)
}

0 comments on commit e7c2eae

Please sign in to comment.