Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Bitcoin Dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential cmake pkgconf python3 libevent-dev libboost-dev capnproto libcapnp-dev ccache
- name: ccache
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: ~/.cache/ccache
key: ccache-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-
- name: Checkout Bitcoin Core
run: git clone --depth 1 --branch 32.x https://github.com/bitcoin/bitcoin.git
- name: Build Bitcoin Core
- name: Build & Run Test Suite
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
ccache --zero-stats
contrib/run-tests.sh bitcoin
ccache --show-stats
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 15 additions & 2 deletions RELEASE_POLICY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@ This policy applies to:

## Branch Model

- `master` tracks the current active development line.
- Maintenance branches (for example `30.x`, `31.x`, `32.x`) track stable backport lines.
- `master` tracks the current active development line, i.e. Bitcoin Core `master`.
- Maintenance branches (for example `30.x`, `31.x`) track stable backport lines, i.e. the Bitcoin Core branch of the same name.
- A release must be cut from the branch that owns that version line.

### Maintenance Branches

- A maintenance branch is created from `master` after Bitcoin Core branches off, at a point where the schema files match the new Bitcoin Core branch.
- Its CI builds the Bitcoin Core branch of the same name, and runs for pushes and pull requests that target the maintenance branch.
- After creation it only receives backports from `master` and fixes specific to that branch. It must never be fast-forwarded to, or merged with, `master`.
- The schema files must keep matching the corresponding Bitcoin Core branch. Interface changes are only backported if Bitcoin Core backported them. Test and build changes can be backported more freely.
- Backported commits reference the original pull request and commit on `master`, using the Bitcoin Core convention:

```
Github-Pull: #<number>
Rebased-From: <commit hash on master>
```

## Version Line Mapping

- `30.x` branch -> `0.1.x`
Expand Down
48 changes: 48 additions & 0 deletions contrib/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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 <path-to-bitcoin-source>

set -euo pipefail

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path-to-bitcoin-source>" >&2
exit 1
fi

BITCOIN_SRC=$(cd "$1" && pwd)
REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
BITCOIN_BIN="$BITCOIN_SRC/build/bin/bitcoin"
TEMP_DATADIR=$(mktemp -d)

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 --parallel "$(getconf _NPROCESSORS_ONLN)"
)

stop_bitcoin() {
if [ -n "${BITCOIN_STARTED:-}" ]; then
echo "==> Stopping bitcoin"
"$BITCOIN_BIN" rpc -chain=regtest -datadir="$TEMP_DATADIR" stop || true
fi
}
trap stop_bitcoin EXIT

echo "==> Starting bitcoin node (regtest, IPC) with -datadir=$TEMP_DATADIR"
"$BITCOIN_BIN" node -chain=regtest -ipcbind=unix -server -debug=ipc -datadir="$TEMP_DATADIR" -daemon
BITCOIN_STARTED=1

echo "==> Running cargo test"
(
cd "$REPO_ROOT"
BITCOIN_BIN="$BITCOIN_BIN" BITCOIN_DATADIR="$TEMP_DATADIR" cargo test
)
68 changes: 53 additions & 15 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bitcoin_capnp_types::{
};
use capnp_rpc::{RpcSystem, rpc_twoparty_capnp::Side};
use encoding::encode_to_vec;
use std::time::Duration;
use tokio::task::LocalSet;

mod util;
Expand Down Expand Up @@ -109,7 +110,7 @@ async fn rpc_query_uptime() {
.map_err(|e| format!("failed to parse rpc response as JSON: {e}"))
.unwrap();
let uptime = v["result"].as_i64().unwrap();
assert!(uptime > 0, "Uptime must be greater than zero");
assert!(uptime >= 0, "Uptime must not be negative");
})
.await;
}
Expand Down Expand Up @@ -242,6 +243,32 @@ async fn mining_wait_tip_changed() {
let wait_result = resp.get().unwrap().get_result().unwrap();
assert_eq!(wait_result.get_hash().unwrap().len(), 32);
assert_eq!(wait_result.get_height(), tip_height);

// No timeout. Pin a local task on the wait, then interrupt it.
let mut req = mining.wait_tip_changed_request();
req.get().set_current_tip(&tip_hash);
let waiter = tokio::task::spawn_local(req.send().promise);

// Give the waiter time to block before interrupting.
tokio::time::sleep(Duration::from_millis(100)).await;
assert!(
!waiter.is_finished(),
"waitTipChanged returned before interrupt"
);
mining
.interrupt_request()
.send()
.promise
.await
.expect("interrupt should not fail");

let joined = tokio::time::timeout(Duration::from_secs(10), waiter)
.await
.expect("interrupt should unblock waitTipChanged");
assert!(
joined.is_ok_and(|resp| resp.is_ok()),
"interrupted waitTipChanged should return normally"
);
})
.await;
}
Expand Down Expand Up @@ -333,7 +360,7 @@ async fn mining_block_template_inspection() {
.await;
}

/// waitNext (short timeout), interruptWait, submitSolution (garbage), destroy.
/// waitNext (short timeout), waitNext interrupted by interruptWait, submitSolution (garbage), destroy.
#[tokio::test]
// Serialized because submitSolution behavior depends on current chain tip.
#[serial_test::serial]
Expand All @@ -355,14 +382,34 @@ async fn mining_block_template_lifecycle() {
"waitNext should time out without a new template"
);

// interruptWait — should not crash.
// waitNext — no timeout. Pin a local task on the wait, then interrupt it.
let mut req = template.wait_next_request();
req.get()
.init_options()
.set_fee_threshold(mining_capnp::MAX_MONEY);
let waiter = tokio::task::spawn_local(req.send().promise);

// Give the waiter time to block before interrupting.
tokio::time::sleep(Duration::from_millis(100)).await;
assert!(
!waiter.is_finished(),
"waitNext returned before interruptWait"
);
template
.interrupt_wait_request()
.send()
.promise
.await
.expect("interruptWait should not fail");

let joined = tokio::time::timeout(Duration::from_secs(10), waiter)
.await
.expect("interrupWait should unblock waitNext");
assert!(
joined.is_ok_and(|resp| resp.is_ok()),
"interrupted waitNext should return normally"
);

// submitSolution — garbage coinbase should be rejected.
// This mutates the template, so we do it right before destroy.
let mut req = template.submit_solution_request();
Expand Down Expand Up @@ -627,11 +674,10 @@ async fn mining_get_transactions() {
.await;
}

/// checkBlock with a template block payload, and interrupt.
/// checkBlock with a template block payload.
#[tokio::test]
// Serialized because interrupt() can affect other in-flight mining waits.
#[serial_test::serial]
async fn mining_check_block_and_interrupt() {
#[serial_test::parallel]
async fn mining_check_block() {
with_mining_client(|_client, mining| async move {
let template = make_block_template(&mining).await;

Expand Down Expand Up @@ -663,14 +709,6 @@ async fn mining_check_block_and_interrupt() {
}

destroy_template(&template).await;

// interrupt — should not crash.
mining
.interrupt_request()
.send()
.promise
.await
.expect("interrupt should not fail");
})
.await;
}
Expand Down
26 changes: 16 additions & 10 deletions tests/util/bitcoin_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::{
};

use crate::util::bitcoin_core_wallet::{
bitcoin_rpc_json, bitcoin_test_wallet, ensure_wallet_loaded, mine_blocks_to_new_address,
bitcoin_datadir, bitcoin_rpc_json, bitcoin_test_wallet, ensure_wallet_loaded,
mine_blocks_to_new_address,
};
use bitcoin_capnp_types::{
init_capnp::init,
Expand All @@ -23,15 +24,20 @@ use tokio_util::compat::{Compat, TokioAsyncReadCompatExt, TokioAsyncWriteCompatE
static CHAIN_SETUP: Once = Once::new();

pub fn unix_socket_path() -> PathBuf {
let home_dir_string = std::env::var("HOME").unwrap();
let home_dir = home_dir_string.parse::<PathBuf>().unwrap();
let bitcoin_dir = if cfg!(target_os = "macos") {
home_dir
.join("Library")
.join("Application Support")
.join("Bitcoin")
} else {
home_dir.join(".bitcoin")
let bitcoin_dir = match bitcoin_datadir() {
Some(datadir) => datadir.parse::<PathBuf>().unwrap(),
None => {
let home_dir_string = std::env::var("HOME").unwrap();
let home_dir = home_dir_string.parse::<PathBuf>().unwrap();
if cfg!(target_os = "macos") {
home_dir
.join("Library")
.join("Application Support")
.join("Bitcoin")
} else {
home_dir.join(".bitcoin")
}
}
};
let regtest_dir = bitcoin_dir.join("regtest");
regtest_dir.join("node.sock")
Expand Down
7 changes: 7 additions & 0 deletions tests/util/bitcoin_core_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ fn bitcoin_bin() -> String {
std::env::var("BITCOIN_BIN").unwrap_or_else(|_| "bitcoin".to_owned())
}

pub fn bitcoin_datadir() -> Option<String> {
std::env::var("BITCOIN_DATADIR").ok()
}

fn bitcoin_rpc(wallet: Option<&str>, args: &[&str]) -> Result<String, String> {
let owned_args: Vec<String> = args.iter().map(|arg| (*arg).to_owned()).collect();
bitcoin_rpc_owned(wallet, &owned_args)
Expand All @@ -29,6 +33,9 @@ pub fn bitcoin_test_wallet() -> String {
fn bitcoin_rpc_owned(wallet: Option<&str>, args: &[String]) -> Result<String, String> {
let mut command = Command::new(bitcoin_bin());
command.arg("rpc").arg("-chain=regtest").arg("-rpcwait");
if let Some(datadir) = bitcoin_datadir() {
command.arg(format!("-datadir={datadir}"));
}
if let Some(wallet) = wallet {
command.arg(format!("-rpcwallet={wallet}"));
}
Expand Down
Loading