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

Add tests for querying the UpgradedClientState endpoint. #5711

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
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
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
Loading