|
|
@@ -15,7 +15,6 @@
|
|
|
//! - Duplicate proof detection
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
-use std::time::Duration;
|
|
|
|
|
|
use bip39::Mnemonic;
|
|
|
use cashu::Amount;
|
|
|
@@ -27,6 +26,7 @@ use cdk::nuts::{
|
|
|
};
|
|
|
use cdk::wallet::types::TransactionDirection;
|
|
|
use cdk::wallet::{HttpClient, MintConnector, Wallet};
|
|
|
+use cdk::StreamExt;
|
|
|
use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription};
|
|
|
use cdk_integration_tests::attempt_to_swap_pending;
|
|
|
use cdk_sqlite::wallet::memory;
|
|
|
@@ -47,15 +47,13 @@ async fn test_fake_tokens_pending() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Pending,
|
|
|
@@ -90,15 +88,13 @@ async fn test_fake_melt_payment_fail() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Unknown,
|
|
|
@@ -156,15 +152,13 @@ async fn test_fake_melt_payment_fail_and_check() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Unknown,
|
|
|
@@ -205,15 +199,13 @@ async fn test_fake_melt_payment_return_fail_status() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Failed,
|
|
|
@@ -269,15 +261,13 @@ async fn test_fake_melt_payment_error_unknown() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Failed,
|
|
|
@@ -333,15 +323,13 @@ async fn test_fake_melt_payment_err_paid() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
|
pay_invoice_state: MeltQuoteState::Failed,
|
|
|
@@ -375,15 +363,13 @@ async fn test_fake_melt_change_in_quote() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let _mint_amount = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let _proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let transaction = wallet
|
|
|
.list_transactions(Some(TransactionDirection::Incoming))
|
|
|
@@ -445,15 +431,13 @@ async fn test_fake_mint_with_witness() {
|
|
|
.expect("failed to create new wallet");
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::default(), None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let mint_amount = proofs.total_amount().unwrap();
|
|
|
|
|
|
@@ -474,10 +458,13 @@ async fn test_fake_mint_without_witness() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
+ let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
+
|
|
|
+ payment_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
|
|
|
|
|
|
@@ -515,10 +502,13 @@ async fn test_fake_mint_with_wrong_witness() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
+ let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
+
|
|
|
+ payment_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
|
|
|
|
|
|
@@ -562,10 +552,13 @@ async fn test_fake_mint_inflated() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
+ let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
+
|
|
|
+ payment_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
@@ -621,10 +614,13 @@ async fn test_fake_mint_multiple_units() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
+ let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
+
|
|
|
+ payment_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
@@ -701,15 +697,13 @@ async fn test_fake_mint_multiple_unit_swap() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let wallet_usd = Wallet::new(
|
|
|
MINT_URL,
|
|
|
@@ -723,15 +717,14 @@ async fn test_fake_mint_multiple_unit_swap() {
|
|
|
|
|
|
let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams =
|
|
|
+ wallet_usd.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let usd_proofs = wallet_usd
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let usd_proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
@@ -817,15 +810,13 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
println!("Minted sat");
|
|
|
|
|
|
@@ -841,15 +832,14 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
|
|
|
println!("Minted quote usd");
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams =
|
|
|
+ wallet_usd.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let usd_proofs = wallet_usd
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let usd_proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
{
|
|
|
let inputs: Proofs = vec![
|
|
|
@@ -937,15 +927,13 @@ async fn test_fake_mint_input_output_mismatch() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let wallet_usd = Wallet::new(
|
|
|
MINT_URL,
|
|
|
@@ -996,15 +984,14 @@ async fn test_fake_mint_swap_inflated() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
+
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
let pre_mint =
|
|
|
PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
|
|
|
@@ -1041,15 +1028,14 @@ async fn test_fake_mint_swap_spend_after_fail() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
+
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
let pre_mint =
|
|
|
@@ -1113,15 +1099,14 @@ async fn test_fake_mint_melt_spend_after_fail() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
+
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
let pre_mint =
|
|
|
@@ -1186,15 +1171,13 @@ async fn test_fake_mint_duplicate_proofs_swap() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
|
|
|
|
|
|
@@ -1267,15 +1250,13 @@ async fn test_fake_mint_duplicate_proofs_melt() {
|
|
|
|
|
|
let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
- wallet
|
|
|
- .wait_for_payment(&mint_quote, Duration::from_secs(60))
|
|
|
- .await
|
|
|
- .unwrap();
|
|
|
+ let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
- let proofs = wallet
|
|
|
- .mint(&mint_quote.id, SplitTarget::None, None)
|
|
|
+ let proofs = proof_streams
|
|
|
+ .next()
|
|
|
.await
|
|
|
- .unwrap();
|
|
|
+ .expect("payment")
|
|
|
+ .expect("no error");
|
|
|
|
|
|
let inputs = vec![proofs[0].clone(), proofs[0].clone()];
|
|
|
|