Skip to content

Commit

Permalink
imp(e2e): added generic grpc querier (#5979)
Browse files Browse the repository at this point in the history
* e2e: testsuite updated

* test: fixed client_test

* test: fixed ica tests

* e2e: query refactor and fix more tests

* test: fixed more tests

* style: ran 'golangci-lint'

* style: renamed query methods

* refactor: fix more golangci-lint errors

* e2e: attempted fix of client state query

* test: fix and refactor

* test: attempted fix of cmttypes

* imp: fixed queries for cmttypes

* fix: attempted fix for assert relayed

* fix: assert relayed

* imp: client fix

* fix: new test

* docs: fix godocs

* style: ran golangci-lint

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
3 people authored Apr 16, 2024
1 parent ca33574 commit bb4ce39
Show file tree
Hide file tree
Showing 24 changed files with 636 additions and 787 deletions.
74 changes: 37 additions & 37 deletions e2e/tests/core/02-client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/cosmos/ibc-go/e2e/dockerutil"
"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
Expand All @@ -51,23 +52,9 @@ type ClientTestSuite struct {
testsuite.E2ETestSuite
}

// Status queries the current status of the client
func (s *ClientTestSuite) Status(ctx context.Context, chain ibc.Chain, clientID string) (string, error) {
queryClient := s.GetChainGRCPClients(chain).ClientQueryClient
res, err := queryClient.ClientStatus(ctx, &clienttypes.QueryClientStatusRequest{
ClientId: clientID,
})
if err != nil {
return "", err
}

return res.Status, nil
}

// QueryAllowedClients queries the on-chain AllowedClients parameter for 02-client
func (s *ClientTestSuite) QueryAllowedClients(ctx context.Context, chain ibc.Chain) []string {
queryClient := s.GetChainGRCPClients(chain).ClientQueryClient
res, err := queryClient.ClientParams(ctx, &clienttypes.QueryClientParamsRequest{})
res, err := query.GRPCQuery[clienttypes.QueryClientParamsResponse](ctx, chain, &clienttypes.QueryClientParamsRequest{})
s.Require().NoError(err)

return res.Params.AllowedClients
Expand All @@ -87,11 +74,11 @@ func (s *ClientTestSuite) TestScheduleIBCUpgrade_Succeeds() {
var newChainID string

t.Run("execute proposal for MsgIBCSoftwareUpgrade", func(t *testing.T) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
authority, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)

clientState, err := s.QueryClientState(ctx, chainB, ibctesting.FirstClientID)
clientState, err := query.ClientState(ctx, chainB, ibctesting.FirstClientID)
s.Require().NoError(err)

originalChainID := clientState.(*ibctm.ClientState).ChainId
Expand Down Expand Up @@ -119,26 +106,35 @@ func (s *ClientTestSuite) TestScheduleIBCUpgrade_Succeeds() {

t.Run("check that IBC software upgrade has been scheduled successfully on chainA", func(t *testing.T) {
// checks there is an upgraded client state stored
cs, err := s.QueryUpgradedClientState(ctx, chainA, ibctesting.FirstClientID)
upgradedCsResp, err := query.GRPCQuery[clienttypes.QueryUpgradedClientStateResponse](ctx, chainA, &clienttypes.QueryUpgradedClientStateRequest{})
s.Require().NoError(err)

clientStateAny := upgradedCsResp.UpgradedClientState

cfg := chainA.Config().EncodingConfig
var cs ibcexported.ClientState
err = cfg.InterfaceRegistry.UnpackAny(clientStateAny, &cs)
s.Require().NoError(err)

upgradedClientState, ok := cs.(*ibctm.ClientState)
s.Require().True(ok)
s.Require().Equal(upgradedClientState.ChainId, newChainID)

plan, err := s.QueryCurrentUpgradePlan(ctx, chainA)
planResponse, err := query.GRPCQuery[upgradetypes.QueryCurrentPlanResponse](ctx, chainA, &upgradetypes.QueryCurrentPlanRequest{})
s.Require().NoError(err)

plan := planResponse.Plan

s.Require().Equal("upgrade-client", plan.Name)
s.Require().Equal(planHeight, plan.Height)
})

t.Run("ensure legacy proposal does not succeed", func(t *testing.T) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
authority, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)

clientState, err := s.QueryClientState(ctx, chainB, ibctesting.FirstClientID)
clientState, err := query.ClientState(ctx, chainB, ibctesting.FirstClientID)
s.Require().NoError(err)

originalChainID := clientState.(*ibctm.ClientState).ChainId
Expand Down Expand Up @@ -212,13 +208,13 @@ func (s *ClientTestSuite) TestClientUpdateProposal_Succeeds() {

t.Run("check status of each client", func(t *testing.T) {
t.Run("substitute should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, substituteClientID)
status, err := query.ClientStatus(ctx, chainA, substituteClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})

t.Run("subject should be expired", func(t *testing.T) {
status, err := s.Status(ctx, chainA, subjectClientID)
status, err := query.ClientStatus(ctx, chainA, subjectClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Expired.String(), status)
})
Expand All @@ -231,13 +227,13 @@ func (s *ClientTestSuite) TestClientUpdateProposal_Succeeds() {

t.Run("check status of each client", func(t *testing.T) {
t.Run("substitute should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, substituteClientID)
status, err := query.ClientStatus(ctx, chainA, substituteClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})

t.Run("subject should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, subjectClientID)
status, err := query.ClientStatus(ctx, chainA, subjectClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})
Expand Down Expand Up @@ -295,20 +291,20 @@ func (s *ClientTestSuite) TestRecoverClient_Succeeds() {

t.Run("check status of each client", func(t *testing.T) {
t.Run("substitute should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, substituteClientID)
status, err := query.ClientStatus(ctx, chainA, substituteClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})

t.Run("subject should be expired", func(t *testing.T) {
status, err := s.Status(ctx, chainA, subjectClientID)
status, err := query.ClientStatus(ctx, chainA, subjectClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Expired.String(), status)
})
})

t.Run("execute proposal for MsgRecoverClient", func(t *testing.T) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
authority, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
recoverClientMsg := clienttypes.NewMsgRecoverClient(authority.String(), subjectClientID, substituteClientID)
s.Require().NotNil(recoverClientMsg)
Expand All @@ -317,13 +313,13 @@ func (s *ClientTestSuite) TestRecoverClient_Succeeds() {

t.Run("check status of each client", func(t *testing.T) {
t.Run("substitute should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, substituteClientID)
status, err := query.ClientStatus(ctx, chainA, substituteClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})

t.Run("subject should be active", func(t *testing.T) {
status, err := s.Status(ctx, chainA, subjectClientID)
status, err := query.ClientStatus(ctx, chainA, subjectClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})
Expand Down Expand Up @@ -354,7 +350,7 @@ func (s *ClientTestSuite) TestClient_Update_Misbehaviour() {
err := relayer.UpdateClients(ctx, s.GetRelayerExecReporter(), s.GetPathName(0))
s.Require().NoError(err)

clientState, err = s.QueryClientState(ctx, chainA, ibctesting.FirstClientID)
clientState, err = query.ClientState(ctx, chainA, ibctesting.FirstClientID)
s.Require().NoError(err)
})

Expand All @@ -370,7 +366,7 @@ func (s *ClientTestSuite) TestClient_Update_Misbehaviour() {
err := relayer.UpdateClients(ctx, s.GetRelayerExecReporter(), s.GetPathName(0))
s.Require().NoError(err)

clientState, err = s.QueryClientState(ctx, chainA, ibctesting.FirstClientID)
clientState, err = query.ClientState(ctx, chainA, ibctesting.FirstClientID)
s.Require().NoError(err)
})

Expand All @@ -386,12 +382,16 @@ func (s *ClientTestSuite) TestClient_Update_Misbehaviour() {
var validators []*cmtservice.Validator

t.Run("fetch block header at latest client state height", func(t *testing.T) {
header, err = s.GetBlockHeaderByHeight(ctx, chainB, latestHeight.GetRevisionHeight())
headerResp, err := query.GRPCQuery[cmtservice.GetBlockByHeightResponse](ctx, chainB, &cmtservice.GetBlockByHeightRequest{
Height: int64(latestHeight.GetRevisionHeight()),
})
s.Require().NoError(err)

header = &headerResp.SdkBlock.Header
})

t.Run("get validators at latest height", func(t *testing.T) {
validators, err = s.GetValidatorSetByHeight(ctx, chainB, latestHeight.GetRevisionHeight())
validators, err = query.GetValidatorSetByHeight(ctx, chainB, latestHeight.GetRevisionHeight())
s.Require().NoError(err)
})

Expand Down Expand Up @@ -426,7 +426,7 @@ func (s *ClientTestSuite) TestClient_Update_Misbehaviour() {
})

t.Run("ensure client status is frozen", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, ibctesting.FirstClientID)
status, err := query.ClientStatus(ctx, chainA, ibctesting.FirstClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Frozen.String(), status)
})
Expand Down Expand Up @@ -461,7 +461,7 @@ func (s *ClientTestSuite) TestAllowedClientsParam() {
allowedClient := ibcexported.Solomachine
t.Run("change the allowed client to only allow solomachine clients", func(t *testing.T) {
if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
authority, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)

Expand All @@ -485,7 +485,7 @@ func (s *ClientTestSuite) TestAllowedClientsParam() {
})

t.Run("ensure querying non-allowed client's status returns Unauthorized Status", func(t *testing.T) {
status, err := s.QueryClientStatus(ctx, chainA, ibctesting.FirstClientID)
status, err := query.ClientStatus(ctx, chainA, ibctesting.FirstClientID)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Unauthorized.String(), status)
})
Expand Down
11 changes: 5 additions & 6 deletions e2e/tests/core/03-connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand All @@ -35,14 +36,12 @@ type ConnectionTestSuite struct {
// QueryMaxExpectedTimePerBlockParam queries the on-chain max expected time per block param for 03-connection
func (s *ConnectionTestSuite) QueryMaxExpectedTimePerBlockParam(ctx context.Context, chain ibc.Chain) uint64 {
if testvalues.SelfParamsFeatureReleases.IsSupported(chain.Config().Images[0].Version) {
queryClient := s.GetChainGRCPClients(chain).ConnectionQueryClient
res, err := queryClient.ConnectionParams(ctx, &connectiontypes.QueryConnectionParamsRequest{})
res, err := query.GRPCQuery[connectiontypes.QueryConnectionParamsResponse](ctx, chain, &connectiontypes.QueryConnectionParamsRequest{})
s.Require().NoError(err)

return res.Params.MaxExpectedTimePerBlock
}
queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient
res, err := queryClient.Params(ctx, &paramsproposaltypes.QueryParamsRequest{
res, err := query.GRPCQuery[paramsproposaltypes.QueryParamsResponse](ctx, chain, &paramsproposaltypes.QueryParamsRequest{
Subspace: ibcexported.ModuleName,
Key: string(connectiontypes.KeyMaxExpectedTimePerBlock),
})
Expand Down Expand Up @@ -85,7 +84,7 @@ func (s *ConnectionTestSuite) TestMaxExpectedTimePerBlockParam() {
t.Run("change the delay to 60 seconds", func(t *testing.T) {
delay := uint64(1 * time.Minute)
if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
authority, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)

Expand Down Expand Up @@ -128,7 +127,7 @@ func (s *ConnectionTestSuite) TestMaxExpectedTimePerBlockParam() {
t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1)

actualBalance, err := s.QueryBalance(ctx, chainA, chainAAddress, chainAIBCToken.IBCDenom())
actualBalance, err := query.Balance(ctx, chainA, chainAAddress, chainAIBCToken.IBCDenom())

s.Require().NoError(err)

Expand Down
Loading

0 comments on commit bb4ce39

Please sign in to comment.