Skip to content

Commit

Permalink
fix: regtest wait
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Feb 8, 2025
1 parent fc8da82 commit 9f0c0a0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,21 @@ jobs:
--bin cdk-mintd --no-default-features --features management-rpc,
--bin cdk-mint-cli,
]
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Build
run: nix develop -i -L .#stable --command cargo build ${{ matrix.build-args }}
- name: Clippy
run: nix develop -i -L .#stable --command cargo clippy ${{ matrix.build-args }} -- -D warnings
- name: Test
run: nix develop -i -L .#stable --command cargo test ${{ matrix.build-args }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Build
run: nix develop -i -L .#stable --command cargo build ${{ matrix.build-args }}
- name: Clippy
run: nix develop -i -L .#stable --command cargo clippy ${{ matrix.build-args }} -- -D warnings
- name: Test
run: nix develop -i -L .#stable --command cargo test ${{ matrix.build-args }}

itest:
name: "Integration regtest tests"
Expand Down
3 changes: 1 addition & 2 deletions crates/cdk-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Core Cashu Development Kit library implementing the Cashu protoco
license = "MIT"
homepage = "https://github.com/cashubtc/cdk"
repository = "https://github.com/cashubtc/cdk.git"
rust-version = "1.63.0" # MSRV


[features]
Expand Down Expand Up @@ -36,7 +35,7 @@ uuid = { version = "1", features = ["v4"] }
serde = "1"
serde_json = "1"
# ln-regtest-rs = { path = "../../../../ln-regtest-rs" }
ln-regtest-rs = { git = "https://github.com/thesimplekid/ln-regtest-rs", rev = "f9e7bbbb" }
ln-regtest-rs = { git = "https://github.com/thesimplekid/ln-regtest-rs", rev = "bf09ad6" }
lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
tracing = { version = "0.1", default-features = false, features = [
"attributes",
Expand Down
33 changes: 27 additions & 6 deletions crates/cdk-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub async fn attempt_to_swap_pending(wallet: &Wallet) -> Result<()> {
Ok(())
}

#[allow(clippy::incompatible_msrv)]
pub async fn wait_for_mint_to_be_paid(
wallet: &Wallet,
mint_quote_id: &str,
Expand All @@ -165,16 +166,36 @@ pub async fn wait_for_mint_to_be_paid(
]))
.await;

// Create the timeout future
// Create the wait future that handles both subscription and periodic state checks
let wait_future = async {
while let Some(msg) = subscription.recv().await {
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
if response.state == MintQuoteState::Paid {
return Ok(());
let mut interval = tokio::time::interval(Duration::from_secs(5));

loop {
tokio::select! {
// Check subscription messages
Some(msg) = subscription.recv() => {
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
if response.state == MintQuoteState::Paid {
return Ok(());
}
}
}
// Periodic state check
_ = interval.tick() => {
match wallet.mint_quote_state(mint_quote_id).await {
Ok(state) => {
if state.state == MintQuoteState::Paid {
return Ok(());
}
}
Err(e) => {
// Log the error but continue waiting, as this is just a backup check
tracing::warn!("Failed to check mint quote state: {}", e);
}
}
}
}
}
Ok(())
};

// Wait for either the payment to complete or timeout
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk-integration-tests/tests/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ 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, 60).await?;

let proofs = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
.await?;
Expand Down Expand Up @@ -352,8 +354,6 @@ async fn test_internal_payment() -> Result<()> {

let _melted = wallet.melt(&melt.id).await.unwrap();

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)
.await
Expand Down

0 comments on commit 9f0c0a0

Please sign in to comment.