#!/usr/bin/env bash
set -xeuo pipefail

cd "$(git rev-parse --show-toplevel)"

./tests/chutney/setup proxy

# shellcheck disable=SC1091
source tests/chutney/arti.run
# Validate that CHUTNEY_DATA_DIR is set.
[ -n "${CHUTNEY_DATA_DIR:?}" ]

./tests/chutney/test
./tests/chutney/stop-arti

# Get the socks port of a tor client to use for benchmarking comparison.
# TODO: Do this in a more robust way.
[ -n "${target:?}" ] # should have been set from arti.run
if [ "${target}" = "basic" ]; then
    tor_client_port=9008
else
    echo "Don't know how to get tor client port of target $target"
    exit 1
fi

RUST_LOG=debug target/x86_64-unknown-linux-gnu/release/arti-bench -c "$CHUTNEY_DATA_DIR"/nodes/arti.toml --socks5 127.0.0.1:"$tor_client_port" -o benchmark_results.json

./tests/chutney/teardown
