Skip to content
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

IsFrozen() changed to Status() #140

Merged
merged 23 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8a5ab72
initial work, pause for feedback
colin-axner Apr 9, 2021
7afeca9
Merge branch 'main' of github.com:cosmos/ibc-go into colin/98-client-…
colin-axner Apr 22, 2021
0db05e6
IsFrozen() -> Status()
colin-axner Apr 26, 2021
47448e1
Merge branch 'main' of github.com:cosmos/ibc-go into colin/98-client-…
colin-axner Apr 26, 2021
7899060
fix bug
colin-axner Apr 26, 2021
400e719
fix tests
colin-axner Apr 26, 2021
e34a9af
remove typo
colin-axner Apr 26, 2021
9c4c899
add verify tests
colin-axner Apr 27, 2021
dc26cd3
error message and code cleanup
colin-axner Apr 27, 2021
94cafbe
self review fixes
colin-axner Apr 27, 2021
3ed46b2
Update modules/core/02-client/keeper/client.go
colin-axner Apr 27, 2021
2ae5339
Merge branch 'main' into colin/98-client-status
colin-axner Apr 27, 2021
ffd9e1b
add gRPC route to proto
colin-axner Apr 28, 2021
2f67828
add gRPC route and tests
colin-axner Apr 28, 2021
ea8644a
update changelog
colin-axner Apr 28, 2021
cb0eb3f
apply review suggestions
colin-axner Apr 28, 2021
0ac6588
Update modules/light-clients/06-solomachine/types/client_state_test.go
colin-axner Apr 28, 2021
8c4b1f1
code ordering
colin-axner Apr 28, 2021
d3e203c
Merge branch 'colin/98-client-status' of github.com:cosmos/ibc-go int…
colin-axner Apr 28, 2021
470dff8
Merge branch 'main' into colin/98-client-status
colin-axner Apr 29, 2021
90c9f29
add set consensus state helper function
colin-axner Apr 29, 2021
cca717d
use typed string for status
colin-axner May 3, 2021
2ad2e25
Merge branch 'main' into colin/98-client-status
colin-axner May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add gRPC route and tests
  • Loading branch information
colin-axner committed Apr 28, 2021
commit 2f67828c9be920b5d2c9606287f5960d3be7100b
27 changes: 27 additions & 0 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,33 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
}, nil
}

// ClientStatus implements the Query/ClientStatus gRPC method
func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, 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())
}

ctx := sdk.UnwrapSDKContext(c)
clientState, found := q.GetClientState(ctx, req.ClientId)
if !found {
return nil, status.Error(
codes.NotFound,
sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(),
)
}

clientStore := q.ClientStore(ctx, req.ClientId)
status := clientState.Status(ctx, clientStore, q.cdc)

return &types.QueryClientStatusResponse{
Status: status,
}, nil
}

// ClientParams implements the Query/ClientParams gRPC method
func (q Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
Expand Down
168 changes: 144 additions & 24 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func (suite *KeeperTestSuite) TestQueryClientState() {
malleate func()
expPass bool
}{
{"req is nil",
func() {
req = nil
},
false,
},
Comment on lines +31 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case panics using the old old testing setup. Another reason to use the new one 🙂

{"invalid clientID",
func() {
req = &types.QueryClientStateRequest{}
Expand All @@ -45,15 +51,15 @@ func (suite *KeeperTestSuite) TestQueryClientState() {
{
"success",
func() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, types.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)

var err error
expClientState, err = types.PackClientState(clientState)
expClientState, err = types.PackClientState(path.EndpointA.GetClientState())
suite.Require().NoError(err)

req = &types.QueryClientStateRequest{
ClientId: testClientID,
ClientId: path.EndpointA.ClientID,
}
},
true,
Expand All @@ -65,8 +71,8 @@ func (suite *KeeperTestSuite) TestQueryClientState() {
suite.SetupTest() // reset

tc.malleate()
ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.queryClient.ClientState(ctx, req)
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
res, err := suite.chainA.QueryServer.ClientState(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
Expand Down Expand Up @@ -94,6 +100,12 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
malleate func()
expPass bool
}{
{"req is nil",
func() {
req = nil
},
false,
},
{
"empty pagination",
func() {
Expand Down Expand Up @@ -179,6 +191,12 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
malleate func()
expPass bool
}{
{"req is nil",
func() {
req = nil
},
false,
},
{
"invalid clientID",
func() {
Expand All @@ -202,7 +220,7 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
"consensus state not found",
func() {
req = &types.QueryConsensusStateRequest{
ClientId: testClientID,
ClientId: ibctesting.FirstClientID,
LatestHeight: true,
}
},
Expand All @@ -211,19 +229,16 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
{
"success latest height",
func() {
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
cs := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), nil,
)
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)
cs := path.EndpointA.GetConsensusState(path.EndpointA.GetClientState().GetLatestHeight())

var err error
expConsensusState, err = types.PackConsensusState(cs)
suite.Require().NoError(err)

req = &types.QueryConsensusStateRequest{
ClientId: testClientID,
ClientId: path.EndpointA.ClientID,
LatestHeight: true,
}
},
Expand All @@ -232,19 +247,22 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
{
"success with height",
func() {
cs := ibctmtypes.NewConsensusState(
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), nil,
)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)
height := path.EndpointA.GetClientState().GetLatestHeight()
cs := path.EndpointA.GetConsensusState(height)

var err error
expConsensusState, err = types.PackConsensusState(cs)
suite.Require().NoError(err)

// update client to new height
path.EndpointA.UpdateClient()

req = &types.QueryConsensusStateRequest{
ClientId: testClientID,
RevisionNumber: 0,
RevisionHeight: height,
ClientId: path.EndpointA.ClientID,
RevisionNumber: height.GetRevisionNumber(),
RevisionHeight: height.GetRevisionHeight(),
}
},
true,
Expand All @@ -256,8 +274,8 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
suite.SetupTest() // reset

tc.malleate()
ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.queryClient.ConsensusState(ctx, req)
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
res, err := suite.chainA.QueryServer.ConsensusState(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
Expand Down Expand Up @@ -378,6 +396,102 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
}
}

func (suite *KeeperTestSuite) TestQueryClientStatus() {
var (
req *types.QueryClientStatusRequest
)

testCases := []struct {
msg string
malleate func()
expPass bool
expStatus string
}{
{"req is nil",
func() {
req = nil
},
false, "",
},
{"invalid clientID",
func() {
req = &types.QueryClientStatusRequest{}
},
false, "",
},
{"client not found",
func() {
req = &types.QueryClientStatusRequest{
ClientId: ibctesting.InvalidID,
}
},
false, "",
},
{
"Active client status",
func() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)
req = &types.QueryClientStatusRequest{
ClientId: path.EndpointA.ClientID,
}
},
true, exported.Active,
},
{
"Unknown client status",
func() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)
clientState := path.EndpointA.GetClientState().(*ibctmtypes.ClientState)

// increment latest height so no consensus state is stored
clientState.LatestHeight = clientState.LatestHeight.Increment().(types.Height)
path.EndpointA.SetClientState(clientState)

req = &types.QueryClientStatusRequest{
ClientId: path.EndpointA.ClientID,
}
},
true, exported.Unknown,
},
{
"Frozen client status",
func() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)
clientState := path.EndpointA.GetClientState().(*ibctmtypes.ClientState)

clientState.FrozenHeight = types.NewHeight(0, 1)
path.EndpointA.SetClientState(clientState)

req = &types.QueryClientStatusRequest{
ClientId: path.EndpointA.ClientID,
}
},
true, exported.Frozen,
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

tc.malleate()
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
res, err := suite.chainA.QueryServer.ClientStatus(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(tc.expStatus, res.Status)
} else {
suite.Require().Error(err)
}
})
}
}

func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() {
var (
req *types.QueryUpgradedConsensusStateRequest
Expand All @@ -390,6 +504,12 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() {
malleate func()
expPass bool
}{
{"req is nil",
func() {
req = nil
},
false,
},
{
"no plan",
func() {
Expand Down Expand Up @@ -437,6 +557,6 @@ func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() {
func (suite *KeeperTestSuite) TestQueryParams() {
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
expParams := types.DefaultParams()
res, _ := suite.queryClient.ClientParams(ctx, &types.QueryClientParamsRequest{})
res, _ := suite.chainA.QueryServer.ClientParams(ctx, &types.QueryClientParamsRequest{})
suite.Require().Equal(&expParams, res.Params)
}
2 changes: 2 additions & 0 deletions modules/core/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type KeeperTestSuite struct {
now time.Time
past time.Time

// TODO: deprecate
queryClient types.QueryClient
}

Expand Down Expand Up @@ -122,6 +123,7 @@ func (suite *KeeperTestSuite) SetupTest() {
)
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), exported.Localhost, localHostClient)

// TODO: deprecate
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.IBCKeeper.ClientKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)
Expand Down
Loading