Skip to content

Commit 5508a1a

Browse files
committed
gossip-test-suite: use the right methods from NostrGossip and re-export tokio
Follow-up of f75e730 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent f75e730 commit 5508a1a

File tree

1 file changed

+22
-19
lines changed
  • gossip/nostr-gossip-test-suite/src

1 file changed

+22
-19
lines changed

gossip/nostr-gossip-test-suite/src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! Gossip test suite
22
3+
pub extern crate tokio;
4+
35
/// Macro to generate common gossip store tests.
46
#[macro_export]
57
macro_rules! gossip_unit_tests {
68
($store_type:ty, $setup_fn:expr) => {
7-
use nostr::prelude::*;
89
use nostr_gossip::prelude::*;
910

11+
use $crate::tokio;
12+
1013
#[tokio::test]
1114
async fn test_process_event() {
1215
let store: $store_type = $setup_fn().await;
@@ -35,15 +38,15 @@ macro_rules! gossip_unit_tests {
3538

3639
// Test Read selection
3740
let read_relays = store
38-
._get_best_relays(&public_key, BestRelaySelection::Read { limit: 2 })
39-
.await;
41+
.get_best_relays(&public_key, BestRelaySelection::Read { limit: 2 })
42+
.await.unwrap();
4043

4144
assert_eq!(read_relays.len(), 2); // relay.damus.io and nos.lol
4245

4346
// Test Write selection
4447
let write_relays = store
45-
._get_best_relays(&public_key, BestRelaySelection::Write { limit: 2 })
46-
.await;
48+
.get_best_relays(&public_key, BestRelaySelection::Write { limit: 2 })
49+
.await.unwrap();
4750

4851
assert_eq!(write_relays.len(), 2); // relay.damus.io and relay.nostr.band
4952
}
@@ -62,8 +65,8 @@ macro_rules! gossip_unit_tests {
6265

6366
// Test PrivateMessage selection
6467
let pm_relays = store
65-
._get_best_relays(&public_key, BestRelaySelection::PrivateMessage { limit: 4 })
66-
.await;
68+
.get_best_relays(&public_key, BestRelaySelection::PrivateMessage { limit: 4 })
69+
.await.unwrap();
6770

6871
assert_eq!(pm_relays.len(), 3); // inbox.nostr.wine and relay.primal.net
6972
}
@@ -93,8 +96,8 @@ macro_rules! gossip_unit_tests {
9396
store.process(&event, None).await.unwrap();
9497

9598
let hint_relays = store
96-
._get_best_relays(&public_key, BestRelaySelection::Hints { limit: 5 })
97-
.await;
99+
.get_best_relays(&public_key, BestRelaySelection::Hints { limit: 5 })
100+
.await.unwrap();
98101

99102
assert_eq!(hint_relays.len(), 1);
100103
assert!(hint_relays.iter().any(|r| r == &relay_url));
@@ -118,11 +121,11 @@ macro_rules! gossip_unit_tests {
118121

119122
// Test MostReceived selection
120123
let most_received = store
121-
._get_best_relays(
124+
.get_best_relays(
122125
&keys.public_key,
123126
BestRelaySelection::MostReceived { limit: 10 },
124127
)
125-
.await;
128+
.await.unwrap();
126129

127130
assert_eq!(most_received.len(), 1);
128131
assert!(most_received.iter().any(|r| r == &relay_url));
@@ -157,7 +160,7 @@ macro_rules! gossip_unit_tests {
157160

158161
// Test All selection
159162
let all_relays = store
160-
._get_best_relays(
163+
.get_best_relays(
161164
&public_key,
162165
BestRelaySelection::All {
163166
read: 5,
@@ -166,7 +169,7 @@ macro_rules! gossip_unit_tests {
166169
most_received: 5,
167170
},
168171
)
169-
.await;
172+
.await.unwrap();
170173

171174
// Should have relays from all categories (duplicates removed by HashSet)
172175
assert!(all_relays.len() >= 3);
@@ -193,7 +196,7 @@ macro_rules! gossip_unit_tests {
193196
.unwrap();
194197

195198
// Initially should be outdated
196-
let status = store.get_status(&public_key, GossipListKind::Nip65).await;
199+
let status = store.status(&public_key, GossipListKind::Nip65).await.unwrap();
197200
assert!(matches!(status, GossipPublicKeyStatus::Outdated { .. }));
198201

199202
// Process a NIP-65 event
@@ -203,11 +206,11 @@ macro_rules! gossip_unit_tests {
203206

204207
// Update fetch attempt
205208
store
206-
._update_fetch_attempt(&public_key, GossipListKind::Nip65)
207-
.await;
209+
.update_fetch_attempt(&public_key, GossipListKind::Nip65)
210+
.await.unwrap();
208211

209212
// Should now be updated
210-
let status = store.get_status(&public_key, GossipListKind::Nip65).await;
213+
let status = store.status(&public_key, GossipListKind::Nip65).await.unwrap();
211214
assert!(matches!(status, GossipPublicKeyStatus::Updated));
212215
}
213216

@@ -222,8 +225,8 @@ macro_rules! gossip_unit_tests {
222225

223226
// Should return empty set
224227
let relays = store
225-
._get_best_relays(&public_key, BestRelaySelection::Read { limit: 10 })
226-
.await;
228+
.get_best_relays(&public_key, BestRelaySelection::Read { limit: 10 })
229+
.await.unwrap();
227230

228231
assert_eq!(relays.len(), 0);
229232
}

0 commit comments

Comments
 (0)