notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 2a2c1773009c08276752ad9c3314bea2163cabe8
parent b228411b8db9ecef6388d85e3b0f496a5d76eada
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon, 14 Apr 2025 19:56:14 -0400

Fix flaky test_zap_event

Closes: #808
Co-authored-by: William Casarin <jb55@jb55.com>
Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/zaps/zap.rs | 54+++++++++++++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/crates/notedeck/src/zaps/zap.rs b/crates/notedeck/src/zaps/zap.rs @@ -242,7 +242,10 @@ fn get_zap_tags(ev: nostrdb::Note) -> Option<ZapTags> { #[cfg(test)] mod tests { - use enostr::Pubkey; + use enostr::{NoteId, Pubkey}; + + use nostrdb::{Config, Filter, IngestMetadata, Ndb, Transaction}; + use tempfile::TempDir; use crate::zaps::zap::{valid_zap_request, Zap}; @@ -258,34 +261,35 @@ mod tests { assert!(valid_zap_request(note)); } - fn enostr_note_to_nostrdb_note<'a>(note: &'a enostr::Note) -> Option<nostrdb::Note<'a>> { - let mut n = nostrdb::NoteBuilder::new() - .pubkey(&note.pubkey) - .created_at(note.created_at) - .kind(note.kind.try_into().ok()?) - .content(&note.content); - - for tag in &note.tags { - n = n.start_tag(); - - for tag_ind in tag { - n = n.tag_str(&tag_ind); - } - } - - n.build() - } - - #[test] - fn test_zap_event() { + #[tokio::test] + async fn test_zap_event() { let pk = Pubkey::from_hex("be1d89794bf92de5dd64c1e60f6a2c70c140abac9932418fee30c5c637fe9479") .unwrap(); - let note = enostr::Note::from_json(ZAP_RECEIPT).unwrap(); - let nostrdb_note = enostr_note_to_nostrdb_note(&note).unwrap(); - - let zap = Zap::from_zap_event(nostrdb_note, &pk); + let tmp_dir = TempDir::new().unwrap(); + let ndb = Ndb::new(tmp_dir.path().to_str().unwrap(), &Config::new()).unwrap(); + + let ev = format!(r#"["EVENT", "random_string", {ZAP_RECEIPT}]"#); + let filter = Filter::new().authors([pk.bytes()]).build(); + let sub_id = ndb.subscribe(&[filter]).unwrap(); + let res = ndb.process_event_with(&ev, IngestMetadata::new()); + assert!(res.is_ok()); + + let note_key = ndb.wait_for_notes(sub_id, 1).await.unwrap()[0]; + let txn = Transaction::new(&ndb).unwrap(); + let note = ndb.get_note_by_key(&txn, note_key).unwrap(); + + assert!( + note.id() + == NoteId::from_hex( + "c8a5767f33cd73716cf670c9615a73ec50cb91c373100f6c0d5cc160237b58dc" + ) + .unwrap() + .bytes() + ); + + let zap = Zap::from_zap_event(note, &pk); assert!(zap.is_some()); }