integration_tests_pure.rs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. use std::assert_eq;
  2. use std::collections::HashSet;
  3. use std::hash::RandomState;
  4. use cdk::amount::SplitTarget;
  5. use cdk::nuts::nut00::ProofsMethods;
  6. use cdk::wallet::SendOptions;
  7. use cdk::Amount;
  8. use cdk_integration_tests::init_pure_tests::*;
  9. #[tokio::test]
  10. async fn test_swap_to_send() -> anyhow::Result<()> {
  11. setup_tracing();
  12. let mint_bob = create_and_start_test_mint().await?;
  13. let wallet_alice = create_test_wallet_arc_for_mint(mint_bob.clone()).await?;
  14. // Alice gets 64 sats
  15. fund_wallet(wallet_alice.clone(), 64).await?;
  16. let balance_alice = wallet_alice.total_balance().await?;
  17. assert_eq!(Amount::from(64), balance_alice);
  18. // Alice wants to send 40 sats, which internally swaps
  19. let prepared_send = wallet_alice
  20. .prepare_send(Amount::from(40), SendOptions::default())
  21. .await?;
  22. assert_eq!(
  23. HashSet::<_, RandomState>::from_iter(prepared_send.proofs().ys()?),
  24. HashSet::from_iter(wallet_alice.get_reserved_proofs().await?.ys()?)
  25. );
  26. let token = wallet_alice.send(prepared_send, None).await?;
  27. assert_eq!(Amount::from(40), token.proofs().total_amount()?);
  28. assert_eq!(Amount::from(24), wallet_alice.total_balance().await?);
  29. assert_eq!(
  30. HashSet::<_, RandomState>::from_iter(token.proofs().ys()?),
  31. HashSet::from_iter(wallet_alice.get_pending_spent_proofs().await?.ys()?)
  32. );
  33. // Alice sends cashu, Carol receives
  34. let wallet_carol = create_test_wallet_arc_for_mint(mint_bob.clone()).await?;
  35. let received_amount = wallet_carol
  36. .receive_proofs(token.proofs(), SplitTarget::None, &[], &[])
  37. .await?;
  38. assert_eq!(Amount::from(40), received_amount);
  39. assert_eq!(Amount::from(40), wallet_carol.total_balance().await?);
  40. Ok(())
  41. }
  42. /// Pure integration tests related to NUT-06 (Mint Information)
  43. mod nut06 {
  44. use std::str::FromStr;
  45. use std::sync::Arc;
  46. use anyhow::Result;
  47. use cashu::mint_url::MintUrl;
  48. use cashu::Amount;
  49. use cdk_integration_tests::init_pure_tests::*;
  50. #[tokio::test]
  51. async fn test_swap_to_send() -> Result<()> {
  52. setup_tracing();
  53. let mint_bob = create_and_start_test_mint().await?;
  54. let wallet_alice_guard = create_test_wallet_arc_mut_for_mint(mint_bob.clone()).await?;
  55. let mut wallet_alice = wallet_alice_guard.lock().await;
  56. // Alice gets 64 sats
  57. fund_wallet(Arc::new(wallet_alice.clone()), 64).await?;
  58. let balance_alice = wallet_alice.total_balance().await?;
  59. assert_eq!(Amount::from(64), balance_alice);
  60. let initial_mint_url = wallet_alice.mint_url.clone();
  61. let mint_info_before = wallet_alice.get_mint_info().await?.unwrap();
  62. assert!(mint_info_before
  63. .urls
  64. .unwrap()
  65. .contains(&initial_mint_url.to_string()));
  66. // Wallet updates mint URL
  67. let new_mint_url = MintUrl::from_str("https://new-mint-url")?;
  68. wallet_alice.update_mint_url(new_mint_url.clone()).await?;
  69. // Check balance after mint URL was updated
  70. let balance_alice_after = wallet_alice.total_balance().await?;
  71. assert_eq!(Amount::from(64), balance_alice_after);
  72. Ok(())
  73. }
  74. }