|
8 | 8 |
|
9 | 9 | "github.com/cosmos/cosmos-sdk/types/query"
|
10 | 10 |
|
| 11 | + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" |
11 | 12 | "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper"
|
12 | 13 | "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
|
13 | 14 | commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
|
@@ -89,6 +90,106 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
|
89 | 90 | }
|
90 | 91 | }
|
91 | 92 |
|
| 93 | +func (suite *KeeperTestSuite) TestQueryChannelClientState() { |
| 94 | + var ( |
| 95 | + req *types.QueryChannelClientStateRequest |
| 96 | + expIdentifiedClientState clienttypes.IdentifiedClientState |
| 97 | + ) |
| 98 | + |
| 99 | + testCases := []struct { |
| 100 | + msg string |
| 101 | + malleate func() |
| 102 | + expError error |
| 103 | + }{ |
| 104 | + { |
| 105 | + "success", |
| 106 | + func() { |
| 107 | + path := ibctesting.NewPath(suite.chainA, suite.chainB) |
| 108 | + path.SetupV2() |
| 109 | + |
| 110 | + expClientState := suite.chainA.GetClientState(path.EndpointA.ClientID) |
| 111 | + expIdentifiedClientState = clienttypes.NewIdentifiedClientState(path.EndpointA.ClientID, expClientState) |
| 112 | + |
| 113 | + req = &types.QueryChannelClientStateRequest{ |
| 114 | + ChannelId: path.EndpointA.ChannelID, |
| 115 | + } |
| 116 | + }, |
| 117 | + nil, |
| 118 | + }, |
| 119 | + { |
| 120 | + "empty request", |
| 121 | + func() { |
| 122 | + req = nil |
| 123 | + }, |
| 124 | + status.Error(codes.InvalidArgument, "empty request"), |
| 125 | + }, |
| 126 | + { |
| 127 | + "invalid channel ID", |
| 128 | + func() { |
| 129 | + req = &types.QueryChannelClientStateRequest{ |
| 130 | + ChannelId: "", |
| 131 | + } |
| 132 | + }, |
| 133 | + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), |
| 134 | + }, |
| 135 | + { |
| 136 | + "channel not found", |
| 137 | + func() { |
| 138 | + req = &types.QueryChannelClientStateRequest{ |
| 139 | + ChannelId: "test-channel-id", |
| 140 | + } |
| 141 | + }, |
| 142 | + status.Error(codes.NotFound, fmt.Sprintf("channel-id: %s: channel not found", "test-channel-id")), |
| 143 | + }, |
| 144 | + { |
| 145 | + "client state not found", |
| 146 | + func() { |
| 147 | + path := ibctesting.NewPath(suite.chainA, suite.chainB) |
| 148 | + path.SetupV2() |
| 149 | + |
| 150 | + channel, found := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID) |
| 151 | + suite.Require().True(found) |
| 152 | + channel.ClientId = ibctesting.SecondClientID |
| 153 | + |
| 154 | + path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID, channel) |
| 155 | + |
| 156 | + req = &types.QueryChannelClientStateRequest{ |
| 157 | + ChannelId: path.EndpointA.ChannelID, |
| 158 | + } |
| 159 | + }, |
| 160 | + status.Error(codes.NotFound, fmt.Sprintf("client-id: %s: light client not found", ibctesting.SecondClientID)), |
| 161 | + }, |
| 162 | + } |
| 163 | + |
| 164 | + for _, tc := range testCases { |
| 165 | + tc := tc |
| 166 | + |
| 167 | + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { |
| 168 | + suite.SetupTest() // reset |
| 169 | + |
| 170 | + tc.malleate() |
| 171 | + ctx := suite.chainA.GetContext() |
| 172 | + |
| 173 | + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeperV2) |
| 174 | + res, err := queryServer.ChannelClientState(ctx, req) |
| 175 | + |
| 176 | + expPass := tc.expError == nil |
| 177 | + if expPass { |
| 178 | + suite.Require().NoError(err) |
| 179 | + suite.Require().NotNil(res) |
| 180 | + suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState) |
| 181 | + |
| 182 | + // ensure UnpackInterfaces is defined |
| 183 | + cachedValue := res.IdentifiedClientState.ClientState.GetCachedValue() |
| 184 | + suite.Require().NotNil(cachedValue) |
| 185 | + } else { |
| 186 | + suite.Require().ErrorIs(err, tc.expError) |
| 187 | + suite.Require().Nil(res) |
| 188 | + } |
| 189 | + }) |
| 190 | + } |
| 191 | +} |
| 192 | + |
92 | 193 | func (suite *KeeperTestSuite) TestQueryPacketCommitment() {
|
93 | 194 | var (
|
94 | 195 | expCommitment []byte
|
|
0 commit comments