5cae6d45de5f56a778fc95b2e78b5c5fd9f5ffb6
[rust-lightning] / ci / ci-tests.sh
1 #!/bin/bash
2 set -eox pipefail
3
4 RUSTC_MINOR_VERSION=$(rustc --version | awk '{ split($2,a,"."); print a[2] }')
5 HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
6
7 # Some crates require pinning to meet our MSRV even for our downstream users,
8 # which we do here.
9 # Further crates which appear only as dev-dependencies are pinned further down.
10 function PIN_RELEASE_DEPS {
11         return 0 # Don't fail the script if our rustc is higher than the last check
12 }
13
14 # The tests of `lightning-transaction-sync` require `electrs` and `bitcoind`
15 # binaries. Here, we download the binaries, validate them, and export their
16 # location via `ELECTRS_EXE`/`BITCOIND_EXE` which will be used by the
17 # `electrsd`/`bitcoind` crates in our tests.
18 function DOWNLOAD_ELECTRS_AND_BITCOIND {
19         ELECTRS_DL_ENDPOINT="https://github.com/RCasatta/electrsd/releases/download/electrs_releases"
20         ELECTRS_VERSION="esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254"
21         BITCOIND_DL_ENDPOINT="https://bitcoincore.org/bin/"
22         BITCOIND_VERSION="25.1"
23         if [[ "$HOST_PLATFORM" == *linux* ]]; then
24                 ELECTRS_DL_FILE_NAME=electrs_linux_"$ELECTRS_VERSION".zip
25                 ELECTRS_DL_HASH="865e26a96e8df77df01d96f2f569dcf9622fc87a8d99a9b8fe30861a4db9ddf1"
26                 BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-linux-gnu.tar.gz
27                 BITCOIND_DL_HASH="a978c407b497a727f0444156e397b50491ce862d1f906fef9b521415b3611c8b"
28         elif [[ "$HOST_PLATFORM" == *darwin* ]]; then
29                 ELECTRS_DL_FILE_NAME=electrs_macos_"$ELECTRS_VERSION".zip
30                 ELECTRS_DL_HASH="2d5ff149e8a2482d3658e9b386830dfc40c8fbd7c175ca7cbac58240a9505bcd"
31                 BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-apple-darwin.tar.gz
32                 BITCOIND_DL_HASH="1acfde0ec3128381b83e3e5f54d1c7907871d324549129592144dd12a821eff1"
33         else
34                 echo -e "\n\nUnsupported platform. Exiting.."
35                 exit 1
36         fi
37
38         DL_TMP_DIR=$(mktemp -d)
39         trap 'rm -rf -- "$DL_TMP_DIR"' EXIT
40
41         pushd "$DL_TMP_DIR"
42         ELECTRS_DL_URL="$ELECTRS_DL_ENDPOINT"/"$ELECTRS_DL_FILE_NAME"
43         curl -L -o "$ELECTRS_DL_FILE_NAME" "$ELECTRS_DL_URL"
44         echo "$ELECTRS_DL_HASH  $ELECTRS_DL_FILE_NAME"|shasum -a 256 -c
45         unzip "$ELECTRS_DL_FILE_NAME"
46         export ELECTRS_EXE="$DL_TMP_DIR"/electrs
47         chmod +x "$ELECTRS_EXE"
48
49         BITCOIND_DL_URL="$BITCOIND_DL_ENDPOINT"/bitcoin-core-"$BITCOIND_VERSION"/"$BITCOIND_DL_FILE_NAME"
50         curl -L -o "$BITCOIND_DL_FILE_NAME" "$BITCOIND_DL_URL"
51         echo "$BITCOIND_DL_HASH  $BITCOIND_DL_FILE_NAME"|shasum -a 256 -c
52         tar xzf "$BITCOIND_DL_FILE_NAME"
53         export BITCOIND_EXE="$DL_TMP_DIR"/bitcoin-"$BITCOIND_VERSION"/bin/bitcoind
54         chmod +x "$BITCOIND_EXE"
55         popd
56 }
57
58 PIN_RELEASE_DEPS # pin the release dependencies in our main workspace
59
60 # Starting with version 1.10.0, the `regex` crate has an MSRV of rustc 1.65.0.
61 [ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
62
63 # The addr2line v0.21 crate (a dependency of `backtrace` starting with 0.3.69) relies on rustc 1.65
64 [ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p backtrace --precise "0.3.68" --verbose
65
66 # Starting with version 0.5.9 (there is no .6-.8), the `home` crate has an MSRV of rustc 1.70.0.
67 [ "$RUSTC_MINOR_VERSION" -lt 70 ] && cargo update -p home --precise "0.5.5" --verbose
68
69 export RUST_BACKTRACE=1
70
71 # Build `lightning-transaction-sync` in no_download mode.
72 export RUSTFLAGS="$RUSTFLAGS --cfg no_download"
73
74 echo -e "\n\nBuilding and testing all workspace crates..."
75 cargo test --verbose --color always
76 cargo check --verbose --color always
77
78 echo -e "\n\nBuilding and testing Block Sync Clients with features"
79 pushd lightning-block-sync
80 cargo test --verbose --color always --features rest-client
81 cargo check --verbose --color always --features rest-client
82 cargo test --verbose --color always --features rpc-client
83 cargo check --verbose --color always --features rpc-client
84 cargo test --verbose --color always --features rpc-client,rest-client
85 cargo check --verbose --color always --features rpc-client,rest-client
86 cargo test --verbose --color always --features rpc-client,rest-client,tokio
87 cargo check --verbose --color always --features rpc-client,rest-client,tokio
88 popd
89
90 if [[ "$HOST_PLATFORM" != *windows* ]]; then
91         echo -e "\n\nBuilding and testing Transaction Sync Clients with features"
92         pushd lightning-transaction-sync
93
94         DOWNLOAD_ELECTRS_AND_BITCOIND
95
96         cargo test --verbose --color always --features esplora-blocking
97         cargo check --verbose --color always --features esplora-blocking
98         cargo test --verbose --color always --features esplora-async
99         cargo check --verbose --color always --features esplora-async
100         cargo test --verbose --color always --features esplora-async-https
101         cargo check --verbose --color always --features esplora-async-https
102         cargo test --verbose --color always --features electrum
103         cargo check --verbose --color always --features electrum
104         popd
105 fi
106
107 echo -e "\n\nTest futures builds"
108 pushd lightning-background-processor
109 cargo test --verbose --color always --features futures
110 popd
111
112 echo -e "\n\nTest Custom Message Macros"
113 pushd lightning-custom-message
114 cargo test --verbose --color always
115 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
116 popd
117
118 echo -e "\n\nTest backtrace-debug builds"
119 pushd lightning
120 cargo test --verbose --color always --features backtrace
121 popd
122
123 echo -e "\n\nBuilding with all Log-Limiting features"
124 pushd lightning
125 grep '^max_level_' Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
126         RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check --verbose --color always --features "$FEATURE"
127 done
128 popd
129
130 echo -e "\n\nTesting no-std flags in various combinations"
131 for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
132         cargo test -p $DIR --verbose --color always --no-default-features --features no-std
133         # check if there is a conflict between no-std and the default std feature
134         cargo test -p $DIR --verbose --color always --features no-std
135 done
136
137 for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
138         # check if there is a conflict between no-std and the c_bindings cfg
139         RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
140 done
141 RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
142
143 # Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
144 pushd lightning
145 cargo test --verbose --color always --no-default-features --features=std,_test_vectors
146 popd
147 # This one only works for lightning-invoice
148 pushd lightning-invoice
149 # check that compile with no-std and serde works in lightning-invoice
150 cargo test --verbose --color always --no-default-features --features no-std --features serde
151 popd
152
153 echo -e "\n\nTesting no-std build on a downstream no-std crate"
154 # check no-std compatibility across dependencies
155 pushd no-std-check
156 cargo check --verbose --color always --features lightning-transaction-sync
157 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
158 popd
159
160 # Test that we can build downstream code with only the "release pins".
161 pushd msrv-no-dev-deps-check
162 PIN_RELEASE_DEPS
163 cargo check
164 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
165 popd
166
167 if [ -f "$(which arm-none-eabi-gcc)" ]; then
168         pushd no-std-check
169         cargo build --target=thumbv7m-none-eabi
170         [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
171         popd
172 fi
173
174 echo -e "\n\nTest cfg-flag builds"
175 RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
176 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
177 RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
178 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
179 RUSTFLAGS="--cfg=dual_funding" cargo test --verbose --color always -p lightning