Skip to content

Commit

Permalink
Merge PR #73: Add rocketzone to integration tests 🚀 🌔
Browse files Browse the repository at this point in the history
* added rocketzone integration tests

* fix badge link

* fixed linter

* add streaming test

* fixed streaming test for rocketzone
  • Loading branch information
jhernandezb authored Apr 1, 2020
1 parent 195ae9c commit 5e71020
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/rocketzone-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: TESTING - rocketzone to ibc integration

on: [push]

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go

# setup docker
- name: Set up Docker 19.03
uses: docker-practice/[email protected]
with:
docker-version: 19.03
docker-channel: stable

# checkout relayer
- name: checkout relayer
uses: actions/checkout@v2

# build cache
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# run tests
- name: run rocketzone tests
run: make test-rocketzone
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ test-gaia:
test-mtd:
@go test -mod=readonly -v -coverprofile coverage.out ./test/... -run TestMtd*

test-rocketzone:
@go test -mod=readonly -v -coverprofile coverage.out ./test/... -run TestRocket*

coverage:
@echo "viewing test coverage..."
@go tool cover --html=coverage.out
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ If you would like to join the relayer testnet, please [check out the instruction
|-------|--------|----------------|
| [`gaia`](https://github.com/cosmos/gaia) | ![gaia](https://github.com/iqlusioninc/relayer/workflows/TESTING%20-%20gaia%20to%20gaia%20integration/badge.svg) | `transfer` |
| `microtick` | ![microtick](https://github.com/iqlusioninc/relayer/workflows/TESTING%20-%20mtd%20to%20ibc%20integration/badge.svg) | `transfer` |
| [`rocketzone`](https://github.com/rocket-protocol/rocketzone) | ![rocketzone](https://github.com/iqlusioninc/relayer/workflows/TESTING%20-%20rocketzone%20to%20ibc%20integration/badge.svg) | `transfer` |

## Demoing the Relayer

Expand Down
158 changes: 158 additions & 0 deletions test/relayer_rocketzone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package test

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

var (
rocketChains = []testChain{
{"ibc0", gaiaTestConfig},
{"ibc1", rocketTestConfig},
}
)

func TestRocket_GaiaToRocketBasicTransfer(t *testing.T) {
chains := spinUpTestChains(t, rocketChains...)

_, err := genTestPathAndSet(chains.MustGet("ibc0"), chains.MustGet("ibc1"), "transfer", "transfer")
require.NoError(t, err)

var (
src = chains.MustGet("ibc0")
dst = chains.MustGet("ibc1")
testDenom = "samoleans"
dstDenom = fmt.Sprintf("%s/%s/%s", dst.PathEnd.PortID, dst.PathEnd.ChannelID, testDenom)
testCoin = sdk.NewCoin(testDenom, sdk.NewInt(1000))
expectedCoin = sdk.NewCoin(dstDenom, sdk.NewInt(1000))
)

// Check if clients have been created, if not create them
// then test querying clients from src and dst sides
require.NoError(t, src.CreateClients(dst))
testClientPair(t, src, dst)

// Check if connection has been created, if not create it
// the test querying connections from src and dst sides
require.NoError(t, src.CreateConnection(dst, src.GetTimeout()))
testConnectionPair(t, src, dst)

// Check if channel has been created, if not create it
// then test querying channels from src and dst sides
require.NoError(t, src.CreateChannel(dst, true, src.GetTimeout()))
testChannelPair(t, src, dst)

// Then send the transfer
require.NoError(t, src.SendTransferBothSides(dst, testCoin, dst.MustGetAddress(), true))

// ...and check the balance
dstBal, err := dst.QueryBalance(dst.Key)
require.NoError(t, err)
require.Equal(t, expectedCoin.Amount.Int64(), dstBal.AmountOf(dstDenom).Int64())
}

func TestRocket_RocketToGaiaBasicTransfer(t *testing.T) {
chains := spinUpTestChains(t, rocketChains...)

_, err := genTestPathAndSet(chains.MustGet("ibc0"), chains.MustGet("ibc1"), "transfer", "transfer")
require.NoError(t, err)

var (
src = chains.MustGet("ibc1")
dst = chains.MustGet("ibc0")
testDenom = "ufuel"
dstDenom = fmt.Sprintf("%s/%s/%s", dst.PathEnd.PortID, dst.PathEnd.ChannelID, testDenom)
testCoin = sdk.NewCoin(testDenom, sdk.NewInt(1000))
expectedCoin = sdk.NewCoin(dstDenom, sdk.NewInt(1000))
)

// Check if clients have been created, if not create them
// then test querying clients from src and dst sides
require.NoError(t, src.CreateClients(dst))
testClientPair(t, src, dst)

// Check if connection has been created, if not create it
// the test querying connections from src and dst sides
require.NoError(t, src.CreateConnection(dst, src.GetTimeout()))
testConnectionPair(t, src, dst)

// Check if channel has been created, if not create it
// then test querying channels from src and dst sides
require.NoError(t, src.CreateChannel(dst, true, src.GetTimeout()))
testChannelPair(t, src, dst)

// Then send the transfer
require.NoError(t, src.SendTransferBothSides(dst, testCoin, dst.MustGetAddress(), true))

// ...and check the balance
dstBal, err := dst.QueryBalance(dst.Key)
require.NoError(t, err)
require.Equal(t, expectedCoin.Amount.Int64(), dstBal.AmountOf(dstDenom).Int64())
}

func TestRocket_GaiaToRocketStreamingRelayer(t *testing.T) {
chains := spinUpTestChains(t, rocketChains...)

var (
src = chains.MustGet("ibc0")
dst = chains.MustGet("ibc1")
testDenomSrc = "samoleans"
testDenomDst = "nitro"
testCoinSrc = sdk.NewCoin(testDenomSrc, sdk.NewInt(1000))
twoTestCoinSrc = sdk.NewCoin(testDenomSrc, sdk.NewInt(2000))
testCoinDst = sdk.NewCoin(testDenomDst, sdk.NewInt(1000))
twoTestCoinDst = sdk.NewCoin(testDenomDst, sdk.NewInt(2000))
)

path, err := genTestPathAndSet(src, dst, "transfer", "transfer")
require.NoError(t, err)

// query initial balances to compare against at the end
srcExpected, err := src.QueryBalance(src.Key)
require.NoError(t, err)
dstExpected, err := dst.QueryBalance(dst.Key)
require.NoError(t, err)

// create path
require.NoError(t, src.CreateClients(dst))
require.NoError(t, src.CreateConnection(dst, src.GetTimeout()))
require.NoError(t, src.CreateChannel(dst, true, src.GetTimeout()))

// send a couple of transfers to the queue on src
require.NoError(t, src.SendTransferMsg(dst, testCoinSrc, dst.MustGetAddress(), true))
require.NoError(t, src.SendTransferMsg(dst, testCoinSrc, dst.MustGetAddress(), true))

// send a couple of transfers to the queue on dst
require.NoError(t, dst.SendTransferMsg(src, testCoinDst, src.MustGetAddress(), true))
require.NoError(t, dst.SendTransferMsg(src, testCoinDst, src.MustGetAddress(), true))

// Wait for message inclusion in both chains
require.NoError(t, dst.WaitForNBlocks(1))

// start the relayer process in it's own goroutine
rlyDone, err := path.MustGetStrategy().Run(src, dst)
require.NoError(t, err)

// send those tokens from dst back to dst and src back to src
require.NoError(t, src.SendTransferMsg(dst, twoTestCoinDst, dst.MustGetAddress(), false))
require.NoError(t, dst.SendTransferMsg(src, twoTestCoinSrc, src.MustGetAddress(), false))

// wait for packet processing
require.NoError(t, dst.WaitForNBlocks(4))

// kill relayer routine
rlyDone()

// check balance on src against expected
srcGot, err := src.QueryBalance(src.Key)
require.NoError(t, err)
require.Equal(t, srcExpected.AmountOf(testDenomSrc).Int64(), srcGot.AmountOf(testDenomSrc).Int64())

// check balance on dst against expected
dstGot, err := dst.QueryBalance(dst.Key)
require.NoError(t, err)
require.Equal(t, dstExpected.AmountOf(testDenomDst).Int64(), dstGot.AmountOf(testDenomDst).Int64())
}
18 changes: 18 additions & 0 deletions test/test_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ var (
defaultDenom: "stake",
trustingPeriod: "330h",
}

// RocketZone
// timeout_commit = "1000ms"
// timeout_propose = "1000ms"
// 3 second relayer timeout works well with these block times
rocketTestConfig = testChainConfig{
cdc: codecstd.NewAppCodec(codecstd.MakeCodec(simapp.ModuleBasics)),
amino: codecstd.MakeCodec(simapp.ModuleBasics),
dockerImage: "rocketprotocol/rocketzone-relayer-test",
dockerTag: "latest",
timeout: 3 * time.Second,
rpcPort: "26657",
accountPrefix: "cosmos",
gas: 200000,
gasPrices: "0.025ufuel",
defaultDenom: "ufuel",
trustingPeriod: "330h",
}
)

type (
Expand Down
2 changes: 1 addition & 1 deletion test/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, pool *
Cmd: []string{c.ChainID, c.MustGetAddress().String()},
ExposedPorts: []string{tc.t.rpcPort},
PortBindings: map[dc.Port][]dc.PortBinding{
dc.Port(tc.t.rpcPort): []dc.PortBinding{{HostPort: c.GetRPCPort()}},
dc.Port(tc.t.rpcPort): {{HostPort: c.GetRPCPort()}},
},
}

Expand Down

0 comments on commit 5e71020

Please sign in to comment.