Skip to content

Commit 5b20403

Browse files
authored
Merge pull request #220 from tnull/2023-12-homogenous-ci
Make CI scripts more homogeneous
2 parents 6a8c9d9 + 4b8220b commit 5b20403

21 files changed

+878
-1092
lines changed

.github/workflows/cln.yml renamed to .github/workflows/cln-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration Checks - CLN
1+
name: CI Checks - CLN Integration Tests
22

33
on: [push, pull_request]
44

.github/workflows/kotlin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration Checks - Kotlin
1+
name: CI Checks - Kotlin Tests
22

33
on: [push, pull_request]
44

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration Checks - Python
1+
name: CI Checks - Python Tests
22

33
on: [push, pull_request]
44

.github/workflows/build.yml renamed to .github/workflows/rust.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration Checks
1+
name: CI Checks - Rust Tests
22

33
on: [push, pull_request]
44

@@ -46,13 +46,18 @@ jobs:
4646
cargo update -p proptest --precise "1.2.0" --verbose # proptest 1.3.0 requires rustc 1.64.0
4747
cargo update -p reqwest --precise "0.11.20" --verbose # reqwest 0.11.21 broke 1.63.0 MSRV
4848
cargo update -p regex --precise "1.9.6" --verbose # regex 1.10.0 requires rustc 1.65.0
49-
cargo update -p jobserver --precise "0.1.26" --verbose # jobserver 0.1.27 requires rustc 1.66.0
50-
cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5" --verbose # zstd-sys 2.0.9+zstd.1.5.5 requires rustc 1.64.0
51-
cargo update -p petgraph --precise "0.6.3" --verbose # petgraph v0.6.4, requires rustc 1.64 or newer
5249
cargo update -p home --precise "0.5.5" --verbose # home v0.5.9, requires rustc 1.70 or newer
5350
- name: Set RUSTFLAGS to deny warnings
5451
if: "matrix.toolchain == 'stable'"
5552
run: echo "RUSTFLAGS=-D warnings" >> "$GITHUB_ENV"
53+
- name: Download bitcoind/electrs and set environment variables
54+
if: "matrix.platform != 'windows-latest'"
55+
run: |
56+
source ./scripts/download_bitcoind_electrs.sh
57+
cp "$BITCOIND_EXE" "$HOME"/bitcoind
58+
cp "$ELECTRS_EXE" "$HOME"/electrs
59+
echo "BITCOIND_EXE=$HOME/bitcoind" >> "$GITHUB_ENV"
60+
echo "ELECTRS_EXE=$HOME/electrs" >> "$GITHUB_ENV"
5661
- name: Build on Rust ${{ matrix.toolchain }}
5762
run: cargo build --verbose --color always
5863
- name: Build with UniFFI support on Rust ${{ matrix.toolchain }}
@@ -69,10 +74,12 @@ jobs:
6974
run: cargo check --release --features uniffi --verbose --color always
7075
- name: Test on Rust ${{ matrix.toolchain }}
7176
if: "matrix.platform != 'windows-latest'"
72-
run: cargo test
77+
run: |
78+
RUSTFLAGS="--cfg no_download" cargo test
7379
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
7480
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
75-
run: cargo test --features uniffi
81+
run: |
82+
RUSTFLAGS="--cfg no_download" cargo test --features uniffi
7683
- name: Check formatting on Rust ${{ matrix.toolchain }}
7784
if: matrix.check-fmt
7885
run: rustup component add rustfmt && cargo fmt --all -- --check

.github/workflows/vss-integration.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: VSS Integration Test
1+
name: CI Checks - VSS Integration Tests
22

33
on: [push, pull_request]
44

@@ -74,8 +74,8 @@ jobs:
7474
run: |
7575
cd ldk-node
7676
export TEST_VSS_BASE_URL="http://localhost:8080/vss"
77-
RUSTFLAGS="--cfg=vss_test --cfg=vss" cargo build --verbose --color always
78-
RUSTFLAGS="--cfg=vss_test --cfg=vss" cargo test -- --nocapture
77+
RUSTFLAGS="--cfg vss_test --cfg vss" cargo build --verbose --color always
78+
RUSTFLAGS="--cfg vss_test --cfg vss" cargo test --test integration_tests_vss
7979
8080
- name: Cleanup
8181
run: |

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ winapi = { version = "0.3", features = ["winbase"] }
7676
[dev-dependencies]
7777
lightning = { version = "0.0.119", features = ["std", "_test_utils"] }
7878
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
79-
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
80-
electrum-client = { version = "0.18.0", default-features = true }
79+
electrum-client = { version = "0.15.1", default-features = true }
80+
bitcoincore-rpc = { version = "0.17.0", default-features = false }
8181
proptest = "1.0.0"
8282
regex = "1.5.6"
8383

84+
[target.'cfg(not(no_download))'.dev-dependencies]
85+
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
86+
87+
[target.'cfg(no_download)'.dev-dependencies]
88+
electrsd = { version = "0.26.0", features = ["legacy"] }
89+
8490
[target.'cfg(cln_test)'.dev-dependencies]
8591
clightningrpc = { version = "0.3.0-beta.8", default-features = false }
86-
bitcoincore-rpc = { version = "0.17.0", default-features = false }
8792

8893
[build-dependencies]
8994
uniffi = { version = "0.25.1", features = ["build"], optional = true }

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ hard_tabs = true # use tab characters for indentation, spaces for alignment
22
use_field_init_shorthand = true
33
max_width = 100
44
use_small_heuristics = "Max"
5-
fn_args_layout = "Compressed"
5+
fn_params_layout = "Compressed"

scripts/download_bitcoind_electrs.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Our Esplora-based tests require `electrs` and `bitcoind`
2+
# binaries. Here, we download the binaries, validate them, and export their
3+
# location via `ELECTRS_EXE`/`BITCOIND_EXE` which will be used by the
4+
# `electrsd`/`bitcoind` crates in our tests.
5+
6+
HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
7+
ELECTRS_DL_ENDPOINT="https://github.com/RCasatta/electrsd/releases/download/electrs_releases"
8+
ELECTRS_VERSION="esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254"
9+
BITCOIND_DL_ENDPOINT="https://bitcoincore.org/bin/"
10+
BITCOIND_VERSION="25.1"
11+
if [[ "$HOST_PLATFORM" == *linux* ]]; then
12+
ELECTRS_DL_FILE_NAME=electrs_linux_"$ELECTRS_VERSION".zip
13+
ELECTRS_DL_HASH="865e26a96e8df77df01d96f2f569dcf9622fc87a8d99a9b8fe30861a4db9ddf1"
14+
BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-linux-gnu.tar.gz
15+
BITCOIND_DL_HASH="a978c407b497a727f0444156e397b50491ce862d1f906fef9b521415b3611c8b"
16+
elif [[ "$HOST_PLATFORM" == *darwin* ]]; then
17+
ELECTRS_DL_FILE_NAME=electrs_macos_"$ELECTRS_VERSION".zip
18+
ELECTRS_DL_HASH="2d5ff149e8a2482d3658e9b386830dfc40c8fbd7c175ca7cbac58240a9505bcd"
19+
BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-apple-darwin.tar.gz
20+
BITCOIND_DL_HASH="1acfde0ec3128381b83e3e5f54d1c7907871d324549129592144dd12a821eff1"
21+
else
22+
echo "\n\nUnsupported platform: $HOST_PLATFORM Exiting.."
23+
exit 1
24+
fi
25+
26+
DL_TMP_DIR=$(mktemp -d)
27+
trap 'rm -rf -- "$DL_TMP_DIR"' EXIT
28+
29+
pushd "$DL_TMP_DIR"
30+
ELECTRS_DL_URL="$ELECTRS_DL_ENDPOINT"/"$ELECTRS_DL_FILE_NAME"
31+
curl -L -o "$ELECTRS_DL_FILE_NAME" "$ELECTRS_DL_URL"
32+
echo "$ELECTRS_DL_HASH $ELECTRS_DL_FILE_NAME"|shasum -a 256 -c
33+
unzip "$ELECTRS_DL_FILE_NAME"
34+
export ELECTRS_EXE="$DL_TMP_DIR"/electrs
35+
chmod +x "$ELECTRS_EXE"
36+
37+
BITCOIND_DL_URL="$BITCOIND_DL_ENDPOINT"/bitcoin-core-"$BITCOIND_VERSION"/"$BITCOIND_DL_FILE_NAME"
38+
curl -L -o "$BITCOIND_DL_FILE_NAME" "$BITCOIND_DL_URL"
39+
echo "$BITCOIND_DL_HASH $BITCOIND_DL_FILE_NAME"|shasum -a 256 -c
40+
tar xzf "$BITCOIND_DL_FILE_NAME"
41+
export BITCOIND_EXE="$DL_TMP_DIR"/bitcoin-"$BITCOIND_VERSION"/bin/bitcoind
42+
chmod +x "$BITCOIND_EXE"
43+
popd

src/event.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,7 @@ where
795795
#[cfg(test)]
796796
mod tests {
797797
use super::*;
798-
use crate::test::utils::TestLogger;
799-
use lightning::util::test_utils::TestStore;
798+
use lightning::util::test_utils::{TestLogger, TestStore};
800799

801800
#[test]
802801
fn event_queue_persistence() {

src/io/sqlite_store/migrations.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ pub(super) fn migrate_schema(
6969
#[cfg(test)]
7070
mod tests {
7171
use crate::io::sqlite_store::SqliteStore;
72-
use crate::io::test_utils::do_read_write_remove_list_persist;
73-
use crate::test::utils::random_storage_path;
72+
use crate::io::test_utils::{do_read_write_remove_list_persist, random_storage_path};
7473

7574
use lightning::util::persist::KVStore;
7675

src/io/sqlite_store/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ impl KVStore for SqliteStore {
284284
#[cfg(test)]
285285
mod tests {
286286
use super::*;
287-
use crate::io::test_utils::{do_read_write_remove_list_persist, do_test_store};
288-
use crate::test::utils::random_storage_path;
287+
use crate::io::test_utils::{
288+
do_read_write_remove_list_persist, do_test_store, random_storage_path,
289+
};
289290

290291
impl Drop for SqliteStore {
291292
fn drop(&mut self) {

src/io/test_utils.rs

Lines changed: 12 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use crate::io::sqlite_store::SqliteStore;
2-
use lightning_persister::fs_store::FilesystemStore;
3-
41
use lightning::ln::functional_test_utils::{
52
connect_block, create_announced_chan_between_nodes, create_chanmon_cfgs, create_dummy_block,
63
create_network, create_node_cfgs, create_node_chanmgrs, send_payment,
@@ -9,12 +6,22 @@ use lightning::util::persist::{read_channel_monitors, KVStore, KVSTORE_NAMESPACE
96

107
use lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
118
use lightning::events::ClosureReason;
12-
use lightning::util::test_utils::{self, TestStore};
9+
use lightning::util::test_utils;
1310
use lightning::{check_added_monitors, check_closed_broadcast, check_closed_event};
1411

12+
use rand::distributions::Alphanumeric;
13+
use rand::{thread_rng, Rng};
14+
1515
use std::panic::RefUnwindSafe;
1616
use std::path::PathBuf;
17-
use std::sync::RwLock;
17+
18+
pub(crate) fn random_storage_path() -> PathBuf {
19+
let mut temp_path = std::env::temp_dir();
20+
let mut rng = thread_rng();
21+
let rand_dir: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
22+
temp_path.push(rand_dir);
23+
temp_path
24+
}
1825

1926
pub(crate) fn do_read_write_remove_list_persist<K: KVStore + RefUnwindSafe>(kv_store: &K) {
2027
let data = [42u8; 32];
@@ -173,148 +180,3 @@ pub(crate) fn do_test_store<K: KVStore>(store_0: &K, store_1: &K) {
173180
// Make sure everything is persisted as expected after close.
174181
check_persisted_data!(CLOSED_CHANNEL_UPDATE_ID);
175182
}
176-
177-
// A `KVStore` impl for testing purposes that wraps all our `KVStore`s and asserts their synchronicity.
178-
pub(crate) struct TestSyncStore {
179-
serializer: RwLock<()>,
180-
test_store: TestStore,
181-
fs_store: FilesystemStore,
182-
sqlite_store: SqliteStore,
183-
}
184-
185-
impl TestSyncStore {
186-
pub(crate) fn new(dest_dir: PathBuf) -> Self {
187-
let serializer = RwLock::new(());
188-
let mut fs_dir = dest_dir.clone();
189-
fs_dir.push("fs_store");
190-
let fs_store = FilesystemStore::new(fs_dir);
191-
let mut sql_dir = dest_dir.clone();
192-
sql_dir.push("sqlite_store");
193-
let sqlite_store = SqliteStore::new(
194-
sql_dir,
195-
Some("test_sync_db".to_string()),
196-
Some("test_sync_table".to_string()),
197-
)
198-
.unwrap();
199-
let test_store = TestStore::new(false);
200-
Self { serializer, fs_store, sqlite_store, test_store }
201-
}
202-
203-
fn do_list(
204-
&self, primary_namespace: &str, secondary_namespace: &str,
205-
) -> std::io::Result<Vec<String>> {
206-
let fs_res = self.fs_store.list(primary_namespace, secondary_namespace);
207-
let sqlite_res = self.sqlite_store.list(primary_namespace, secondary_namespace);
208-
let test_res = self.test_store.list(primary_namespace, secondary_namespace);
209-
210-
match fs_res {
211-
Ok(mut list) => {
212-
list.sort();
213-
214-
let mut sqlite_list = sqlite_res.unwrap();
215-
sqlite_list.sort();
216-
assert_eq!(list, sqlite_list);
217-
218-
let mut test_list = test_res.unwrap();
219-
test_list.sort();
220-
assert_eq!(list, test_list);
221-
222-
Ok(list)
223-
}
224-
Err(e) => {
225-
assert!(sqlite_res.is_err());
226-
assert!(test_res.is_err());
227-
Err(e)
228-
}
229-
}
230-
}
231-
}
232-
233-
impl KVStore for TestSyncStore {
234-
fn read(
235-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
236-
) -> std::io::Result<Vec<u8>> {
237-
let _guard = self.serializer.read().unwrap();
238-
239-
let fs_res = self.fs_store.read(primary_namespace, secondary_namespace, key);
240-
let sqlite_res = self.sqlite_store.read(primary_namespace, secondary_namespace, key);
241-
let test_res = self.test_store.read(primary_namespace, secondary_namespace, key);
242-
243-
match fs_res {
244-
Ok(read) => {
245-
assert_eq!(read, sqlite_res.unwrap());
246-
assert_eq!(read, test_res.unwrap());
247-
Ok(read)
248-
}
249-
Err(e) => {
250-
assert!(sqlite_res.is_err());
251-
assert_eq!(e.kind(), unsafe { sqlite_res.unwrap_err_unchecked().kind() });
252-
assert!(test_res.is_err());
253-
assert_eq!(e.kind(), unsafe { test_res.unwrap_err_unchecked().kind() });
254-
Err(e)
255-
}
256-
}
257-
}
258-
259-
fn write(
260-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8],
261-
) -> std::io::Result<()> {
262-
let _guard = self.serializer.write().unwrap();
263-
let fs_res = self.fs_store.write(primary_namespace, secondary_namespace, key, buf);
264-
let sqlite_res = self.sqlite_store.write(primary_namespace, secondary_namespace, key, buf);
265-
let test_res = self.test_store.write(primary_namespace, secondary_namespace, key, buf);
266-
267-
assert!(self
268-
.do_list(primary_namespace, secondary_namespace)
269-
.unwrap()
270-
.contains(&key.to_string()));
271-
272-
match fs_res {
273-
Ok(()) => {
274-
assert!(sqlite_res.is_ok());
275-
assert!(test_res.is_ok());
276-
Ok(())
277-
}
278-
Err(e) => {
279-
assert!(sqlite_res.is_err());
280-
assert!(test_res.is_err());
281-
Err(e)
282-
}
283-
}
284-
}
285-
286-
fn remove(
287-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
288-
) -> std::io::Result<()> {
289-
let _guard = self.serializer.write().unwrap();
290-
let fs_res = self.fs_store.remove(primary_namespace, secondary_namespace, key, lazy);
291-
let sqlite_res =
292-
self.sqlite_store.remove(primary_namespace, secondary_namespace, key, lazy);
293-
let test_res = self.test_store.remove(primary_namespace, secondary_namespace, key, lazy);
294-
295-
assert!(!self
296-
.do_list(primary_namespace, secondary_namespace)
297-
.unwrap()
298-
.contains(&key.to_string()));
299-
300-
match fs_res {
301-
Ok(()) => {
302-
assert!(sqlite_res.is_ok());
303-
assert!(test_res.is_ok());
304-
Ok(())
305-
}
306-
Err(e) => {
307-
assert!(sqlite_res.is_err());
308-
assert!(test_res.is_err());
309-
Err(e)
310-
}
311-
}
312-
}
313-
314-
fn list(
315-
&self, primary_namespace: &str, secondary_namespace: &str,
316-
) -> std::io::Result<Vec<String>> {
317-
let _guard = self.serializer.read().unwrap();
318-
self.do_list(primary_namespace, secondary_namespace)
319-
}
320-
}

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ mod logger;
8585
mod payment_store;
8686
mod peer_store;
8787
mod sweep;
88-
#[cfg(test)]
89-
mod test;
9088
mod tx_broadcaster;
9189
mod types;
9290
#[cfg(feature = "uniffi")]

src/payment_store.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ where
219219
#[cfg(test)]
220220
mod tests {
221221
use super::*;
222-
use crate::test::utils::TestLogger;
223-
use lightning::util::test_utils::TestStore;
222+
use lightning::util::test_utils::{TestLogger, TestStore};
224223
use std::sync::Arc;
225224

226225
#[test]

src/peer_store.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ impl_writeable_tlv_based!(PeerInfo, {
143143
#[cfg(test)]
144144
mod tests {
145145
use super::*;
146-
use crate::test::utils::TestLogger;
147-
148-
use lightning::util::test_utils::TestStore;
146+
use lightning::util::test_utils::{TestLogger, TestStore};
149147

150148
use std::str::FromStr;
151149
use std::sync::Arc;

0 commit comments

Comments
 (0)