Skip to content

Commit

Permalink
Add tests for querying the UpgradedClientState endpoint. (cosmos#5711)
Browse files Browse the repository at this point in the history
* Add tests for querying the UpgradedClientState endpoint.

* nit: linter nits.

* Update modules/core/02-client/keeper/grpc_query_test.go

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
DimitrisJim and crodriguezvega committed Jan 24, 2024
1 parent 01e6c7c commit 942efd7
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package keeper_test
import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

upgradetypes "cosmossdk.io/x/upgrade/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/query"

Expand Down Expand Up @@ -590,6 +595,113 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() {
}
}

func (suite *KeeperTestSuite) TestQueryUpgradedClientState() {
var (
req *types.QueryUpgradedClientStateRequest
path *ibctesting.Path
expClientState *ibctm.ClientState
)

upgradePlan := upgradetypes.Plan{
Name: "upgrade IBC clients",
Height: 1000,
}

testCases := []struct {
msg string
malleate func()
expError error
}{
{
"success",
func() {
validAuthority := suite.chainA.App.GetIBCKeeper().GetAuthority()

// update trusting period
clientState := path.EndpointA.GetClientState()
clientState.(*ibctm.ClientState).TrustingPeriod += 100

msg, err := types.NewMsgIBCSoftwareUpgrade(
validAuthority,
upgradePlan,
clientState,
)
suite.Require().NoError(err)

resp, err := suite.chainA.App.GetIBCKeeper().IBCSoftwareUpgrade(suite.chainA.GetContext(), msg)
suite.Require().NoError(err)
suite.Require().NotNil(resp)

expClientState = clientState.(*ibctm.ClientState)
},
nil,
},
{
"req is nil",
func() {
req = nil
},
status.Error(codes.InvalidArgument, "empty request"),
},
{
"no plan",
func() {
req = &types.QueryUpgradedClientStateRequest{}
},
status.Error(codes.NotFound, "upgrade plan not found"),
},
{
"no upgraded client set in store",
func() {
err := suite.chainA.GetSimApp().UpgradeKeeper.ScheduleUpgrade(suite.chainA.GetContext(), upgradePlan)
suite.Require().NoError(err)
},
status.Error(codes.NotFound, "upgraded client not found"),
},
{
"invalid upgraded client state",
func() {
err := suite.chainA.GetSimApp().UpgradeKeeper.ScheduleUpgrade(suite.chainA.GetContext(), upgradePlan)
suite.Require().NoError(err)

bz := []byte{1, 2, 3}
err = suite.chainA.GetSimApp().UpgradeKeeper.SetUpgradedClient(suite.chainA.GetContext(), upgradePlan.Height, bz)
suite.Require().NoError(err)
},
status.Error(codes.Internal, "proto: Any: illegal tag 0 (wire type 1)"),
},
}

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

path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)

req = &types.QueryUpgradedClientStateRequest{}

tc.malleate()

res, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.UpgradedClientState(suite.chainA.GetContext(), req)

expPass := tc.expError == nil
if expPass {
suite.Require().NoError(err)

upgradedClientState, err := types.UnpackClientState(res.UpgradedClientState)
suite.Require().NoError(err)
upgradedClientStateCmt, ok := upgradedClientState.(*ibctm.ClientState)
suite.Require().True(ok)

suite.Require().Equal(expClientState.ZeroCustomFields(), upgradedClientStateCmt)
} else {
suite.Require().ErrorIs(err, tc.expError)
}
})
}
}

func (suite *KeeperTestSuite) TestQueryUpgradedConsensusStates() {
var (
req *types.QueryUpgradedConsensusStateRequest
Expand Down

0 comments on commit 942efd7

Please sign in to comment.