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

Add tm2eth test #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions .github/workflows/v0.4-tm2eth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: [email protected]
on: [push, pull_request]

env:
CACHE_BIN_RELAYER_KEY: bin-relayer
CACHE_BIN_RELAYER_PATH: ./build/yrly
CACHE_DOCKER_TENDERMINT_KEY: docker-tendermint
CACHE_DOCKER_TENDERMINT_DIR: /tmp/tendermint
CACHE_DOCKER_ETHEREUM_KEY: docker-ethereum
CACHE_DOCKER_ETHEREUM_DIR: /tmp/ethereum

jobs:
tm2eth-test:
name: tm2eth-test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Wait for build to succeed
uses: lewagon/[email protected]
with:
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.sha) || github.sha }}
check-regexp: '(relayer|tendermint)-build'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 30
- name: Restore relayer binary cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_BIN_RELAYER_PATH }}
key: ${{ runner.os }}-${{ env.CACHE_BIN_RELAYER_KEY }}-${{ hashFiles('relayer/**', 'go.sum') }}
- name: Restore Tendermint docker image cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DOCKER_TENDERMINT_DIR }}
key: ${{ runner.os }}-${{ env.CACHE_DOCKER_TENDERMINT_KEY }}-${{ hashFiles('tests/chains/tendermint/**', '!**/.git/**') }}
- name: Restore Ethereum docker image cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DOCKER_ETHEREUM_DIR }}
key: ${{ runner.os }}-${{ env.CACHE_DOCKER_ETHEREUM_KEY }}-${{ hashFiles('tests/chains/ethereum/**', '!**/.git/**') }}
- name: Load Tendermint docker images
working-directory: ./tests/scripts
run: |
./load_docker_images $CACHE_DOCKER_TENDERMINT_DIR tendermint-chain0:latest
./load_docker_images $CACHE_DOCKER_ETHEREUM_DIR ethereum-ganache0:latest
- name: Run Test
working-directory: ./tests/cases/tm2eth
run: |
make network
make test
make network-down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ replace (
)

require (
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.3
github.com/hyperledger-labs/yui-relayer v0.4.7
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.6
github.com/hyperledger-labs/yui-relayer v0.4.14
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbd
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.3 h1:cib07hGm41YyssO3oz38BiHTX6K5iquo0INZ9yBS9hU=
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.3/go.mod h1:Rbn+hsaEaYz7154ckk3blm5df9T0mMccWK26id6JcJs=
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.6 h1:sVonmqqP+uIe8UAfIe778icn/el6xwUv3u7eboJDv2Y=
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.6/go.mod h1:pSJ5MCqRsSERugEQtXMoKiznET4HbP81PE1Z0ZUfUv4=
github.com/datachainlab/ibc-mock-client v0.3.2 h1:SxBkaiuHWQ+1L085m2L35Fku3am7I6YL6B7dwurtDOM=
github.com/datachainlab/ibc-mock-client v0.3.2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -740,8 +740,8 @@ github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXM
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/hyperledger-labs/yui-relayer v0.4.7 h1:cAzaptjIIskhST+fLBihmGp7l9UFZQoKknyAq+2GDao=
github.com/hyperledger-labs/yui-relayer v0.4.7/go.mod h1:1+JWE6Z1NML9dp54NTDUwPtqV9IrqO0+eS9FmC79J1Q=
github.com/hyperledger-labs/yui-relayer v0.4.14 h1:cuQwwhGjb52fT/qgKuYLW6FI/phnrUwFkEHoJWm+d/s=
github.com/hyperledger-labs/yui-relayer v0.4.14/go.mod h1:Hdc/ERCPDhbipri45/U6+/3kDH7EttIWGdql+Rd3tZg=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
Expand Down
4 changes: 3 additions & 1 deletion tests/cases/eth2eth/configs/chains/ibc-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"hdw_path": "m/44'/60'/0'/0/0",
"ibc_address": "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841",
"initial_send_checkpoint": 1,
"initial_recv_checkpoint": 1
"initial_recv_checkpoint": 1,
"average_block_time_msec": 1000,
"max_retry_for_inclusion": 5
},
"prover": {
"@type": "/relayer.provers.mock.config.ProverConfig",
Expand Down
4 changes: 3 additions & 1 deletion tests/cases/eth2eth/configs/chains/ibc-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"hdw_path": "m/44'/60'/0'/0/0",
"ibc_address": "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841",
"initial_send_checkpoint": 1,
"initial_recv_checkpoint": 1
"initial_recv_checkpoint": 1,
"average_block_time_msec": 1000,
"max_retry_for_inclusion": 5
},
"prover": {
"@type": "/relayer.provers.mock.config.ProverConfig",
Expand Down
1 change: 1 addition & 0 deletions tests/cases/tm2eth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/
22 changes: 22 additions & 0 deletions tests/cases/tm2eth/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include ../../docker.mk

.PHONY: network
network:
TAG=${DOCKER_TAG} $(DOCKER_COMPOSE) \
-f ./docker-compose-test.yaml \
up -d \
tendermint-chain0 \
ethereum-ganache0

.PHONY: test
test:
./scripts/fixture
./scripts/init-rly
./scripts/handshake
./scripts/test-tx

.PHONY: network-down
network-down:
TAG=${DOCKER_TAG} $(DOCKER_COMPOSE) \
-f ./docker-compose-test.yaml \
down -v --remove-orphans
17 changes: 17 additions & 0 deletions tests/cases/tm2eth/configs/demo/ibc-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"chain": {
"@type": "/relayer.chains.tendermint.config.ChainConfig",
"key": "testkey",
"chain_id": "ibc0",
"rpc_addr": "http://localhost:26657",
"account_prefix": "cosmos",
"gas_adjustment": 1.5,
"gas_prices": "0.025stake",
"average_block_time_msec": 1000,
"max_retry_for_commit": 5
},
"prover": {
"@type": "/relayer.provers.mock.config.ProverConfig",
"finality_delay": 3
}
}
20 changes: 20 additions & 0 deletions tests/cases/tm2eth/configs/demo/ibc-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"chain": {
"@type": "/relayer.chains.ethereum.config.ChainConfig",
"chain_id": "ibc1",
"eth_chain_id": 2018,
"rpc_addr": "http://localhost:8645",
"hdw_mnemonic": "math razor capable expose worth grape metal sunset metal sudden usage scheme",
"hdw_path": "m/44'/60'/0'/0/0",
"ibc_address": "0x702E40245797c5a2108A566b3CE2Bf14Bc6aF841",
"initial_send_checkpoint": 0,
"initial_recv_checkpoint": 0,
"enable_debug_trace": true,
"average_block_time_msec": 1000,
"max_retry_for_inclusion": 5
},
"prover": {
"@type": "/relayer.provers.mock.config.ProverConfig",
"finality_delay": 3
}
}
23 changes: 23 additions & 0 deletions tests/cases/tm2eth/configs/path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"src": {
"chain-id": "ibc0",
"client-id": "mock-client-0",
"connection-id": "connection-0",
"channel-id": "channel-0",
"port-id": "mockapp",
"order": "unordered",
"version": "mockapp-1"
},
"dst": {
"chain-id": "ibc1",
"client-id": "mock-client-0",
"connection-id": "connection-0",
"channel-id": "channel-0",
"port-id": "mockapp",
"order": "unordered",
"version": "mockapp-1"
},
"strategy": {
"type": "naive"
}
}
39 changes: 39 additions & 0 deletions tests/cases/tm2eth/docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3.5'

networks:
relayer-e2e:
name: &network-common relayer-e2e

services:
# Tendermint
tendermint-chain0:
container_name: tendermint-chain0
image: tendermint-chain0:${TAG}
ports:
- 26656:26656
- 26657:26657
- 6060:6060
- 9090:9090
healthcheck:
test: "wget -q -O - http://localhost:26657/health || exit 1"
interval: 30s
timeout: 10s
retries: 5
networks:
- *network-common
environment:
USE_MOCK_CLIENT: 1

# Ethereum
ethereum-ganache0:
container_name: ethereum-ganache0
image: ethereum-ganache0:${TAG}
ports:
- 8645:8545
healthcheck:
test: "wget -q -O - http://localhost:8545/health || exit 1"
interval: 30s
timeout: 10s
retries: 5
networks:
- *network-common
16 changes: 16 additions & 0 deletions tests/cases/tm2eth/scripts/fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eux

DOCKER=docker
FIXTURES_DIR=./fixtures

# Setup test fixtures

# first, remove the old fixtures
rm -rf ${FIXTURES_DIR}

# for tendermint

mkdir -p ${FIXTURES_DIR}/tendermint/ibc0
# retrieve the mnemonic from the container to the local
${DOCKER} cp tendermint-chain0:/root/data/ibc0/key_seed.json ${FIXTURES_DIR}/tendermint/ibc0/key_seed.json
21 changes: 21 additions & 0 deletions tests/cases/tm2eth/scripts/handshake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -eux

source $(cd $(dirname "$0"); pwd)/../../../scripts/util

SCRIPT_DIR=$(cd $(dirname $0); pwd)
RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly
RLY="${RLY_BINARY} --debug"

CHAINID_ONE=ibc0
CHAINID_TWO=ibc1
RLYKEY=testkey
PATH_NAME=ibc01

# add a path between chain0 and chain1
$RLY paths add $CHAINID_ONE $CHAINID_TWO $PATH_NAME --file=./configs/path.json

retry 5 $RLY tx clients $PATH_NAME
retry 5 $RLY tx connection $PATH_NAME
retry 5 $RLY tx channel $PATH_NAME
33 changes: 33 additions & 0 deletions tests/cases/tm2eth/scripts/init-rly
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -eux

SCRIPT_DIR=$(cd $(dirname $0); pwd)

RELAYER_CONF="$HOME/.yui-relayer"
RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly
RLY="${RLY_BINARY} --debug"
FIXTURES_DIR=${SCRIPT_DIR}/../fixtures

CHAINID_ONE=ibc0
CHAINID_TWO=ibc1
RLYKEY=testkey
PATH_NAME=ibc01

echo "Generating ${RLY_BINARY} configurations..."

# Ensure ${RLY_BINARY} is installed
if ! [ -x ${RLY_BINARY} ]; then
echo "Error: ${RLY_BINARY} is not installed." >&2
exit 1
fi

rm -rf ${RELAYER_CONF} &> /dev/null

${RLY} config init
${RLY} chains add-dir configs/demo/

# A setup for tendermint client

SEED0=$(jq -r '.mnemonic' < ${FIXTURES_DIR}/tendermint/ibc0/key_seed.json)
echo "Key $(${RLY} tendermint keys restore ibc0 testkey "$SEED0") imported from ibc0 to relayer..."
38 changes: 38 additions & 0 deletions tests/cases/tm2eth/scripts/test-tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eux

SCRIPT_DIR=$(cd $(dirname $0); pwd)

RELAYER_CONF="$HOME/.yui-relayer"
RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly
RLY="${RLY_BINARY} --debug"

# XXX set proper value
TX_INTERNAL=120
TM_USER_ADDRESS=$(${RLY} tendermint keys show ibc0 testkey)

retry() {
local -r -i max_attempts="$1"; shift
local -r cmd="$@"
local -i attempt_num=1

until $cmd
do
if (( attempt_num == max_attempts ))
then
echo "Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $(( attempt_num++ ))
fi
done
}

echo "!!! ibc0 -> ibc1 !!!"

docker exec tendermint-chain0 sh -c "simd --home /root/data/ibc0 tx --keyring-backend=test --from ${TM_USER_ADDRESS} --chain-id ibc0 mockapp send mockapp channel-0 msg0 --yes"
sleep 5
retry 10 ${RLY} tx relay ibc01
sleep ${TX_INTERNAL}
retry 10 ${RLY} tx acks ibc01
4 changes: 3 additions & 1 deletion tests/cases/tm2tm/configs/demo/ibc-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"rpc_addr": "http://localhost:26657",
"account_prefix": "cosmos",
"gas_adjustment": 1.5,
"gas_prices": "0.025stake"
"gas_prices": "0.025stake",
"average_block_time_msec": 1000,
"max_retry_for_commit": 5
},
"prover": {
"@type": "/relayer.chains.tendermint.config.ProverConfig",
Expand Down
4 changes: 3 additions & 1 deletion tests/cases/tm2tm/configs/demo/ibc-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"rpc_addr": "http://localhost:26557",
"account_prefix": "cosmos",
"gas_adjustment": 1.5,
"gas_prices": "0.025stake"
"gas_prices": "0.025stake",
"average_block_time_msec": 1000,
"max_retry_for_commit": 5
},
"prover": {
"@type": "/relayer.chains.tendermint.config.ProverConfig",
Expand Down
Loading