Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-write CI #338

Closed
wants to merge 4 commits into from
Closed
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
139 changes: 82 additions & 57 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,87 @@
on: [push, pull_request]
on:
push:
branches:
- master
- 'test-ci/**'
pull_request:

name: Continuous integration

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rust: stable
env:
RUSTFMTCHK: true
- rust: nightly
env:
RUSTFMTCHK: false
- rust: 1.56.1
env:
RUSTFMTCHK: false
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Running test script
env: ${{ matrix.env }}
run: ./contrib/test.sh
Stable:
name: Test - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: "Run test script"
run: ./contrib/run_task.sh stable

integrations-tests:
name: Integration Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable]
bitcoinversion:
[
"0.18.0",
"0.18.1",
"0.19.0.1",
"0.19.1",
"0.20.0",
"0.20.1",
"0.21.0",
]
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Running test script
env:
BITCOINVERSION: ${{ matrix.bitcoinversion }}
run: ./contrib/test.sh
Nightly:
name: Test - nightly toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@nightly
- name: "Run test script"
run: ./contrib/run_task.sh nightly

MSRV:
name: Test - 1.56.1 toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.56.1"
- name: "Run test script"
run: ./contrib/run_task.sh msrv

Format:
name: Format - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: "Check formatting"
run: cargo fmt --all -- --check

Integration:
name: Integration Tests - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bitcoin_version:
[
"0.18.0",
"0.18.1",
"0.19.0.1",
"0.19.1",
"0.20.0",
"0.20.1",
"0.21.0",
]
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: Running test script
run: ./contrib/run_task.sh integration ${{ matrix.bitcoin_version }}
16 changes: 13 additions & 3 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ edition = "2018"
name = "bitcoincore_rpc"
path = "src/lib.rs"

[features]
verifymessage = ["bitcoincore-rpc-json/verifymessage"]

[dependencies]
bitcoincore-rpc-json = { version = "0.18.0", path = "../json" }

log = "0.4.5"
jsonrpc = "0.14.0"

# Used for deserialization of JSON.
serde = "1"
serde_json = "1"
serde = "1.0.156"
serde_json = "1.0.96"

[dev-dependencies]
tempfile = "3.3.0"
tempfile = "3.6.0"

[[example]]
name = "retry_client"
required-features = ["verifymessage"]

[[example]]
name = "test_against_node"
required-features = []
16 changes: 12 additions & 4 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use jsonrpc;
use serde;
use serde_json;

use crate::bitcoin::address::{NetworkUnchecked, NetworkChecked};
use crate::bitcoin::address::{NetworkChecked, NetworkUnchecked};
use crate::bitcoin::hashes::hex::FromHex;
use bitcoin::sign_message::MessageSignature;
use crate::bitcoin::{
Address, Amount, Block, OutPoint, PrivateKey, PublicKey, Script, Transaction,
};
use bitcoin::sign_message::MessageSignature;
use log::Level::{Debug, Trace, Warn};

use crate::error::*;
Expand Down Expand Up @@ -871,6 +871,7 @@ pub trait RpcApi: Sized {
self.call("stop", &[])
}

#[cfg(feature = "verifymessage")]
fn verify_message(
&self,
address: &Address,
Expand All @@ -891,7 +892,10 @@ pub trait RpcApi: Sized {
}

/// Generate new address for receiving change
fn get_raw_change_address(&self, address_type: Option<json::AddressType>) -> Result<Address<NetworkUnchecked>> {
fn get_raw_change_address(
&self,
address_type: Option<json::AddressType>,
) -> Result<Address<NetworkUnchecked>> {
self.call("getrawchangeaddress", &[opt_into_json(address_type)?])
}

Expand Down Expand Up @@ -1182,7 +1186,11 @@ pub trait RpcApi: Sized {
self.call("finalizepsbt", handle_defaults(&mut args, &[true.into()]))
}

fn derive_addresses(&self, descriptor: &str, range: Option<[u32; 2]>) -> Result<Vec<Address<NetworkUnchecked>>> {
fn derive_addresses(
&self,
descriptor: &str,
range: Option<[u32; 2]>,
) -> Result<Vec<Address<NetworkUnchecked>>> {
let mut args = [into_json(descriptor)?, opt_into_json(range)?];
self.call("deriveaddresses", handle_defaults(&mut args, &[null()]))
}
Expand Down
149 changes: 149 additions & 0 deletions contrib/run_task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env bash
#
# Run CI task, called by the `rust.yml` GitHub action.

set -euo pipefail

REPO_DIR=$(git rev-parse --show-toplevel)
MSRV="1.56.1"

usage() {
cat <<EOF
Usage:

./run_task.sh TASK

TASK
- stable Run stable toolchain tests.
- nightly Run nightly toolchain tests.
- msrv Run MSRV toolchain tests.
- fmt Run the formatter (rustfmt).
- integration Run integration test for specific Bitcoin Core version.

./run_task.sh integration BITCOIN_CORE_VERSION [DOWNLOAD_CORE]

Example
./run_task.sh integration # Runs integration tests against bitcoind from your path.
./run_task.sh integration 0.21.0 # Downloads Core version 0.21.0 and runs integration tests againts it.

EOF
}

# Make all cargo invocations verbose.
export CARGO_TERM_VERBOSE=true

main() {
local task="${1:-usage}"
local bitcoin_version="${2:-none}"

if [ "$task" = "usage" ] || [ "$task" = "-h" ] || [ "$task" = "--help" ]; then
usage
exit 0
fi

check_required_commands

cargo --version
rustc --version
/usr/bin/env bash --version
locale
env

case $task in
stable)
build_and_test "+stable"
;;

nightly)
build_and_test "+nightly"
;;

msrv)
do_msrv_pins
build_and_test "+$MSRV"
;;

fmt)
do_fmt
;;

integration)
integration "$bitcoin_version"
;;

*)
echo ""
usage
err "Error: unknown task $task"
;;
esac
}

# Build and test workspace.
build_and_test() {
local toolchain="$1"

for crate in json client integration_test; do
pushd "$REPO_DIR/$crate" > /dev/null;

cargo "$toolchain" build
cargo "$toolchain" test

popd > /dev/null
done
}

# Pin dependencies to get the MSRV build to work.
do_msrv_pins() {
cargo update -p tempfile --precise 3.6.0
cargo update -p cc --precise 1.0.79
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.96
cargo update -p serde --precise 1.0.156
}

# Check the workspace formatting.
do_fmt() {
cargo +stable fmt --all --check
}

# Pulls down Bitcoin Core binary and runs the integration tests.
integration() {
local core_version="$1"

cd "$REPO_DIR"

if [ "$core_version" != "none" ]; then
wget "https://bitcoincore.org/bin/bitcoin-core-$bitcoin_version/bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
tar -xzvf "bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
export PATH=$PATH:"$REPO_DIR/bitcoin-$bitcoin_version/bin"
fi

need_cmd "bitcoind"

cd "$REPO_DIR/integration_test"
./run.sh
}

# Check all the commands we use are present in the current environment.
check_required_commands() {
need_cmd cargo
need_cmd rustc
}

need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
then err "need '$1' (command not found)"
fi
}

err() {
echo "$1" >&2
exit 1
}

#
# Main script
#
main "$@"
exit 0
3 changes: 3 additions & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ fi
# Test pinned versions.
if cargo --version | grep ${MSRV}; then
cargo update -p tempfile --precise 3.3.0
cargo update -p cc --precise 1.0.79
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.96
cargo update -p serde --precise 1.0.156
fi

# Integration test.
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Steven Roose <steven@stevenroose.org>"]
edition = "2018"

[dependencies]
bitcoincore-rpc = { path = "../client" }
bitcoincore-rpc = { path = "../client", features = ["verifymessage"] }
bitcoin = { version = "0.31.0", features = ["serde", "rand", "base64"]}
lazy_static = "1.4.0"
log = "0.4"
Loading