-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * move logic * fix all tests and types * genesis proto and gen * gen * godoc * core genesis * core genesis wiring * wire and test * lint fix * fmt * fmt * add defensive checks * fix all --------- Co-authored-by: Aditya <14364734+AdityaSripal@users.noreply.github.com>
- Loading branch information
1 parent
ec66b11
commit 5296070
Showing
49 changed files
with
2,827 additions
and
569 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,46 @@ | ||
package clientv2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" | ||
"github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
) | ||
|
||
// InitGenesis initializes the ibc client/v2 submodule's state from a provided genesis | ||
// state. | ||
func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
if err := gs.Validate(); err != nil { | ||
panic(fmt.Errorf("invalid genesis state: %w", err)) | ||
} | ||
|
||
for _, info := range gs.CounterpartyInfos { | ||
k.SetClientCounterparty(sdkCtx, info.ClientId, info.CounterpartyInfo) | ||
} | ||
} | ||
|
||
// ExportGenesis returns the ibc client/v2 submodule's exported genesis. | ||
func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
clients := k.ClientV1Keeper.GetAllGenesisClients(ctx) | ||
gs := types.GenesisState{ | ||
CounterpartyInfos: make([]types.GenesisCounterpartyInfo, 0), | ||
} | ||
for _, client := range clients { | ||
counterpartyInfo, found := k.GetClientCounterparty(sdkCtx, client.ClientId) | ||
if found { | ||
gs.CounterpartyInfos = append(gs.CounterpartyInfos, types.GenesisCounterpartyInfo{ | ||
ClientId: client.ClientId, | ||
CounterpartyInfo: counterpartyInfo, | ||
}) | ||
} | ||
} | ||
|
||
return gs | ||
} |
This file contains 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,54 @@ | ||
package clientv2_test | ||
|
||
import ( | ||
clientv2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2" | ||
"github.com/cosmos/ibc-go/v9/modules/core/02-client/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() | ||
|
||
path3 := ibctesting.NewPath(suite.chainB, suite.chainC) | ||
path3.SetupV2() | ||
|
||
app := suite.chainA.App | ||
|
||
emptyGenesis := types.DefaultGenesisState() | ||
|
||
// create a valid genesis state that uses the counterparty info set during setup | ||
existingGS := clientv2.ExportGenesis(suite.chainA.GetContext(), app.GetIBCKeeper().ClientV2Keeper) | ||
|
||
tests := []struct { | ||
name string | ||
genState types.GenesisState | ||
expectedState types.GenesisState | ||
}{ | ||
{ | ||
name: "no modifications genesis", | ||
genState: emptyGenesis, | ||
expectedState: existingGS, | ||
}, | ||
{ | ||
name: "valid - default genesis", | ||
genState: types.DefaultGenesisState(), | ||
expectedState: existingGS, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
suite.Run(tt.name, func() { | ||
clientV2Keeper := app.GetIBCKeeper().ClientV2Keeper | ||
|
||
clientv2.InitGenesis(suite.chainA.GetContext(), clientV2Keeper, tt.genState) | ||
|
||
exported := clientv2.ExportGenesis(suite.chainA.GetContext(), clientV2Keeper) | ||
suite.Require().Equal(tt.expectedState, exported) | ||
}) | ||
} | ||
} |
This file contains 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,49 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
host "github.com/cosmos/ibc-go/v9/modules/core/24-host" | ||
) | ||
|
||
var _ types.QueryServer = (*queryServer)(nil) | ||
|
||
// queryServer implements the 02-client/v2 types.QueryServer interface. | ||
// It embeds the client keeper to leverage store access while limiting the api of the client keeper. | ||
type queryServer struct { | ||
*Keeper | ||
} | ||
|
||
// NewQueryServer returns a new 02-client/v2 types.QueryServer implementation. | ||
func NewQueryServer(k *Keeper) types.QueryServer { | ||
return &queryServer{ | ||
Keeper: k, | ||
} | ||
} | ||
|
||
// CounterpartyInfo gets the CounterpartyInfo from the store corresponding to the request client ID. | ||
func (q queryServer) CounterpartyInfo(ctx context.Context, req *types.QueryCounterpartyInfoRequest) (*types.QueryCounterpartyInfoResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
if err := host.ClientIdentifierValidator(req.ClientId); err != nil { | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
|
||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
info, found := q.GetClientCounterparty(sdkCtx, req.ClientId) | ||
if !found { | ||
return nil, status.Error(codes.NotFound, fmt.Sprintf("client %s counterparty not found", req.ClientId)) | ||
} | ||
|
||
return &types.QueryCounterpartyInfoResponse{CounterpartyInfo: &info}, nil | ||
} |
Oops, something went wrong.