From 62d5169f210907d1bfe11085f1601fde50ede304 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:20:14 +1000 Subject: [PATCH 1/8] Fail script if command fails Use the Bash `set -e` option to make the test script fail if a command fails. While we are at it add sanity check commands that call the compiler and `cargo`. --- contrib/test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 021027cce..1140dd25c 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,5 +1,7 @@ #!/bin/sh -ex +set -e + FEATURES="compiler use-serde rand" # Use toolchain if explicitly specified @@ -8,6 +10,9 @@ then alias cargo="cargo +$TOOLCHAIN" fi +cargo --version +rustc --version + # Format if told to if [ "$DO_FMT" = true ] then From b072a5f8122fdc0ed162fb61b4cb748b46286d24 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:22:12 +1000 Subject: [PATCH 2/8] Do not run fuzzer in subprocess There is no obvious reason to run the fuzzer in a subprocess. Remove the subprocess from the fuzzing code. While we are at it change the code comment to state what it does instead of mentioning the CI vms. --- contrib/test.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index 1140dd25c..55649e305 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -25,14 +25,12 @@ fi # Fuzz if told to if [ "$DO_FUZZ" = true ] then - ( - cd fuzz - cargo test --verbose - ./travis-fuzz.sh - # Exit out of the fuzzer, - # run stable tests in other CI vms - exit 0 - ) + cd fuzz + cargo test --verbose + ./travis-fuzz.sh + + # Exit out of the fuzzer, do not run other tests. + exit 0 fi # Test without any features first From 04577224f72bf66e24de7c5d0d0137797a706ed3 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:27:10 +1000 Subject: [PATCH 3/8] Do not run formatter in subprocess There is no obvious reason to run the fuzzer in a subprocess. Remove the subprocess from the fuzzing code. --- contrib/test.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index 55649e305..48049a9f4 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -16,10 +16,8 @@ rustc --version # Format if told to if [ "$DO_FMT" = true ] then - ( - rustup component add rustfmt - cargo fmt --all -- --check - ) + rustup component add rustfmt + cargo fmt --all -- --check fi # Fuzz if told to From 3913a08dfb3d55fd7b0153f66bb8c6d36fca0f6f Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:35:57 +1000 Subject: [PATCH 4/8] Improve test coverage In an effort to improve test coverage without being inefficient add a new env variable `DO_FEATURE_MATRIX` to the test script. This is how we do it over in `rust-secp256k1`, it enables good test coverage while not having to run the whole matrix in every CI job. Add cargo calls for each example because the current way we run the examples does not work for those who configure the build output directory to something other than the default. --- contrib/test.sh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index 48049a9f4..0b3197eac 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -31,19 +31,29 @@ then exit 0 fi -# Test without any features first -cargo test --verbose +# Defaults / sanity checks +cargo test -# Test each feature -for feature in ${FEATURES} -do - cargo test --verbose --features="$feature" -done +if [ "$DO_FEATURE_MATRIX" = true ] +then + # All features + cargo test --features="$FEATURES" + + # Single features + for feature in ${FEATURES} + do + cargo test --features="$feature" + done -# Also build and run each example to catch regressions -cargo build --examples -# run all examples -run-parts ./target/debug/examples + # Run all the examples + cargo build --examples + cargo run --example htlc --features=compiler + cargo run --example parse + cargo run --example sign_multisig + cargo run --example verify_tx > /dev/null + cargo run --example psbt + cargo run --example xpub_descriptors +fi # Bench if told to (this only works with the nightly toolchain) if [ "$DO_BENCH" = true ] From a5718f76a9885a1e2c0d51992527bc3ed115fb94 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:44:09 +1000 Subject: [PATCH 5/8] Explicitly exit test script with 0 Be a good UNIX hacker and exit the test script explicitly with a success value. --- contrib/test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 0b3197eac..65d3038a9 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -78,3 +78,5 @@ if [ -n "$BITCOINVERSION" ]; then rm -rf bitcoin-$BITCOINVERSION exit 0 fi + +exit 0 From ca9988de6cb441c5b4293d78fc0b3b10920d5333 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:52:06 +1000 Subject: [PATCH 6/8] Add additional information to nightly job As we do in `rust-secp256k1` use a string that includes 'Nightly' in name of the nightly test. --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index efca76af8..0e70d6a08 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,7 +27,7 @@ jobs: run: ./contrib/test.sh Nightly: - name: Bench + Docs + Fmt + name: Nightly - Bench + Docs + Fmt runs-on: ubuntu-latest steps: - name: Checkout Crate From 27df8630e5c7f419d5f1a3d0d7b2095f3731ab82 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:54:49 +1000 Subject: [PATCH 7/8] Run feature matrix tests In the `Tests` CI job run the feature matrix tests. Also run these tests for 4 toolchains, stable, beta, nightly, and 1.41.1 --- .github/workflows/rust.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0e70d6a08..2b6bfe099 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -51,14 +51,12 @@ jobs: DO_FMT: true run: ./contrib/test.sh - UnitTests: + Tests: name: Tests runs-on: ubuntu-latest strategy: matrix: - rust: - - 1.41.1 - - beta + rust: [stable, beta, nightly, 1.41.1] steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -69,6 +67,8 @@ jobs: toolchain: ${{ matrix.rust }} override: true - name: Running cargo + env: + DO_FEATURE_MATRIX: true run: ./contrib/test.sh AllTests: From ed51323a0bb3257b09abfb5eb51ca21815b815af Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 15:56:57 +1000 Subject: [PATCH 8/8] Rename and simplify integration test job Rename the integration test job to `IntTests` now that we do not run the full matrix of unit tests in this job. Simplify the yaml by removing the strategy section since we only use a single toolchain in this job. --- .github/workflows/rust.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2b6bfe099..4680dd209 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -71,13 +71,9 @@ jobs: DO_FEATURE_MATRIX: true run: ./contrib/test.sh - AllTests: - name: Unit + Int tests + IntTests: + name: Integration tests runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -85,7 +81,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: stable override: true - name: Running cargo env: