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 ibc transfer e2e test #247

Closed
wants to merge 9 commits 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
30 changes: 30 additions & 0 deletions .github/workflows/ibc-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: IBC E2E Test
on:
pull_request:
push:
branches:
- main
jobs:
test-fnsa-fnsa:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Test finschia to finschia
run: |
rm -rf .git
cd ibc_e2e
make build-docker
make test-fnsa-fnsa-in-docker

test-fnsa-gaia:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Test finschia to gaia
run: |
rm -rf .git
cd ibc_e2e
make build-docker
make test-fnsa-gaia-in-docker
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (ci) [\#233](https://github.com/Finschia/finschia/pull/233) add smart contract CI test
* (build) [\#237](https://github.com/Finschia/finschia/pull/237) rearrange Dockerfile and Makefile commands
* (build) [\#241](https://github.com/Finschia/finschia/pull/241) Update golang version to 1.20
* (ci) [\#247](https://github.com/Finschia/finschia/pull/247) Add ibc transfer e2e test

### Docs

Expand Down
2 changes: 2 additions & 0 deletions ibc_e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
data
5 changes: 5 additions & 0 deletions ibc_e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM golang:1.20-bullseye

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y jq lsof
53 changes: 53 additions & 0 deletions ibc_e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
RLY_VERSION := 2.3.1
GAIA_VERSION := 10.0.2
ARCH := $(shell dpkg --print-architecture)
PATH := $(shell pwd)/bin:$(PATH)
MAKE := $(shell which make)
DOCKER := $(shell which docker)
HOME_DIR := $(shell cd .. && pwd)

bin/fnsad:
@mkdir -p bin && \
cd ../ && \
make build && \
mv build/fnsad ibc_e2e/bin
@fnsad version --long

bin/gaiad:
@mkdir -p bin/gaia && \
cd bin/gaia && \
curl -L https://github.com/cosmos/gaia/releases/download/v$(GAIA_VERSION)/gaiad-v$(GAIA_VERSION)-linux-$(ARCH) --output gaiad && \
chmod 755 gaiad && \
mv gaiad ../gaiad
@gaiad version --long

bin/rly:
@mkdir -p bin/relayer && \
cd bin/relayer && \
curl -L https://github.com/cosmos/relayer/releases/download/v$(RLY_VERSION)/Cosmos.Relayer_$(RLY_VERSION)_linux_$(ARCH).tar.gz --output relayer.tar.gz && \
tar -xf relayer.tar.gz --transform 's!^[^/]*!relayer_archive!' && \
mv relayer_archive/rly ../
@rly version

test-fnsa-fnsa: bin/rly bin/fnsad
@./e2e fnsa-fnsa fnsa-0 fnsad 438 fnsa-1 fnsad 438 "skip"

test-fnsa-gaia: bin/rly bin/fnsad bin/gaiad
@./e2e fnsa-gaia fnsa-0 fnsad 438 gaia-1 gaiad 118 "skip"

test-fnsa-fnsa-in-docker:
@$(DOCKER) run --rm -v ${HOME_DIR}:/workspace -w /workspace/ibc_e2e ibc-e2e:latest make test-fnsa-fnsa

test-fnsa-gaia-in-docker:
@$(DOCKER) run --rm -v ${HOME_DIR}:/workspace -w /workspace/ibc_e2e ibc-e2e:latest make test-fnsa-gaia

build-docker:
@$(DOCKER) build . -t ibc-e2e:latest

clean-all:
@rm -rf bin data

clean-data:
@rm -rf data

.PHONY: test-fnsa-fnsa test-fnsa-gaia clean-all clean-data
18 changes: 18 additions & 0 deletions ibc_e2e/configs/chains/fnsa-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "cosmos",
"value": {
"key": "testkey",
"chain-id": "fnsa-0",
"rpc-addr": "http://localhost:26657",
"grpc-addr": "",
"account-prefix": "link",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.025stake",
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}

18 changes: 18 additions & 0 deletions ibc_e2e/configs/chains/fnsa-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "cosmos",
"value": {
"key": "testkey",
"chain-id": "fnsa-1",
"rpc-addr": "http://localhost:26557",
"grpc-addr": "",
"account-prefix": "link",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.025rice",
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}

18 changes: 18 additions & 0 deletions ibc_e2e/configs/chains/gaia-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "cosmos",
"value": {
"key": "testkey",
"chain-id": "gaia-1",
"rpc-addr": "http://localhost:26557",
"grpc-addr": "",
"account-prefix": "cosmos",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.025rice",
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}

12 changes: 12 additions & 0 deletions ibc_e2e/configs/paths/fnsa-fnsa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"src": {
"chain-id": "fnsa-0"
},
"dst": {
"chain-id": "fnsa-1"
},
"src-channel-filter": {
"rule": null,
"channel-list": []
}
}
12 changes: 12 additions & 0 deletions ibc_e2e/configs/paths/fnsa-gaia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"src": {
"chain-id": "fnsa-0"
},
"dst": {
"chain-id": "gaia-1"
},
"src-channel-filter": {
"rule": null,
"channel-list": []
}
}
110 changes: 110 additions & 0 deletions ibc_e2e/e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash -e
RELAYER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
HOME_DIR="$(pwd)/data"
RLY_HOME="$HOME_DIR/relayer"

CHAIN_PATH=$1
CHAIN0_ID=$2
CHAIN0_BIN=$3
CHAIN0_COINID=$4
CHAIN1_ID=$5
CHAIN1_BIN=$6
CHAIN1_COINID=$7

# Ensure user understands what will be deleted
if ([[ -d $HOME_DIR ]]) && [[ ! "$8" == "skip" ]]; then
read -p "$0 will delete \$HOME/.relayer and \$(pwd)/data folder. Do you wish to continue? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi

# spin up two ibc enabled chains and add relevant config info for relaying
bash scripts/chainz $CHAIN0_ID $CHAIN0_BIN $CHAIN0_COINID $CHAIN1_ID $CHAIN1_BIN $CHAIN1_COINID "$8"

echo "waiting for blocks..."
sleep 5

ps
echo "chain 0"
cat $HOME_DIR/$CHAIN0_ID.log
echo "chain 1"
cat $HOME_DIR/$CHAIN1_ID.log

# creates clients, connections and channels (all this happens in rly tx command)
rly --home $RLY_HOME tx link $CHAIN_PATH -d -t 3s
sleep 2

BAL0=$(rly --home $RLY_HOME q bal $CHAIN0_ID)
BAL1=$(rly --home $RLY_HOME q bal $CHAIN1_ID)

echo "-- Initial balances --"
echo "balance 0 $BAL0"
echo "balance 1 $BAL1"

if [[ "$BAL0" != *"100000000000samoleans"* ]]; then
echo "balance 0 is wrong"
exit 1
fi
if [[ "$BAL1" != *"100000000000beans"* ]]; then
echo "balance 1 is wrong"
exit 1
fi

echo "-- Sending IBC transaction... --"
rly --home $RLY_HOME tx transfer $CHAIN0_ID $CHAIN1_ID 100000samoleans "$(rly --home $RLY_HOME keys show $CHAIN1_ID)" channel-0 -d
sleep 5

# relay remaining packets -- (could also be accomplished by running: `rly start`)
rly --home $RLY_HOME tx relay-packets $CHAIN_PATH channel-0 -d
sleep 5

# relay remaining acknowledgments -- (could also be accomplished by running: `rly start`)
rly --home $RLY_HOME tx relay-acknowledgements $CHAIN_PATH channel-0 -d
sleep 5

BAL0=$(rly --home $RLY_HOME q bal $CHAIN0_ID)
BAL1=$(rly --home $RLY_HOME q bal $CHAIN1_ID)

echo "-- Balances after packets are sent --"
echo "balance 0 $BAL0"
echo "balance 1 $BAL1"

if [[ "$BAL0" != *"{99999900000samoleans"* ]]; then
echo "balance 0 is wrong"
exit 1
fi
if [[ "$BAL1" != *"100000000000beans,100000transfer/channel-0/samoleans"* ]]; then
echo "balance 1 is wrong"
exit 1
fi

echo "-- Sending tokens back to original wallet... --"
rly --home $RLY_HOME tx transfer $CHAIN1_ID $CHAIN0_ID 100000transfer/channel-0/samoleans "$(rly --home $RLY_HOME keys show $CHAIN0_ID)" channel-0 -d
sleep 5

rly --home $RLY_HOME tx relay-packets $CHAIN_PATH channel-0 -d
sleep 5

rly --home $RLY_HOME tx relay-acknowledgements $CHAIN_PATH channel-0 -d
sleep 5

BAL0=$(rly --home $RLY_HOME q bal $CHAIN0_ID)
BAL1=$(rly --home $RLY_HOME q bal $CHAIN1_ID)

echo "-- Balances after sending packets back --"
echo "balance 0 $BAL0"
echo "balance 1 $BAL1"

if [[ "$BAL0" != *"100000000000samoleans"* ]]; then
echo "balance 0 is wrong"
exit 1
fi
if [[ "$BAL1" != *"100000000000beans"* ]]; then
echo "balance 1 is wrong"
exit 1
fi

pkill fnsad &> /dev/null || true
pkill gaiad &> /dev/null || true
74 changes: 74 additions & 0 deletions ibc_e2e/scripts/chainz
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
# two-chainz creates two chains and configures the relayer to

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
HOME_DIR="$(pwd)/data"
RLY_HOME="$HOME_DIR/relayer"

CHAIN0_ID=$1
CHAIN0_BIN=$2
CHAIN0_COINID=$3
CHAIN1_ID=$4
CHAIN1_BIN=$5
CHAIN1_COINID=$6

# Ensure binary is installed
if ! [ -x "$(which $CHAIN0_BIN)" ]; then
echo "Error: $CHAIN0_BIN is not installed. Try running 'make bin/$CHAIN0_BIN'" >&2
exit 1
fi
if ! [ -x "$(which $CHAIN1_BIN)" ]; then
echo "Error: $CHAIN1_BIN is not installed. Try running 'make bin/$CHAIN1_BIN'" >&2
exit 1
fi

# Display software version for testers
echo "BINARY VERSION INFO:"
$CHAIN0_BIN version --long --log_level=info
$CHAIN1_BIN version --long --log_level=info

# Ensure jq is installed
if [[ ! -x "$(which jq)" ]]; then
echo "jq (a tool for parsing json in the command line) is required..."
echo "https://stedolan.github.io/jq/download/"
exit 1
fi

# Ensure user understands what will be deleted
if [[ -d $HOME_DIR ]] && [[ ! "$7" == "skip" ]]; then
read -p "$(basename $0) will delete \$(pwd)/data and \$HOME/.relayer folders. Do you wish to continue? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi

# Delete data from old runs
rm -rf $HOME_DIR &> /dev/null

# Stop existing binary processes
pkill fnsad &> /dev/null
pkill gaiad &> /dev/null

set -e

echo "Generating binary configurations..."
mkdir -p $HOME_DIR && cd $HOME_DIR && cd ../
./scripts/one-chain $CHAIN0_BIN $CHAIN0_ID $HOME_DIR 26657 26656 6060 9090 stake samoleans
sleep 5
./scripts/one-chain $CHAIN1_BIN $CHAIN1_ID $HOME_DIR 26557 26556 6061 9091 rice beans

[ -f $HOME_DIR/$CHAIN0_ID.log ] && echo "$CHAIN0_ID initialized. Watch file $HOME_DIR/$CHAIN0_ID.log to see its execution."
[ -f $HOME_DIR/$CHAIN1_ID.log ] && echo "$CHAIN1_ID initialized. Watch file $HOME_DIR/$CHAIN1_ID.log to see its execution."

echo "Generating rly configurations..."
rly --home $RLY_HOME config init
rly --home $RLY_HOME chains add-dir configs/chains

SEED0=$(jq -r '.mnemonic' $HOME_DIR/$CHAIN0_ID/key_seed.json)
SEED1=$(jq -r '.mnemonic' $HOME_DIR/$CHAIN1_ID/key_seed.json)

echo "Key $(rly --home $RLY_HOME keys restore $CHAIN0_ID testkey "$SEED0" --coin-type $CHAIN0_COINID) imported from $CHAIN0_ID to relayer..."
echo "Key $(rly --home $RLY_HOME keys restore $CHAIN1_ID testkey "$SEED1" --coin-type $CHAIN1_COINID) imported from $CHAIN1_ID to relayer..."

rly --home $RLY_HOME paths add-dir configs/paths
Loading