From 910fe4728a80090a093dd3c7d4c914062a05cc26 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 16 Jan 2023 12:22:39 -0800 Subject: [PATCH] Add Bitcoin Core test job to CI (#1191) --- .github/workflows/ci.yaml | 21 +++++++++++++++++++++ bin/install-bitcoin-core-linux | 15 +++++++++++++++ deploy/setup | 3 +-- src/subcommand/preview.rs | 2 +- tests/{preview.rs => core.rs} | 29 +++++++++++++++-------------- tests/lib.rs | 2 +- 6 files changed, 54 insertions(+), 18 deletions(-) create mode 100755 bin/install-bitcoin-core-linux rename tests/{preview.rs => core.rs} (55%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 56e5fc7030..670de3de50 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -68,6 +68,7 @@ jobs: run: | sudo apt-get install ripgrep ./bin/forbid + test: strategy: matrix: @@ -91,3 +92,23 @@ jobs: - name: Test run: cargo test --all + + core: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Install Rust Toolchain Components + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + + - uses: Swatinem/rust-cache@v2 + + - name: Install Bitcoin Core + run: ./bin/install-bitcoin-core-linux + + - name: Test + run: cargo test --all -- --ignored diff --git a/bin/install-bitcoin-core-linux b/bin/install-bitcoin-core-linux new file mode 100755 index 0000000000..778ba5bc80 --- /dev/null +++ b/bin/install-bitcoin-core-linux @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +version=24.0.1 + +wget \ + -O bitcoin.tar.gz \ + https://bitcoincore.org/bin/bitcoin-core-$version/bitcoin-$version-x86_64-linux-gnu.tar.gz + +tar \ + -xzvf bitcoin.tar.gz \ + -C /usr/local/bin \ + --strip-components 2 \ + bitcoin-$version/bin/{bitcoin-cli,bitcoind} diff --git a/deploy/setup b/deploy/setup index 7d3a7e391f..913832e5a3 100755 --- a/deploy/setup +++ b/deploy/setup @@ -55,8 +55,7 @@ esac ufw --force enable if ! which bitcoind; then - wget -O bitcoin.tar.gz 'https://bitcoincore.org/bin/bitcoin-core-23.0/bitcoin-23.0-x86_64-linux-gnu.tar.gz' - tar -xzvf bitcoin.tar.gz -C /usr/local/bin --strip-components=2 "bitcoin-23.0/bin/bitcoin-cli" "bitcoin-23.0/bin/bitcoind" + ./bin/install-bitcoin-core-linux fi bitcoind --version diff --git a/src/subcommand/preview.rs b/src/subcommand/preview.rs index d54363068d..c8446f9b94 100644 --- a/src/subcommand/preview.rs +++ b/src/subcommand/preview.rs @@ -33,7 +33,7 @@ impl Preview { arg }) .arg("-regtest") - .arg("-txindex=1") + .arg("-txindex") .arg("-listen=0") .arg(format!("-rpcport={rpc_port}")) .spawn() diff --git a/tests/preview.rs b/tests/core.rs similarity index 55% rename from tests/preview.rs rename to tests/core.rs index 8d7f067e2d..0d70784b6b 100644 --- a/tests/preview.rs +++ b/tests/core.rs @@ -1,26 +1,29 @@ use super::*; +struct KillOnDrop(std::process::Child); + +impl Drop for KillOnDrop { + fn drop(&mut self) { + self.0.kill().unwrap() + } +} + #[test] #[ignore] -fn run() { - let rpc_server = test_bitcoincore_rpc::spawn(); - +fn preview() { let port = TcpListener::bind("127.0.0.1:0") .unwrap() .local_addr() .unwrap() .port(); - let builder = CommandBuilder::new(format!("preview --http-port {port} foo.txt")) - .rpc_server(&rpc_server) - .write("foo.txt", "TEST_INSCRIPTION"); - - let mut command = builder.command(); + let builder = + CommandBuilder::new(format!("preview --http-port {port} foo.txt")).write("foo.txt", "foo"); - let mut child = command.spawn().unwrap(); + let _child = KillOnDrop(builder.command().spawn().unwrap()); for attempt in 0.. { - if let Ok(response) = reqwest::blocking::get(format!("http://localhost:{port}/status")) { + if let Ok(response) = reqwest::blocking::get(format!("http://127.0.0.1:{port}/status")) { if response.status() == 200 { assert_eq!(response.text().unwrap(), "OK"); break; @@ -35,12 +38,10 @@ fn run() { } assert!( - reqwest::blocking::get(format!("http://localhost:{port}/inscriptions")) + reqwest::blocking::get(format!("http://127.0.0.1:{port}/inscriptions")) .unwrap() .text() .unwrap() - .contains("TEST_INSCRIPTION") + .contains("