-
Notifications
You must be signed in to change notification settings - Fork 751
feat: channel-v2 genesis #7933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: channel-v2 genesis #7933
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b22155e
add
6459667
fix and wire to core
fb1c3db
sequence check and cleanup
71d127e
Merge branch 'main' into feat/channel-v2-genesis
3bb7753
have more than one client in state on tests
AdityaSripal aecd1a2
refactor
8e13af6
lint fix
4a3cd5c
Merge branch 'main' into feat/channel-v2-genesis
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package channelv2 | ||
|
|
||
| import ( | ||
| "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" | ||
| ) | ||
|
|
||
| func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { | ||
| // set acks | ||
| for _, ack := range gs.Acknowledgements { | ||
| k.SetPacketAcknowledgement(ctx, ack.ClientId, ack.Sequence, ack.Data) | ||
| } | ||
|
|
||
| // set commits | ||
| for _, commitment := range gs.Commitments { | ||
| k.SetPacketCommitment(ctx, commitment.ClientId, commitment.Sequence, commitment.Data) | ||
| } | ||
|
|
||
| // set receipts | ||
| for _, receipt := range gs.Receipts { | ||
| k.SetPacketReceipt(ctx, receipt.ClientId, receipt.Sequence) | ||
| } | ||
|
|
||
| // set send sequences | ||
| for _, seq := range gs.SendSequences { | ||
| k.SetNextSequenceSend(ctx, seq.ClientId, seq.Sequence) | ||
| } | ||
| } | ||
|
|
||
| func ExportGenesis(ctx context.Context, k *keeper.Keeper) 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| 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 *ModuleTestSuite) 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() | ||
|
|
||
| // 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() { | ||
| channelV2Keeper := app.GetIBCKeeper().ChannelKeeperV2 | ||
|
|
||
| channelv2.InitGenesis(suite.chainA.GetContext(), channelV2Keeper, tt.genState) | ||
|
|
||
| exported := channelv2.ExportGenesis(suite.chainA.GetContext(), channelV2Keeper) | ||
| suite.Require().Equal(tt.genState, exported) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.