Skip to content

Commit 06cf0a0

Browse files
authored
test: replacing nostr-rs-relay crate with github aciton (#791)
1 parent 53b8286 commit 06cf0a0

3 files changed

Lines changed: 12 additions & 75 deletions

File tree

.github/workflows/test.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
partition: [1,2,3,4,5,6,7,8,9,10]
16+
partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1717
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
20-
18+
- name: Start up Nostr Relay
19+
uses: hulxv/[email protected]
20+
with:
21+
version: "0.9.0"
22+
port: "8000"
23+
address: "127.0.0.1"
2124
- name: Install protobuf compiler
2225
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
2328

2429
- name: Cache
2530
uses: actions/cache@v4
@@ -60,4 +65,4 @@ jobs:
6065
uses: codecov/codecov-action@v4
6166
with:
6267
token: ${{ secrets.CODECOV_TOKEN }}
63-
files: ./coverage/reports/cobertura-${{ strategy.job-index }}.xml
68+
files: ./coverage/reports/cobertura-${{ strategy.job-index }}.xml

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ crossbeam-channel = "0.5.15"
4141
[dev-dependencies]
4242
flate2 = {version = "1.0.35"}
4343
tar = {version = "0.4.43"}
44-
nostr-rs-relay = "0.8.12"
4544

4645
#Empty default feature set, (helpful to generalise in github actions)
4746
[features]

tests/test_framework/mod.rs

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ macro_rules! assert_in_range {
2929

3030
use bip39::rand;
3131
use bitcoin::Amount;
32-
use nostr_rs_relay::{config, server::start_server};
3332
use std::{
3433
env,
3534
fs::{self, create_dir_all, File},
3635
io::{BufReader, Read},
37-
net::TcpStream,
3836
path::{Path, PathBuf},
3937
sync::{
4038
atomic::{AtomicBool, Ordering::Relaxed},
41-
mpsc, Arc, Mutex,
39+
Arc, Mutex,
4240
},
4341
thread::{self, JoinHandle},
44-
time::{Duration, Instant},
42+
time::Duration,
4543
};
4644

4745
use flate2::read::GzDecoder;
@@ -536,8 +534,6 @@ pub struct TestFramework {
536534
pub(super) bitcoind: BitcoinD,
537535
pub(super) temp_dir: PathBuf,
538536
shutdown: AtomicBool,
539-
nostr_relay_shutdown: mpsc::Sender<()>,
540-
nostr_relay_handle: Option<JoinHandle<()>>,
541537
block_generation_handle: Mutex<Option<JoinHandle<()>>>,
542538
makers: Mutex<Option<Vec<Arc<Maker>>>>,
543539
taproot_makers: Mutex<Option<Vec<Arc<TaprootMaker>>>>, // Added
@@ -576,17 +572,11 @@ impl TestFramework {
576572

577573
let bitcoind = init_bitcoind(&temp_dir, zmq_addr.clone());
578574

579-
log::info!("🌐 Spawning local nostr relay for tests");
580-
let (nostr_relay_shutdown, nostr_relay_handle) = spawn_nostr_relay(&temp_dir);
581-
_ = wait_for_relay_healthy();
582-
583575
let shutdown = AtomicBool::new(false);
584576
let test_framework = Arc::new(Self {
585577
bitcoind,
586578
temp_dir: temp_dir.clone(),
587579
shutdown,
588-
nostr_relay_shutdown,
589-
nostr_relay_handle: Some(nostr_relay_handle),
590580
block_generation_handle: Mutex::new(None),
591581
makers: Mutex::new(None),
592582
taproot_makers: Mutex::new(None),
@@ -714,16 +704,11 @@ impl TestFramework {
714704

715705
let bitcoind = init_bitcoind(&temp_dir, zmq_addr.clone());
716706

717-
log::info!("🌐 Spawning local nostr relay for tests");
718-
let (nostr_relay_shutdown, nostr_relay_handle) = spawn_nostr_relay(&temp_dir);
719-
720707
let shutdown = AtomicBool::new(false);
721708
let test_framework = Arc::new(Self {
722709
bitcoind,
723710
temp_dir: temp_dir.clone(),
724711
shutdown,
725-
nostr_relay_shutdown,
726-
nostr_relay_handle: Some(nostr_relay_handle),
727712
block_generation_handle: Mutex::new(None),
728713
makers: Mutex::new(None),
729714
taproot_makers: Mutex::new(None),
@@ -848,15 +833,6 @@ impl Drop for TestFramework {
848833
log::info!("Shutting down bitcoind...");
849834
let _ = self.bitcoind.client.stop().unwrap();
850835

851-
log::info!("Shutting down nostr relay...");
852-
_ = self.nostr_relay_shutdown.send(());
853-
854-
if let Some(handle) = self.nostr_relay_handle.take() {
855-
if let Err(e) = handle.join() {
856-
log::error!("Nostr relay thread join failed: {:?}", e);
857-
}
858-
}
859-
860836
log::info!("Test Framework cleanup complete.");
861837
}
862838
}
@@ -873,46 +849,3 @@ impl From<&TestFramework> for RPCConfig {
873849
}
874850
}
875851
}
876-
877-
fn spawn_nostr_relay(temp_dir: &Path) -> (mpsc::Sender<()>, JoinHandle<()>) {
878-
let data_dir = temp_dir.join("nostr-relay");
879-
std::fs::create_dir_all(&data_dir).unwrap();
880-
881-
let addr = "127.0.0.1".to_string();
882-
let port = 8000;
883-
884-
let mut settings = config::Settings::default();
885-
settings.network.address = addr;
886-
settings.network.port = port;
887-
settings.database.min_conn = 4;
888-
settings.database.max_conn = 8;
889-
settings.database.in_memory = true;
890-
settings.diagnostics.tracing = true;
891-
892-
let (shutdown_tx, shutdown_rx) = mpsc::channel::<()>();
893-
894-
let handle = thread::spawn(move || {
895-
start_server(&settings, shutdown_rx).expect("nostr relay crashed");
896-
});
897-
898-
(shutdown_tx, handle)
899-
}
900-
901-
fn wait_for_relay_healthy() -> Result<(), String> {
902-
let addr = "127.0.0.1:8000".to_string();
903-
let timeout = Duration::from_secs(10);
904-
let start = Instant::now();
905-
906-
while start.elapsed() < timeout {
907-
if TcpStream::connect(&addr).is_ok() {
908-
log::info!("Nostr relay is alive");
909-
return Ok(());
910-
}
911-
912-
std::thread::sleep(Duration::from_millis(50));
913-
}
914-
915-
log::error!("Nostr relay not alive");
916-
917-
Err("nostr relay did not become healthy on port 8000".to_string())
918-
}

0 commit comments

Comments
 (0)