Skip to content

Commit 6459667

Browse files
author
aljo242
committed
fix and wire to core
1 parent b22155e commit 6459667

File tree

6 files changed

+142
-90
lines changed

6 files changed

+142
-90
lines changed

modules/core/04-channel/v2/module.go

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,36 @@ package client
22

33
import (
44
"context"
5-
"encoding/json"
6-
"fmt"
75

86
"github.com/spf13/cobra"
97

10-
"cosmossdk.io/core/appmodule"
11-
12-
"github.com/cosmos/cosmos-sdk/codec"
138
sdk "github.com/cosmos/cosmos-sdk/types"
14-
"github.com/cosmos/cosmos-sdk/types/module"
159

1610
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli"
1711
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper"
1812
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
1913
)
2014

21-
var (
22-
_ appmodule.AppModule = (*AppModule)(nil)
23-
24-
_ module.AppModule = (*AppModule)(nil)
25-
_ module.HasGenesis = (*AppModule)(nil)
26-
)
27-
28-
// AppModule represents the AppModule for this module
29-
type AppModule struct {
30-
cdc codec.Codec
31-
keeper *keeper.Keeper
32-
}
33-
34-
func (AppModule) IsAppModule() {}
35-
36-
func (AppModule) IsOnePerModuleType() {}
37-
38-
func (m AppModule) DefaultGenesis() json.RawMessage {
39-
gs := types.DefaultGenesisState()
40-
return m.cdc.MustMarshalJSON(&gs)
41-
}
42-
43-
func (m AppModule) ValidateGenesis(data json.RawMessage) error {
44-
gs := &types.GenesisState{}
45-
err := m.cdc.UnmarshalJSON(data, gs)
46-
if err != nil {
47-
return err
48-
}
49-
50-
return gs.Validate()
51-
}
52-
53-
func (m AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error {
54-
gs := &types.GenesisState{}
55-
err := m.cdc.UnmarshalJSON(data, gs)
56-
if err != nil {
57-
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
58-
}
59-
15+
func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) {
6016
sdkCtx := sdk.UnwrapSDKContext(ctx)
61-
m.keeper.InitGenesis(sdkCtx, *gs)
62-
63-
return nil
17+
k.InitGenesis(sdkCtx, gs)
6418
}
6519

66-
func (m AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) {
20+
func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState {
6721
sdkCtx := sdk.UnwrapSDKContext(ctx)
68-
gs := m.keeper.ExportGenesis(sdkCtx)
69-
return json.Marshal(gs)
70-
}
71-
72-
// Name returns the IBC channel/v2 name
73-
func (AppModule) Name() string {
74-
return types.SubModuleName
22+
return k.ExportGenesis(sdkCtx)
7523
}
7624

7725
func Name() string {
78-
return AppModule{}.Name()
79-
}
80-
81-
// GetQueryCmd returns the root query command for IBC channels v2.
82-
func (AppModule) GetQueryCmd() *cobra.Command {
83-
return cli.GetQueryCmd()
26+
return types.SubModuleName
8427
}
8528

8629
// GetQueryCmd returns the root query command for IBC channels v2.
8730
func GetQueryCmd() *cobra.Command {
88-
return AppModule{}.GetQueryCmd()
89-
}
90-
91-
// GetTxCmd returns the root tx command for IBC channels v2.
92-
func (AppModule) GetTxCmd() *cobra.Command {
93-
return cli.NewTxCmd()
31+
return cli.GetQueryCmd()
9432
}
9533

9634
// GetTxCmd returns the root tx command for IBC channels v2.
9735
func GetTxCmd() *cobra.Command {
98-
return AppModule{}.GetTxCmd()
36+
return cli.NewTxCmd()
9937
}

modules/core/genesis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
client "github.com/cosmos/ibc-go/v9/modules/core/02-client"
77
connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection"
88
channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel"
9+
channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2"
910
"github.com/cosmos/ibc-go/v9/modules/core/keeper"
1011
"github.com/cosmos/ibc-go/v9/modules/core/types"
1112
)
@@ -18,6 +19,7 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, gs *types.GenesisState) e
1819
}
1920
connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis)
2021
channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis)
22+
channelv2.InitGenesis(ctx, k.ChannelKeeperV2, gs.ChannelV2Genesis)
2123
return nil
2224
}
2325

@@ -31,5 +33,6 @@ func ExportGenesis(ctx context.Context, k keeper.Keeper) (*types.GenesisState, e
3133
ClientGenesis: gs,
3234
ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper),
3335
ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper),
36+
ChannelV2Genesis: channelv2.ExportGenesis(ctx, k.ChannelKeeperV2),
3437
}, nil
3538
}

modules/core/genesis_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
1414
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
1515
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
16+
channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
1617
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
1718
"github.com/cosmos/ibc-go/v9/modules/core/exported"
1819
"github.com/cosmos/ibc-go/v9/modules/core/types"
@@ -145,6 +146,20 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
145146
0,
146147
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
147148
),
149+
ChannelV2Genesis: channelv2types.NewGenesisState(
150+
[]channelv2types.PacketState{
151+
channelv2types.NewPacketState(channel2, 1, []byte("ack")),
152+
},
153+
[]channelv2types.PacketState{
154+
channelv2types.NewPacketState(channel2, 1, []byte("")),
155+
},
156+
[]channelv2types.PacketState{
157+
channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")),
158+
},
159+
[]channelv2types.PacketSequence{
160+
channelv2types.NewPacketSequence(channel1, 1),
161+
},
162+
),
148163
},
149164
expError: nil,
150165
},
@@ -172,6 +187,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
172187
2,
173188
),
174189
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
190+
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
175191
},
176192
expError: errors.New("genesis metadata key cannot be empty"),
177193
},
@@ -189,6 +205,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
189205
0,
190206
connectiontypes.Params{},
191207
),
208+
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
192209
},
193210
expError: errors.New("invalid connection"),
194211
},
@@ -202,6 +219,21 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
202219
channeltypes.NewPacketState("(portID)", channel1, 1, []byte("ack")),
203220
},
204221
},
222+
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
223+
},
224+
expError: errors.New("invalid acknowledgement"),
225+
},
226+
{
227+
name: "invalid channel v2 genesis",
228+
genState: &types.GenesisState{
229+
ClientGenesis: clienttypes.DefaultGenesisState(),
230+
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
231+
ChannelGenesis: channeltypes.DefaultGenesisState(),
232+
ChannelV2Genesis: channelv2types.GenesisState{
233+
Acknowledgements: []channelv2types.PacketState{
234+
channelv2types.NewPacketState(channel1, 1, nil),
235+
},
236+
},
205237
},
206238
expError: errors.New("invalid acknowledgement"),
207239
},
@@ -305,6 +337,20 @@ func (suite *IBCTestSuite) TestInitGenesis() {
305337
0,
306338
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
307339
),
340+
ChannelV2Genesis: channelv2types.NewGenesisState(
341+
[]channelv2types.PacketState{
342+
channelv2types.NewPacketState(channel2, 1, []byte("ack")),
343+
},
344+
[]channelv2types.PacketState{
345+
channelv2types.NewPacketState(channel2, 1, []byte("")),
346+
},
347+
[]channelv2types.PacketState{
348+
channelv2types.NewPacketState(channel1, 1, []byte("commit_hash")),
349+
},
350+
[]channelv2types.PacketSequence{
351+
channelv2types.NewPacketSequence(channel1, 1),
352+
},
353+
),
308354
},
309355
},
310356
}

modules/core/types/genesis.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
77
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
88
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
9+
channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
910
)
1011

1112
var _ gogoprotoany.UnpackInterfacesMessage = (*GenesisState)(nil)
@@ -16,6 +17,7 @@ func DefaultGenesisState() *GenesisState {
1617
ClientGenesis: clienttypes.DefaultGenesisState(),
1718
ConnectionGenesis: connectiontypes.DefaultGenesisState(),
1819
ChannelGenesis: channeltypes.DefaultGenesisState(),
20+
ChannelV2Genesis: channelv2types.DefaultGenesisState(),
1921
}
2022
}
2123

@@ -35,5 +37,9 @@ func (gs *GenesisState) Validate() error {
3537
return err
3638
}
3739

38-
return gs.ChannelGenesis.Validate()
40+
if err := gs.ChannelGenesis.Validate(); err != nil {
41+
return err
42+
}
43+
44+
return gs.ChannelV2Genesis.Validate()
3945
}

modules/core/types/genesis.pb.go

Lines changed: 76 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)