Skip to content

Commit

Permalink
Add Bitcoin Core test job to CI (ordinals#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Jan 16, 2023
1 parent 004e615 commit 910fe47
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
run: |
sudo apt-get install ripgrep
./bin/forbid
test:
strategy:
matrix:
Expand All @@ -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
15 changes: 15 additions & 0 deletions bin/install-bitcoin-core-linux
Original file line number Diff line number Diff line change
@@ -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}
3 changes: 1 addition & 2 deletions deploy/setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Preview {
arg
})
.arg("-regtest")
.arg("-txindex=1")
.arg("-txindex")
.arg("-listen=0")
.arg(format!("-rpcport={rpc_port}"))
.spawn()
Expand Down
29 changes: 15 additions & 14 deletions tests/preview.rs → tests/core.rs
Original file line number Diff line number Diff line change
@@ -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:https://localhost:{port}/status")) {
if let Ok(response) = reqwest::blocking::get(format!("http:https://127.0.0.1:{port}/status")) {
if response.status() == 200 {
assert_eq!(response.text().unwrap(), "OK");
break;
Expand All @@ -35,12 +38,10 @@ fn run() {
}

assert!(
reqwest::blocking::get(format!("http:https://localhost:{port}/inscriptions"))
reqwest::blocking::get(format!("http:https://127.0.0.1:{port}/inscriptions"))
.unwrap()
.text()
.unwrap()
.contains("TEST_INSCRIPTION")
.contains("<a href=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/inscription/")
);

child.kill().unwrap();
}
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ fn create_wallet(rpc_server: &test_bitcoincore_rpc::Handle) {
}

mod command_builder;
mod core;
mod epochs;
mod expected;
mod find;
mod index;
mod info;
mod list;
mod parse;
mod preview;
mod server;
mod subsidy;
mod supply;
Expand Down

0 comments on commit 910fe47

Please sign in to comment.