mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-10 00:16:02 +01:00
Merge pull request #567 from thesimplekid/fix_mint_melt_test
fix: add time out to wait invoice in tests
This commit is contained in:
@@ -209,7 +209,7 @@ pub async fn fund_wallet(wallet: Arc<Wallet>, amount: u64) -> anyhow::Result<Amo
|
||||
let desired_amount = Amount::from(amount);
|
||||
let quote = wallet.mint_quote(desired_amount, None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, "e.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, "e.id, 60).await?;
|
||||
|
||||
Ok(wallet
|
||||
.mint("e.id, SplitTarget::default(), None)
|
||||
|
||||
@@ -15,6 +15,7 @@ use cdk::wallet::client::{HttpClient, MintConnector};
|
||||
use cdk::wallet::subscription::SubscriptionManager;
|
||||
use cdk::wallet::WalletSubscription;
|
||||
use cdk::Wallet;
|
||||
use tokio::time::{timeout, Duration};
|
||||
|
||||
pub mod init_fake_wallet;
|
||||
pub mod init_mint;
|
||||
@@ -153,21 +154,32 @@ pub async fn attempt_to_swap_pending(wallet: &Wallet) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Keep polling the state of the mint quote id until it's paid
|
||||
pub async fn wait_for_mint_to_be_paid(wallet: &Wallet, mint_quote_id: &str) -> Result<()> {
|
||||
pub async fn wait_for_mint_to_be_paid(
|
||||
wallet: &Wallet,
|
||||
mint_quote_id: &str,
|
||||
timeout_secs: u64,
|
||||
) -> Result<()> {
|
||||
let mut subscription = wallet
|
||||
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![
|
||||
mint_quote_id.to_owned(),
|
||||
]))
|
||||
.await;
|
||||
|
||||
while let Some(msg) = subscription.recv().await {
|
||||
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
|
||||
if response.state == MintQuoteState::Paid {
|
||||
break;
|
||||
// Create the timeout future
|
||||
let wait_future = async {
|
||||
while let Some(msg) = subscription.recv().await {
|
||||
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
|
||||
if response.state == MintQuoteState::Paid {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
Ok(())
|
||||
// Wait for either the payment to complete or timeout
|
||||
match timeout(Duration::from_secs(timeout_secs), wait_future).await {
|
||||
Ok(result) => result,
|
||||
Err(_) => Err(anyhow::anyhow!("Timeout waiting for mint quote to be paid")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ async fn test_fake_tokens_pending() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -69,7 +69,7 @@ async fn test_fake_melt_payment_fail() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -132,7 +132,7 @@ async fn test_fake_melt_payment_fail_and_check() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -177,7 +177,7 @@ async fn test_fake_melt_payment_return_fail_status() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -237,7 +237,7 @@ async fn test_fake_melt_payment_error_unknown() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -298,7 +298,7 @@ async fn test_fake_melt_payment_err_paid() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -336,7 +336,7 @@ async fn test_fake_melt_change_in_quote() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -388,7 +388,7 @@ async fn test_fake_mint_with_witness() -> Result<()> {
|
||||
)?;
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let proofs = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -413,7 +413,7 @@ async fn test_fake_mint_without_witness() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let http_client = HttpClient::new(MINT_URL.parse()?);
|
||||
|
||||
@@ -437,7 +437,6 @@ async fn test_fake_mint_without_witness() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Rewrite this test to include witness wrong
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
||||
async fn test_fake_mint_with_wrong_witness() -> Result<()> {
|
||||
let wallet = Wallet::new(
|
||||
@@ -450,7 +449,7 @@ async fn test_fake_mint_with_wrong_witness() -> Result<()> {
|
||||
|
||||
let mint_quote = wallet.mint_quote(100.into(), None).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let http_client = HttpClient::new(MINT_URL.parse()?);
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ async fn test_regtest_mint_melt_round_trip() -> Result<()> {
|
||||
|
||||
lnd_client.pay_invoice(mint_quote.request).await.unwrap();
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let proofs = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -179,7 +179,7 @@ async fn test_regtest_mint_melt() -> Result<()> {
|
||||
|
||||
lnd_client.pay_invoice(mint_quote.request).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let proofs = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -209,7 +209,7 @@ async fn test_restore() -> Result<()> {
|
||||
|
||||
lnd_client.pay_invoice(mint_quote.request).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -271,7 +271,7 @@ async fn test_pay_invoice_twice() -> Result<()> {
|
||||
.await
|
||||
.expect("Could not pay invoice");
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let proofs = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -327,7 +327,7 @@ async fn test_internal_payment() -> Result<()> {
|
||||
|
||||
lnd_client.pay_invoice(mint_quote.request).await?;
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _mint_amount = wallet
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
@@ -353,7 +353,7 @@ async fn test_internal_payment() -> Result<()> {
|
||||
|
||||
let _melted = wallet.melt(&melt.id).await.unwrap();
|
||||
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;
|
||||
wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?;
|
||||
|
||||
let _wallet_2_mint = wallet_2
|
||||
.mint(&mint_quote.id, SplitTarget::default(), None)
|
||||
|
||||
Reference in New Issue
Block a user