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

imp(e2e): added generic grpc querier #5979

Merged
merged 30 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f23688e
e2e: testsuite updated
srdtrk Mar 12, 2024
1ff12e7
test: fixed client_test
srdtrk Mar 12, 2024
807271d
test: fixed ica tests
srdtrk Mar 12, 2024
a23f860
e2e: query refactor and fix more tests
srdtrk Mar 12, 2024
2054c12
test: fixed more tests
srdtrk Mar 13, 2024
e7a88a8
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Mar 13, 2024
59d1b5a
style: ran 'golangci-lint'
srdtrk Mar 13, 2024
e31f5d5
style: renamed query methods
srdtrk Mar 13, 2024
537dc24
refactor: fix more golangci-lint errors
srdtrk Mar 13, 2024
31af2a1
e2e: attempted fix of client state query
srdtrk Mar 13, 2024
c81e897
test: fix and refactor
srdtrk Mar 13, 2024
ea357db
test: attempted fix of cmttypes
srdtrk Mar 13, 2024
d88dd4a
imp: fixed queries for cmttypes
srdtrk Mar 13, 2024
3e943fc
fix: attempted fix for assert relayed
srdtrk Mar 13, 2024
ef4e8bc
fix: assert relayed
srdtrk Mar 13, 2024
d4dad0b
imp: client fix
srdtrk Mar 13, 2024
143de08
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Mar 14, 2024
692c6e9
fix: new test
srdtrk Mar 15, 2024
66674b3
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Mar 15, 2024
395380d
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 2, 2024
cb78e06
docs: fix godocs
srdtrk Apr 2, 2024
71e1b66
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 2, 2024
168bd97
style: ran golangci-lint
srdtrk Apr 2, 2024
ec95453
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 3, 2024
da9d1f0
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 3, 2024
263d2ff
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 4, 2024
ba64d51
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
DimitrisJim Apr 9, 2024
893ab53
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 15, 2024
adad7f8
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
crodriguezvega Apr 15, 2024
467178a
Merge branch 'main' into serdar/issue#5714-e2e-grpc-querier
srdtrk Apr 16, 2024
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
72 changes: 35 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{})
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -118,26 +105,33 @@ 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{})

clientStateAny := upgradedCsResp.UpgradedClientState
s.Require().NoError(err)

cs, err := clienttypes.UnpackClientState(clientStateAny)
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 @@ -211,13 +205,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 @@ -230,13 +224,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 @@ -294,20 +288,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 @@ -316,13 +310,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 @@ -353,7 +347,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 @@ -369,7 +363,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 @@ -385,12 +379,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 @@ -425,7 +423,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 @@ -460,7 +458,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 @@ -484,7 +482,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
27 changes: 14 additions & 13 deletions e2e/tests/interchain_accounts/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order chan

t.Run("verify interchain account", func(t *testing.T) {
var err error
hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
hostAccount, err = query.InterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
s.Require().NoError(err)
s.Require().NotZero(len(hostAccount))

Expand Down Expand Up @@ -142,10 +143,10 @@ func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order chan
})

t.Run("verify tokens transferred", func(t *testing.T) {
balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
balance, err := query.Balance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
s.Require().NoError(err)

_, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom)
_, err = query.Balance(ctx, chainB, hostAccount, chainB.Config().Denom)
s.Require().NoError(err)

expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
Expand Down Expand Up @@ -185,7 +186,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientF

t.Run("verify interchain account", func(t *testing.T) {
var err error
hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
hostAccount, err = query.InterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
s.Require().NoError(err)
s.Require().NotZero(len(hostAccount))

Expand All @@ -196,7 +197,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientF

t.Run("fail to execute bank transfer over ICA", func(t *testing.T) {
t.Run("verify empty host wallet", func(t *testing.T) {
hostAccountBalance, err := s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom)
hostAccountBalance, err := query.Balance(ctx, chainB, hostAccount, chainB.Config().Denom)

s.Require().NoError(err)
s.Require().Zero(hostAccountBalance.Int64())
Expand Down Expand Up @@ -235,7 +236,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientF
})

t.Run("verify balance is the same", func(t *testing.T) {
balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
balance, err := query.Balance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
s.Require().NoError(err)

expected := testvalues.StartingTokenAmount
Expand Down Expand Up @@ -283,11 +284,11 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop

t.Run("verify interchain account", func(t *testing.T) {
var err error
hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
hostAccount, err = query.InterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
s.Require().NoError(err)
s.Require().NotZero(len(hostAccount))

_, err = s.QueryChannel(ctx, chainA, portID, initialChannelID)
_, err = query.Channel(ctx, chainA, portID, initialChannelID)
s.Require().NoError(err)
})

Expand Down Expand Up @@ -347,17 +348,17 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
})

t.Run("verify channel is closed due to timeout on ordered channel", func(t *testing.T) {
channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID)
channel, err := query.Channel(ctx, chainA, portID, initialChannelID)
s.Require().NoError(err)

s.Require().Equal(channeltypes.CLOSED, channel.State, "the channel was not in an expected state")
})

t.Run("verify tokens not transferred", func(t *testing.T) {
balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
balance, err := query.Balance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
s.Require().NoError(err)

_, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom)
_, err = query.Balance(ctx, chainB, hostAccount, chainB.Config().Denom)
s.Require().NoError(err)

expected := testvalues.StartingTokenAmount
Expand All @@ -376,7 +377,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
})

t.Run("verify new channel is now open and interchain account has been reregistered with the same portID", func(t *testing.T) {
channel, err := s.QueryChannel(ctx, chainA, portID, channelIDAfterReopening)
channel, err := query.Channel(ctx, chainA, portID, channelIDAfterReopening)
s.Require().NoError(err)

s.Require().Equal(channeltypes.OPEN, channel.State, "the channel was not in an expected state")
Expand Down Expand Up @@ -417,7 +418,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
})

t.Run("verify tokens transferred", func(t *testing.T) {
balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
balance, err := query.Balance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
s.Require().NoError(err)

expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
Expand Down
Loading
Loading