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 e2e ci test #21

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
35 changes: 35 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: E2E Test
# Tests / Code Coverage workflow runs unit tests and uploads a code coverage report
# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing this ci to be enable to test on all branch?

jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"

e2e-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- name: Display go version
run: go version
- name: Install relayer and simapp
run: |
cd e2e
sudo make install-relayer
make install-simapp
- name: Test e2e
run: |
cd e2e
make test-e2e
2 changes: 1 addition & 1 deletion CHANGELOG_FNSA.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Finschia Changelog

- [\#18](https://github.com/Finschia/ibc-go/pull/18) Apply finshia-sdk@v0.47.1-0.20230725074611-f8840edecbaa

- [\#21](https://github.com/Finschia/ibc-go/pull/21) Add e2e ci test
19 changes: 19 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
RLY_VERSION := 2.3.1
ARCH := $(shell dpkg --print-architecture)

install-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 /usr/bin
@rly version
@rm -rf relayer.tar.gz relayer_archive

install-simapp:
@cd ../ && \
make install
@simd version --long

test-e2e:
@./e2e

.PHONY: install-relayer install-simapp test-e2e
18 changes: 18 additions & 0 deletions 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 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"
}
}

12 changes: 12 additions & 0 deletions 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": []
}
}
98 changes: 98 additions & 0 deletions e2e/e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash -e
RELAYER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
RELAYER_CONF="$HOME/.relayer"
FNSA_CONF="$(pwd)/data"

# Ensure user understands what will be deleted
if ([[ -d $RELAYER_CONF ]] || [[ -d $FNSA_CONF ]]) && [[ ! "$1" == "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

cd $RELAYER_DIR
rm -rf $RELAYER_CONF &> /dev/null
pwd
# spin up two ibc enabled chains and add relevant config info for relaying
bash scripts/fnsa-chainz "skip"

echo "waiting for blocks..."
sleep 3

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

BAL0=$(rly q bal fnsa-0)
BAL1=$(rly q bal fnsa-1)

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 tx transfer fnsa-0 fnsa-1 100000samoleans "$(rly keys show fnsa-1)" channel-0 -d
sleep 5

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

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

BAL0=$(rly q bal fnsa-0)
BAL1=$(rly q bal fnsa-1)

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 tx transfer fnsa-1 fnsa-0 100000transfer/channel-0/samoleans "$(rly keys show fnsa-0)" channel-0 -d
sleep 5

rly tx relay-packets fnsa-fnsa channel-0 -d
sleep 5

rly tx relay-acknowledgements fnsa-fnsa channel-0 -d
sleep 5

BAL0=$(rly q bal fnsa-0)
BAL1=$(rly q bal fnsa-1)

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

killall simd &> /dev/null
66 changes: 66 additions & 0 deletions e2e/scripts/fnsa-chainz
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# two-chainz creates two simd chains and configures the relayer to

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

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

# Display software version for testers
echo "SIMD VERSION INFO:"
simd version --long

# 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 $FNSA_DATA ]] && [[ ! "$1" == "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 $FNSA_DATA &> /dev/null
rm -rf $RELAYER_CONF &> /dev/null

# Stop existing simd processes
killall gaiad &> /dev/null
killall akash &> /dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this binaries is not used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I think we need the test between gaiad and fnsad.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding tests with simd of cosmos/ibc-go in this repo and adding tests with fnsad and gaiad in Finschia/finschia repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding tests with simd of cosmos/ibc-go in this repo and adding tests with fnsad and gaiad in Finschia/finschia repo?

That's a good idea. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test with cosmos's simd.

killall simd &> /dev/null

set -e

chainid0=fnsa-0
chainid1=fnsa-1

echo "Generating fnsa configurations..."
mkdir -p $FNSA_DATA && cd $FNSA_DATA && cd ../
./scripts/one-chain simd $chainid0 ./data 26657 26656 6060 9090 stake samoleans
./scripts/one-chain simd $chainid1 ./data 26557 26556 6061 9091 rice beans

[ -f $FNSA_DATA/$chainid0.log ] && echo "$chainid0 initialized. Watch file $FNSA_DATA/$chainid0.log to see its execution."
[ -f $FNSA_DATA/$chainid1.log ] && echo "$chainid1 initialized. Watch file $FNSA_DATA/$chainid1.log to see its execution."

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

SEED0=$(jq -r '.mnemonic' $FNSA_DATA/fnsa-0/key_seed.json)
SEED1=$(jq -r '.mnemonic' $FNSA_DATA/fnsa-1/key_seed.json)
COINID=438
echo "Key $(rly keys restore fnsa-0 testkey "$SEED0" --coin-type $COINID) imported from fnsa-0 to relayer..."
echo "Key $(rly keys restore fnsa-1 testkey "$SEED1" --coin-type $COINID) imported from fnsa-1 to relayer..."

rly paths add-dir configs/paths
116 changes: 116 additions & 0 deletions e2e/scripts/one-chain
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

display_usage() {
echo "\nMissing $1 parameter. Please check if all parameters were specified."
echo "\nUsage: ./one-chain [BINARY] [CHAIN_ID] [CHAIN_DIR] [RPC_PORT] [P2P_PORT] [PROFILING_PORT] [GRPC_PORT]"
echo "\nExample: ./one-chain $BINARY test-chain-id ./data 26657 26656 6060 9090 \n"
exit 1
}

KEYRING=--keyring-backend="test"
SILENT=1

redirect() {
if [ "$SILENT" -eq 1 ]; then
"$@" > /dev/null 2>&1
else
"$@"
fi
}

BINARY=$1
CHAINID=$2
CHAINDIR=$3
RPCPORT=$4
P2PPORT=$5
PROFPORT=$6
GRPCPORT=$7
DENOM=$8
BASEDENOM=$9

if [ -z "$1" ]; then
display_usage "[BINARY] ($BINARY|akash)"
fi

if [ -z "$2" ]; then
display_usage "[CHAIN_ID]"
fi

if [ -z "$3" ]; then
display_usage "[CHAIN_DIR]"
fi

if [ -z "$4" ]; then
display_usage "[RPC_PORT]"
fi

if [ -z "$5" ]; then
display_usage "[P2P_PORT]"
fi

if [ -z "$6" ]; then
display_usage "[PROFILING_PORT]"
fi

if [ -z "$7" ]; then
display_usage "[GRPC_PORT]"
fi

echo "Creating $BINARY instance: home=$CHAINDIR | chain-id=$CHAINID | p2p=:$P2PPORT | rpc=:$RPCPORT | profiling=:$PROFPORT | grpc=:$GRPCPORT"

# Add dir for chain, exit if error
if ! mkdir -p $CHAINDIR/$CHAINID 2>/dev/null; then
echo "Failed to create chain folder. Aborting..."
exit 1
fi

# Build genesis file incl account for passed address
coins="100000000000$DENOM,100000000000$BASEDENOM"
delegate="100000000000$DENOM"

redirect $BINARY --home $CHAINDIR/$CHAINID --chain-id $CHAINID init $CHAINID
sleep 1
$BINARY --home $CHAINDIR/$CHAINID keys add validator $KEYRING --output json > $CHAINDIR/$CHAINID/validator_seed.json 2>&1
sleep 1
$BINARY --home $CHAINDIR/$CHAINID keys add user $KEYRING --output json > $CHAINDIR/$CHAINID/key_seed.json 2>&1
sleep 1
redirect $BINARY --home $CHAINDIR/$CHAINID add-genesis-account $($BINARY --home $CHAINDIR/$CHAINID keys $KEYRING show user -a) $coins
sleep 1
redirect $BINARY --home $CHAINDIR/$CHAINID add-genesis-account $($BINARY --home $CHAINDIR/$CHAINID keys $KEYRING show validator -a) $coins
sleep 1
redirect $BINARY --home $CHAINDIR/$CHAINID gentx validator $delegate $KEYRING --chain-id $CHAINID
sleep 1
redirect $BINARY --home $CHAINDIR/$CHAINID collect-gentxs
sleep 1

# Check platform
platform='unknown'
unamestr=`uname`
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
fi

# Set proper defaults and change ports (use a different sed for Mac or Linux)
echo "Change settings in config.toml and genesis.json files..."
if [ $platform = 'linux' ]; then
sed -i 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i 's/"bond_denom": "stake"/"bond_denom": "'"$DENOM"'"/g' $CHAINDIR/$CHAINID/config/genesis.json
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml
else
sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's/"bond_denom": "stake"/"bond_denom": "'"$DENOM"'"/g' $CHAINDIR/$CHAINID/config/genesis.json
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml
fi

# Start the gaia
$BINARY --home $CHAINDIR/$CHAINID start --pruning=nothing --grpc-web.enable=false --grpc.address="0.0.0.0:$GRPCPORT" > $CHAINDIR/$CHAINID.log 2>&1 &