Skip to content

Commit

Permalink
Add tests for querying the UpgradedClientState endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Jan 24, 2024
1 parent 6896814 commit 8690396
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 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,8 +3,11 @@ package keeper_test
import (
"fmt"

Check failure on line 5 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
upgradetypes "cosmossdk.io/x/upgrade/types"

Check failure on line 6 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc/codes"

Check failure on line 9 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
"google.golang.org/grpc/status"

"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down Expand Up @@ -590,6 +593,109 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() {
}
}

func (suite *KeeperTestSuite) TestQueryUpgradedClientStates() {
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)

_, err = suite.chainA.App.GetIBCKeeper().IBCSoftwareUpgrade(suite.chainA.GetContext(), msg)
suite.Require().NoError(err)

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() {
suite.chainA.GetSimApp().UpgradeKeeper.ScheduleUpgrade(suite.chainA.GetContext(), upgradePlan)

Check failure on line 653 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `.ScheduleUpgrade` is not checked (errcheck)
},
status.Error(codes.NotFound, "upgraded client not found"),
},
{
"invalid upgraded client state",
func() {
suite.chainA.GetSimApp().UpgradeKeeper.ScheduleUpgrade(suite.chainA.GetContext(), upgradePlan)

Check failure on line 660 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `.ScheduleUpgrade` is not checked (errcheck)

bz := []byte{1, 2, 3}
suite.chainA.GetSimApp().UpgradeKeeper.SetUpgradedClient(suite.chainA.GetContext(), upgradePlan.Height, bz)

Check failure on line 663 in modules/core/02-client/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `.SetUpgradedClient` is not checked (errcheck)
},
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 8690396

Please sign in to comment.