From 67086055c20fd33e78a9730e910226f2e03b1f19 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Fri, 29 Sep 2023 10:36:18 +0800 Subject: [PATCH] add compliance test --- .gitea/workflows/tests.yml | 62 ++++++++++++++++- scripts/compare-statediffs.sh | 121 ++++++++++++++++++++++++++++++++++ scripts/request-range.sh | 2 +- test/ci-config.toml | 8 ++- 4 files changed, 188 insertions(+), 5 deletions(-) create mode 100755 scripts/compare-statediffs.sh diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index e89919b..0964bd4 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: # Complete integration tests are TODO - name: Run basic integration test env: - DATABASE_TYPE: postgres + STATEDIFF_MODE: postgres LEVELDB_PATH: ./fixtures/chaindata/_data/small LEVELDB_ANCIENT: ./fixtures/chaindata/_data/small/ancient LOG_FILE: ./server-log @@ -71,3 +71,63 @@ jobs: [[ "$(count_results eth.header_cids)" = 33 ]] [[ "$(count_results eth.state_cids)" = 21 ]] [[ "$(count_results eth.storage_cids)" = 18 ]] + + compliance-test: + name: Run compliance tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + path: ./eth-statediff-service + - uses: actions/setup-go@v3 + with: + go-version-file: ./eth-statediff-service/go.mod + check-latest: true + - name: Install test fixtures + uses: actions/checkout@v3 + with: + repository: cerc-io/eth-testing + path: ./fixtures + ref: v0.3.1 + - name: Configure Gitea access + env: + TOKEN: ${{ secrets.CICD_REPO_TOKEN }} + run: | + git config --global url."https://$TOKEN:@git.vdb.to/".insteadOf https://git.vdb.to/ + - name: Build current version + working-directory: ./eth-statediff-service + run: go build -o ../service-current . + + - name: Checkout canonical version + uses: actions/checkout@v3 + with: + path: ./eth-statediff-service-canonical + ref: ${{ env.CANONICAL_VERSION }} + - name: Build canonical version + working-directory: ./eth-statediff-service-canonical + run: go build -o ../service-canonical . + + - name: Run dockerd + run: | + dockerd -H $DOCKER_HOST --userland-proxy=false & + sleep 5 + - name: Run DB container + working-directory: ./eth-statediff-service + run: docker compose -f test/compose.yml up --wait + - name: Compare statediff output + timeout-minutes: 10 + env: + LEVELDB_PATH: ./fixtures/chaindata/_data/small2 + LEVELDB_ANCIENT: ./fixtures/chaindata/_data/small2/ancient + ETH_GENESIS_BLOCK: "0x8a3c7cddacbd1ab4ec1b03805fa2a287f3a75e43d87f4f987fcc399f5c042614" + ETH_CHAIN_CONFIG: ./eth-statediff-service/test/ci-chain.json + run: | + until + ready_query='select max(version_id) from goose_db_version;' + version=$(docker exec -e PGPASSWORD=password test-ipld-eth-db-1 \ + psql -tA cerc_testing -U vdbm -c "$ready_query") + [[ "$version" -ge 18 ]] + do sleep 1; done + + ./eth-statediff-service/scripts/compare-statediffs.sh \ + ./service-canonical ./service-current diff --git a/scripts/compare-statediffs.sh b/scripts/compare-statediffs.sh new file mode 100755 index 0000000..6478166 --- /dev/null +++ b/scripts/compare-statediffs.sh @@ -0,0 +1,121 @@ +#!/bin/bash +# +# Usage: compare-versions.sh [-d ] +# +# Compares full statediff output from two versions of the service. +# Configure the input data using environment vars. +( + set -u + : $LEVELDB_PATH + : $LEVELDB_ANCIENT + : $ETH_GENESIS_BLOCK + : $ETH_CHAIN_CONFIG +) || exit 1 + +# Range of diffs to request +range_start=50 +range_end=100 + +# Get the parent directory +script_dir=$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")") + +while getopts d: opt; do + case $opt in + d) output_dir="$OPTARG" + esac +done +shift $((OPTIND - 1)) + +binary_A=$1 +binary_B=$2 +shift 2 + +if [[ -z $output_dir ]]; then + output_dir=$(mktemp -d) +fi + +export STATEDIFF_MODE=postgres +export STATEDIFF_TRIE_WORKERS=32 +export STATEDIFF_SERVICE_WORKERS=8 +export STATEDIFF_WORKER_QUEUE_SIZE=1024 + +export DATABASE_NAME="cerc_testing" +export DATABASE_HOSTNAME="localhost" +export DATABASE_PORT=8077 +export DATABASE_USER="vdbm" +export DATABASE_PASSWORD="password" + +export ETH_NODE_ID=test-node +export ETH_CLIENT_NAME=test-client +export ETH_NETWORK_ID=test-network +export ETH_CHAIN_ID=4242 + +export SERVICE_HTTP_PATH='127.0.0.1:8545' +export LOG_LEVEL=debug + +dump_table() { + statement="copy (select * from $1) to stdout with csv" + docker exec -e PGPASSWORD="$DATABASE_PASSWORD" test-ipld-eth-db-1 \ + psql -q $DATABASE_NAME -U $DATABASE_USER -c "$statement" | sort -u > "$2/$1.csv" +} + +clear_table() { + docker exec -e PGPASSWORD="$DATABASE_PASSWORD" test-ipld-eth-db-1 \ + psql -q $DATABASE_NAME -U $DATABASE_USER -c "truncate $1" +} + +tables=( + eth.log_cids + eth.receipt_cids + eth.state_cids + eth.storage_cids + eth.transaction_cids + eth.uncle_cids + ipld.blocks + public.nodes +) + +for table in "${tables[@]}"; do + clear_table $table +done + +run_service() { + export LOG_FILE=$(mktemp) + export LOG_FILE_PATH=$LOG_FILE + + service_binary=$1 + service_output_dir=$2 + + $service_binary serve & + + until grep "HTTP endpoint opened" $LOG_FILE + do sleep 1; done + + $script_dir/request-range.sh $range_start $range_end + if E=$?; [[ $E != 0 ]]; then + cat $LOG_FILE + return $E + fi + + echo "Waiting for service to complete requests..." + + until grep \ + -e "Finished processing block $range_end" \ + -e "finished processing statediff height $range_end" \ + $LOG_FILE + do sleep 1; done + + kill -INT $! + + mkdir -p $service_output_dir + for table in "${tables[@]}"; do + dump_table $table $service_output_dir + clear_table $table + done +} + +set -e +run_service $binary_A $output_dir/A +run_service $binary_B $output_dir/B + +diff -rs $output_dir/A $output_dir/B diff --git a/scripts/request-range.sh b/scripts/request-range.sh index 6924fe5..1bd6ce6 100755 --- a/scripts/request-range.sh +++ b/scripts/request-range.sh @@ -4,7 +4,7 @@ set -eu FROM=$1 TO=$2 -URL=127.0.0.1:8545 +URL='127.0.0.1:8545' DATA='{ "jsonrpc": "2.0", diff --git a/test/ci-config.toml b/test/ci-config.toml index cbc6fca..c2ef305 100644 --- a/test/ci-config.toml +++ b/test/ci-config.toml @@ -1,3 +1,5 @@ +# Config file for service in compose.yml + [leveldb] mode = "local" url = "http://127.0.0.1:8082/" @@ -29,7 +31,7 @@ [ethereum] chainConfig = "test/ci-chain.json" - nodeID = "" - clientName = "eth-statediff-service" - networkID = 1 + nodeID = "test-node" + clientName = "test-eth-statediff-service" + networkID = "test-network" chainID = 41337