Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Sep 28, 2023
1 parent 58bfa93 commit f7ae8d8
Show file tree
Hide file tree
Showing 24 changed files with 407 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build/
bin/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lcp"]
path = lcp
url = https://github.com/datachainlab/lcp
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ protoVer=0.13.1
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=docker run --user 0 --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

.PHONY: yrly
yrly:
go build -o ./bin/yrly -tags customcert ./relay/bin

.PHONY: lcp
lcp:
$(MAKE) -C ./lcp -B && mv ./lcp/bin/* ./bin/

.PHONY: proto-gen proto-update-deps
proto-gen:
@echo "Generating Protobuf files"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ lcp-go includes the followings:
## Compatibility

- [lcp v0.2.2](https://github.com/datachainlab/lcp/releases/tag/v0.2.2)
- [ibc v7.2](https://github.com/cosmos/ibc-go/releases/tag/v7.2.0).
- [ibc-go v7.2](https://github.com/cosmos/ibc-go/releases/tag/v7.2.0).
1 change: 1 addition & 0 deletions lcp
Submodule lcp added at c073f8
27 changes: 27 additions & 0 deletions scripts/run_e2e_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
set -ex

LCP_BIN=./bin/lcp
ENCLAVE_PATH=./bin/enclave.signed.so
CERTS_DIR=./lcp/tests/certs

rm -rf ~/.lcp

enclave_key=$(${LCP_BIN} --log_level=off enclave generate-key --enclave=${ENCLAVE_PATH})
./tests/e2e/scripts/gen_rly_config.sh

if [ -z "$SGX_MODE" -o "$SGX_MODE" = "HW" ]; then
./bin/lcp attestation ias --enclave=${ENCLAVE_PATH} --enclave_key=${enclave_key}
else
./bin/lcp attestation simulate --enclave=${ENCLAVE_PATH} --enclave_key=${enclave_key} --signing_cert_path=${CERTS_DIR}/signing.crt.der --signing_key=${CERTS_DIR}/signing.key
export LCP_RA_ROOT_CERT_HEX=$(cat ${CERTS_DIR}/root.crt | xxd -p -c 1000000)
fi

./bin/lcp --log_level=info service start --enclave=${ENCLAVE_PATH} --address=127.0.0.1:50051 --threads=2 &
LCP_PID=$!

make -C tests/e2e/cases/tm2tm network
sleep 3
make -C tests/e2e/cases/tm2tm test
make -C tests/e2e/cases/tm2tm network-down
kill $LCP_PID
41 changes: 41 additions & 0 deletions tests/e2e/cases/docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.5'

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

services:
tendermint-chain0:
container_name: tendermint-chain0
image: tendermint-chain0:${TAG}
environment:
- LCP_RA_ROOT_CERT_HEX=${LCP_RA_ROOT_CERT_HEX}
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
tendermint-chain1:
container_name: tendermint-chain1
image: tendermint-chain1:${TAG}
environment:
- LCP_RA_ROOT_CERT_HEX=${LCP_RA_ROOT_CERT_HEX}
ports:
- 26566:26656
- 26557:26657
- 6061:6060
- 9091:9090
healthcheck:
test: "wget -q -O - http://localhost:26657/health || exit 1"
interval: 30s
timeout: 10s
retries: 5
networks:
- *network-common
1 change: 1 addition & 0 deletions tests/e2e/cases/tm2tm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/
27 changes: 27 additions & 0 deletions tests/e2e/cases/tm2tm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
DOCKER ?= docker
DOCKER_COMPOSE ?= docker compose
DOCKER_REPO ?= ""
DOCKER_TAG ?= latest
DOCKER_BUILD ?= $(DOCKER) build --rm --no-cache --pull

RLY_BIN ?= ../../../../bin/yrly

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

.PHONY: network-down
network-down:
TAG=${DOCKER_TAG} $(DOCKER_COMPOSE) \
-f ../docker-compose-test.yaml \
down --volumes --remove-orphans

.PHONY: test
test:
./scripts/fixture
RLY_BIN=$(RLY_BIN) ./scripts/init-rly
RLY_BIN=$(RLY_BIN) ./scripts/handshake
RLY_BIN=$(RLY_BIN) ./scripts/test-tx
7 changes: 7 additions & 0 deletions tests/e2e/cases/tm2tm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Usage

```shell
$ make network
$ make test
$ make network-down
```
1 change: 1 addition & 0 deletions tests/e2e/cases/tm2tm/configs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
demo/*.json
4 changes: 4 additions & 0 deletions tests/e2e/cases/tm2tm/configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Demo configs

**WARNING** These configurations are intended only for testing and development.
You must modify them for your environment and security level in production.
23 changes: 23 additions & 0 deletions tests/e2e/cases/tm2tm/configs/path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"src": {
"chain-id": "ibc0",
"client-id": "lcp-client-0",
"connection-id": "connection-0",
"channel-id": "channel-0",
"port-id": "transfer",
"order": "unordered",
"version": "ics20-1"
},
"dst": {
"chain-id": "ibc1",
"client-id": "lcp-client-0",
"connection-id": "connection-0",
"channel-id": "channel-0",
"port-id": "transfer",
"order": "unordered",
"version": "ics20-1"
},
"strategy": {
"type": "naive"
}
}
24 changes: 24 additions & 0 deletions tests/e2e/cases/tm2tm/configs/templates/ibc-0.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"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"
},
"prover": {
"@type": "/relayer.provers.lcp.config.ProverConfig",
"origin_prover": {
"@type": "/relayer.chains.tendermint.config.ProverConfig",
"trusting_period": "336h"
},
"lcp_service_address": "localhost:50051",
"mrenclave": "$MRENCLAVE",
"allowed_quote_statuses": ["GROUP_OUT_OF_DATE"],
"allowed_advisory_ids": ["INTEL-SA-00219","INTEL-SA-00289","INTEL-SA-00334","INTEL-SA-00477","INTEL-SA-00614","INTEL-SA-00615","INTEL-SA-00617"],
"key_expiration": 604800,
"elc_client_id": "07-tendermint-1"
}
}
24 changes: 24 additions & 0 deletions tests/e2e/cases/tm2tm/configs/templates/ibc-1.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"chain": {
"@type": "/relayer.chains.tendermint.config.ChainConfig",
"key": "testkey",
"chain_id": "ibc1",
"rpc_addr": "http://localhost:26557",
"account_prefix": "cosmos",
"gas_adjustment": 1.5,
"gas_prices": "0.025stake"
},
"prover": {
"@type": "/relayer.provers.lcp.config.ProverConfig",
"origin_prover": {
"@type": "/relayer.chains.tendermint.config.ProverConfig",
"trusting_period": "336h"
},
"lcp_service_address": "localhost:50051",
"mrenclave": "$MRENCLAVE",
"allowed_quote_statuses": ["GROUP_OUT_OF_DATE"],
"allowed_advisory_ids": ["INTEL-SA-00219","INTEL-SA-00289","INTEL-SA-00334","INTEL-SA-00477","INTEL-SA-00614","INTEL-SA-00615","INTEL-SA-00617"],
"key_expiration": 604800,
"elc_client_id": "07-tendermint-0"
}
}
18 changes: 18 additions & 0 deletions tests/e2e/cases/tm2tm/scripts/fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eu

DOCKER=docker
SCRIPT_DIR=$(cd $(dirname $0); pwd)
FIXTURES_DIR=${SCRIPT_DIR}/../fixtures

## Setup test fixtures

set +x
rm -rf ${FIXTURES_DIR}
mkdir -p ${FIXTURES_DIR}/tendermint/ibc0
mkdir -p ${FIXTURES_DIR}/tendermint/ibc1
set -x

## copy tendermint's node mnemonic from node container
${DOCKER} cp tendermint-chain0:/root/data/ibc0/key_seed.json ${FIXTURES_DIR}/tendermint/ibc0/key_seed.json
${DOCKER} cp tendermint-chain1:/root/data/ibc1/key_seed.json ${FIXTURES_DIR}/tendermint/ibc1/key_seed.json
49 changes: 49 additions & 0 deletions tests/e2e/cases/tm2tm/scripts/handshake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -eux

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
}

RLY="${RLY_BIN} --debug"

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

$RLY tendermint keys show $CHAINID_ONE $RLYKEY
$RLY tendermint keys show $CHAINID_TWO $RLYKEY

# initialize the light client for {{chain_id}}
retry 5 $RLY lcp-tendermint light init $CHAINID_ONE -f
retry 5 $RLY lcp-tendermint light init $CHAINID_TWO -f

# 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
sleep 3
retry 5 $RLY lcp update-enclave-key $PATH_NAME --src=true
retry 5 $RLY lcp update-enclave-key $PATH_NAME --src=false
sleep 3
retry 5 $RLY lcp activate-client $PATH_NAME --src=true
retry 5 $RLY lcp activate-client $PATH_NAME --src=false
sleep 3
retry 5 $RLY tx connection $PATH_NAME
retry 5 $RLY tx channel $PATH_NAME
29 changes: 29 additions & 0 deletions tests/e2e/cases/tm2tm/scripts/init-rly
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -eux

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

RLY_HOME="$HOME/.yui-relayer"
RLY="${RLY_BIN} --debug"
FIXTURES_DIR=${SCRIPT_DIR}/../fixtures

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

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

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

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

# setup key 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..."

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

set -eux

RLY="${RLY_BIN} --debug"

# XXX set proper value
TX_INTERNAL=3

TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey)
TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey)

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

echo "Before ibc0 balance: $(${RLY} query balance ibc0 ${TM_ADDRESS0})"
echo "Before ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})"

${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1}
sleep ${TX_INTERNAL}
${RLY} tx relay ibc01
sleep ${TX_INTERNAL}
${RLY} tx acks ibc01
sleep ${TX_INTERNAL}

echo "After ibc0 balance: $(${RLY} query balance ibc0 ${TM_ADDRESS0})"
echo "After ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})"
8 changes: 8 additions & 0 deletions tests/e2e/scripts/gen_rly_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -eux
TEMPLATE_DIR=./tests/e2e/cases/tm2tm/configs/templates
CONFIG_DIR=./tests/e2e/cases/tm2tm/configs/demo
mkdir -p $CONFIG_DIR
MRENCLAVE=$(./bin/lcp enclave metadata --enclave=./bin/enclave.signed.so | jq -r .mrenclave)
jq --arg MRENCLAVE ${MRENCLAVE} -r '.prover.mrenclave = $MRENCLAVE' ${TEMPLATE_DIR}/ibc-0.json.tpl > ${CONFIG_DIR}/ibc-0.json
jq --arg MRENCLAVE ${MRENCLAVE} -r '.prover.mrenclave = $MRENCLAVE' ${TEMPLATE_DIR}/ibc-1.json.tpl > ${CONFIG_DIR}/ibc-1.json
18 changes: 18 additions & 0 deletions tests/e2e/scripts/load_docker_images
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -eox pipefail

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

LOAD_DIR=$1
if [ ! -d $LOAD_DIR ];then
echo "Directory not exists."
exit 1
fi

shift

for image in "$@"; do
key=$(createDockerImageCacheKey $image)
docker load -i "${LOAD_DIR}/${key}"
done
20 changes: 20 additions & 0 deletions tests/e2e/scripts/save_docker_images
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -eox pipefail

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

echo $@

SAVE_DIR=$1
if [ ! -d $SAVE_DIR ];then
echo "Directory not exists."
mkdir -p $SAVE_DIR
fi

shift

for image in "$@"; do
key=$(createDockerImageCacheKey $image)
docker save -o "${SAVE_DIR}/${key}" $image
done
Loading

0 comments on commit f7ae8d8

Please sign in to comment.