From d2077fb057e49c7197e32b8dadc6de7ad8be4647 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 | 60 +++++++++++++++++- scripts/compare-statediffs.sh | 112 ++++++++++++++++++++++++++++++++++ scripts/request-range.sh | 2 +- 3 files changed, 172 insertions(+), 2 deletions(-) create mode 100755 scripts/compare-statediffs.sh diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index e89919b..b7fac61 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,61 @@ 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 + env: + LEVELDB_PATH: ./fixtures/chaindata/_data/small2 + LEVELDB_ANCIENT: ./fixtures/chaindata/_data/small2/ancient + ETH_GENESIS_BLOCK: "0x8a3c7cddacbd1ab4ec1b03805fa2a287f3a75e43d87f4f987fcc399f5c042614" + 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..e6fc8d8 --- /dev/null +++ b/scripts/compare-statediffs.sh @@ -0,0 +1,112 @@ +#!/bin/bash +# Compare the full snapshot output from two versions of the service +# +# Usage: compare-versions.sh [-d ] +# +# Configure the input data using environment vars. +( + set -u + : $LEVELDB_PATH + : $LEVELDB_ANCIENT + : $ETH_GENESIS_BLOCK +) + +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 DATABASE_NAME="cerc_testing" +export DATABASE_HOSTNAME="localhost" +export DATABASE_PORT=8077 +export DATABASE_USER="vdbm" +export DATABASE_PASSWORD="password" + +export ETH_CLIENT_NAME=test-client +export ETH_NODE_ID=test-node +export ETH_NETWORK_ID=test-network + +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 + +range_start=190 +range_end=200 + +run_service() { + export LOG_FILE=$(mktemp) + export LOG_FILE_PATH=$LOG_FILE + + service_binary=$1 + service_output_dir=$2 + + $service_binary serve --config ./test/ci-config.toml serve & + + until grep "HTTP endpoint opened" $LOG_FILE + do sleep 1; done + + ./scripts/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",