diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2985a39..bc7617d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,14 +26,5 @@ jobs: restore-keys: ccache-${{ runner.os }}- - name: Checkout Bitcoin Core run: git clone --depth 1 --branch master https://github.com/bitcoin/bitcoin.git - - name: Build Bitcoin Core - run: | - cd bitcoin - cmake -B build -DENABLE_WALLET=ON -DBUILD_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build build -j $(nproc) - - name: Run Bitcoin Core Daemon - run: cd bitcoin && ./build/bin/bitcoin node -chain=regtest -ipcbind=unix -server -debug=ipc -daemon - - name: Run Test Suite - env: - BITCOIN_BIN: ${{ github.workspace }}/bitcoin/build/bin/bitcoin - run: cargo test + - name: Build & Run Test Suite + run: contrib/run-tests.sh bitcoin diff --git a/README.md b/README.md index af642a4..a86d620 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ cargo build ## Running integration tests -The integration tests connect to a running bitcoin node via IPC. +The integration tests connect to a running bitcoin node via IPC. For a single test script, see `contrib/run-tests.sh`. ### 1. Build Bitcoin Core diff --git a/contrib/run-tests.sh b/contrib/run-tests.sh new file mode 100755 index 0000000..24b5ea3 --- /dev/null +++ b/contrib/run-tests.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# +# Build Bitcoin Core, launch a regtest node with IPC enabled, run the +# integration test suite against it, and shut the node down. +# +# Usage: contrib/run-tests.sh + +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +BITCOIN_SRC=$(cd "$1" && pwd) +REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd) +BITCOIN_BIN="$BITCOIN_SRC/build/bin/bitcoin" + +echo "==> Building Bitcoin Core in $BITCOIN_SRC" +( + cd "$BITCOIN_SRC" + CMAKE_ARGS=(-DENABLE_WALLET=ON -DBUILD_TESTS=OFF) + if command -v ccache >/dev/null 2>&1; then + CMAKE_ARGS+=(-DCMAKE_C_COMPILER_LAUNCHER=ccache + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache) + fi + cmake -B build "${CMAKE_ARGS[@]}" + cmake --build build -j"$(nproc)" +) + +stop_bitcoin() { + if [ -n "${BITCOIN_STARTED:-}" ]; then + echo "==> Stopping bitcoin" + "$BITCOIN_BIN" rpc -chain=regtest stop || true + fi +} +trap stop_bitcoin EXIT + +echo "==> Starting bitcoin node (regtest, IPC)" +"$BITCOIN_BIN" node -chain=regtest -ipcbind=unix -server -debug=ipc -daemon +BITCOIN_STARTED=1 + +echo "==> Running cargo test" +( + cd "$REPO_ROOT" + BITCOIN_BIN="$BITCOIN_BIN" cargo test +)