Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into host_params
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Apr 16, 2024
2 parents 1670d17 + 8af554c commit f4f883b
Show file tree
Hide file tree
Showing 27 changed files with 658 additions and 802 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ lint-fix:
@echo "--> Running linter"
@./scripts/go-lint-all.sh --fix

#? format: Run gofumpt and mispell
#? format: Run gofumpt and misspell
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs misspell -w
Expand Down
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 f4f883b

Please sign in to comment.