2019-01-24 16:37:55 +00:00
|
|
|
#!/bin/sh -ex
|
|
|
|
|
2022-05-25 06:41:59 +00:00
|
|
|
FEATURES="base64 bitcoinconsensus serde rand secp-recovery"
|
2021-06-09 10:34:44 +00:00
|
|
|
|
|
|
|
# Use toolchain if explicitly specified
|
|
|
|
if [ -n "$TOOLCHAIN" ]
|
|
|
|
then
|
|
|
|
alias cargo="cargo +$TOOLCHAIN"
|
|
|
|
fi
|
2019-01-24 16:37:55 +00:00
|
|
|
|
2019-07-26 19:23:02 +00:00
|
|
|
if [ "$DO_COV" = true ]
|
|
|
|
then
|
|
|
|
export RUSTFLAGS="-C link-dead-code"
|
|
|
|
fi
|
|
|
|
|
2022-07-13 23:43:59 +00:00
|
|
|
cargo --version
|
|
|
|
rustc --version
|
2019-07-26 19:23:02 +00:00
|
|
|
|
2022-07-13 23:53:31 +00:00
|
|
|
# Work out if we are using a nightly toolchain.
|
|
|
|
NIGHTLY=false
|
|
|
|
if cargo --version | grep nightly; then
|
|
|
|
NIGHTLY=true
|
|
|
|
fi
|
|
|
|
|
2022-07-21 01:10:07 +00:00
|
|
|
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies
|
|
|
|
# in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp).
|
2022-08-09 12:49:45 +00:00
|
|
|
cargo update -p serde --precise 1.0.142
|
|
|
|
cargo update -p serde_test --precise 1.0.142
|
|
|
|
cargo update -p serde_derive --precise 1.0.142
|
2022-07-21 01:10:07 +00:00
|
|
|
duplicate_dependencies=$(cargo tree --target=all --all-features --duplicates | wc -l)
|
|
|
|
if [ "$duplicate_dependencies" -ne 0 ]; then
|
|
|
|
echo "Dependency tree is broken, contains duplicates"
|
|
|
|
cargo tree --target=all --all-features --duplicates
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-30 00:40:51 +00:00
|
|
|
if [ "$DO_LINT" = true ]
|
|
|
|
then
|
|
|
|
cargo clippy --all-features --all-targets -- -D warnings
|
|
|
|
cargo clippy --example bip32 -- -D warnings
|
|
|
|
cargo clippy --example handshake -- -D warnings
|
|
|
|
cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
|
|
|
|
fi
|
|
|
|
|
2021-06-09 10:34:44 +00:00
|
|
|
echo "********* Testing std *************"
|
|
|
|
# Test without any features other than std first
|
|
|
|
cargo test --verbose --no-default-features --features="std"
|
2019-01-24 16:37:55 +00:00
|
|
|
|
2021-06-09 10:34:44 +00:00
|
|
|
echo "********* Testing default *************"
|
2020-10-07 15:46:48 +00:00
|
|
|
# Then test with the default features
|
2019-01-24 16:37:55 +00:00
|
|
|
cargo test --verbose
|
|
|
|
|
2021-06-09 10:34:44 +00:00
|
|
|
if [ "$DO_NO_STD" = true ]
|
|
|
|
then
|
2022-03-08 04:30:09 +00:00
|
|
|
echo "********* Testing no-std build *************"
|
|
|
|
# Build no_std, to make sure that cfg(test) doesn't hide any issues
|
|
|
|
cargo build --verbose --features="no-std" --no-default-features
|
2021-06-09 10:34:44 +00:00
|
|
|
|
2022-03-08 04:30:09 +00:00
|
|
|
# Build std + no_std, to make sure they are not incompatible
|
|
|
|
cargo build --verbose --features="no-std"
|
2021-06-09 10:34:44 +00:00
|
|
|
|
2022-03-08 04:30:09 +00:00
|
|
|
# Test no_std
|
|
|
|
cargo test --verbose --features="no-std" --no-default-features
|
2021-06-09 10:34:44 +00:00
|
|
|
|
2022-03-08 04:30:09 +00:00
|
|
|
# Build all features
|
|
|
|
cargo build --verbose --features="no-std $FEATURES" --no-default-features
|
2021-06-09 10:34:44 +00:00
|
|
|
|
2022-03-08 04:30:09 +00:00
|
|
|
# Build specific features
|
|
|
|
for feature in ${FEATURES}
|
|
|
|
do
|
|
|
|
cargo build --verbose --features="no-std $feature"
|
|
|
|
done
|
2021-06-09 10:34:44 +00:00
|
|
|
|
2022-03-08 04:30:09 +00:00
|
|
|
cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
|
|
|
|
cargo run --no-default-features --features no-std --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
|
2021-06-09 10:34:44 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-24 16:37:55 +00:00
|
|
|
# Test each feature
|
|
|
|
for feature in ${FEATURES}
|
|
|
|
do
|
2021-06-09 10:34:44 +00:00
|
|
|
echo "********* Testing "$feature" *************"
|
2019-01-24 16:37:55 +00:00
|
|
|
cargo test --verbose --features="$feature"
|
|
|
|
done
|
|
|
|
|
2022-07-19 01:02:20 +00:00
|
|
|
cargo run --example ecdsa-psbt --features=bitcoinconsensus
|
|
|
|
|
2022-03-08 04:36:54 +00:00
|
|
|
# Build the docs if told to (this only works with the nightly toolchain)
|
|
|
|
if [ "$DO_DOCS" = true ]; then
|
2022-06-20 23:12:40 +00:00
|
|
|
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links
|
2022-03-08 04:36:54 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-24 16:37:55 +00:00
|
|
|
# Fuzz if told to
|
|
|
|
if [ "$DO_FUZZ" = true ]
|
|
|
|
then
|
|
|
|
(
|
|
|
|
cd fuzz
|
|
|
|
cargo test --verbose
|
|
|
|
./travis-fuzz.sh
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
2022-07-12 00:07:38 +00:00
|
|
|
# Bench if told to, only works with non-stable toolchain (nightly, beta).
|
2019-01-24 16:37:55 +00:00
|
|
|
if [ "$DO_BENCH" = true ]
|
|
|
|
then
|
2022-07-13 23:53:31 +00:00
|
|
|
if [ "NIGHTLY" = false ]
|
|
|
|
then
|
|
|
|
if [ -n "TOOLCHAIN" ]
|
|
|
|
then
|
|
|
|
echo "TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
|
|
|
|
else
|
|
|
|
echo "DO_BENCH requires a nightly toolchain"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-07-12 00:07:38 +00:00
|
|
|
RUSTFLAGS='--cfg=bench' cargo bench
|
2019-01-24 16:37:55 +00:00
|
|
|
fi
|
2019-08-18 16:26:52 +00:00
|
|
|
|
|
|
|
# Use as dependency if told to
|
2021-06-09 10:34:44 +00:00
|
|
|
if [ "$AS_DEPENDENCY" = true ]
|
2019-08-18 16:26:52 +00:00
|
|
|
then
|
|
|
|
cargo new dep_test
|
|
|
|
cd dep_test
|
2022-05-25 06:41:59 +00:00
|
|
|
echo 'bitcoin = { path = "..", features = ["serde"] }' >> Cargo.toml
|
2022-08-09 12:49:45 +00:00
|
|
|
cargo update -p serde --precise 1.0.142
|
|
|
|
cargo update -p serde_derive --precise 1.0.142
|
2020-09-10 17:55:47 +00:00
|
|
|
|
2019-08-18 16:26:52 +00:00
|
|
|
cargo test --verbose
|
|
|
|
fi
|