diff --git a/Makefile b/Makefile index 1311e48f56..d4bcc97005 100644 --- a/Makefile +++ b/Makefile @@ -173,7 +173,6 @@ test-race: test-cover: @go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./... - benchmark: @go test -mod=readonly -bench=. ./... diff --git a/contrib/relayer-tests/.gitignore b/contrib/relayer-tests/.gitignore new file mode 100644 index 0000000000..d369e35ff8 --- /dev/null +++ b/contrib/relayer-tests/.gitignore @@ -0,0 +1,3 @@ +# Testing +.relayer +data diff --git a/contrib/relayer-tests/README.md b/contrib/relayer-tests/README.md new file mode 100644 index 0000000000..317f830b91 --- /dev/null +++ b/contrib/relayer-tests/README.md @@ -0,0 +1,6 @@ +# Relayer tests + +The setup scripts here are taken from [cosmos/relayer](https://github.com/cosmos/relayer) +Thank your relayer team for these scripts. + + diff --git a/contrib/relayer-tests/RELAYER_TEST.md b/contrib/relayer-tests/RELAYER_TEST.md new file mode 100644 index 0000000000..fbdd682499 --- /dev/null +++ b/contrib/relayer-tests/RELAYER_TEST.md @@ -0,0 +1,8 @@ +# Relayer tests + +These scripts helps to test go-relayer with two local wasmd chains. \ +Make sure you run below scripts under `wasmd/contrib/relayer-tests` directory. + +- `./init_two_chainz_relayer.sh` will spin two chains and runs +- `./one_chain.sh` will spin a single chain. This script used by the one above +-`./test_ibc_transfer.sh` will setup a path between chains and send tokens between chains. diff --git a/contrib/relayer-tests/configs/wasmd/demo.json b/contrib/relayer-tests/configs/wasmd/demo.json new file mode 100644 index 0000000000..26942c74d1 --- /dev/null +++ b/contrib/relayer-tests/configs/wasmd/demo.json @@ -0,0 +1 @@ +{"src":{"chain-id":"ibc-0","client-id":"","connection-id":"","channel-id":"","port-id":"transfer","order":"unordered","version":"ics20-1"},"dst":{"chain-id":"ibc-1","client-id":"","connection-id":"","channel-id":"","port-id":"transfer","order":"unordered","version":"ics20-1"},"strategy":{"type":"naive"}} diff --git a/contrib/relayer-tests/configs/wasmd/ibc-0.json b/contrib/relayer-tests/configs/wasmd/ibc-0.json new file mode 100644 index 0000000000..854f76492e --- /dev/null +++ b/contrib/relayer-tests/configs/wasmd/ibc-0.json @@ -0,0 +1 @@ +{"key":"testkey","chain-id":"ibc-0","rpc-addr":"http://localhost:26657","account-prefix":"wasm","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"} diff --git a/contrib/relayer-tests/configs/wasmd/ibc-1.json b/contrib/relayer-tests/configs/wasmd/ibc-1.json new file mode 100644 index 0000000000..88696b6f3d --- /dev/null +++ b/contrib/relayer-tests/configs/wasmd/ibc-1.json @@ -0,0 +1 @@ +{"key":"testkey","chain-id":"ibc-1","rpc-addr":"http://localhost:26557","account-prefix":"wasm","gas-adjustment":1.5,"gas-prices":"0.025stake", "trusting-period":"336h"} diff --git a/contrib/relayer-tests/init_two_chainz_relayer.sh b/contrib/relayer-tests/init_two_chainz_relayer.sh new file mode 100755 index 0000000000..bcedb7c862 --- /dev/null +++ b/contrib/relayer-tests/init_two_chainz_relayer.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# init_two_chainz_relayer creates two wasmd chains and configures the relayer + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +WASMD_DATA="$(pwd)/data" +RELAYER_CONF="$(pwd)/.relayer" + +# Ensure relayer is installed +if ! [ -x "$(which rly)" ]; then + echo "Error: wasmd is not installed. Try running 'make build-wasmd'" >&2 + exit 1 +fi + +# Ensure wasmd is installed +if ! [ -x "$(which wasmd)" ]; then + echo "Error: wasmd is not installed. Try running 'make build-wasmd'" >&2 + exit 1 +fi + +# Display software version for testers +echo "WASMD VERSION INFO:" +wasmd 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 + +# Delete data from old runs +rm -rf $WASMD_DATA &> /dev/null +rm -rf $RELAYER_CONF &> /dev/null + +# Stop existing wasmd processes +killall wasmd &> /dev/null + +set -e + +chainid0=ibc-0 +chainid1=ibc-1 + +echo "Generating wasmd configurations..." +mkdir -p $WASMD_DATA && cd $WASMD_DATA && cd ../ +./one_chain.sh wasmd $chainid0 ./data 26657 26656 6060 9090 +./one_chain.sh wasmd $chainid1 ./data 26557 26556 6061 9091 + +[ -f $WASMD_DATA/$chainid0.log ] && echo "$chainid0 initialized. Watch file $WASMD_DATA/$chainid0.log to see its execution." +[ -f $WASMD_DATA/$chainid1.log ] && echo "$chainid1 initialized. Watch file $WASMD_DATA/$chainid1.log to see its execution." + + +echo "Generating rly configurations..." +rly config init +rly config add-dir configs/wasmd/ + +SEED0=$(jq -r '.mnemonic' $WASMD_DATA/ibc-0/key_seed.json) +SEED1=$(jq -r '.mnemonic' $WASMD_DATA/ibc-1/key_seed.json) +echo "Key $(rly keys restore ibc-0 testkey "$SEED0") imported from ibc-0 to relayer..." +echo "Key $(rly keys restore ibc-1 testkey "$SEED1") imported from ibc-1 to relayer..." +echo "Creating light clients..." +sleep 3 +rly light init ibc-0 -f +rly light init ibc-1 -f diff --git a/contrib/relayer-tests/one_chain.sh b/contrib/relayer-tests/one_chain.sh new file mode 100755 index 0000000000..3e8ba5666a --- /dev/null +++ b/contrib/relayer-tests/one_chain.sh @@ -0,0 +1,115 @@ +#!/bin/sh + +set -e + +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 + +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 +chain_one_coins="100000000000stake,100000000000umuon,100000000000test" +chain_two_coins="100000000000stake,100000000000umuon" +delegate="100000000000stake" + +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> /dev/null +sleep 1 +$BINARY --home $CHAINDIR/$CHAINID keys add user $KEYRING --output json > $CHAINDIR/$CHAINID/key_seed.json 2> /dev/null +sleep 1 +redirect $BINARY --home $CHAINDIR/$CHAINID add-genesis-account $($BINARY --home $CHAINDIR/$CHAINID keys $KEYRING show user -a) $chain_one_coins +sleep 1 +redirect $BINARY --home $CHAINDIR/$CHAINID add-genesis-account $($BINARY --home $CHAINDIR/$CHAINID keys $KEYRING show validator -a) $chain_two_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 file..." +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#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#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 +redirect $BINARY --home $CHAINDIR/$CHAINID start --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT" > $CHAINDIR/$CHAINID.log & diff --git a/contrib/relayer-tests/test_ibc_transfer.sh b/contrib/relayer-tests/test_ibc_transfer.sh new file mode 100755 index 0000000000..d00504cf1e --- /dev/null +++ b/contrib/relayer-tests/test_ibc_transfer.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +# Ensure relayer is installed +if ! [ -x "$(which rly)" ]; then + echo "Error: rly is not installed." >&2 + exit 1 +fi + +rly tx link demo -d + +rly tx transfer ibc-0 ibc-1 1000000test $(rly chains address ibc-1) + +sleep 2 + +EXPECTED_BALANCE="100000000000test" +CHAIN_1_BALANCE=$(rly q bal ibc-1) + +if [[ "$CHAIN_1_BALANCE" == *"$EXPECTED_BALANCE" ]]; then + echo "Token not sent correctly" + echo "$EXPECTED_BALANCE not found in $CHAIN_1_BALANCE" + exit 1 +fi + +echo "IBC transfer executed successfully"