-
Notifications
You must be signed in to change notification settings - Fork 629
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: add client recovery proposal test #2130
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f7a71e
add scaffolding
colin-axner 0aca07e
continue scaffolding
colin-axner 14678db
Merge branch 'main' of github.com:cosmos/ibc-go into colin/1965-e2e-c…
colin-axner 35a8a78
add client recovery proposal test
colin-axner 70fcd8a
generate a new path when creating clients
colin-axner c81598f
Merge branch 'main' of github.com:cosmos/ibc-go into colin/1965-e2e-c…
colin-axner 000b56d
apply e2e restructure
colin-axner 69fa664
Update e2e/testsuite/testsuite.go
colin-axner d8b426d
bump relayer version to v2.0.0
colin-axner 4604820
Merge branch 'main' into colin/1965-e2e-client-updateproposal
colin-axner f7df074
Merge branch 'main' into colin/1965-e2e-client-updateproposal
colin-axner 7a81543
Merge branch 'main' into colin/1965-e2e-client-updateproposal
colin-axner c5e103a
Merge branch 'main' into colin/1965-e2e-client-updateproposal
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/strangelove-ventures/ibctest/ibc" | ||
"github.com/strangelove-ventures/ibctest/test" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/ibc-go/e2e/testsuite" | ||
"github.com/cosmos/ibc-go/e2e/testvalues" | ||
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" | ||
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" | ||
ibctesting "github.com/cosmos/ibc-go/v5/testing" | ||
) | ||
|
||
func TestClientTestSuite(t *testing.T) { | ||
suite.Run(t, new(ClientTestSuite)) | ||
} | ||
|
||
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 | ||
} | ||
|
||
func (s *ClientTestSuite) TestClientUpdateProposal_Succeeds() { | ||
t := s.T() | ||
ctx := context.TODO() | ||
|
||
var ( | ||
pathName string | ||
relayer ibc.Relayer | ||
subjectClientID string | ||
substituteClientID string | ||
badTrustingPeriod = time.Duration(time.Second) | ||
) | ||
|
||
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) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ type E2ETestSuite struct { | |
DockerClient *dockerclient.Client | ||
network string | ||
startRelayerFn func(relayer ibc.Relayer) | ||
|
||
// pathNameIndex is the latest index to be used for generating paths | ||
pathNameIndex uint64 | ||
} | ||
|
||
// GRPCClients holds a reference to any GRPC clients that are needed by the tests. | ||
|
@@ -110,8 +113,7 @@ func (s *E2ETestSuite) SetupChainsRelayerAndChannel(ctx context.Context, channel | |
|
||
r := newCosmosRelayer(s.T(), testconfig.FromEnv(), s.logger, s.DockerClient, s.network) | ||
|
||
pathName := fmt.Sprintf("%s-path", s.T().Name()) | ||
pathName = strings.ReplaceAll(pathName, "/", "-") | ||
pathName := s.generatePathName() | ||
|
||
ic := ibctest.NewInterchain(). | ||
AddChain(chainA). | ||
|
@@ -159,6 +161,39 @@ func (s *E2ETestSuite) SetupChainsRelayerAndChannel(ctx context.Context, channel | |
return r, chainAChannels[len(chainAChannels)-1] | ||
} | ||
|
||
// generatePathName generates the path name using the test suites name | ||
func (s *E2ETestSuite) generatePathName() string { | ||
pathName := fmt.Sprintf("%s-path-%d", s.T().Name(), s.pathNameIndex) | ||
s.pathNameIndex++ | ||
return strings.ReplaceAll(pathName, "/", "-") | ||
Comment on lines
+166
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for every endpoint (client/connection/channel) stack we need a new path name, so I added an index kept by the |
||
} | ||
|
||
// generatePath generates the path name using the test suites name | ||
func (s *E2ETestSuite) generatePath(ctx context.Context, relayer ibc.Relayer) string { | ||
chainA, chainB := s.GetChains() | ||
chainAID := chainA.Config().ChainID | ||
chainBID := chainB.Config().ChainID | ||
|
||
pathName := s.generatePathName() | ||
err := relayer.GeneratePath(ctx, s.GetRelayerExecReporter(), chainAID, chainBID, pathName) | ||
s.Require().NoError(err) | ||
|
||
return pathName | ||
} | ||
|
||
// SetupClients creates clients on chainA and chainB using the provided create client options | ||
func (s *E2ETestSuite) SetupClients(ctx context.Context, relayer ibc.Relayer, opts ibc.CreateClientOptions) { | ||
pathName := s.generatePath(ctx, relayer) | ||
err := relayer.CreateClients(ctx, s.GetRelayerExecReporter(), pathName, opts) | ||
s.Require().NoError(err) | ||
} | ||
|
||
// UpdateClients updates clients on chainA and chainB using the provided create client options | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (s *E2ETestSuite) UpdateClients(ctx context.Context, relayer ibc.Relayer, pathName string) { | ||
err := relayer.UpdateClients(ctx, s.GetRelayerExecReporter(), pathName) | ||
s.Require().NoError(err) | ||
} | ||
|
||
// GetChains returns two chains that can be used in a test. The pair returned | ||
// is unique to the current test being run. Note: this function does not create containers. | ||
func (s *E2ETestSuite) GetChains(chainOpts ...testconfig.ChainOptionConfiguration) (*cosmos.CosmosChain, *cosmos.CosmosChain) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are a bit hacky, but I think it is better to just do this for now and figure out a better solution later. I think adding the endpoint type should solve the issue in both cases