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

Run Cosmos relayer process inside TestIBCCallFromSmartContract integration test #673

Closed
wants to merge 10 commits into from
46 changes: 42 additions & 4 deletions integration-tests/ibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ibc

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand All @@ -29,8 +30,9 @@ func ConvertToIBCDenom(channelID, denom string) string {
).IBCDenom()
}

// CreateIBCChannelsAndConnect creates two new channels for the provided ports on provided chains and connects them.
func CreateIBCChannelsAndConnect(
// CreateOpenIBCChannelsAndStartRelaying creates two new channels for the provided ports on provided chains,
// connects them and starts relaying them.
func CreateOpenIBCChannelsAndStartRelaying(
ctx context.Context,
t *testing.T,
srcChain integration.Chain,
Expand Down Expand Up @@ -63,6 +65,10 @@ func CreateIBCChannelsAndConnect(
}

pathName := fmt.Sprintf("%s-%s", srcChain.ChainSettings.ChainID, dstChain.ChainSettings.ChainID)

// port name samples:
// coreum: wasm.devcore14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sd4f0ak
// osmosis: wasm.osmo14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sq2r9g9
require.NoError(t, relayerSrcChain.CreateOpenChannels(
ctx,
relayerDstChain,
Expand All @@ -74,10 +80,42 @@ func CreateIBCChannelsAndConnect(
"",
pathName,
))
closerFunc := func() {

relErrCh := cosmosrelayer.StartRelayer(
ctx,
log.With(zap.String("process", "relayer")),
map[string]*cosmosrelayer.Chain{
srcChain.ChainSettings.ChainID: relayerSrcChain,
dstChain.ChainSettings.ChainID: relayerDstChain,
},
[]cosmosrelayer.NamedPath{
{Name: pathName, Path: &cosmosrelayer.Path{
Src: relayerSrcChain.PathEnd,
Dst: relayerDstChain.PathEnd,
Filter: cosmosrelayer.ChannelFilter{},
}},
},
cosmosrelayer.DefaultMaxMsgLength,
"",
cosmosrelayer.DefaultClientUpdateThreshold,
cosmosrelayer.DefaultFlushInterval,
nil,
cosmosrelayer.ProcessorEvents,
0,
nil,
)

go func() {
err := <-relErrCh
if !errors.Is(err, context.Canceled) {
return
}
require.NoError(t, err, "Cosmos Relayer start error")
}()

return func() {
require.NoError(t, relayerSrcChain.CloseChannel(ctx, relayerDstChain, 5, 5*time.Second, srcChain.ChainSettings.ChainID, srcChainPort, "", pathName))
}
return closerFunc
}

func setupRelayerChain(
Expand Down
20 changes: 12 additions & 8 deletions integration-tests/ibc/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,13 @@ func TestIBCTransferFromSmartContract(t *testing.T) {
requireT.NoError(osmosisChain.AwaitForBalance(ctx, t, osmosisRecipient, expectedOsmosisRecipientBalance))
}

// TestIBCCallFromSmartContract tests the IBC contract calls.
// TestIBCCallFromSmartContract tests the WASM contract calls via WASM IBC channel.
func TestIBCCallFromSmartContract(t *testing.T) {
// we don't enable the t.Parallel here since that test uses the config unseal hack because of the cosmos relayer
// implementation
// Temporary skip this test because it is incompatible with crust but crust PR needs changes from coreum.
t.SkipNow()

// We don't enable the t.Parallel here since that test uses the config unseal hack.
// Config unseal is needed to run cosmos relayer which interacts with both chain SDK configs internally.
restoreSDKConfig := unsealSDKConfig()
defer restoreSDKConfig()

Expand Down Expand Up @@ -235,7 +238,7 @@ func TestIBCCallFromSmartContract(t *testing.T) {
requireT.NotEmpty(osmosisIBCPort)
t.Logf("Osmisis contrac IBC port:%s", osmosisIBCPort)

closerFunc := CreateIBCChannelsAndConnect(
closerFunc := CreateOpenIBCChannelsAndStartRelaying(
ctx,
t,
coreumChain.Chain,
Expand All @@ -251,21 +254,22 @@ func TestIBCCallFromSmartContract(t *testing.T) {
osmosisToCoreumChannelID := osmosisChain.AwaitForIBCChannelID(ctx, t, osmosisIBCPort, coreumChain.ChainSettings.ChainID)
t.Logf("Channels are ready coreum channel ID:%s, osmosis channel ID:%s", coreumToOsmosisChannelID, osmosisToCoreumChannelID)

t.Logf("Sendng two IBC transactions from coreum contract to osmosis contract")
// make sure that initial values are correct.
awaitWasmCounterValue(ctx, t, coreumChain.Chain, coreumToOsmosisChannelID, coreumContractAddr, 0)
awaitWasmCounterValue(ctx, t, osmosisChain, osmosisToCoreumChannelID, osmosisContractAddr, 0)

// execute coreum counter twice
t.Logf("Sendng two IBC-increment transactions from coreum contract to osmosis contract")
executeWasmIncrement(ctx, requireT, coreumChain.Chain, coreumCaller, coreumToOsmosisChannelID, coreumContractAddr)
executeWasmIncrement(ctx, requireT, coreumChain.Chain, coreumCaller, coreumToOsmosisChannelID, coreumContractAddr)

// check that current state is expected
// the order of assertion is important because we are waiting for the expected non-zero counter first to be sure
// that async operation is completed fully before the second assertion
// that async operations are completed fully before the second assertion.
// This is done to make sure that all IBC operations are finished before we make second assertion.
awaitWasmCounterValue(ctx, t, osmosisChain, osmosisToCoreumChannelID, osmosisContractAddr, 2)
awaitWasmCounterValue(ctx, t, coreumChain.Chain, coreumToOsmosisChannelID, coreumContractAddr, 0)

t.Logf("Sendng three IBC transactions from osmosis contract to coreum contract")
t.Logf("Sendng three IBC-increment transactions from osmosis contract to coreum contract")
executeWasmIncrement(ctx, requireT, osmosisChain, osmosisCaller, osmosisToCoreumChannelID, osmosisContractAddr)
executeWasmIncrement(ctx, requireT, osmosisChain, osmosisCaller, osmosisToCoreumChannelID, osmosisContractAddr)
executeWasmIncrement(ctx, requireT, osmosisChain, osmosisCaller, osmosisToCoreumChannelID, osmosisContractAddr)
Expand Down