From b22155e8e62995d4e152aafea303186025df3f41 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 7 Feb 2025 11:03:34 -0500 Subject: [PATCH 1/6] add --- modules/core/04-channel/v2/keeper/genesis.go | 58 +++++++++++++ .../core/04-channel/v2/keeper/genesis_test.go | 55 +++++++++++++ modules/core/04-channel/v2/keeper/keeper.go | 59 ++++++++++++- modules/core/04-channel/v2/module.go | 82 ++++++++++++++++++- .../04-channel/v2/types/expected_keepers.go | 2 + modules/core/24-host/v2/packet_keys.go | 14 +++- 6 files changed, 262 insertions(+), 8 deletions(-) create mode 100644 modules/core/04-channel/v2/keeper/genesis.go create mode 100644 modules/core/04-channel/v2/keeper/genesis_test.go diff --git a/modules/core/04-channel/v2/keeper/genesis.go b/modules/core/04-channel/v2/keeper/genesis.go new file mode 100644 index 00000000000..1689f80982f --- /dev/null +++ b/modules/core/04-channel/v2/keeper/genesis.go @@ -0,0 +1,58 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// InitGenesis sets the genesis state in the store. +func (k *Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { + // set acks + for _, ack := range data.Acknowledgements { + k.SetPacketAcknowledgement(ctx, ack.ClientId, ack.Sequence, ack.Data) + } + + // set commits + for _, commitment := range data.Commitments { + k.SetPacketCommitment(ctx, commitment.ClientId, commitment.Sequence, commitment.Data) + } + + // set receipts + for _, receipt := range data.Receipts { + k.SetPacketReceipt(ctx, receipt.ClientId, receipt.Sequence) + } + + // set send sequences + for _, seq := range data.SendSequences { + k.SetNextSequenceSend(ctx, seq.ClientId, seq.Sequence) + } +} + +// ExportGenesis exports the current state to a genesis state. +func (k *Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { + clientStates := k.ClientKeeper.GetAllGenesisClients(ctx) + gs := types.GenesisState{ + Acknowledgements: make([]types.PacketState, 0), + Commitments: make([]types.PacketState, 0), + Receipts: make([]types.PacketState, 0), + SendSequences: make([]types.PacketSequence, 0), + } + for _, clientState := range clientStates { + acks := k.GetAllPacketAcknowledgementsForClient(ctx, clientState.ClientId) + gs.Acknowledgements = append(gs.Acknowledgements, acks...) + + comms := k.GetAllPacketCommitmentsForClient(ctx, clientState.ClientId) + gs.Commitments = append(gs.Commitments, comms...) + + receipts := k.GetAllPacketReceiptsForClient(ctx, clientState.ClientId) + gs.Receipts = append(gs.Receipts, receipts...) + + seq, ok := k.GetNextSequenceSend(ctx, clientState.ClientId) + if ok { + gs.SendSequences = append(gs.SendSequences, types.NewPacketSequence(clientState.ClientId, seq)) + } + } + + return gs +} diff --git a/modules/core/04-channel/v2/keeper/genesis_test.go b/modules/core/04-channel/v2/keeper/genesis_test.go new file mode 100644 index 00000000000..4b0fa8b0cc7 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/genesis_test.go @@ -0,0 +1,55 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +// TestInitExportGenesis tests the import and export flow for the channel v2 keeper. +func (suite *KeeperTestSuite) TestInitExportGenesis() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + app := suite.chainA.App + + emptyGenesis := types.DefaultGenesisState() + + // create a valid genesis state that uses the client keepers existing client IDs + clientStates := app.GetIBCKeeper().ClientKeeper.GetAllGenesisClients(suite.chainA.GetContext()) + validGs := types.DefaultGenesisState() + for i, clientState := range clientStates { + ack := types.NewPacketState(clientState.ClientId, uint64(i+1), []byte("ack")) + receipt := types.NewPacketState(clientState.ClientId, uint64(i+1), []byte{byte(0x2)}) + commitment := types.NewPacketState(clientState.ClientId, uint64(i+1), []byte("commit_hash")) + seq := types.NewPacketSequence(clientState.ClientId, uint64(i+1)) + + validGs.Acknowledgements = append(validGs.Acknowledgements, ack) + validGs.Receipts = append(validGs.Receipts, receipt) + validGs.Commitments = append(validGs.Commitments, commitment) + validGs.SendSequences = append(validGs.SendSequences, seq) + emptyGenesis.SendSequences = append(emptyGenesis.SendSequences, seq) + } + + tests := []struct { + name string + genState types.GenesisState + }{ + { + name: "no modifications genesis", + genState: emptyGenesis, + }, + { + name: "valid", + genState: validGs, + }, + } + + for _, tt := range tests { + suite.Run(tt.name, func() { + app.GetIBCKeeper().ChannelKeeperV2.InitGenesis(suite.chainA.GetContext(), tt.genState) + + exported := app.GetIBCKeeper().ChannelKeeperV2.ExportGenesis(suite.chainA.GetContext()) + suite.Require().Equal(tt.genState, exported) + }) + } +} diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go index 00076b6e903..8ad68e200d4 100644 --- a/modules/core/04-channel/v2/keeper/keeper.go +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -1,12 +1,15 @@ package keeper import ( + "bytes" "context" "cosmossdk.io/core/appmodule" "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" @@ -50,7 +53,7 @@ func NewKeeper( } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx context.Context) log.Logger { +func (*Keeper) Logger(ctx context.Context) log.Logger { sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } @@ -194,3 +197,57 @@ func (k *Keeper) DeleteAsyncPacket(ctx context.Context, clientID string, sequenc panic(err) } } + +// GetAllPacketCommitmentsForClient returns all stored PacketCommitments objects for a specified +// client ID. +func (k *Keeper) GetAllPacketCommitmentsForClient(ctx context.Context, clientID string) []types.PacketState { + store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) + storePrefix := hostv2.PacketCommitmentPrefixKey(clientID) + iterator := storetypes.KVStorePrefixIterator(store, storePrefix) + + var commitments []types.PacketState + for ; iterator.Valid(); iterator.Next() { + sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) + sequence := sdk.BigEndianToUint64(sequenceBz) + state := types.NewPacketState(clientID, sequence, iterator.Value()) + + commitments = append(commitments, state) + } + return commitments +} + +// GetAllPacketAcknowledgementsForClient returns all stored PacketAcknowledgements objects for a specified +// client ID. +func (k *Keeper) GetAllPacketAcknowledgementsForClient(ctx context.Context, clientID string) []types.PacketState { + store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) + storePrefix := hostv2.PacketAcknowledgementPrefixKey(clientID) + iterator := storetypes.KVStorePrefixIterator(store, storePrefix) + + var acknowledgements []types.PacketState + for ; iterator.Valid(); iterator.Next() { + sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) + sequence := sdk.BigEndianToUint64(sequenceBz) + state := types.NewPacketState(clientID, sequence, iterator.Value()) + + acknowledgements = append(acknowledgements, state) + } + return acknowledgements +} + +// GetAllPacketReceiptsForClient returns all stored PacketReceipts objects for a specified +// client ID. +func (k *Keeper) GetAllPacketReceiptsForClient(ctx context.Context, clientID string) []types.PacketState { + store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) + storePrefix := hostv2.PacketReceiptPrefixKey(clientID) + iterator := storetypes.KVStorePrefixIterator(store, storePrefix) + + var receipts []types.PacketState + for ; iterator.Valid(); iterator.Next() { + sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) + sequence := sdk.BigEndianToUint64(sequenceBz) + state := types.NewPacketState(clientID, sequence, iterator.Value()) + + receipts = append(receipts, state) + } + return receipts +} diff --git a/modules/core/04-channel/v2/module.go b/modules/core/04-channel/v2/module.go index 9f6fbf8f7d6..bcc04493746 100644 --- a/modules/core/04-channel/v2/module.go +++ b/modules/core/04-channel/v2/module.go @@ -1,23 +1,99 @@ package client import ( + "context" + "encoding/json" + "fmt" + "github.com/spf13/cobra" + "cosmossdk.io/core/appmodule" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) +var ( + _ appmodule.AppModule = (*AppModule)(nil) + + _ module.AppModule = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) +) + +// AppModule represents the AppModule for this module +type AppModule struct { + cdc codec.Codec + keeper *keeper.Keeper +} + +func (AppModule) IsAppModule() {} + +func (AppModule) IsOnePerModuleType() {} + +func (m AppModule) DefaultGenesis() json.RawMessage { + gs := types.DefaultGenesisState() + return m.cdc.MustMarshalJSON(&gs) +} + +func (m AppModule) ValidateGenesis(data json.RawMessage) error { + gs := &types.GenesisState{} + err := m.cdc.UnmarshalJSON(data, gs) + if err != nil { + return err + } + + return gs.Validate() +} + +func (m AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { + gs := &types.GenesisState{} + err := m.cdc.UnmarshalJSON(data, gs) + if err != nil { + return fmt.Errorf("failed to unmarshal genesis state: %w", err) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + m.keeper.InitGenesis(sdkCtx, *gs) + + return nil +} + +func (m AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + gs := m.keeper.ExportGenesis(sdkCtx) + return json.Marshal(gs) +} + // Name returns the IBC channel/v2 name -func Name() string { +func (AppModule) Name() string { return types.SubModuleName } +func Name() string { + return AppModule{}.Name() +} + // GetQueryCmd returns the root query command for IBC channels v2. -func GetQueryCmd() *cobra.Command { +func (AppModule) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } +// GetQueryCmd returns the root query command for IBC channels v2. +func GetQueryCmd() *cobra.Command { + return AppModule{}.GetQueryCmd() +} + // GetTxCmd returns the root tx command for IBC channels v2. -func GetTxCmd() *cobra.Command { +func (AppModule) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } + +// GetTxCmd returns the root tx command for IBC channels v2. +func GetTxCmd() *cobra.Command { + return AppModule{}.GetTxCmd() +} diff --git a/modules/core/04-channel/v2/types/expected_keepers.go b/modules/core/04-channel/v2/types/expected_keepers.go index 41db0741876..2078b5ac0f6 100644 --- a/modules/core/04-channel/v2/types/expected_keepers.go +++ b/modules/core/04-channel/v2/types/expected_keepers.go @@ -25,4 +25,6 @@ type ClientKeeper interface { GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) // GetClientCounterparty returns the counterpartyInfo given a clientID GetClientCounterparty(ctx context.Context, clientID string) (clienttypes.CounterpartyInfo, bool) + // GetAllGenesisClients returns all the clients in state with their client ids returned as IdentifiedClientState + GetAllGenesisClients(ctx context.Context) clienttypes.IdentifiedClientStates } diff --git a/modules/core/24-host/v2/packet_keys.go b/modules/core/24-host/v2/packet_keys.go index 03f15a858d5..1a0e5d796da 100644 --- a/modules/core/24-host/v2/packet_keys.go +++ b/modules/core/24-host/v2/packet_keys.go @@ -6,22 +6,28 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +const ( + PacketCommitmentBasePrefix = byte(1) + PacketReceiptBasePrefix = byte(2) + PacketAcknowledgementBasePrefix = byte(3) +) + // PacketCommitmentPrefixKey returns the store key prefix under which packet commitments for a particular channel are stored. // channelID must be a generated identifier, not provided externally so key collisions are not possible. func PacketCommitmentPrefixKey(channelID string) []byte { - return append([]byte(channelID), byte(1)) + return append([]byte(channelID), PacketCommitmentBasePrefix) } // PacketCommitmentKey returns the store key of under which a packet commitment is stored. // channelID must be a generated identifier, not provided externally so key collisions are not possible. func PacketCommitmentKey(channelID string, sequence uint64) []byte { - return append(PacketCommitmentPrefixKey((channelID)), sdk.Uint64ToBigEndian(sequence)...) + return append(PacketCommitmentPrefixKey(channelID), sdk.Uint64ToBigEndian(sequence)...) } // PacketReceiptPrefixKey returns the store key prefix under which packet receipts for a particular channel are stored. // channelID must be a generated identifier, not provided externally so key collisions are not possible. func PacketReceiptPrefixKey(channelID string) []byte { - return append([]byte(channelID), byte(2)) + return append([]byte(channelID), PacketReceiptBasePrefix) } // PacketReceiptKey returns the store key of under which a packet receipt is stored. @@ -33,7 +39,7 @@ func PacketReceiptKey(channelID string, sequence uint64) []byte { // PacketAcknowledgementPrefixKey returns the store key prefix under which packet acknowledgements for a particular channel are stored. // channelID must be a generated identifier, not provided externally so key collisions are not possible. func PacketAcknowledgementPrefixKey(channelID string) []byte { - return append([]byte(channelID), byte(3)) + return append([]byte(channelID), PacketAcknowledgementBasePrefix) } // PacketAcknowledgementKey returns the store key of under which a packet acknowledgement is stored. From 645966712b67a07192c9797a5116c6fc0650a72b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 7 Feb 2025 12:57:37 -0500 Subject: [PATCH 2/6] fix and wire to core --- modules/core/04-channel/v2/module.go | 76 ++------------------- modules/core/genesis.go | 3 + modules/core/genesis_test.go | 46 +++++++++++++ modules/core/types/genesis.go | 8 ++- modules/core/types/genesis.pb.go | 96 +++++++++++++++++++++------ proto/ibc/core/types/v1/genesis.proto | 3 + 6 files changed, 142 insertions(+), 90 deletions(-) diff --git a/modules/core/04-channel/v2/module.go b/modules/core/04-channel/v2/module.go index bcc04493746..9bfa2a01f01 100644 --- a/modules/core/04-channel/v2/module.go +++ b/modules/core/04-channel/v2/module.go @@ -2,98 +2,36 @@ package client import ( "context" - "encoding/json" - "fmt" "github.com/spf13/cobra" - "cosmossdk.io/core/appmodule" - - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) -var ( - _ appmodule.AppModule = (*AppModule)(nil) - - _ module.AppModule = (*AppModule)(nil) - _ module.HasGenesis = (*AppModule)(nil) -) - -// AppModule represents the AppModule for this module -type AppModule struct { - cdc codec.Codec - keeper *keeper.Keeper -} - -func (AppModule) IsAppModule() {} - -func (AppModule) IsOnePerModuleType() {} - -func (m AppModule) DefaultGenesis() json.RawMessage { - gs := types.DefaultGenesisState() - return m.cdc.MustMarshalJSON(&gs) -} - -func (m AppModule) ValidateGenesis(data json.RawMessage) error { - gs := &types.GenesisState{} - err := m.cdc.UnmarshalJSON(data, gs) - if err != nil { - return err - } - - return gs.Validate() -} - -func (m AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { - gs := &types.GenesisState{} - err := m.cdc.UnmarshalJSON(data, gs) - if err != nil { - return fmt.Errorf("failed to unmarshal genesis state: %w", err) - } - +func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { sdkCtx := sdk.UnwrapSDKContext(ctx) - m.keeper.InitGenesis(sdkCtx, *gs) - - return nil + k.InitGenesis(sdkCtx, gs) } -func (m AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { +func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { sdkCtx := sdk.UnwrapSDKContext(ctx) - gs := m.keeper.ExportGenesis(sdkCtx) - return json.Marshal(gs) -} - -// Name returns the IBC channel/v2 name -func (AppModule) Name() string { - return types.SubModuleName + return k.ExportGenesis(sdkCtx) } func Name() string { - return AppModule{}.Name() -} - -// GetQueryCmd returns the root query command for IBC channels v2. -func (AppModule) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() + return types.SubModuleName } // GetQueryCmd returns the root query command for IBC channels v2. func GetQueryCmd() *cobra.Command { - return AppModule{}.GetQueryCmd() -} - -// GetTxCmd returns the root tx command for IBC channels v2. -func (AppModule) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() + return cli.GetQueryCmd() } // GetTxCmd returns the root tx command for IBC channels v2. func GetTxCmd() *cobra.Command { - return AppModule{}.GetTxCmd() + return cli.NewTxCmd() } diff --git a/modules/core/genesis.go b/modules/core/genesis.go index ebe016ef56d..403b63a38d9 100644 --- a/modules/core/genesis.go +++ b/modules/core/genesis.go @@ -6,6 +6,7 @@ import ( client "github.com/cosmos/ibc-go/v9/modules/core/02-client" connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection" channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel" + channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" "github.com/cosmos/ibc-go/v9/modules/core/keeper" "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -18,6 +19,7 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, gs *types.GenesisState) e } connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis) channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis) + channelv2.InitGenesis(ctx, k.ChannelKeeperV2, gs.ChannelV2Genesis) return nil } @@ -31,5 +33,6 @@ func ExportGenesis(ctx context.Context, k keeper.Keeper) (*types.GenesisState, e ClientGenesis: gs, ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper), ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper), + ChannelV2Genesis: channelv2.ExportGenesis(ctx, k.ChannelKeeperV2), }, nil } diff --git a/modules/core/genesis_test.go b/modules/core/genesis_test.go index f3e5c71148b..08efe0db73d 100644 --- a/modules/core/genesis_test.go +++ b/modules/core/genesis_test.go @@ -13,6 +13,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" "github.com/cosmos/ibc-go/v9/modules/core/types" @@ -145,6 +146,20 @@ func (suite *IBCTestSuite) TestValidateGenesis() { 0, channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout}, ), + ChannelV2Genesis: channelv2types.NewGenesisState( + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel2, 1, []byte("ack")), + }, + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel2, 1, []byte("")), + }, + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")), + }, + []channelv2types.PacketSequence{ + channelv2types.NewPacketSequence(channel1, 1), + }, + ), }, expError: nil, }, @@ -172,6 +187,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { 2, ), ConnectionGenesis: connectiontypes.DefaultGenesisState(), + ChannelV2Genesis: channelv2types.DefaultGenesisState(), }, expError: errors.New("genesis metadata key cannot be empty"), }, @@ -189,6 +205,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { 0, connectiontypes.Params{}, ), + ChannelV2Genesis: channelv2types.DefaultGenesisState(), }, expError: errors.New("invalid connection"), }, @@ -202,6 +219,21 @@ func (suite *IBCTestSuite) TestValidateGenesis() { channeltypes.NewPacketState("(portID)", channel1, 1, []byte("ack")), }, }, + ChannelV2Genesis: channelv2types.DefaultGenesisState(), + }, + expError: errors.New("invalid acknowledgement"), + }, + { + name: "invalid channel v2 genesis", + genState: &types.GenesisState{ + ClientGenesis: clienttypes.DefaultGenesisState(), + ConnectionGenesis: connectiontypes.DefaultGenesisState(), + ChannelGenesis: channeltypes.DefaultGenesisState(), + ChannelV2Genesis: channelv2types.GenesisState{ + Acknowledgements: []channelv2types.PacketState{ + channelv2types.NewPacketState(channel1, 1, nil), + }, + }, }, expError: errors.New("invalid acknowledgement"), }, @@ -305,6 +337,20 @@ func (suite *IBCTestSuite) TestInitGenesis() { 0, channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout}, ), + ChannelV2Genesis: channelv2types.NewGenesisState( + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel2, 1, []byte("ack")), + }, + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel2, 1, []byte("")), + }, + []channelv2types.PacketState{ + channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")), + }, + []channelv2types.PacketSequence{ + channelv2types.NewPacketSequence(channel1, 1), + }, + ), }, }, } diff --git a/modules/core/types/genesis.go b/modules/core/types/genesis.go index 7d5d73103c5..b250fa8bd1a 100644 --- a/modules/core/types/genesis.go +++ b/modules/core/types/genesis.go @@ -6,6 +6,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) var _ gogoprotoany.UnpackInterfacesMessage = (*GenesisState)(nil) @@ -16,6 +17,7 @@ func DefaultGenesisState() *GenesisState { ClientGenesis: clienttypes.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(), ChannelGenesis: channeltypes.DefaultGenesisState(), + ChannelV2Genesis: channelv2types.DefaultGenesisState(), } } @@ -35,5 +37,9 @@ func (gs *GenesisState) Validate() error { return err } - return gs.ChannelGenesis.Validate() + if err := gs.ChannelGenesis.Validate(); err != nil { + return err + } + + return gs.ChannelV2Genesis.Validate() } diff --git a/modules/core/types/genesis.pb.go b/modules/core/types/genesis.pb.go index 752101a366d..c216f00f74c 100644 --- a/modules/core/types/genesis.pb.go +++ b/modules/core/types/genesis.pb.go @@ -10,6 +10,7 @@ import ( types "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" types1 "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" types2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + types3 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" io "io" math "math" math_bits "math/bits" @@ -34,6 +35,8 @@ type GenesisState struct { ConnectionGenesis types1.GenesisState `protobuf:"bytes,2,opt,name=connection_genesis,json=connectionGenesis,proto3" json:"connection_genesis"` // ICS004 - Channel genesis state ChannelGenesis types2.GenesisState `protobuf:"bytes,3,opt,name=channel_genesis,json=channelGenesis,proto3" json:"channel_genesis"` + // ICS004 - Channel/v2 genesis state + ChannelV2Genesis types3.GenesisState `protobuf:"bytes,4,opt,name=channel_v2_genesis,json=channelV2Genesis,proto3" json:"channel_v2_genesis"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -90,6 +93,13 @@ func (m *GenesisState) GetChannelGenesis() types2.GenesisState { return types2.GenesisState{} } +func (m *GenesisState) GetChannelV2Genesis() types3.GenesisState { + if m != nil { + return m.ChannelV2Genesis + } + return types3.GenesisState{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.core.types.v1.GenesisState") } @@ -97,26 +107,27 @@ func init() { func init() { proto.RegisterFile("ibc/core/types/v1/genesis.proto", fileDescriptor_b9a49c5663e6fc59) } var fileDescriptor_b9a49c5663e6fc59 = []byte{ - // 293 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xb1, 0x4e, 0xeb, 0x30, - 0x14, 0x40, 0x93, 0xbe, 0x27, 0x86, 0x00, 0x45, 0x8d, 0x18, 0x50, 0x06, 0x37, 0x45, 0x1d, 0x58, - 0xb0, 0x15, 0x98, 0x58, 0xbb, 0xc0, 0x82, 0x84, 0x60, 0x82, 0x05, 0x35, 0xc6, 0x72, 0x2d, 0x25, - 0xbe, 0x55, 0xed, 0x46, 0xe2, 0x17, 0x98, 0xf8, 0xac, 0x8e, 0x1d, 0x99, 0x10, 0x4a, 0x7e, 0x04, - 0xd5, 0x36, 0x4e, 0xa4, 0xa8, 0x5b, 0x94, 0x73, 0x7c, 0x7c, 0x6d, 0x47, 0x63, 0x91, 0x53, 0x42, - 0x61, 0xc5, 0x88, 0x7e, 0x5f, 0x32, 0x45, 0xaa, 0x8c, 0x70, 0x26, 0x99, 0x12, 0x0a, 0x2f, 0x57, - 0xa0, 0x21, 0x1e, 0x89, 0x9c, 0xe2, 0x9d, 0x80, 0x8d, 0x80, 0xab, 0x2c, 0x39, 0xe5, 0xc0, 0xc1, - 0x50, 0xb2, 0xfb, 0xb2, 0x62, 0x92, 0xfa, 0x12, 0x2d, 0x04, 0x93, 0xba, 0x97, 0x4a, 0xa6, 0xad, - 0x01, 0x52, 0x32, 0xaa, 0x05, 0xc8, 0xbe, 0x35, 0x69, 0xad, 0xc5, 0x5c, 0x4a, 0x56, 0xf4, 0x94, - 0xf3, 0x8f, 0x41, 0x74, 0x74, 0x6b, 0xff, 0x3c, 0xe9, 0xb9, 0x66, 0xf1, 0x7d, 0x34, 0xb4, 0x9b, - 0xbe, 0x3a, 0xf1, 0x2c, 0x4c, 0xc3, 0x8b, 0xc3, 0xab, 0x14, 0xfb, 0xe9, 0x2d, 0xc7, 0x55, 0x86, - 0xbb, 0x2b, 0x67, 0xff, 0x37, 0xdf, 0xe3, 0xe0, 0xf1, 0xd8, 0x52, 0x47, 0xe2, 0xe7, 0x28, 0x6e, - 0x27, 0xf4, 0xc9, 0x81, 0x49, 0x4e, 0x3b, 0x49, 0xef, 0xec, 0xc9, 0x8e, 0x5a, 0xe3, 0x2f, 0xfd, - 0x10, 0x9d, 0xb8, 0x63, 0xf9, 0xee, 0x3f, 0xd3, 0x9d, 0x74, 0xba, 0x56, 0xd8, 0x13, 0x1d, 0x3a, - 0xec, 0xd0, 0xec, 0x6e, 0x53, 0xa3, 0x70, 0x5b, 0xa3, 0xf0, 0xa7, 0x46, 0xe1, 0x67, 0x83, 0x82, - 0x6d, 0x83, 0x82, 0xaf, 0x06, 0x05, 0x2f, 0x98, 0x0b, 0xbd, 0x58, 0xe7, 0x98, 0x42, 0x49, 0x28, - 0xa8, 0x12, 0x14, 0x11, 0x39, 0xbd, 0xe4, 0x40, 0xaa, 0x1b, 0x52, 0xc2, 0xdb, 0xba, 0x60, 0xaa, - 0xf3, 0xf6, 0xf9, 0x81, 0xb9, 0xdd, 0xeb, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x65, 0x21, 0x36, - 0x53, 0x14, 0x02, 0x00, 0x00, + // 316 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0xd2, 0xb1, 0x4a, 0xc3, 0x40, + 0x1c, 0xc7, 0xf1, 0xa4, 0x16, 0x87, 0x53, 0xab, 0x0d, 0x0e, 0xd2, 0xe1, 0xda, 0x4a, 0x07, 0x17, + 0xef, 0x68, 0x9c, 0x5c, 0xbb, 0xe8, 0x22, 0x88, 0xa2, 0xa0, 0x8b, 0x34, 0xe7, 0x91, 0x1e, 0xb4, + 0xf7, 0x2f, 0xbd, 0x6b, 0xc0, 0xb7, 0xf0, 0xb1, 0x3a, 0x76, 0x74, 0x12, 0x4d, 0x5e, 0x44, 0x9a, + 0xbb, 0x5c, 0x22, 0x35, 0xe0, 0x16, 0xf2, 0xfb, 0xe6, 0x43, 0x8e, 0x04, 0x75, 0x45, 0xc4, 0x28, + 0x83, 0x05, 0xa7, 0xfa, 0x6d, 0xce, 0x15, 0x4d, 0x86, 0x34, 0xe6, 0x92, 0x2b, 0xa1, 0xc8, 0x7c, + 0x01, 0x1a, 0x82, 0xb6, 0x88, 0x18, 0xd9, 0x04, 0x24, 0x0f, 0x48, 0x32, 0xec, 0x1c, 0xc7, 0x10, + 0x43, 0xbe, 0xd2, 0xcd, 0x95, 0x09, 0x3b, 0x3d, 0x27, 0xb1, 0xa9, 0xe0, 0x52, 0x6f, 0x51, 0x9d, + 0x41, 0x59, 0x80, 0x94, 0x9c, 0x69, 0x01, 0x72, 0xbb, 0xea, 0x97, 0xd5, 0x64, 0x2c, 0x25, 0x9f, + 0xfe, 0x2b, 0x09, 0x7f, 0x27, 0xa7, 0xdf, 0x0d, 0xb4, 0x7f, 0x65, 0xee, 0xdc, 0xeb, 0xb1, 0xe6, + 0xc1, 0x0d, 0x6a, 0x99, 0xf7, 0x7a, 0xb1, 0xe1, 0x89, 0xdf, 0xf3, 0xcf, 0xf6, 0xc2, 0x1e, 0x71, + 0x07, 0x34, 0x3b, 0x49, 0x86, 0xa4, 0xfa, 0xe4, 0xa8, 0xb9, 0xfa, 0xec, 0x7a, 0x77, 0x07, 0x66, + 0xb5, 0x4b, 0xf0, 0x84, 0x82, 0xf2, 0x10, 0x8e, 0x6c, 0xe4, 0xe4, 0xa0, 0x42, 0xba, 0xa6, 0x86, + 0x6d, 0x97, 0x45, 0x41, 0xdf, 0xa2, 0x43, 0x7b, 0x2c, 0xe7, 0xee, 0xe4, 0x6e, 0xbf, 0xe2, 0x9a, + 0xa0, 0x06, 0x6d, 0xd9, 0xb9, 0x10, 0x1f, 0x50, 0x50, 0x88, 0x49, 0xe8, 0xd0, 0x66, 0x2d, 0x1a, + 0xfe, 0x85, 0x1e, 0xd9, 0xf9, 0x31, 0xb4, 0xe3, 0xe8, 0x7a, 0x95, 0x62, 0x7f, 0x9d, 0x62, 0xff, + 0x2b, 0xc5, 0xfe, 0x7b, 0x86, 0xbd, 0x75, 0x86, 0xbd, 0x8f, 0x0c, 0x7b, 0xcf, 0x24, 0x16, 0x7a, + 0xb2, 0x8c, 0x08, 0x83, 0x19, 0x65, 0xa0, 0x66, 0xa0, 0xa8, 0x88, 0xd8, 0x79, 0x0c, 0x34, 0xb9, + 0xa4, 0x33, 0x78, 0x5d, 0x4e, 0xb9, 0xaa, 0xfc, 0x75, 0xd1, 0x6e, 0xfe, 0xd1, 0x2e, 0x7e, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x30, 0xba, 0x18, 0x2c, 0x8e, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -139,6 +150,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.ChannelV2Genesis.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 { size, err := m.ChannelGenesis.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -195,6 +216,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.ChannelGenesis.Size() n += 1 + l + sovGenesis(uint64(l)) + l = m.ChannelV2Genesis.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -332,6 +355,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelV2Genesis", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ChannelV2Genesis.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/proto/ibc/core/types/v1/genesis.proto b/proto/ibc/core/types/v1/genesis.proto index 4c6571da60a..6e087c6d547 100644 --- a/proto/ibc/core/types/v1/genesis.proto +++ b/proto/ibc/core/types/v1/genesis.proto @@ -8,6 +8,7 @@ import "gogoproto/gogo.proto"; import "ibc/core/client/v1/genesis.proto"; import "ibc/core/connection/v1/genesis.proto"; import "ibc/core/channel/v1/genesis.proto"; +import "ibc/core/channel/v2/genesis.proto"; // GenesisState defines the ibc module's genesis state. message GenesisState { @@ -17,4 +18,6 @@ message GenesisState { ibc.core.connection.v1.GenesisState connection_genesis = 2 [(gogoproto.nullable) = false]; // ICS004 - Channel genesis state ibc.core.channel.v1.GenesisState channel_genesis = 3 [(gogoproto.nullable) = false]; + // ICS004 - Channel/v2 genesis state + ibc.core.channel.v2.GenesisState channel_v2_genesis = 4 [(gogoproto.nullable) = false]; } From fb1c3dbf2cca1848929f674493d95b37e3d5cfe2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 10 Feb 2025 13:12:18 -0500 Subject: [PATCH 3/6] sequence check and cleanup --- modules/core/04-channel/v2/keeper/keeper.go | 64 +++++++++++---------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go index 8ad68e200d4..4db622e3828 100644 --- a/modules/core/04-channel/v2/keeper/keeper.go +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -3,7 +3,6 @@ package keeper import ( "bytes" "context" - "cosmossdk.io/core/appmodule" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -198,56 +197,59 @@ func (k *Keeper) DeleteAsyncPacket(ctx context.Context, clientID string, sequenc } } +// extractSequenceFromKey takes the full store key as well as a packet store prefix and extracts +// the encoded sequence number from the key. +// +// This function panics of the provided key once trimmed is larger than 8 bytes as the expected +// sequence byte length is always 8. +func extractSequenceFromKey(key, storePrefix []byte) uint64 { + sequenceBz := bytes.TrimPrefix(key, storePrefix) + if len(sequenceBz) > 8 { + panic("sequence is too long - expected 8 bytes") + } + return sdk.BigEndianToUint64(sequenceBz) +} + // GetAllPacketCommitmentsForClient returns all stored PacketCommitments objects for a specified // client ID. func (k *Keeper) GetAllPacketCommitmentsForClient(ctx context.Context, clientID string) []types.PacketState { - store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) - storePrefix := hostv2.PacketCommitmentPrefixKey(clientID) - iterator := storetypes.KVStorePrefixIterator(store, storePrefix) + return k.getAllPacketsForClientStore(ctx, clientID, hostv2.PacketCommitmentPrefixKey) - var commitments []types.PacketState - for ; iterator.Valid(); iterator.Next() { - sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) - sequence := sdk.BigEndianToUint64(sequenceBz) - state := types.NewPacketState(clientID, sequence, iterator.Value()) - - commitments = append(commitments, state) - } - return commitments } // GetAllPacketAcknowledgementsForClient returns all stored PacketAcknowledgements objects for a specified // client ID. func (k *Keeper) GetAllPacketAcknowledgementsForClient(ctx context.Context, clientID string) []types.PacketState { - store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) - storePrefix := hostv2.PacketAcknowledgementPrefixKey(clientID) - iterator := storetypes.KVStorePrefixIterator(store, storePrefix) - - var acknowledgements []types.PacketState - for ; iterator.Valid(); iterator.Next() { - sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) - sequence := sdk.BigEndianToUint64(sequenceBz) - state := types.NewPacketState(clientID, sequence, iterator.Value()) + return k.getAllPacketsForClientStore(ctx, clientID, hostv2.PacketAcknowledgementPrefixKey) - acknowledgements = append(acknowledgements, state) - } - return acknowledgements } // GetAllPacketReceiptsForClient returns all stored PacketReceipts objects for a specified // client ID. func (k *Keeper) GetAllPacketReceiptsForClient(ctx context.Context, clientID string) []types.PacketState { + return k.getAllPacketsForClientStore(ctx, clientID, hostv2.PacketReceiptPrefixKey) +} + +// prefixKeyConstructor is a function that constructs a store key for a specific packet store using the provided +// clientID. +type prefixKeyConstructor func(clientID string) []byte + +// getAllPacketsForClientStore gets all PacketState objects for the specified clientID using a provided +// function for constructing the key prefix for the store. +// +// For example, to get all PacketReceipts for a clientID the hostv2.PacketReceiptPrefixKey function can be +// passed to get the PacketReceipt store key prefix. +func (k *Keeper) getAllPacketsForClientStore(ctx context.Context, clientID string, prefixFn prefixKeyConstructor) []types.PacketState { store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx)) - storePrefix := hostv2.PacketReceiptPrefixKey(clientID) + storePrefix := prefixFn(clientID) iterator := storetypes.KVStorePrefixIterator(store, storePrefix) - var receipts []types.PacketState + var packets []types.PacketState for ; iterator.Valid(); iterator.Next() { - sequenceBz := bytes.TrimPrefix(iterator.Key(), storePrefix) - sequence := sdk.BigEndianToUint64(sequenceBz) + sequence := extractSequenceFromKey(iterator.Key(), storePrefix) state := types.NewPacketState(clientID, sequence, iterator.Value()) - receipts = append(receipts, state) + packets = append(packets, state) } - return receipts + return packets } From 3bb7753750f4c96ccc30e97596abddb79751ed3f Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:09:33 -0500 Subject: [PATCH 4/6] have more than one client in state on tests --- modules/core/04-channel/v2/keeper/genesis_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/04-channel/v2/keeper/genesis_test.go b/modules/core/04-channel/v2/keeper/genesis_test.go index 4b0fa8b0cc7..24c55f7c188 100644 --- a/modules/core/04-channel/v2/keeper/genesis_test.go +++ b/modules/core/04-channel/v2/keeper/genesis_test.go @@ -10,6 +10,9 @@ func (suite *KeeperTestSuite) TestInitExportGenesis() { path := ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupV2() + path2 := ibctesting.NewPath(suite.chainA, suite.chainC) + path2.SetupV2() + app := suite.chainA.App emptyGenesis := types.DefaultGenesisState() From aecd1a25de337163409a21a22e624088669b2890 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 10 Feb 2025 16:05:16 -0500 Subject: [PATCH 5/6] refactor --- .../04-channel/v2/{keeper => }/genesis.go | 19 ++++++------ .../v2/{keeper => }/genesis_test.go | 12 ++++--- modules/core/04-channel/v2/module.go | 17 +--------- modules/core/04-channel/v2/module_test.go | 31 +++++++++++++++++++ 4 files changed, 49 insertions(+), 30 deletions(-) rename modules/core/04-channel/v2/{keeper => }/genesis.go (73%) rename modules/core/04-channel/v2/{keeper => }/genesis_test.go (81%) create mode 100644 modules/core/04-channel/v2/module_test.go diff --git a/modules/core/04-channel/v2/keeper/genesis.go b/modules/core/04-channel/v2/genesis.go similarity index 73% rename from modules/core/04-channel/v2/keeper/genesis.go rename to modules/core/04-channel/v2/genesis.go index 1689f80982f..29515d46bf0 100644 --- a/modules/core/04-channel/v2/keeper/genesis.go +++ b/modules/core/04-channel/v2/genesis.go @@ -1,36 +1,35 @@ -package keeper +package channelv2 import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) -// InitGenesis sets the genesis state in the store. -func (k *Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { +func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { // set acks - for _, ack := range data.Acknowledgements { + for _, ack := range gs.Acknowledgements { k.SetPacketAcknowledgement(ctx, ack.ClientId, ack.Sequence, ack.Data) } // set commits - for _, commitment := range data.Commitments { + for _, commitment := range gs.Commitments { k.SetPacketCommitment(ctx, commitment.ClientId, commitment.Sequence, commitment.Data) } // set receipts - for _, receipt := range data.Receipts { + for _, receipt := range gs.Receipts { k.SetPacketReceipt(ctx, receipt.ClientId, receipt.Sequence) } // set send sequences - for _, seq := range data.SendSequences { + for _, seq := range gs.SendSequences { k.SetNextSequenceSend(ctx, seq.ClientId, seq.Sequence) } } -// ExportGenesis exports the current state to a genesis state. -func (k *Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { +func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { clientStates := k.ClientKeeper.GetAllGenesisClients(ctx) gs := types.GenesisState{ Acknowledgements: make([]types.PacketState, 0), diff --git a/modules/core/04-channel/v2/keeper/genesis_test.go b/modules/core/04-channel/v2/genesis_test.go similarity index 81% rename from modules/core/04-channel/v2/keeper/genesis_test.go rename to modules/core/04-channel/v2/genesis_test.go index 24c55f7c188..df567f817de 100644 --- a/modules/core/04-channel/v2/keeper/genesis_test.go +++ b/modules/core/04-channel/v2/genesis_test.go @@ -1,12 +1,14 @@ -package keeper_test +package channelv2_test import ( + channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" ) // TestInitExportGenesis tests the import and export flow for the channel v2 keeper. -func (suite *KeeperTestSuite) TestInitExportGenesis() { +func (suite *ModuleTestSuite) TestInitExportGenesis() { path := ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupV2() @@ -49,9 +51,11 @@ func (suite *KeeperTestSuite) TestInitExportGenesis() { for _, tt := range tests { suite.Run(tt.name, func() { - app.GetIBCKeeper().ChannelKeeperV2.InitGenesis(suite.chainA.GetContext(), tt.genState) + channelV2Keeper := app.GetIBCKeeper().ChannelKeeperV2 + + channelv2.InitGenesis(suite.chainA.GetContext(), channelV2Keeper, tt.genState) - exported := app.GetIBCKeeper().ChannelKeeperV2.ExportGenesis(suite.chainA.GetContext()) + exported := channelv2.ExportGenesis(suite.chainA.GetContext(), channelV2Keeper) suite.Require().Equal(tt.genState, exported) }) } diff --git a/modules/core/04-channel/v2/module.go b/modules/core/04-channel/v2/module.go index 9bfa2a01f01..aa899ec2291 100644 --- a/modules/core/04-channel/v2/module.go +++ b/modules/core/04-channel/v2/module.go @@ -1,27 +1,12 @@ -package client +package channelv2 import ( - "context" - "github.com/spf13/cobra" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli" - "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) -func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - k.InitGenesis(sdkCtx, gs) -} - -func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { - sdkCtx := sdk.UnwrapSDKContext(ctx) - return k.ExportGenesis(sdkCtx) -} - func Name() string { return types.SubModuleName } diff --git a/modules/core/04-channel/v2/module_test.go b/modules/core/04-channel/v2/module_test.go new file mode 100644 index 00000000000..dcac04a2614 --- /dev/null +++ b/modules/core/04-channel/v2/module_test.go @@ -0,0 +1,31 @@ +package channelv2_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func TestModuleTestSuite(t *testing.T) { + testifysuite.Run(t, new(ModuleTestSuite)) +} + +type ModuleTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain +} + +func (suite *ModuleTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) +} From 8e13af615eaba4c3fe9c847b965370821916c059 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 10 Feb 2025 16:28:25 -0500 Subject: [PATCH 6/6] lint fix --- modules/core/04-channel/v2/genesis_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/04-channel/v2/genesis_test.go b/modules/core/04-channel/v2/genesis_test.go index df567f817de..e56be7b23a2 100644 --- a/modules/core/04-channel/v2/genesis_test.go +++ b/modules/core/04-channel/v2/genesis_test.go @@ -3,7 +3,6 @@ package channelv2_test import ( channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" - ibctesting "github.com/cosmos/ibc-go/v9/testing" )