From 90cac0c5bf5359692bbe5683509f15207c5eb5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:17:54 +0200 Subject: [PATCH 1/4] scaffolding for 29-fee --- modules/apps/29-fee/client/cli/cli.go | 40 +++ modules/apps/29-fee/client/cli/query.go | 3 + modules/apps/29-fee/client/cli/tx.go | 3 + modules/apps/29-fee/keeper/genesis.go | 16 + modules/apps/29-fee/keeper/grpc_query.go | 5 + modules/apps/29-fee/keeper/keeper.go | 87 ++++++ modules/apps/29-fee/keeper/keeper_test.go | 59 ++++ modules/apps/29-fee/keeper/msg_server.go | 4 + modules/apps/29-fee/module.go | 275 ++++++++++++++++++ modules/apps/29-fee/module_test.go | 244 ++++++++++++++++ modules/apps/29-fee/spec/01_concepts.md | 6 + modules/apps/29-fee/spec/02_state.md | 6 + .../apps/29-fee/spec/03_state_transitions.md | 6 + modules/apps/29-fee/spec/04_messages.md | 6 + modules/apps/29-fee/spec/05_events.md | 6 + modules/apps/29-fee/spec/06_metrics.md | 6 + modules/apps/29-fee/spec/07_params.md | 6 + modules/apps/29-fee/spec/README.md | 11 + modules/apps/29-fee/types/codec.go | 14 + modules/apps/29-fee/types/errors.go | 8 + modules/apps/29-fee/types/events.go | 4 + modules/apps/29-fee/types/expected_keepers.go | 50 ++++ modules/apps/29-fee/types/genesis.go | 29 ++ modules/apps/29-fee/types/genesis_test.go | 49 ++++ modules/apps/29-fee/types/keys.go | 15 + modules/apps/29-fee/types/msgs.go | 32 ++ modules/apps/29-fee/types/msgs_test.go | 36 +++ 27 files changed, 1026 insertions(+) create mode 100644 modules/apps/29-fee/client/cli/cli.go create mode 100644 modules/apps/29-fee/client/cli/query.go create mode 100644 modules/apps/29-fee/client/cli/tx.go create mode 100644 modules/apps/29-fee/keeper/genesis.go create mode 100644 modules/apps/29-fee/keeper/grpc_query.go create mode 100644 modules/apps/29-fee/keeper/keeper.go create mode 100644 modules/apps/29-fee/keeper/keeper_test.go create mode 100644 modules/apps/29-fee/keeper/msg_server.go create mode 100644 modules/apps/29-fee/module.go create mode 100644 modules/apps/29-fee/module_test.go create mode 100644 modules/apps/29-fee/spec/01_concepts.md create mode 100644 modules/apps/29-fee/spec/02_state.md create mode 100644 modules/apps/29-fee/spec/03_state_transitions.md create mode 100644 modules/apps/29-fee/spec/04_messages.md create mode 100644 modules/apps/29-fee/spec/05_events.md create mode 100644 modules/apps/29-fee/spec/06_metrics.md create mode 100644 modules/apps/29-fee/spec/07_params.md create mode 100644 modules/apps/29-fee/spec/README.md create mode 100644 modules/apps/29-fee/types/codec.go create mode 100644 modules/apps/29-fee/types/errors.go create mode 100644 modules/apps/29-fee/types/events.go create mode 100644 modules/apps/29-fee/types/expected_keepers.go create mode 100644 modules/apps/29-fee/types/genesis.go create mode 100644 modules/apps/29-fee/types/genesis_test.go create mode 100644 modules/apps/29-fee/types/keys.go create mode 100644 modules/apps/29-fee/types/msgs.go create mode 100644 modules/apps/29-fee/types/msgs_test.go diff --git a/modules/apps/29-fee/client/cli/cli.go b/modules/apps/29-fee/client/cli/cli.go new file mode 100644 index 00000000000..fb8b9db8320 --- /dev/null +++ b/modules/apps/29-fee/client/cli/cli.go @@ -0,0 +1,40 @@ +package cli + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" +) + +// GetQueryCmd returns the query commands for 29-fee +func GetQueryCmd() *cobra.Command { + queryCmd := &cobra.Command{ + Use: "ibc-fee", + Short: "", // TODO + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + } + + queryCmd.AddCommand( + // TODO + ) + + return queryCmd +} + +// NewTxCmd returns the transaction commands for 29-fee +func NewTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: "ibc-fee", + Short: "", // TODO + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + txCmd.AddCommand( + // TODO + ) + + return txCmd +} diff --git a/modules/apps/29-fee/client/cli/query.go b/modules/apps/29-fee/client/cli/query.go new file mode 100644 index 00000000000..e8878f3e042 --- /dev/null +++ b/modules/apps/29-fee/client/cli/query.go @@ -0,0 +1,3 @@ +package cli + +// TODO diff --git a/modules/apps/29-fee/client/cli/tx.go b/modules/apps/29-fee/client/cli/tx.go new file mode 100644 index 00000000000..e8878f3e042 --- /dev/null +++ b/modules/apps/29-fee/client/cli/tx.go @@ -0,0 +1,3 @@ +package cli + +// TODO diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go new file mode 100644 index 00000000000..cb500443231 --- /dev/null +++ b/modules/apps/29-fee/keeper/genesis.go @@ -0,0 +1,16 @@ +package keeper + +/* +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// InitGenesis +func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { +} + +// ExportGenesis +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + return &types.GenesisState{} +} +*/ diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go new file mode 100644 index 00000000000..185ad775c93 --- /dev/null +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -0,0 +1,5 @@ +package keeper + +// TODO + +//var _ types.QueryServer = Keeper{} diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go new file mode 100644 index 00000000000..db304dd4cf9 --- /dev/null +++ b/modules/apps/29-fee/keeper/keeper.go @@ -0,0 +1,87 @@ +package keeper + +/* +import ( + "github.com/tendermint/tendermint/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/ibc-go/modules/apps/transfer/types" + host "github.com/cosmos/ibc-go/modules/core/24-host" +) + +// Keeper defines the IBC fungible transfer keeper +type Keeper struct { + storeKey sdk.StoreKey + cdc codec.BinaryCodec + + channelKeeper types.ChannelKeeper + portKeeper types.PortKeeper + authKeeper types.AccountKeeper + bankKeeper types.BankKeeper + scopedKeeper capabilitykeeper.ScopedKeeper +} + + +// NewKeeper creates a new 29-fee Keeper instance +func NewKeeper( + cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, + channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, + authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, +) Keeper { + + return Keeper{ + cdc: cdc, + storeKey: key, + channelKeeper: channelKeeper, + portKeeper: portKeeper, + authKeeper: authKeeper, + bankKeeper: bankKeeper, + scopedKeeper: scopedKeeper, + } +} + +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName) +} + +// IsBound checks if the transfer module is already bound to the desired port +func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) + return ok +} + +// BindPort defines a wrapper function for the ort Keeper's function in +// order to expose it to module's InitGenesis function +func (k Keeper) BindPort(ctx sdk.Context, portID string) error { + cap := k.portKeeper.BindPort(ctx, portID) + return k.ClaimCapability(ctx, cap, host.PortPath(portID)) +} + +// GetPort returns the portID for the transfer module. Used in ExportGenesis +func (k Keeper) GetPort(ctx sdk.Context) string { + store := ctx.KVStore(k.storeKey) + return string(store.Get(types.PortKey)) +} + +// SetPort sets the portID for the transfer module. Used in InitGenesis +func (k Keeper) SetPort(ctx sdk.Context, portID string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.PortKey, []byte(portID)) +} + +// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function +func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool { + return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) +} + +// ClaimCapability allows the transfer module that can claim a capability that IBC module +// passes to it +func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cap, name) +} +*/ diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go new file mode 100644 index 00000000000..de3902df669 --- /dev/null +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -0,0 +1,59 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/apps/transfer/types" + ibctesting "github.com/cosmos/ibc-go/testing" +) + +type KeeperTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain + + queryClient types.QueryClient +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + + queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().TransferKeeper) + suite.queryClient = types.NewQueryClient(queryHelper) +} + +func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort + + return path +} + +func (suite *KeeperTestSuite) TestGetTransferAccount() { + expectedMaccAddr := sdk.AccAddress(crypto.AddressHash([]byte(types.ModuleName))) + + macc := suite.chainA.GetSimApp().TransferKeeper.GetTransferAccount(suite.chainA.GetContext()) + + suite.Require().NotNil(macc) + suite.Require().Equal(types.ModuleName, macc.GetName()) + suite.Require().Equal(expectedMaccAddr, macc.GetAddress()) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go new file mode 100644 index 00000000000..2194eed8a68 --- /dev/null +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -0,0 +1,4 @@ +package keeper + +// TODO +//var _ types.MsgServer = Keeper{} diff --git a/modules/apps/29-fee/module.go b/modules/apps/29-fee/module.go new file mode 100644 index 00000000000..22e47f71767 --- /dev/null +++ b/modules/apps/29-fee/module.go @@ -0,0 +1,275 @@ +package transfer + +import ( + "context" + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/ibc-go/modules/apps/transfer/client/cli" + "github.com/cosmos/ibc-go/modules/apps/transfer/keeper" + "github.com/cosmos/ibc-go/modules/apps/transfer/simulation" + "github.com/cosmos/ibc-go/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/modules/core/exported" +) + +var ( + _ module.AppModule = AppModule{} + _ porttypes.IBCModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic is the 29-fee AppModuleBasic +type AppModuleBasic struct{} + +// Name implements AppModuleBasic interface +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec implements AppModuleBasic interface +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} + +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// DefaultGenesis returns default genesis state as raw bytes for the ibc +// transfer module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the 29-fee module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var gs types.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return gs.Validate() +} + +// RegisterRESTRoutes implements AppModuleBasic interface +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +} + +// GetTxCmd implements AppModuleBasic interface +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd() +} + +// GetQueryCmd implements AppModuleBasic interface +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// AppModule represents the AppModule for this module +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +// NewAppModule creates a new 29-fee module +func NewAppModule(k keeper.Keeper) AppModule { + return AppModule{ + keeper: k, + } +} + +// RegisterInvariants implements the AppModule interface +func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { + // TODO +} + +// Route implements the AppModule interface +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute implements the AppModule interface +func (AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +// LegacyQuerierHandler implements the AppModule interface +func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// InitGenesis performs genesis initialization for the ibc-transfer module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the ibc-transfer +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock implements the AppModule interface +func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { +} + +// EndBlock implements the AppModule interface +func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the transfer module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized ibc-transfer param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return simulation.ParamChanges(r) +} + +// RegisterStoreDecoder registers a decoder for transfer module's types +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { + sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) +} + +// WeightedOperations returns the all the transfer module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} + +// OnChanOpenInit implements the IBCModule interface +func (am AppModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) error { + return nil +} + +// OnChanOpenTry implements the IBCModule interface +func (am AppModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version, + counterpartyVersion string, +) error { + return nil +} + +// OnChanOpenAck implements the IBCModule interface +func (am AppModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + counterpartyVersion string, +) error { + return nil +} + +// OnChanOpenConfirm implements the IBCModule interface +func (am AppModule) OnChanOpenConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return nil +} + +// OnChanCloseInit implements the IBCModule interface +func (am AppModule) OnChanCloseInit( + ctx sdk.Context, + portID, + channelID string, +) error { + // Disallow user-initiated channel closing for 29-fee channels + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") +} + +// OnChanCloseConfirm implements the IBCModule interface +func (am AppModule) OnChanCloseConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface. +func (am AppModule) OnRecvPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) ibcexported.Acknowledgement { + return nil +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (am AppModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + return nil +} + +// OnTimeoutPacket implements the IBCModule interface +func (am AppModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + return nil +} diff --git a/modules/apps/29-fee/module_test.go b/modules/apps/29-fee/module_test.go new file mode 100644 index 00000000000..df78524e5bd --- /dev/null +++ b/modules/apps/29-fee/module_test.go @@ -0,0 +1,244 @@ +package fee_test + +/* +import ( + "math" + + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/testing" +) + +func (suite *FeeTestSuite) TestOnChanOpenInit() { + var ( + channel *channeltypes.Channel + path *ibctesting.Path + chanCap *capabilitytypes.Capability + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + + { + "success", func() {}, true, + }, + { + "max channels reached", func() { + path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(math.MaxUint32 + 1) + }, false, + }, + { + "invalid order - ORDERED", func() { + channel.Ordering = channeltypes.ORDERED + }, false, + }, + { + "invalid port ID", func() { + path.EndpointA.ChannelConfig.PortID = ibctesting.MockPort + }, false, + }, + { + "invalid version", func() { + channel.Version = "version" + }, false, + }, + { + "capability already claimed", func() { + err := suite.chainA.GetSimApp().ScopedFeeKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + suite.Require().NoError(err) + }, false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + path = NewFeePath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + path.EndpointA.ChannelID = ibctesting.FirstChannelID + + counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + channel = &channeltypes.Channel{ + State: channeltypes.INIT, + Ordering: channeltypes.UNORDERED, + Counterparty: counterparty, + ConnectionHops: []string{path.EndpointA.ConnectionID}, + Version: types.Version, + } + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) + suite.Require().NoError(err) + + chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.FeePort, path.EndpointA.ChannelID)) + suite.Require().NoError(err) + + cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + + tc.malleate() // explicitly change fields in channel and testChannel + + err = cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), + ) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + + }) + } +} + +func (suite *FeeTestSuite) TestOnChanOpenTry() { + var ( + channel *channeltypes.Channel + chanCap *capabilitytypes.Capability + path *ibctesting.Path + counterpartyVersion string + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + + { + "success", func() {}, true, + }, + { + "max channels reached", func() { + path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(math.MaxUint32 + 1) + }, false, + }, + { + "capability already claimed in INIT should pass", func() { + err := suite.chainA.GetSimApp().ScopedFeeKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + suite.Require().NoError(err) + }, true, + }, + { + "invalid order - ORDERED", func() { + channel.Ordering = channeltypes.ORDERED + }, false, + }, + { + "invalid port ID", func() { + path.EndpointA.ChannelConfig.PortID = ibctesting.MockPort + }, false, + }, + { + "invalid version", func() { + channel.Version = "version" + }, false, + }, + { + "invalid counterparty version", func() { + counterpartyVersion = "version" + }, false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = NewFeePath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + path.EndpointA.ChannelID = ibctesting.FirstChannelID + + counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + channel = &channeltypes.Channel{ + State: channeltypes.TRYOPEN, + Ordering: channeltypes.UNORDERED, + Counterparty: counterparty, + ConnectionHops: []string{path.EndpointA.ConnectionID}, + Version: types.Version, + } + counterpartyVersion = types.Version + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) + suite.Require().NoError(err) + + chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.FeePort, path.EndpointA.ChannelID)) + suite.Require().NoError(err) + + cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + + tc.malleate() // explicitly change fields in channel and testChannel + + err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), counterpartyVersion, + ) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + + }) + } +} + +func (suite *FeeTestSuite) TestOnChanOpenAck() { + var counterpartyVersion string + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + + { + "success", func() {}, true, + }, + { + "invalid counterparty version", func() { + counterpartyVersion = "version" + }, false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path := NewFeePath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + path.EndpointA.ChannelID = ibctesting.FirstChannelID + counterpartyVersion = types.Version + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) + suite.Require().NoError(err) + + cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + + tc.malleate() // explicitly change fields in channel and testChannel + + err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyVersion) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + + }) + } +} +*/ diff --git a/modules/apps/29-fee/spec/01_concepts.md b/modules/apps/29-fee/spec/01_concepts.md new file mode 100644 index 00000000000..119c857b0cc --- /dev/null +++ b/modules/apps/29-fee/spec/01_concepts.md @@ -0,0 +1,6 @@ + + +# Concepts + diff --git a/modules/apps/29-fee/spec/02_state.md b/modules/apps/29-fee/spec/02_state.md new file mode 100644 index 00000000000..336ed0f5b65 --- /dev/null +++ b/modules/apps/29-fee/spec/02_state.md @@ -0,0 +1,6 @@ + + +# State + diff --git a/modules/apps/29-fee/spec/03_state_transitions.md b/modules/apps/29-fee/spec/03_state_transitions.md new file mode 100644 index 00000000000..dc70ea002c6 --- /dev/null +++ b/modules/apps/29-fee/spec/03_state_transitions.md @@ -0,0 +1,6 @@ + + +# State Transitions + diff --git a/modules/apps/29-fee/spec/04_messages.md b/modules/apps/29-fee/spec/04_messages.md new file mode 100644 index 00000000000..0a97f2d6b9d --- /dev/null +++ b/modules/apps/29-fee/spec/04_messages.md @@ -0,0 +1,6 @@ + + +# Messages + diff --git a/modules/apps/29-fee/spec/05_events.md b/modules/apps/29-fee/spec/05_events.md new file mode 100644 index 00000000000..eb988be063a --- /dev/null +++ b/modules/apps/29-fee/spec/05_events.md @@ -0,0 +1,6 @@ + + +# Events + diff --git a/modules/apps/29-fee/spec/06_metrics.md b/modules/apps/29-fee/spec/06_metrics.md new file mode 100644 index 00000000000..24996d36b3d --- /dev/null +++ b/modules/apps/29-fee/spec/06_metrics.md @@ -0,0 +1,6 @@ + + +# Metrics + diff --git a/modules/apps/29-fee/spec/07_params.md b/modules/apps/29-fee/spec/07_params.md new file mode 100644 index 00000000000..77d7696b559 --- /dev/null +++ b/modules/apps/29-fee/spec/07_params.md @@ -0,0 +1,6 @@ + + +# Parameters + diff --git a/modules/apps/29-fee/spec/README.md b/modules/apps/29-fee/spec/README.md new file mode 100644 index 00000000000..c5c926f7b9f --- /dev/null +++ b/modules/apps/29-fee/spec/README.md @@ -0,0 +1,11 @@ + + +# `29-fee` + +## Abstract + diff --git a/modules/apps/29-fee/types/codec.go b/modules/apps/29-fee/types/codec.go new file mode 100644 index 00000000000..c2089bdc40b --- /dev/null +++ b/modules/apps/29-fee/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterInterfaces register the 29-fee module interfaces to protobuf +// Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + // registry.RegisterImplementations((*sdk.Msg)(nil), &Msg{}) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go new file mode 100644 index 00000000000..9ed5755a9a0 --- /dev/null +++ b/modules/apps/29-fee/types/errors.go @@ -0,0 +1,8 @@ +package types + +import ( +// sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// 29-fee sentinel errors +var () diff --git a/modules/apps/29-fee/types/events.go b/modules/apps/29-fee/types/events.go new file mode 100644 index 00000000000..4b8d5ee8c95 --- /dev/null +++ b/modules/apps/29-fee/types/events.go @@ -0,0 +1,4 @@ +package types + +// 29-fee events +const () diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go new file mode 100644 index 00000000000..68513b476a5 --- /dev/null +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -0,0 +1,50 @@ +package types + +/* +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/modules/core/exported" +) + +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI +} + +// BankKeeper defines the expected bank keeper +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error +} + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error + ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error +} + +// ClientKeeper defines the expected IBC client keeper +type ClientKeeper interface { + GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool) +} + +// ConnectionKeeper defines the expected IBC connection keeper +type ConnectionKeeper interface { + GetConnection(ctx sdk.Context, connectionID string) (connection connectiontypes.ConnectionEnd, found bool) +} + +// PortKeeper defines the expected IBC port keeper +type PortKeeper interface { + BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability +} +*/ diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go new file mode 100644 index 00000000000..4086325bebb --- /dev/null +++ b/modules/apps/29-fee/types/genesis.go @@ -0,0 +1,29 @@ +package types + +/* +import ( + host "github.com/cosmos/ibc-go/modules/core/24-host" +) + +// NewGenesisState creates a 29-fee GenesisState instance. +func NewGenesisState(portID string, denomTraces Traces, params Params) *GenesisState { + return &GenesisState{ + Params: params, + } +} + +// DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + if err := host.PortIdentifierValidator(gs.PortId); err != nil { + return err + } + return nil +} +*/ diff --git a/modules/apps/29-fee/types/genesis_test.go b/modules/apps/29-fee/types/genesis_test.go new file mode 100644 index 00000000000..30516612cce --- /dev/null +++ b/modules/apps/29-fee/types/genesis_test.go @@ -0,0 +1,49 @@ +package types_test + +/* +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/ibc-go/modules/apps/transfer/types" +) + +func TestValidateGenesis(t *testing.T) { + testCases := []struct { + name string + genState *types.GenesisState + expPass bool + }{ + { + name: "default", + genState: types.DefaultGenesisState(), + expPass: true, + }, + { + "valid genesis", + &types.GenesisState{ + PortId: "portidone", + }, + true, + }, + { + "invalid client", + &types.GenesisState{ + PortId: "(INVALIDPORT)", + }, + false, + }, + } + + for _, tc := range testCases { + tc := tc + err := tc.genState.Validate() + if tc.expPass { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + } +} +*/ diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go new file mode 100644 index 00000000000..769113f504a --- /dev/null +++ b/modules/apps/29-fee/types/keys.go @@ -0,0 +1,15 @@ +package types + +const ( + // ModuleName defines the 29-fee name + ModuleName = "ibcfee" + + // StoreKey is the store key string for IBC transfer + StoreKey = ModuleName + + // RouterKey is the message route for IBC transfer + RouterKey = ModuleName + + // QuerierRoute is the querier route for IBC transfer + QuerierRoute = ModuleName +) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go new file mode 100644 index 00000000000..4df0e84ff1a --- /dev/null +++ b/modules/apps/29-fee/types/msgs.go @@ -0,0 +1,32 @@ +package types + +/* +import ( + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/modules/core/24-host" +) + +// NewMsg +func NewMsg() *Msg { + return &Msg{ + } +} + +// ValidateBasic performs a basic check of the Msg fields. +func (msg Msg) ValidateBasic() error { + return nil +} + +// GetSigners implements sdk.Msg +func (msg MsgTransfer) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} +*/ diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go new file mode 100644 index 00000000000..132bde75752 --- /dev/null +++ b/modules/apps/29-fee/types/msgs_test.go @@ -0,0 +1,36 @@ +package types + +/* +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (suite *TypesTestSuite) TestMsgValidateBasic() { + testCases := []struct { + name string + msg *types.Msg + expPass bool + }{ + {"", types.NewMsg(), true}, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + err := tc.msg.ValidateBasic() + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + }) + } +} +*/ From 878861e055ca7db586bfb2301e6938aa2698ca4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:21:48 +0200 Subject: [PATCH 2/4] fix build --- modules/apps/29-fee/module.go | 4 +++- modules/apps/29-fee/types/codec.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/module.go b/modules/apps/29-fee/module.go index 22e47f71767..c0645e3db78 100644 --- a/modules/apps/29-fee/module.go +++ b/modules/apps/29-fee/module.go @@ -1,5 +1,6 @@ -package transfer +package fee +/* import ( "context" "encoding/json" @@ -273,3 +274,4 @@ func (am AppModule) OnTimeoutPacket( ) error { return nil } +*/ diff --git a/modules/apps/29-fee/types/codec.go b/modules/apps/29-fee/types/codec.go index c2089bdc40b..c9dac580ea5 100644 --- a/modules/apps/29-fee/types/codec.go +++ b/modules/apps/29-fee/types/codec.go @@ -1,5 +1,6 @@ package types +/* import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -12,3 +13,4 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } +*/ From 46dab2fc383bc476a13549c11dfc65ed5d665242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:23:57 +0200 Subject: [PATCH 3/4] update keeper test --- modules/apps/29-fee/keeper/keeper_test.go | 24 +++++------------------ 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index de3902df669..b355ccfe847 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -1,5 +1,6 @@ package keeper_test +/* import ( "testing" @@ -21,8 +22,6 @@ type KeeperTestSuite struct { chainA *ibctesting.TestChain chainB *ibctesting.TestChain chainC *ibctesting.TestChain - - queryClient types.QueryClient } func (suite *KeeperTestSuite) SetupTest() { @@ -30,30 +29,17 @@ func (suite *KeeperTestSuite) SetupTest() { suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - - queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().TransferKeeper) - suite.queryClient = types.NewQueryClient(queryHelper) } -func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { +func NewFeePath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { path := ibctesting.NewPath(chainA, chainB) - path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort - path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort + path.EndpointA.ChannelConfig.PortID = ibctesting.FeePort + path.EndpointB.ChannelConfig.PortID = ibctesting.FeePort return path } -func (suite *KeeperTestSuite) TestGetTransferAccount() { - expectedMaccAddr := sdk.AccAddress(crypto.AddressHash([]byte(types.ModuleName))) - - macc := suite.chainA.GetSimApp().TransferKeeper.GetTransferAccount(suite.chainA.GetContext()) - - suite.Require().NotNil(macc) - suite.Require().Equal(types.ModuleName, macc.GetName()) - suite.Require().Equal(expectedMaccAddr, macc.GetAddress()) -} - func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } +*/ From aa8df54a67f9e624b8811417d898f0970ec4a885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:38:45 +0200 Subject: [PATCH 4/4] remove module test --- modules/apps/29-fee/module_test.go | 244 ----------------------------- 1 file changed, 244 deletions(-) delete mode 100644 modules/apps/29-fee/module_test.go diff --git a/modules/apps/29-fee/module_test.go b/modules/apps/29-fee/module_test.go deleted file mode 100644 index df78524e5bd..00000000000 --- a/modules/apps/29-fee/module_test.go +++ /dev/null @@ -1,244 +0,0 @@ -package fee_test - -/* -import ( - "math" - - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/modules/core/24-host" - ibctesting "github.com/cosmos/ibc-go/testing" -) - -func (suite *FeeTestSuite) TestOnChanOpenInit() { - var ( - channel *channeltypes.Channel - path *ibctesting.Path - chanCap *capabilitytypes.Capability - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - - { - "success", func() {}, true, - }, - { - "max channels reached", func() { - path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(math.MaxUint32 + 1) - }, false, - }, - { - "invalid order - ORDERED", func() { - channel.Ordering = channeltypes.ORDERED - }, false, - }, - { - "invalid port ID", func() { - path.EndpointA.ChannelConfig.PortID = ibctesting.MockPort - }, false, - }, - { - "invalid version", func() { - channel.Version = "version" - }, false, - }, - { - "capability already claimed", func() { - err := suite.chainA.GetSimApp().ScopedFeeKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - }, false, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - path = NewFeePath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - path.EndpointA.ChannelID = ibctesting.FirstChannelID - - counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channel = &channeltypes.Channel{ - State: channeltypes.INIT, - Ordering: channeltypes.UNORDERED, - Counterparty: counterparty, - ConnectionHops: []string{path.EndpointA.ConnectionID}, - Version: types.Version, - } - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) - suite.Require().NoError(err) - - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.FeePort, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - - tc.malleate() // explicitly change fields in channel and testChannel - - err = cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - - }) - } -} - -func (suite *FeeTestSuite) TestOnChanOpenTry() { - var ( - channel *channeltypes.Channel - chanCap *capabilitytypes.Capability - path *ibctesting.Path - counterpartyVersion string - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - - { - "success", func() {}, true, - }, - { - "max channels reached", func() { - path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(math.MaxUint32 + 1) - }, false, - }, - { - "capability already claimed in INIT should pass", func() { - err := suite.chainA.GetSimApp().ScopedFeeKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - }, true, - }, - { - "invalid order - ORDERED", func() { - channel.Ordering = channeltypes.ORDERED - }, false, - }, - { - "invalid port ID", func() { - path.EndpointA.ChannelConfig.PortID = ibctesting.MockPort - }, false, - }, - { - "invalid version", func() { - channel.Version = "version" - }, false, - }, - { - "invalid counterparty version", func() { - counterpartyVersion = "version" - }, false, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - path = NewFeePath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - path.EndpointA.ChannelID = ibctesting.FirstChannelID - - counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channel = &channeltypes.Channel{ - State: channeltypes.TRYOPEN, - Ordering: channeltypes.UNORDERED, - Counterparty: counterparty, - ConnectionHops: []string{path.EndpointA.ConnectionID}, - Version: types.Version, - } - counterpartyVersion = types.Version - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) - suite.Require().NoError(err) - - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.FeePort, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - - tc.malleate() // explicitly change fields in channel and testChannel - - err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), counterpartyVersion, - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - - }) - } -} - -func (suite *FeeTestSuite) TestOnChanOpenAck() { - var counterpartyVersion string - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - - { - "success", func() {}, true, - }, - { - "invalid counterparty version", func() { - counterpartyVersion = "version" - }, false, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - path := NewFeePath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - path.EndpointA.ChannelID = ibctesting.FirstChannelID - counterpartyVersion = types.Version - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.FeePort) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - - tc.malleate() // explicitly change fields in channel and testChannel - - err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyVersion) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - - }) - } -} -*/