Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve flakey ci tests #440

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions crates/cdk-integration-tests/tests/fake_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use bip39::Mnemonic;
use cdk::{
amount::SplitTarget,
cdk_database::WalletMemoryDatabase,
nuts::{CurrencyUnit, MeltBolt11Request, MeltQuoteState, PreMintSecrets, State},
nuts::{
CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State,
},
wallet::{
client::{HttpClient, HttpClientMethods},
Wallet,
Expand All @@ -30,7 +32,7 @@ async fn test_fake_tokens_pending() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -70,7 +72,7 @@ async fn test_fake_melt_payment_fail() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -133,7 +135,7 @@ async fn test_fake_melt_payment_fail_and_check() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -178,7 +180,7 @@ async fn test_fake_melt_payment_return_fail_status() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -238,7 +240,7 @@ async fn test_fake_melt_payment_error_unknown() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -299,7 +301,7 @@ async fn test_fake_melt_payment_err_paid() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -337,7 +339,7 @@ async fn test_fake_melt_change_in_quote() -> Result<()> {

let mint_quote = wallet.mint_quote(100.into(), None).await?;

sleep(Duration::from_millis(5)).await;
wait_for_mint_to_be_paid(&wallet, &mint_quote.id).await?;

let _mint_amount = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
Expand Down Expand Up @@ -377,3 +379,15 @@ async fn test_fake_melt_change_in_quote() -> Result<()> {
assert_eq!(melt_change, check);
Ok(())
}

// Keep polling the state of the mint quote id until it's paid
async fn wait_for_mint_to_be_paid(wallet: &Wallet, mint_quote_id: &str) -> Result<()> {
loop {
let status = wallet.mint_quote_state(mint_quote_id).await?;
if status.state == MintQuoteState::Paid {
return Ok(());
}

sleep(Duration::from_millis(5)).await;
}
}
Loading