lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

commit b49706932e67e3b9199ecc8ccb989c900e134032
parent 027daa86bd09bdbf1cd0d003e1a505f3621d37dd
Author: triesap <tyson@radroots.org>
Date:   Fri,  6 Mar 2026 00:40:14 +0000

tests: stabilize codec discount and ndb query hooks

Diffstat:
Mcrates/events-codec/tests/tag_builders.rs | 18+++++++++++++++---
Mcrates/nostr-ndb/src/ndb.rs | 30++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/crates/events-codec/tests/tag_builders.rs b/crates/events-codec/tests/tag_builders.rs @@ -589,9 +589,21 @@ fn listing_and_message_builders_cover_optional_shapes() { RadrootsCoreCurrency::USD, )), }]); - let err = listing_tags_with_options(&listing_with_discount_payload, trade_options) - .expect_err("discounts require serde_json in non-serde lane"); - assert!(matches!(err, EventEncodeError::Json)); + #[cfg(feature = "serde_json")] + { + let tags = listing_tags_with_options(&listing_with_discount_payload, trade_options) + .expect("discount serialization works"); + assert!( + tags.iter() + .any(|tag| tag.first().map(|v| v.as_str()) == Some("radroots:discount")) + ); + } + #[cfg(not(feature = "serde_json"))] + { + let err = listing_tags_with_options(&listing_with_discount_payload, trade_options) + .expect_err("discounts require serde_json in non-serde lane"); + assert!(matches!(err, EventEncodeError::Json)); + } let message_without_relays = RadrootsMessage { recipients: vec![RadrootsMessageRecipient { diff --git a/crates/nostr-ndb/src/ndb.rs b/crates/nostr-ndb/src/ndb.rs @@ -350,9 +350,25 @@ mod tests { use radroots_nostr::prelude::{RadrootsNostrEventBuilder, RadrootsNostrKeys}; use radroots_nostr::prelude::{RadrootsNostrMetadata, radroots_nostr_build_metadata_event}; use std::sync::atomic::Ordering; + use std::sync::{Mutex, OnceLock}; use std::time::Duration; use tempfile::TempDir; + fn query_notes_lock() -> &'static Mutex<()> { + static QUERY_NOTES_LOCK: OnceLock<Mutex<()>> = OnceLock::new(); + QUERY_NOTES_LOCK.get_or_init(|| Mutex::new(())) + } + + fn query_notes_guard() -> std::sync::MutexGuard<'static, ()> { + query_notes_lock().lock().expect("query notes lock") + } + + fn reset_query_flags() { + test_hooks::FORCE_TRANSACTION_ERROR.store(false, Ordering::SeqCst); + test_hooks::FORCE_QUERY_ERROR.store(false, Ordering::SeqCst); + test_hooks::FORCE_NOTE_JSON_ERROR.store(false, Ordering::SeqCst); + } + #[test] fn config_builder_tracks_values() { let config = RadrootsNostrNdbConfig::new("target/testdbs/nostr_ndb_config") @@ -601,6 +617,8 @@ mod tests { #[test] fn query_notes_returns_ingested_results() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -632,6 +650,8 @@ mod tests { #[test] fn query_notes_empty_filters_returns_empty() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -644,6 +664,8 @@ mod tests { #[test] fn query_notes_rejects_invalid_filters() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -659,6 +681,8 @@ mod tests { #[test] fn query_notes_reports_transaction_error() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -672,6 +696,8 @@ mod tests { #[test] fn query_notes_reports_query_error() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -685,6 +711,8 @@ mod tests { #[test] fn query_notes_reports_note_json_error() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir); @@ -894,6 +922,8 @@ mod tests { #[test] fn concurrent_ingest_handles_parallel_writers() { + let _guard = query_notes_guard(); + reset_query_flags(); let tmp_dir = TempDir::new().expect("tempdir should open"); let db_dir = tmp_dir.path().join("ndb"); let config = RadrootsNostrNdbConfig::new(&db_dir);