Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 2001356

Browse files
committed
Add tests for follow/unfollow
1 parent 668463f commit 2001356

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

mutiny-core/src/nostr/mod.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,7 @@ mod test {
22512251
use bitcoin::bip32::ExtendedPrivKey;
22522252
use bitcoin::Network;
22532253
use futures::executor::block_on;
2254+
use futures::try_join;
22542255
use lightning::ln::PaymentSecret;
22552256
use lightning_invoice::{Bolt11Invoice, Currency, InvoiceBuilder};
22562257
use mockall::predicate::eq;
@@ -2958,4 +2959,90 @@ mod test {
29582959
.iter()
29592960
.any(|t| t.as_vec() == vec!["u".to_string(), INVITE_CODE.to_string()]));
29602961
}
2962+
2963+
#[tokio::test]
2964+
async fn test_follow_unfollow() {
2965+
let mut nostr_manager = create_nostr_manager().await;
2966+
nostr_manager
2967+
.client
2968+
.expect_send_event()
2969+
.returning(|e| Ok(e.id));
2970+
2971+
let ben = nostr::PublicKey::from_str(
2972+
"npub1u8lnhlw5usp3t9vmpz60ejpyt649z33hu82wc2hpv6m5xdqmuxhs46turz",
2973+
)
2974+
.unwrap();
2975+
let tony = nostr::PublicKey::from_str(
2976+
"npub1t0nyg64g5vwprva52wlcmt7fkdr07v5dr7s35raq9g0xgc0k4xcsedjgqv",
2977+
)
2978+
.unwrap();
2979+
2980+
let list = nostr_manager.get_follow_list().unwrap();
2981+
assert!(list.is_empty());
2982+
2983+
nostr_manager.follow_npub(ben).await.unwrap();
2984+
let list = nostr_manager.get_follow_list().unwrap();
2985+
assert_eq!(list.len(), 2); // follows ourselves too
2986+
2987+
// test follow twice
2988+
nostr_manager.follow_npub(ben).await.unwrap();
2989+
let list = nostr_manager.get_follow_list().unwrap();
2990+
assert_eq!(list.len(), 2);
2991+
2992+
nostr_manager.follow_npub(tony).await.unwrap();
2993+
let list = nostr_manager.get_follow_list().unwrap();
2994+
assert_eq!(list.len(), 3);
2995+
2996+
nostr_manager.unfollow_npub(ben).await.unwrap();
2997+
let list = nostr_manager.get_follow_list().unwrap();
2998+
assert_eq!(list.len(), 2);
2999+
3000+
nostr_manager.unfollow_npub(tony).await.unwrap();
3001+
let list = nostr_manager.get_follow_list().unwrap();
3002+
assert_eq!(list.len(), 1);
3003+
3004+
// test unfollow twice
3005+
nostr_manager.unfollow_npub(tony).await.unwrap();
3006+
let list = nostr_manager.get_follow_list().unwrap();
3007+
assert_eq!(list.len(), 1);
3008+
}
3009+
3010+
#[tokio::test]
3011+
async fn test_follow_concurrency() {
3012+
let mut nostr_manager = create_nostr_manager().await;
3013+
nostr_manager
3014+
.client
3015+
.expect_send_event()
3016+
.returning(|e| Ok(e.id));
3017+
3018+
let ben = nostr::PublicKey::from_str(
3019+
"npub1u8lnhlw5usp3t9vmpz60ejpyt649z33hu82wc2hpv6m5xdqmuxhs46turz",
3020+
)
3021+
.unwrap();
3022+
let tony = nostr::PublicKey::from_str(
3023+
"npub1t0nyg64g5vwprva52wlcmt7fkdr07v5dr7s35raq9g0xgc0k4xcsedjgqv",
3024+
)
3025+
.unwrap();
3026+
3027+
let list = nostr_manager.get_follow_list().unwrap();
3028+
assert!(list.is_empty());
3029+
3030+
try_join!(
3031+
nostr_manager.follow_npub(ben),
3032+
nostr_manager.follow_npub(tony)
3033+
)
3034+
.unwrap();
3035+
3036+
let list = nostr_manager.get_follow_list().unwrap();
3037+
assert_eq!(list.len(), 3); // follows ourselves too
3038+
3039+
try_join!(
3040+
nostr_manager.unfollow_npub(ben),
3041+
nostr_manager.unfollow_npub(tony)
3042+
)
3043+
.unwrap();
3044+
3045+
let list = nostr_manager.get_follow_list().unwrap();
3046+
assert_eq!(list.len(), 1);
3047+
}
29613048
}

0 commit comments

Comments
 (0)