Skip to content

Commit

Permalink
Fix Wasm E2E Tests (#6660)
Browse files Browse the repository at this point in the history
* wip: fixing wasm tests

* chore: fix wasm tests

* chore: removed excess log lines

---------

Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
chatton and damiannolan authored Jun 24, 2024
1 parent 5bfaa6b commit 62e51f2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 217 deletions.
212 changes: 44 additions & 168 deletions e2e/tests/wasm/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ func (s *GrandpaTestSuite) SetupSuite() {
})
}

func (s *GrandpaTestSuite) SetupTest() {
ctx := context.TODO()
chainA, chainB := s.GetChains()

polkadotChain, ok := chainA.(*polkadot.PolkadotChain)
s.Require().True(ok)

cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

file, err := os.Open("contracts/ics10_grandpa_cw.wasm.gz")
s.Require().NoError(err)

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

err = testutil.WaitForBlocks(ctx, 1, cosmosChain)
s.Require().NoError(err, "cosmos chain failed to make blocks")

s.T().Logf("waited for blocks cosmos wallet")

checksum := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file)
s.Require().NotEmpty(checksum, "checksum was empty but should not have been")
s.T().Log("pushed wasm client proposal")

r := s.GetRelayer()

err = r.SetClientContractHash(ctx, s.GetRelayerExecReporter(), cosmosChain.Config(), checksum)
s.Require().NoError(err)
s.T().Logf("set contract hash %s", checksum)

err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
s.Require().NoError(err, "polkadot chain failed to make blocks")

channelOpts := ibc.DefaultChannelOpts()
channelOpts.Version = transfertypes.V1
s.SetupPath(ibc.DefaultClientOpts(), channelOpts)
}

// TestMsgTransfer_Succeeds_GrandpaContract features
// * sets up a Polkadot parachain
// * sets up a Cosmos chain
Expand All @@ -140,30 +178,10 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() {
cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

// we explicitly skip path creation as the contract needs to be uploaded before we can create clients.
r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) {
options.SkipPathCreation = true
})

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

file, err := os.Open("contracts/ics10_grandpa_cw.wasm.gz")
s.Require().NoError(err)

checksum := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file)

s.Require().NotEmpty(checksum, "checksum was empty but should not have been")
r := s.GetRelayer()

eRep := s.GetRelayerExecReporter()

// Set client contract hash in cosmos chain config
err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), checksum)
s.Require().NoError(err)

// Ensure parachain has started (starts 1 session/epoch after relay chain)
err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
s.Require().NoError(err, "polkadot chain failed to make blocks")

// Fund users on both cosmos and parachain, mints Asset 1 for Alice
fundAmount := int64(12_333_000_000_000)
polkadotUser, cosmosUser := s.fundUsers(ctx, fundAmount, polkadotChain, cosmosChain)
Expand All @@ -177,31 +195,8 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() {
Amount: sdkmath.NewInt(amountToSend),
}

pathName := testsuite.GetPathName(0)

err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName)
s.Require().NoError(err)

// Create new clients
err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness
s.Require().NoError(err)

// Create a new connection
err = r.CreateConnections(ctx, eRep, pathName)
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain)
s.Require().NoError(err)

// Create a new channel & get channels from each chain
err = r.CreateChannel(ctx, eRep, pathName, ibc.DefaultChannelOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain)
s.Require().NoError(err)

// Start relayer
s.Require().NoError(r.StartRelayer(ctx, eRep, pathName))
s.Require().NoError(r.StartRelayer(ctx, eRep, s.GetPaths()...))

t.Run("send successful IBC transfer from Cosmos to Polkadot parachain", func(t *testing.T) {
// Send 1.77 stake from cosmosUser to parachainUser
Expand Down Expand Up @@ -293,30 +288,10 @@ func (s *GrandpaTestSuite) TestMsgTransfer_TimesOut_GrandpaContract() {
cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

// we explicitly skip path creation as the contract needs to be uploaded before we can create clients.
r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) {
options.SkipPathCreation = true
})

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

file, err := os.Open("contracts/ics10_grandpa_cw.wasm.gz")
s.Require().NoError(err)

checksum := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file)

s.Require().NotEmpty(checksum, "checksum was empty but should not have been")
r := s.GetRelayer()

eRep := s.GetRelayerExecReporter()

// Set client contract hash in cosmos chain config
err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), checksum)
s.Require().NoError(err)

// Ensure parachain has started (starts 1 session/epoch after relay chain)
err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
s.Require().NoError(err, "polkadot chain failed to make blocks")

// Fund users on both cosmos and parachain, mints Asset 1 for Alice
fundAmount := int64(12_333_000_000_000)
polkadotUser, cosmosUser := s.fundUsers(ctx, fundAmount, polkadotChain, cosmosChain)
Expand All @@ -332,27 +307,6 @@ func (s *GrandpaTestSuite) TestMsgTransfer_TimesOut_GrandpaContract() {

pathName := testsuite.GetPathName(0)

err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName)
s.Require().NoError(err)

// Create new clients
err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness
s.Require().NoError(err)

// Create a new connection
err = r.CreateConnections(ctx, eRep, pathName)
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain)
s.Require().NoError(err)

// Create a new channel & get channels from each chain
err = r.CreateChannel(ctx, eRep, pathName, ibc.DefaultChannelOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain)
s.Require().NoError(err)

// Start relayer
s.Require().NoError(r.StartRelayer(ctx, eRep, pathName))

Expand Down Expand Up @@ -400,49 +354,13 @@ func (s *GrandpaTestSuite) TestMsgTransfer_TimesOut_GrandpaContract() {
func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() {
ctx := context.Background()

chainA, chainB := s.GetChains()

polkadotChain, ok := chainA.(*polkadot.PolkadotChain)
s.Require().True(ok)
_, chainB := s.GetChains()

cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

// we explicitly skip path creation as the contract needs to be uploaded before we can create clients.
r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) {
options.SkipPathCreation = true
})

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

file, err := os.Open("contracts/ics10_grandpa_cw.wasm.gz")
s.Require().NoError(err)

checksum := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file)

s.Require().NotEmpty(checksum, "checksum was empty but should not have been")

eRep := s.GetRelayerExecReporter()

// Set client contract hash in cosmos chain config
err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), checksum)
s.Require().NoError(err)

// Ensure parachain has started (starts 1 session/epoch after relay chain)
err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
s.Require().NoError(err, "polkadot chain failed to make blocks")

pathName := testsuite.GetPathName(0)

err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName)
s.Require().NoError(err)

// Create new clients
err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness
s.Require().NoError(err)

// Do not start relayer

// This contract is a dummy contract that will always succeed migration.
Expand Down Expand Up @@ -488,48 +406,13 @@ func (s *GrandpaTestSuite) TestMsgMigrateContract_Success_GrandpaContract() {
func (s *GrandpaTestSuite) TestMsgMigrateContract_ContractError_GrandpaContract() {
ctx := context.Background()

chainA, chainB := s.GetChains()

polkadotChain, ok := chainA.(*polkadot.PolkadotChain)
s.Require().True(ok)
_, chainB := s.GetChains()

cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

// we explicitly skip path creation as the contract needs to be uploaded before we can create clients.
r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) {
options.SkipPathCreation = true
})

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

file, err := os.Open("contracts/ics10_grandpa_cw.wasm.gz")
s.Require().NoError(err)
checksum := s.PushNewWasmClientProposal(ctx, cosmosChain, cosmosWallet, file)

s.Require().NotEmpty(checksum, "checksum was empty but should not have been")

eRep := s.GetRelayerExecReporter()

// Set client contract hash in cosmos chain config
err = r.SetClientContractHash(ctx, eRep, cosmosChain.Config(), checksum)
s.Require().NoError(err)

// Ensure parachain has started (starts 1 session/epoch after relay chain)
err = testutil.WaitForBlocks(ctx, 1, polkadotChain)
s.Require().NoError(err, "polkadot chain failed to make blocks")

pathName := testsuite.GetPathName(0)

err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName)
s.Require().NoError(err)

// Create new clients
err = r.CreateClients(ctx, eRep, pathName, ibc.DefaultClientOpts())
s.Require().NoError(err)
err = testutil.WaitForBlocks(ctx, 1, cosmosChain, polkadotChain) // these 1 block waits seem to be needed to reduce flakiness
s.Require().NoError(err)

// Do not start the relayer

// This contract is a dummy contract that will always fail migration.
Expand Down Expand Up @@ -589,10 +472,7 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() {
cosmosChain, ok := chainB.(*cosmos.CosmosChain)
s.Require().True(ok)

// we explicitly skip path creation as the contract needs to be uploaded before we can create clients.
r := s.ConfigureRelayer(ctx, polkadotChain, cosmosChain, nil, func(options *interchaintest.InterchainBuildOptions) {
options.SkipPathCreation = true
})
r := s.GetRelayer()

cosmosWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

Expand All @@ -616,10 +496,6 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() {
fundAmount := int64(12_333_000_000_000)
_, cosmosUser := s.fundUsers(ctx, fundAmount, polkadotChain, cosmosChain)

pathName := testsuite.GetPathName(0)
err = r.GeneratePath(ctx, eRep, cosmosChain.Config().ChainID, polkadotChain.Config().ChainID, pathName)
s.Require().NoError(err)

// create client pair with subject (bad trusting period)
subjectClientID := clienttypes.FormatClientIdentifier(wasmtypes.Wasm, 0)
// TODO: The hyperspace relayer makes no use of create client opts
Expand Down
45 changes: 0 additions & 45 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,51 +326,6 @@ func (s *E2ETestSuite) newInterchain(ctx context.Context, r ibc.Relayer, chains
return ic
}

func (s *E2ETestSuite) ConfigureRelayer(ctx context.Context, chainA, chainB ibc.Chain, channelOpts func(*ibc.CreateChannelOptions), buildOptions ...func(options *interchaintest.InterchainBuildOptions)) ibc.Relayer {
r := relayer.New(s.T(), *LoadConfig().GetActiveRelayerConfig(), s.logger, s.DockerClient, s.network)

pathName := s.generatePathName()

channelOptions := defaultChannelOpts([]ibc.Chain{chainA, chainB})
if channelOpts != nil {
channelOpts(&channelOptions)
}

ic := interchaintest.NewInterchain().
AddChain(chainA).
AddChain(chainB).
AddRelayer(r, "r").
AddLink(interchaintest.InterchainLink{
Chain1: chainA,
Chain2: chainB,
Relayer: r,
Path: pathName,
CreateChannelOpts: channelOptions,
})

buildOpts := interchaintest.InterchainBuildOptions{
TestName: s.T().Name(),
Client: s.DockerClient,
NetworkID: s.network,
}

for _, opt := range buildOptions {
opt(&buildOpts)
}

eRep := s.GetRelayerExecReporter()
s.Require().NoError(ic.Build(ctx, eRep, buildOpts))

s.startRelayerFn = func(relayer ibc.Relayer) {
err := relayer.StartRelayer(ctx, eRep, pathName)
s.Require().NoError(err, fmt.Sprintf("failed to start relayer: %s", err))
// wait for relayer to start.
s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks")
}

return r
}

// generatePathName generates the path name using the test suites name
func (s *E2ETestSuite) generatePathName() string {
pathName := GetPathName(s.pathNameIndex)
Expand Down
10 changes: 6 additions & 4 deletions e2e/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ func (s *E2ETestSuite) BroadcastMessages(ctx context.Context, chain ibc.Chain, u
}
s.Require().NoError(err)

chainA, chainB := s.GetChains()
s.Require().NoError(test.WaitForBlocks(ctx, 2, chainA, chainB))

s.Require().NoError(test.WaitForBlocks(ctx, 2, chain))
s.T().Logf("blocks created on chain %s", chain.Config().ChainID)
return resp
}

Expand Down Expand Up @@ -172,20 +171,23 @@ func (s *E2ETestSuite) ExecuteGovV1Proposal(ctx context.Context, msg sdk.Msg, ch
)
s.Require().NoError(err)

s.T().Logf("submitting proposal with ID: %d", proposalID)
resp := s.BroadcastMessages(ctx, cosmosChain, user, msgSubmitProposal)
s.AssertTxSuccess(resp)

s.Require().NoError(cosmosChain.VoteOnProposalAllValidators(ctx, strconv.Itoa(int(proposalID)), cosmos.ProposalVoteYes))

s.T().Logf("validators voted %s on proposal with ID: %d", cosmos.ProposalVoteYes, proposalID)
return s.waitForGovV1ProposalToPass(ctx, cosmosChain, proposalID)
}

// waitForGovV1ProposalToPass polls for the entire voting period to see if the proposal has passed.
// if the proposal has not passed within the duration of the voting period, an error is returned.
func (*E2ETestSuite) waitForGovV1ProposalToPass(ctx context.Context, chain ibc.Chain, proposalID uint64) error {
func (s *E2ETestSuite) waitForGovV1ProposalToPass(ctx context.Context, chain ibc.Chain, proposalID uint64) error {
var govProposal *govtypesv1.Proposal
// poll for the query for the entire voting period to see if the proposal has passed.
err := test.WaitForCondition(testvalues.VotingPeriod, 10*time.Second, func() (bool, error) {
s.T().Logf("waiting for proposal with ID: %d to pass", proposalID)
proposalResp, err := query.GRPCQuery[govtypesv1.QueryProposalResponse](ctx, chain, &govtypesv1.QueryProposalRequest{
ProposalId: proposalID,
})
Expand Down

0 comments on commit 62e51f2

Please sign in to comment.