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

e2e: schedule IBC software upgrade #4585

Merged
merged 21 commits into from
Sep 11, 2023
Merged
Changes from 8 commits
Commits
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
127 changes: 127 additions & 0 deletions e2e/tests/core/02-client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"cosmossdk.io/x/upgrade/types"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
test "github.com/strangelove-ventures/interchaintest/v7/testutil"
Expand Down Expand Up @@ -71,6 +72,132 @@ func (s *ClientTestSuite) QueryAllowedClients(ctx context.Context, chain ibc.Cha
return res.Params.AllowedClients
}

func (s *ClientTestSuite) TestClientUpdateProposal_Succeeds() {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
t := s.T()
ctx := context.TODO()

var (
pathName string
relayer ibc.Relayer
subjectClientID string
substituteClientID string
// set the trusting period to a value which will still be valid upon client creation, but invalid before the first update
badTrustingPeriod = time.Second * 10
)

t.Run("create substitute client with correct trusting period", func(t *testing.T) {
relayer, _ = s.SetupChainsRelayerAndChannel(ctx)

// TODO: update when client identifier created is accessible
// currently assumes first client is 07-tendermint-0
substituteClientID = clienttypes.FormatClientIdentifier(ibcexported.Tendermint, 0)

// TODO: replace with better handling of path names
pathName = fmt.Sprintf("%s-path-%d", s.T().Name(), 0)
pathName = strings.ReplaceAll(pathName, "/", "-")
})

chainA, chainB := s.GetChains()
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

t.Run("create subject client with bad trusting period", func(t *testing.T) {
createClientOptions := ibc.CreateClientOptions{
TrustingPeriod: badTrustingPeriod.String(),
}

s.SetupClients(ctx, relayer, createClientOptions)

// TODO: update when client identifier created is accessible
// currently assumes second client is 07-tendermint-1
subjectClientID = clienttypes.FormatClientIdentifier(ibcexported.Tendermint, 1)
})

time.Sleep(badTrustingPeriod)

t.Run("update substitute client", func(t *testing.T) {
s.UpdateClients(ctx, relayer, pathName)
})

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")

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)
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)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Expired.String(), status)
})
})

t.Run("pass client update proposal", func(t *testing.T) {
proposal := clienttypes.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subjectClientID, substituteClientID)
s.ExecuteGovProposal(ctx, chainA, chainAWallet, proposal)
})

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)
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)
s.Require().NoError(err)
s.Require().Equal(ibcexported.Active.String(), status)
})
})
}

// TestScheduleIBCUpgrade_Succeeds tests that a governance proposal to schedule an IBC software upgrade is successful.
func (s *ClientTestSuite) TestScheduleIBCUpgrade_Succeeds() {
t := s.T()
ctx := context.TODO()

_, _ = s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

var (
originalTrustingPeriod time.Duration
newTrustingPeriod time.Duration
)

t.Run("send schedule IBC upgrade message", func(t *testing.T) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)
charleenfei marked this conversation as resolved.
Show resolved Hide resolved

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

originalTrustingPeriod = clientState.(*ibctm.ClientState).TrustingPeriod
newTrustingPeriod = originalTrustingPeriod + time.Duration(time.Hour*24)

upgradedClientState := clientState.(*ibctm.ClientState)
upgradedClientState.TrustingPeriod = newTrustingPeriod

latestHeight, err := chainA.Height(ctx)
s.Require().NoError(err)

scheduleUpgradeMsg, err := clienttypes.NewMsgIBCSoftwareUpgrade(
authority.String(),
types.Plan{
Name: "upgrade-client",
Height: int64(latestHeight + 50),
},
upgradedClientState,
)
s.Require().NoError(err)
s.ExecuteGovProposalV1(ctx, scheduleUpgradeMsg, chainA, chainAWallet, 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to query if the plan has been stored/upgraded client state was stored, but realised after digging around that the UpgradeKeeper doesn't seem to have a query client. what do you guys think? our msg_server tests do perform this check, is that sufficient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try to upgrade the client on the counterparty. Hermes might do it automatically. Maybe try starting the relayer and querying the client's status afterward

Copy link
Member

@damiannolan damiannolan Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC correctly hermes previously had an upgrade client cmd which actually submitted the proposal on your behalf. See here - and also here

At a glance I think this is supposed to be doing the upgrade client flow, but I'm unsure how hermes handles this. Does it block and wait(?) until upgrade height, then query the upgradedClient at upgradePath and then upgrade the counterparty.

I think their cmd would need to change for gov v1, maybe it still uses the legacy v1beta1 appraoch

edit: added additional link - looks like they have cmd to send proposal and separate to then carry out the upgrade, my thinking would be that the latter blocks and waits for upgrade height

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try to upgrade the client on the counterparty. Hermes might do it automatically. Maybe try starting the relayer and querying the client's status afterward

Might need to check if interchaintest has built in the support for client updates. Hermes can do it based on the links in my first comment. But I'm unsure if rly also has the same support, and interchaintest would need to expose an API for it in their relayer interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added event emission when the consensus state is written allowing the counterparty client to be upgraded, unsure if hermes started listening for that event

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I regress on my suggestion, happy to finish the full e2e of upgrading the client in a followup pr as this isn't essential for v8 testing

Copy link
Contributor Author

@charleenfei charleenfei Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after discussion with @colin-axner , will just merge this e2e testing the scope of the ScheduleIBCSoftwareUpgrade for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think their cmd would need to change for gov v1, maybe it still uses the legacy v1beta1 appraoch

You're right, @damiannolan: hermes is using gov v1beta proposal. Let's ask them.

})
}

// TestRecoverClient_Succeeds tests that a governance proposal to recover a client using a MsgRecoverClient is successful.
func (s *ClientTestSuite) TestRecoverClient_Succeeds() {
t := s.T()
Expand Down
Loading