|
@@ -45,7 +45,7 @@ async fn test_fake_tokens_pending() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -64,9 +64,18 @@ async fn test_fake_tokens_pending() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
|
|
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
@@ -92,7 +101,7 @@ async fn test_fake_melt_payment_fail() {
|
|
|
)
|
|
)
|
|
|
.expect("Failed to create new wallet");
|
|
.expect("Failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -111,10 +120,19 @@ async fn test_fake_melt_payment_fail() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
let fake_description = FakeInvoiceDescription {
|
|
@@ -126,10 +144,19 @@ async fn test_fake_melt_payment_fail() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
let wallet_bal = wallet.total_balance().await.unwrap();
|
|
let wallet_bal = wallet.total_balance().await.unwrap();
|
|
@@ -149,7 +176,7 @@ async fn test_fake_melt_payment_fail_and_check() {
|
|
|
)
|
|
)
|
|
|
.expect("Failed to create new wallet");
|
|
.expect("Failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -168,10 +195,19 @@ async fn test_fake_melt_payment_fail_and_check() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
assert!(!wallet
|
|
assert!(!wallet
|
|
@@ -195,7 +231,7 @@ async fn test_fake_melt_payment_return_fail_status() {
|
|
|
)
|
|
)
|
|
|
.expect("Failed to create new wallet");
|
|
.expect("Failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -214,10 +250,19 @@ async fn test_fake_melt_payment_return_fail_status() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
wallet.check_all_pending_proofs().await.unwrap();
|
|
wallet.check_all_pending_proofs().await.unwrap();
|
|
@@ -239,10 +284,19 @@ async fn test_fake_melt_payment_return_fail_status() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
wallet.check_all_pending_proofs().await.unwrap();
|
|
wallet.check_all_pending_proofs().await.unwrap();
|
|
@@ -268,7 +322,7 @@ async fn test_fake_melt_payment_error_unknown() {
|
|
|
)
|
|
)
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -287,10 +341,19 @@ async fn test_fake_melt_payment_error_unknown() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
let fake_description = FakeInvoiceDescription {
|
|
let fake_description = FakeInvoiceDescription {
|
|
@@ -302,10 +365,19 @@ async fn test_fake_melt_payment_error_unknown() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// The melt should error at the payment invoice command
|
|
// The melt should error at the payment invoice command
|
|
|
- let melt = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt.is_err());
|
|
assert!(melt.is_err());
|
|
|
|
|
|
|
|
assert!(wallet
|
|
assert!(wallet
|
|
@@ -329,7 +401,7 @@ async fn test_fake_melt_payment_err_paid() {
|
|
|
)
|
|
)
|
|
|
.expect("Failed to create new wallet");
|
|
.expect("Failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -350,17 +422,24 @@ async fn test_fake_melt_payment_err_paid() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
- // The melt should error at the payment invoice command
|
|
|
|
|
- let melt = wallet.melt(&melt_quote.id).await.unwrap();
|
|
|
|
|
|
|
+ // The melt should complete successfully
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
+ let melt = prepared.confirm().await.unwrap();
|
|
|
|
|
|
|
|
- assert!(melt.fee_paid == Amount::ZERO);
|
|
|
|
|
- assert!(melt.amount == Amount::from(7));
|
|
|
|
|
|
|
+ assert!(melt.fee_paid() == Amount::ZERO);
|
|
|
|
|
+ assert!(melt.amount() == Amount::from(7));
|
|
|
|
|
|
|
|
// melt failed, but there is new code to reclaim unspent proofs
|
|
// melt failed, but there is new code to reclaim unspent proofs
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
|
- old_balance - melt.amount,
|
|
|
|
|
|
|
+ old_balance - melt.amount(),
|
|
|
wallet.total_balance().await.expect("new balance")
|
|
wallet.total_balance().await.expect("new balance")
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -384,7 +463,7 @@ async fn test_fake_melt_change_in_quote() {
|
|
|
)
|
|
)
|
|
|
.expect("Failed to create new wallet");
|
|
.expect("Failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -412,7 +491,10 @@ async fn test_fake_melt_change_in_quote() {
|
|
|
|
|
|
|
|
let proofs = wallet.get_unspent_proofs().await.unwrap();
|
|
let proofs = wallet.get_unspent_proofs().await.unwrap();
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let keyset = wallet.fetch_active_keyset().await.unwrap();
|
|
let keyset = wallet.fetch_active_keyset().await.unwrap();
|
|
|
let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
|
|
let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
|
|
@@ -440,7 +522,7 @@ async fn test_fake_melt_change_in_quote() {
|
|
|
|
|
|
|
|
assert!(melt_response.change.is_some());
|
|
assert!(melt_response.change.is_some());
|
|
|
|
|
|
|
|
- let check = wallet.melt_quote_status(&melt_quote.id).await.unwrap();
|
|
|
|
|
|
|
+ let check = client.get_melt_quote_status(&melt_quote.id).await.unwrap();
|
|
|
let mut melt_change = melt_response.change.unwrap();
|
|
let mut melt_change = melt_response.change.unwrap();
|
|
|
melt_change.sort_by(|a, b| a.amount.cmp(&b.amount));
|
|
melt_change.sort_by(|a, b| a.amount.cmp(&b.amount));
|
|
|
|
|
|
|
@@ -461,7 +543,7 @@ async fn test_fake_mint_with_witness() {
|
|
|
None,
|
|
None,
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -488,7 +570,7 @@ async fn test_fake_mint_without_witness() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
|
|
|
|
@@ -540,7 +622,7 @@ async fn test_fake_mint_with_wrong_witness() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
|
|
|
|
@@ -598,7 +680,7 @@ async fn test_fake_mint_inflated() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
|
|
|
|
@@ -671,7 +753,7 @@ async fn test_fake_mint_multiple_units() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
let mut payment_streams = wallet.payment_stream(&mint_quote);
|
|
|
|
|
|
|
@@ -771,7 +853,7 @@ async fn test_fake_mint_multiple_unit_swap() {
|
|
|
|
|
|
|
|
wallet.refresh_keysets().await.unwrap();
|
|
wallet.refresh_keysets().await.unwrap();
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -791,7 +873,10 @@ async fn test_fake_mint_multiple_unit_swap() {
|
|
|
.expect("failed to create usd wallet");
|
|
.expect("failed to create usd wallet");
|
|
|
wallet_usd.refresh_keysets().await.unwrap();
|
|
wallet_usd.refresh_keysets().await.unwrap();
|
|
|
|
|
|
|
|
- let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet_usd
|
|
|
|
|
+ .mint_bolt11_quote(100.into(), None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams =
|
|
let mut proof_streams =
|
|
|
wallet_usd.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
wallet_usd.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
@@ -896,7 +981,7 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -917,7 +1002,10 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet_usd
|
|
|
|
|
+ .mint_bolt11_quote(100.into(), None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
println!("Minted quote usd");
|
|
println!("Minted quote usd");
|
|
|
|
|
|
|
|
let mut proof_streams =
|
|
let mut proof_streams =
|
|
@@ -940,7 +1028,10 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
|
|
|
|
|
let input_amount: u64 = inputs.total_amount().unwrap().into();
|
|
let input_amount: u64 = inputs.total_amount().unwrap().into();
|
|
|
let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
|
|
let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
|
|
let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
|
|
|
|
|
|
|
@@ -994,7 +1085,10 @@ async fn test_fake_mint_multiple_unit_melt() {
|
|
|
let mut sat_outputs = pre_mint.blinded_messages();
|
|
let mut sat_outputs = pre_mint.blinded_messages();
|
|
|
|
|
|
|
|
usd_outputs.append(&mut sat_outputs);
|
|
usd_outputs.append(&mut sat_outputs);
|
|
|
- let quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let melt_request = MeltRequest::new(quote.id, inputs, Some(usd_outputs));
|
|
let melt_request = MeltRequest::new(quote.id, inputs, Some(usd_outputs));
|
|
|
|
|
|
|
@@ -1033,7 +1127,7 @@ async fn test_fake_mint_input_output_mismatch() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1092,7 +1186,7 @@ async fn test_fake_mint_swap_inflated() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
|
|
let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
|
|
@@ -1142,7 +1236,7 @@ async fn test_fake_mint_swap_spend_after_fail() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1229,7 +1323,7 @@ async fn test_fake_mint_melt_spend_after_fail() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1280,7 +1374,10 @@ async fn test_fake_mint_melt_spend_after_fail() {
|
|
|
|
|
|
|
|
let input_amount: u64 = proofs.total_amount().unwrap().into();
|
|
let input_amount: u64 = proofs.total_amount().unwrap().into();
|
|
|
let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
|
|
let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let melt_request = MeltRequest::new(melt_quote.id, proofs, None);
|
|
let melt_request = MeltRequest::new(melt_quote.id, proofs, None);
|
|
|
|
|
|
|
@@ -1317,7 +1414,7 @@ async fn test_fake_mint_duplicate_proofs_swap() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1398,7 +1495,7 @@ async fn test_fake_mint_duplicate_proofs_melt() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1412,7 +1509,10 @@ async fn test_fake_mint_duplicate_proofs_melt() {
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(7000, "".to_string());
|
|
let invoice = create_fake_invoice(7000, "".to_string());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
|
|
let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
|
|
|
|
|
|
|
@@ -1451,7 +1551,7 @@ async fn test_wallet_proof_recovery_after_failed_melt() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Mint 100 sats
|
|
// Mint 100 sats
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
let _roof_streams = wallet
|
|
let _roof_streams = wallet
|
|
|
.wait_and_mint_quote(
|
|
.wait_and_mint_quote(
|
|
|
mint_quote.clone(),
|
|
mint_quote.clone(),
|
|
@@ -1472,10 +1572,19 @@ async fn test_wallet_proof_recovery_after_failed_melt() {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// Attempt to melt - this should fail but trigger proof recovery
|
|
// Attempt to melt - this should fail but trigger proof recovery
|
|
|
- let melt_result = wallet.melt(&melt_quote.id).await;
|
|
|
|
|
|
|
+ let melt_result = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(melt_result.is_err(), "Melt should have failed");
|
|
assert!(melt_result.is_err(), "Melt should have failed");
|
|
|
|
|
|
|
|
// Verify wallet still has balance (proofs recovered)
|
|
// Verify wallet still has balance (proofs recovered)
|
|
@@ -1488,11 +1597,17 @@ async fn test_wallet_proof_recovery_after_failed_melt() {
|
|
|
// Verify we can still spend the recovered proofs
|
|
// Verify we can still spend the recovered proofs
|
|
|
let valid_invoice = create_fake_invoice(7000, "".to_string());
|
|
let valid_invoice = create_fake_invoice(7000, "".to_string());
|
|
|
let valid_melt_quote = wallet
|
|
let valid_melt_quote = wallet
|
|
|
- .melt_quote(valid_invoice.to_string(), None)
|
|
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, valid_invoice.to_string(), None, None)
|
|
|
.await
|
|
.await
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
|
|
|
- let successful_melt = wallet.melt(&valid_melt_quote.id).await;
|
|
|
|
|
|
|
+ let successful_melt = async {
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&valid_melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }
|
|
|
|
|
+ .await;
|
|
|
assert!(
|
|
assert!(
|
|
|
successful_melt.is_ok(),
|
|
successful_melt.is_ok(),
|
|
|
"Should be able to spend recovered proofs"
|
|
"Should be able to spend recovered proofs"
|
|
@@ -1526,7 +1641,7 @@ async fn test_concurrent_melt_same_invoice() {
|
|
|
|
|
|
|
|
// Mint proofs for all wallets
|
|
// Mint proofs for all wallets
|
|
|
for (i, wallet) in wallets.iter().enumerate() {
|
|
for (i, wallet) in wallets.iter().enumerate() {
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
let mut proof_streams =
|
|
let mut proof_streams =
|
|
|
wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
proof_streams
|
|
proof_streams
|
|
@@ -1543,7 +1658,10 @@ async fn test_concurrent_melt_same_invoice() {
|
|
|
// All wallets create melt quotes for the same invoice
|
|
// All wallets create melt quotes for the same invoice
|
|
|
let mut melt_quotes = Vec::with_capacity(NUM_WALLETS);
|
|
let mut melt_quotes = Vec::with_capacity(NUM_WALLETS);
|
|
|
for wallet in &wallets {
|
|
for wallet in &wallets {
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
melt_quotes.push(melt_quote);
|
|
melt_quotes.push(melt_quote);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1560,9 +1678,12 @@ async fn test_concurrent_melt_same_invoice() {
|
|
|
for (wallet, quote) in wallets.iter().zip(melt_quotes.iter()) {
|
|
for (wallet, quote) in wallets.iter().zip(melt_quotes.iter()) {
|
|
|
let wallet_clone = Arc::clone(wallet);
|
|
let wallet_clone = Arc::clone(wallet);
|
|
|
let quote_id = quote.id.clone();
|
|
let quote_id = quote.id.clone();
|
|
|
- handles.push(tokio::spawn(
|
|
|
|
|
- async move { wallet_clone.melt("e_id).await },
|
|
|
|
|
- ));
|
|
|
|
|
|
|
+ handles.push(tokio::spawn(async move {
|
|
|
|
|
+ let prepared = wallet_clone
|
|
|
|
|
+ .prepare_melt("e_id, std::collections::HashMap::new())
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ prepared.confirm().await
|
|
|
|
|
+ }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Collect results
|
|
// Collect results
|
|
@@ -1595,8 +1716,9 @@ async fn test_concurrent_melt_same_invoice() {
|
|
|
assert!(
|
|
assert!(
|
|
|
err_str.contains("duplicate")
|
|
err_str.contains("duplicate")
|
|
|
|| err_str.contains("already paid")
|
|
|| err_str.contains("already paid")
|
|
|
- || err_str.contains("pending"),
|
|
|
|
|
- "Expected duplicate/already paid/pending error, got: {}",
|
|
|
|
|
|
|
+ || err_str.contains("pending")
|
|
|
|
|
+ || err_str.contains("payment failed"),
|
|
|
|
|
+ "Expected duplicate/already paid/pending/payment failed error, got: {}",
|
|
|
err
|
|
err
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -1616,7 +1738,7 @@ async fn test_wallet_proof_recovery_after_failed_swap() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Mint 100 sats
|
|
// Mint 100 sats
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
let initial_proofs = proof_streams
|
|
let initial_proofs = proof_streams
|
|
|
.next()
|
|
.next()
|
|
@@ -1702,7 +1824,10 @@ async fn test_melt_proofs_external() {
|
|
|
)
|
|
)
|
|
|
.expect("failed to create sender wallet");
|
|
.expect("failed to create sender wallet");
|
|
|
|
|
|
|
|
- let mint_quote = wallet_sender.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet_sender
|
|
|
|
|
+ .mint_bolt11_quote(100.into(), None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams =
|
|
let mut proof_streams =
|
|
|
wallet_sender.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
wallet_sender.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
@@ -1739,24 +1864,29 @@ async fn test_melt_proofs_external() {
|
|
|
|
|
|
|
|
// Wallet B creates a melt quote
|
|
// Wallet B creates a melt quote
|
|
|
let melt_quote = wallet_melter
|
|
let melt_quote = wallet_melter
|
|
|
- .melt_quote(invoice.to_string(), None)
|
|
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
.await
|
|
.await
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Wallet B calls melt_proofs with external proofs (from Wallet A)
|
|
// Wallet B calls melt_proofs with external proofs (from Wallet A)
|
|
|
// These proofs are NOT in wallet_melter's database
|
|
// These proofs are NOT in wallet_melter's database
|
|
|
- let melted = wallet_melter
|
|
|
|
|
- .melt_proofs(&melt_quote.id, proofs.clone())
|
|
|
|
|
|
|
+ let prepared = wallet_melter
|
|
|
|
|
+ .prepare_melt_proofs(
|
|
|
|
|
+ &melt_quote.id,
|
|
|
|
|
+ proofs.clone(),
|
|
|
|
|
+ std::collections::HashMap::new(),
|
|
|
|
|
+ )
|
|
|
.await
|
|
.await
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
|
|
+ let melted = prepared.confirm().await.unwrap();
|
|
|
|
|
|
|
|
// Verify the melt succeeded
|
|
// Verify the melt succeeded
|
|
|
- assert_eq!(melted.amount, Amount::from(9));
|
|
|
|
|
- assert_eq!(melted.fee_paid, 1.into());
|
|
|
|
|
|
|
+ assert_eq!(melted.amount(), Amount::from(9));
|
|
|
|
|
+ assert_eq!(melted.fee_paid(), 1.into());
|
|
|
|
|
|
|
|
// Verify change was returned (100 input - 9 melt amount = 91 change, minus fee reserve)
|
|
// Verify change was returned (100 input - 9 melt amount = 91 change, minus fee reserve)
|
|
|
- assert!(melted.change.is_some());
|
|
|
|
|
- let change_amount = melted.change.unwrap().total_amount().unwrap();
|
|
|
|
|
|
|
+ assert!(melted.change().is_some());
|
|
|
|
|
+ let change_amount = melted.change().unwrap().total_amount().unwrap();
|
|
|
assert!(change_amount > Amount::ZERO, "Should have received change");
|
|
assert!(change_amount > Amount::ZERO, "Should have received change");
|
|
|
|
|
|
|
|
// Verify the melter wallet now has the change proofs
|
|
// Verify the melter wallet now has the change proofs
|
|
@@ -1792,7 +1922,7 @@ async fn test_melt_with_swap_for_exact_amount() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Mint 100 sats - this will give us proofs in standard denominations
|
|
// Mint 100 sats - this will give us proofs in standard denominations
|
|
|
- let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1814,7 +1944,10 @@ async fn test_melt_with_swap_for_exact_amount() {
|
|
|
let fake_description = FakeInvoiceDescription::default();
|
|
let fake_description = FakeInvoiceDescription::default();
|
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
tracing::info!(
|
|
tracing::info!(
|
|
|
"Melt quote: amount={}, fee_reserve={}",
|
|
"Melt quote: amount={}, fee_reserve={}",
|
|
@@ -1823,15 +1956,19 @@ async fn test_melt_with_swap_for_exact_amount() {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Call melt() - this should trigger swap-before-melt if proofs don't match exactly
|
|
// Call melt() - this should trigger swap-before-melt if proofs don't match exactly
|
|
|
- let melted = wallet.melt(&melt_quote.id).await.unwrap();
|
|
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
+ let melted = prepared.confirm().await.unwrap();
|
|
|
|
|
|
|
|
// Verify the melt succeeded
|
|
// Verify the melt succeeded
|
|
|
- assert_eq!(melted.amount, Amount::from(7));
|
|
|
|
|
|
|
+ assert_eq!(melted.amount(), Amount::from(7));
|
|
|
|
|
|
|
|
tracing::info!(
|
|
tracing::info!(
|
|
|
"Melt completed: amount={}, fee_paid={}",
|
|
"Melt completed: amount={}, fee_paid={}",
|
|
|
- melted.amount,
|
|
|
|
|
- melted.fee_paid
|
|
|
|
|
|
|
+ melted.amount(),
|
|
|
|
|
+ melted.fee_paid()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Verify final balance is correct (initial - melt_amount - fees)
|
|
// Verify final balance is correct (initial - melt_amount - fees)
|
|
@@ -1840,7 +1977,7 @@ async fn test_melt_with_swap_for_exact_amount() {
|
|
|
"Balance: initial={}, final={}, paid={}",
|
|
"Balance: initial={}, final={}, paid={}",
|
|
|
initial_balance,
|
|
initial_balance,
|
|
|
final_balance,
|
|
final_balance,
|
|
|
- melted.amount + melted.fee_paid
|
|
|
|
|
|
|
+ melted.amount() + melted.fee_paid()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assert!(
|
|
assert!(
|
|
@@ -1849,7 +1986,7 @@ async fn test_melt_with_swap_for_exact_amount() {
|
|
|
);
|
|
);
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
|
final_balance,
|
|
final_balance,
|
|
|
- initial_balance - melted.amount - melted.fee_paid,
|
|
|
|
|
|
|
+ initial_balance - melted.amount() - melted.fee_paid(),
|
|
|
"Final balance should be initial - amount - fees"
|
|
"Final balance should be initial - amount - fees"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -1868,7 +2005,7 @@ async fn test_melt_exact_proofs_no_swap_needed() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Mint a larger amount to have more denomination options
|
|
// Mint a larger amount to have more denomination options
|
|
|
- let mint_quote = wallet.mint_quote(1000.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(1000.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_streams = wallet.proof_stream(mint_quote.clone(), SplitTarget::default(), None);
|
|
|
|
|
|
|
@@ -1885,17 +2022,24 @@ async fn test_melt_exact_proofs_no_swap_needed() {
|
|
|
let fake_description = FakeInvoiceDescription::default();
|
|
let fake_description = FakeInvoiceDescription::default();
|
|
|
let invoice = create_fake_invoice(64_000, serde_json::to_string(&fake_description).unwrap()); // 64 sats
|
|
let invoice = create_fake_invoice(64_000, serde_json::to_string(&fake_description).unwrap()); // 64 sats
|
|
|
|
|
|
|
|
- let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
|
|
|
|
|
|
|
+ let melt_quote = wallet
|
|
|
|
|
+ .melt_quote(PaymentMethod::BOLT11, invoice.to_string(), None, None)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
|
|
|
// Melt should succeed
|
|
// Melt should succeed
|
|
|
- let melted = wallet.melt(&melt_quote.id).await.unwrap();
|
|
|
|
|
|
|
+ let prepared = wallet
|
|
|
|
|
+ .prepare_melt(&melt_quote.id, std::collections::HashMap::new())
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
+ let melted = prepared.confirm().await.unwrap();
|
|
|
|
|
|
|
|
- assert_eq!(melted.amount, Amount::from(64));
|
|
|
|
|
|
|
+ assert_eq!(melted.amount(), Amount::from(64));
|
|
|
|
|
|
|
|
let final_balance = wallet.total_balance().await.unwrap();
|
|
let final_balance = wallet.total_balance().await.unwrap();
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
|
final_balance,
|
|
final_balance,
|
|
|
- initial_balance - melted.amount - melted.fee_paid
|
|
|
|
|
|
|
+ initial_balance - melted.amount() - melted.fee_paid()
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1917,7 +2061,7 @@ async fn test_check_all_mint_quotes_bolt11() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Create first mint quote and pay it (using proof_stream triggers fake wallet payment)
|
|
// Create first mint quote and pay it (using proof_stream triggers fake wallet payment)
|
|
|
- let mint_quote_1 = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote_1 = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
// Wait for the payment to be registered (fake wallet auto-pays)
|
|
// Wait for the payment to be registered (fake wallet auto-pays)
|
|
|
let mut payment_stream_1 = wallet.payment_stream(&mint_quote_1);
|
|
let mut payment_stream_1 = wallet.payment_stream(&mint_quote_1);
|
|
@@ -1928,7 +2072,7 @@ async fn test_check_all_mint_quotes_bolt11() {
|
|
|
.expect("no error");
|
|
.expect("no error");
|
|
|
|
|
|
|
|
// Create second mint quote and pay it
|
|
// Create second mint quote and pay it
|
|
|
- let mint_quote_2 = wallet.mint_quote(50.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote_2 = wallet.mint_bolt11_quote(50.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
let mut payment_stream_2 = wallet.payment_stream(&mint_quote_2);
|
|
let mut payment_stream_2 = wallet.payment_stream(&mint_quote_2);
|
|
|
payment_stream_2
|
|
payment_stream_2
|
|
@@ -1940,8 +2084,8 @@ async fn test_check_all_mint_quotes_bolt11() {
|
|
|
// Verify no proofs have been minted yet
|
|
// Verify no proofs have been minted yet
|
|
|
assert_eq!(wallet.total_balance().await.unwrap(), Amount::ZERO);
|
|
assert_eq!(wallet.total_balance().await.unwrap(), Amount::ZERO);
|
|
|
|
|
|
|
|
- // Call check_all_mint_quotes - this should mint both paid quotes
|
|
|
|
|
- let total_minted = wallet.check_all_mint_quotes().await.unwrap();
|
|
|
|
|
|
|
+ // Call mint_unissued_quotes - this should mint both paid quotes
|
|
|
|
|
+ let total_minted = wallet.mint_unissued_quotes().await.unwrap();
|
|
|
|
|
|
|
|
// Verify the total amount minted is correct (100 + 50 = 150)
|
|
// Verify the total amount minted is correct (100 + 50 = 150)
|
|
|
assert_eq!(total_minted, Amount::from(150));
|
|
assert_eq!(total_minted, Amount::from(150));
|
|
@@ -1949,8 +2093,8 @@ async fn test_check_all_mint_quotes_bolt11() {
|
|
|
// Verify wallet balance matches
|
|
// Verify wallet balance matches
|
|
|
assert_eq!(wallet.total_balance().await.unwrap(), Amount::from(150));
|
|
assert_eq!(wallet.total_balance().await.unwrap(), Amount::from(150));
|
|
|
|
|
|
|
|
- // Calling check_all_mint_quotes again should return 0 (quotes already minted)
|
|
|
|
|
- let second_check = wallet.check_all_mint_quotes().await.unwrap();
|
|
|
|
|
|
|
+ // Calling mint_unissued_quotes again should return 0 (quotes already minted)
|
|
|
|
|
+ let second_check = wallet.mint_unissued_quotes().await.unwrap();
|
|
|
assert_eq!(second_check, Amount::ZERO);
|
|
assert_eq!(second_check, Amount::ZERO);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1973,10 +2117,10 @@ async fn test_get_unissued_mint_quotes_wallet() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
// Create a quote but don't pay it (stays unpaid)
|
|
// Create a quote but don't pay it (stays unpaid)
|
|
|
- let unpaid_quote = wallet.mint_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let unpaid_quote = wallet.mint_bolt11_quote(100.into(), None).await.unwrap();
|
|
|
|
|
|
|
|
// Create another quote and pay it but don't mint
|
|
// Create another quote and pay it but don't mint
|
|
|
- let paid_quote = wallet.mint_quote(50.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let paid_quote = wallet.mint_bolt11_quote(50.into(), None).await.unwrap();
|
|
|
let mut payment_stream = wallet.payment_stream(&paid_quote);
|
|
let mut payment_stream = wallet.payment_stream(&paid_quote);
|
|
|
payment_stream
|
|
payment_stream
|
|
|
.next()
|
|
.next()
|
|
@@ -1985,7 +2129,7 @@ async fn test_get_unissued_mint_quotes_wallet() {
|
|
|
.expect("no error");
|
|
.expect("no error");
|
|
|
|
|
|
|
|
// Create a third quote and fully mint it
|
|
// Create a third quote and fully mint it
|
|
|
- let minted_quote = wallet.mint_quote(25.into(), None).await.unwrap();
|
|
|
|
|
|
|
+ let minted_quote = wallet.mint_bolt11_quote(25.into(), None).await.unwrap();
|
|
|
let mut proof_stream = wallet.proof_stream(minted_quote.clone(), SplitTarget::default(), None);
|
|
let mut proof_stream = wallet.proof_stream(minted_quote.clone(), SplitTarget::default(), None);
|
|
|
proof_stream
|
|
proof_stream
|
|
|
.next()
|
|
.next()
|
|
@@ -2026,7 +2170,7 @@ async fn test_get_unissued_mint_quotes_wallet() {
|
|
|
/// 2. Quote state is updated correctly
|
|
/// 2. Quote state is updated correctly
|
|
|
/// 3. The quote is stored properly in the localstore
|
|
/// 3. The quote is stored properly in the localstore
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
|
-async fn test_mint_quote_state_updates_after_minting() {
|
|
|
|
|
|
|
+async fn test_refresh_mint_quote_status_updates_after_minting() {
|
|
|
let wallet = Wallet::new(
|
|
let wallet = Wallet::new(
|
|
|
MINT_URL,
|
|
MINT_URL,
|
|
|
CurrencyUnit::Sat,
|
|
CurrencyUnit::Sat,
|
|
@@ -2037,7 +2181,7 @@ async fn test_mint_quote_state_updates_after_minting() {
|
|
|
.expect("failed to create new wallet");
|
|
.expect("failed to create new wallet");
|
|
|
|
|
|
|
|
let mint_amount = Amount::from(100);
|
|
let mint_amount = Amount::from(100);
|
|
|
- let mint_quote = wallet.mint_quote(mint_amount, None).await.unwrap();
|
|
|
|
|
|
|
+ let mint_quote = wallet.mint_bolt11_quote(mint_amount, None).await.unwrap();
|
|
|
|
|
|
|
|
// Get the quote from localstore before minting
|
|
// Get the quote from localstore before minting
|
|
|
let quote_before = wallet
|
|
let quote_before = wallet
|