integration_tests_pure.rs 2.8 KB

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