Skip to main content

gateway_tests/
main.rs

1#![deny(clippy::pedantic)]
2
3use std::collections::BTreeMap;
4use std::fs::{remove_dir_all, remove_file};
5use std::ops::ControlFlow;
6use std::path::PathBuf;
7use std::str::FromStr;
8use std::time::Duration;
9use std::{env, ffi};
10
11use anyhow::Context;
12use clap::{Parser, Subcommand};
13use devimint::cli::cleanup_on_exit;
14use devimint::envs::FM_DATA_DIR_ENV;
15use devimint::external::{Bitcoind, Esplora};
16use devimint::federation::Federation;
17use devimint::util::{ProcessManager, almost_equal, poll, poll_with_timeout};
18use devimint::version_constants::{VERSION_0_10_0_ALPHA, VERSION_0_12_0_ALPHA};
19use devimint::{Gatewayd, LightningNode, cli, util};
20use fedimint_core::config::FederationId;
21use fedimint_core::time::now;
22use fedimint_core::{Amount, BitcoinAmountOrAll, bitcoin, default_esplora_server};
23use fedimint_gateway_common::{FederationInfo, PaymentDetails, PaymentKind, PaymentStatus};
24use fedimint_logging::LOG_TEST;
25use fedimint_testing_core::node_type::LightningNodeType;
26use itertools::Itertools;
27use tracing::info;
28
29#[derive(Parser)]
30struct GatewayTestOpts {
31    #[clap(subcommand)]
32    test: GatewayTest,
33}
34
35#[derive(Debug, Clone, Subcommand)]
36#[allow(clippy::enum_variant_names)]
37enum GatewayTest {
38    ConfigTest {
39        #[arg(long = "gw-type")]
40        gateway_type: LightningNodeType,
41    },
42    BackupRestoreTest,
43    LiquidityTest,
44    EsploraTest,
45}
46
47#[tokio::main]
48async fn main() -> anyhow::Result<()> {
49    let opts = GatewayTestOpts::parse();
50    match opts.test {
51        GatewayTest::ConfigTest { gateway_type } => Box::pin(config_test(gateway_type)).await,
52        GatewayTest::BackupRestoreTest => Box::pin(backup_restore_test()).await,
53        GatewayTest::LiquidityTest => Box::pin(liquidity_test()).await,
54        GatewayTest::EsploraTest => esplora_test().await,
55    }
56}
57
58async fn backup_restore_test() -> anyhow::Result<()> {
59    Box::pin(
60        devimint::run_devfed_test().call(|dev_fed, process_mgr| async move {
61            let gw = if devimint::util::supports_lnv2() {
62                dev_fed.gw_ldk_connected().await?
63            } else {
64                dev_fed.gw_lnd_registered().await?
65            };
66
67            let fed = dev_fed.fed().await?;
68            fed.pegin_gateways(10_000_000, vec![gw]).await?;
69
70            let mnemonic = gw.client().get_mnemonic().await?.mnemonic;
71
72            // Recover without a backup
73            info!(target: LOG_TEST, "Wiping gateway and recovering without a backup...");
74            let ln = gw.ln.clone();
75            let new_gw = stop_and_recover_gateway(
76                process_mgr.clone(),
77                mnemonic.clone(),
78                gw.to_owned(),
79                ln.clone(),
80                fed,
81            )
82            .await?;
83
84            // Recover with a backup
85            info!(target: LOG_TEST, "Wiping gateway and recovering with a backup...");
86            info!(target: LOG_TEST, "Creating backup...");
87            new_gw.client().backup_to_fed(fed).await?;
88            stop_and_recover_gateway(process_mgr, mnemonic, new_gw, ln, fed).await?;
89
90            info!(target: LOG_TEST, "backup_restore_test successful");
91            Ok(())
92        }),
93    )
94    .await
95}
96
97async fn stop_and_recover_gateway(
98    process_mgr: ProcessManager,
99    mnemonic: Vec<String>,
100    old_gw: Gatewayd,
101    new_ln: LightningNode,
102    fed: &Federation,
103) -> anyhow::Result<Gatewayd> {
104    let gateway_balances = old_gw.client().get_balances().await?;
105    let before_onchain_balance = gateway_balances.onchain_balance_sats;
106
107    // Stop the Gateway
108    let gw_type = old_gw.ln.ln_type();
109    let gw_name = old_gw.gw_name.clone();
110    let old_gw_index = old_gw.gateway_index;
111    old_gw.terminate().await?;
112    info!(target: LOG_TEST, "Terminated Gateway");
113
114    // Delete the gateway's database
115    let data_dir: PathBuf = env::var(FM_DATA_DIR_ENV)
116        .expect("Data dir is not set")
117        .parse()
118        .expect("Could not parse data dir");
119    let gw_db = data_dir.join(gw_name.clone()).join("gatewayd.db");
120    if gw_db.is_file() {
121        // db is single file on redb
122        remove_file(gw_db)?;
123    } else {
124        remove_dir_all(gw_db)?;
125    }
126    info!(target: LOG_TEST, "Deleted the Gateway's database");
127
128    if gw_type == LightningNodeType::Ldk {
129        // Delete LDK's database as well
130        let ldk_data_dir = data_dir.join(gw_name).join("ldk_node");
131        remove_dir_all(ldk_data_dir)?;
132        info!(target: LOG_TEST, "Deleted LDK's database");
133    }
134
135    let seed = mnemonic.join(" ");
136    // TODO: Audit that the environment access only happens in single-threaded code.
137    unsafe { std::env::set_var("FM_GATEWAY_MNEMONIC", seed) };
138    let new_gw = Gatewayd::new(&process_mgr, new_ln, old_gw_index).await?;
139    let new_mnemonic = new_gw.client().get_mnemonic().await?.mnemonic;
140    assert_eq!(mnemonic, new_mnemonic);
141    info!(target: LOG_TEST, "Verified mnemonic is the same after creating new Gateway");
142
143    let federations = serde_json::from_value::<Vec<FederationInfo>>(
144        new_gw.client().get_info().await?["federations"].clone(),
145    )?;
146    assert_eq!(0, federations.len());
147    info!(target: LOG_TEST, "Verified new Gateway has no federations");
148
149    new_gw.client().recover_fed(fed).await?;
150
151    let gateway_balances = new_gw.client().get_balances().await?;
152    let ecash_balance = gateway_balances
153        .ecash_balances
154        .first()
155        .expect("Should have one joined federation");
156    almost_equal(
157        ecash_balance.ecash_balance_msats.sats_round_down(),
158        10_000_000,
159        10,
160    )
161    .unwrap();
162    let after_onchain_balance = gateway_balances.onchain_balance_sats;
163    assert_eq!(before_onchain_balance, after_onchain_balance);
164    info!(target: LOG_TEST, "Verified balances after recovery");
165
166    Ok(new_gw)
167}
168
169/// Test that sets and verifies configurations within the gateway
170#[allow(clippy::too_many_lines)]
171async fn config_test(gw_type: LightningNodeType) -> anyhow::Result<()> {
172    Box::pin(
173        devimint::run_devfed_test()
174            .num_feds(2)
175            .call(|dev_fed, process_mgr| async move {
176                let gw = match gw_type {
177                    LightningNodeType::Lnd => dev_fed.gw_lnd_registered().await?,
178                    LightningNodeType::Ldk => dev_fed.gw_ldk_connected().await?,
179                };
180
181                // Try to connect to already connected federation
182                let invite_code = dev_fed.fed().await?.invite_code()?;
183                gw.client().connect_fed(invite_code).await.expect_err("Connecting to the same federation succeeded");
184                info!(target: LOG_TEST, "Verified that gateway couldn't connect to already connected federation");
185
186                // Change the routing fees for a specific federation
187                let fed_id = dev_fed.fed().await?.calculate_federation_id();
188                gw.client().set_federation_routing_fee(fed_id.clone(), 20, 20000)
189                    .await?;
190
191                let lightning_fee = gw.client().get_lightning_fee(fed_id.clone()).await?;
192                assert_eq!(
193                    lightning_fee.base.msats, 20,
194                    "Federation base msat is not 20"
195                );
196                assert_eq!(
197                    lightning_fee.parts_per_million, 20000,
198                    "Federation proportional millionths is not 20000"
199                );
200                info!(target: LOG_TEST, "Verified per-federation routing fees changed");
201
202                let info_value = gw.client().get_info().await?;
203                let federations = info_value["federations"]
204                    .as_array()
205                    .expect("federations is an array");
206                assert_eq!(
207                    federations.len(),
208                    1,
209                    "Gateway did not have one connected federation"
210                );
211
212                // Get the federation's config and verify it parses correctly
213                gw.client().client_config(fed_id.clone()).await?;
214
215                // Spawn new federation
216                let bitcoind = dev_fed.bitcoind().await?;
217                let new_fed = Federation::new(
218                    &process_mgr,
219                    bitcoind.clone(),
220                    false,
221                    false,
222                    1,
223                    "config-test".to_string(),
224                )
225                .await?;
226                let new_fed_id = new_fed.calculate_federation_id();
227                info!(target: LOG_TEST, "Successfully spawned new federation");
228
229                let new_invite_code = new_fed.invite_code()?;
230                gw.client().connect_fed(new_invite_code.clone()).await?;
231
232                let default_base = 0;
233                let default_ppm = 0;
234
235                let lightning_fee = gw.client().get_lightning_fee(new_fed_id.clone()).await?;
236                assert_eq!(
237                    lightning_fee.base.msats, default_base,
238                    "Default Base msat for new federation was not correct"
239                );
240                assert_eq!(
241                    lightning_fee.parts_per_million, default_ppm,
242                    "Default Base msat for new federation was not correct"
243                );
244
245                info!(target: LOG_TEST, federation_id = %new_fed_id, "Verified new federation");
246
247                // Peg-in sats to gw for the new fed
248                let pegin_amount = Amount::from_msats(10_000_000);
249                new_fed
250                    .pegin_gateways(pegin_amount.sats_round_down(), vec![gw])
251                    .await?;
252
253                // Verify `info` returns multiple federations
254                let info_value = gw.client().get_info().await?;
255                let federations = info_value["federations"]
256                    .as_array()
257                    .expect("federations is an array");
258
259                assert_eq!(
260                    federations.len(),
261                    2,
262                    "Gateway did not have two connected federations"
263                );
264
265                let federation_fake_scids =
266                    serde_json::from_value::<Option<BTreeMap<u64, FederationId>>>(
267                        info_value
268                            .get("channels")
269                            .or_else(|| info_value.get("federation_fake_scids"))
270                            .expect("field  exists")
271                            .to_owned(),
272                    )
273                    .expect("cannot parse")
274                    .expect("should have scids");
275
276                assert_eq!(
277                    federation_fake_scids.keys().copied().collect::<Vec<u64>>(),
278                    vec![1, 2]
279                );
280
281                let first_fed_info = federations
282                    .iter()
283                    .find(|i| {
284                        *i["federation_id"]
285                            .as_str()
286                            .expect("should parse as str")
287                            .to_string()
288                            == fed_id
289                    })
290                    .expect("Could not find federation");
291
292                let second_fed_info = federations
293                    .iter()
294                    .find(|i| {
295                        *i["federation_id"]
296                            .as_str()
297                            .expect("should parse as str")
298                            .to_string()
299                            == new_fed_id
300                    })
301                    .expect("Could not find federation");
302
303                let first_fed_balance_msat =
304                    serde_json::from_value::<Amount>(first_fed_info["balance_msat"].clone())
305                        .expect("fed should have balance");
306
307                let second_fed_balance_msat =
308                    serde_json::from_value::<Amount>(second_fed_info["balance_msat"].clone())
309                        .expect("fed should have balance");
310
311                assert_eq!(first_fed_balance_msat, Amount::ZERO);
312                almost_equal(second_fed_balance_msat.msats, pegin_amount.msats, 10_000).unwrap();
313
314                let fed_id = FederationId::from_str(&fed_id).expect("invalid Federation ID");
315                let fed_info = gw.client().leave_federation(fed_id).await?;
316                assert_eq!(serde_json::from_value::<FederationId>(fed_info["federation_id"].clone())?, fed_id);
317                assert_eq!(fed_info["config"]["federation_index"].as_u64().expect("Was not u64"), 1);
318                gw.client().leave_federation(fed_id).await.expect_err("Successfully left a federation twice");
319
320                let new_fed_id = FederationId::from_str(&new_fed_id).expect("invalid Federation ID");
321                let fed_info = gw.client().leave_federation(new_fed_id).await?;
322                assert_eq!(serde_json::from_value::<FederationId>(fed_info["federation_id"].clone())?, new_fed_id);
323                assert_eq!(fed_info["config"]["federation_index"].as_u64().expect("Was not u64"), 2);
324
325                // Rejoin new federation, verify that the balance is the same
326                let fed_info = gw.client().connect_fed(new_invite_code).await?;
327                assert_eq!(second_fed_balance_msat, Amount::from_msats(fed_info["balance_msat"].as_u64().expect("Balance should be present")));
328
329                if gw.gatewayd_version >= *VERSION_0_10_0_ALPHA {
330                    // Try to get the info over iroh
331                    info!(target: LOG_TEST, gatewayd_version = %gw.gatewayd_version, "Getting info over iroh");
332                    gw.client().with_iroh().get_info().await?;
333                }
334
335                info!(target: LOG_TEST, "Gateway configuration test successful");
336                Ok(())
337            }),
338    )
339    .await
340}
341
342/// Test that verifies the various liquidity tools (onchain, lightning, ecash)
343/// work correctly.
344#[allow(clippy::too_many_lines)]
345async fn liquidity_test() -> anyhow::Result<()> {
346    devimint::run_devfed_test()
347        .call(|dev_fed, _process_mgr| async move {
348            let federation = dev_fed.fed().await?;
349
350            if !devimint::util::supports_lnv2() {
351                info!(target: LOG_TEST, "LNv2 is not supported, which is necessary for LDK GW and liquidity test");
352                return Ok(());
353            }
354
355            let gw_lnd = dev_fed.gw_lnd_registered().await?;
356            let gw_ldk = dev_fed.gw_ldk_connected().await?;
357            let gw_ldk_second = dev_fed.gw_ldk_second_connected().await?;
358            let gateways = [gw_lnd, gw_ldk].to_vec();
359
360            let gateway_matrix = gateways
361                .iter()
362                .cartesian_product(gateways.iter())
363                .filter(|(a, b)| a.ln.ln_type() != b.ln.ln_type());
364
365            info!(target: LOG_TEST, "Pegging-in gateways...");
366            federation
367                .pegin_gateways(1_000_000, gateways.clone())
368                .await?;
369
370            info!(target: LOG_TEST, "Testing ecash payments between gateways...");
371            for (gw_send, gw_receive) in gateway_matrix.clone() {
372                info!(
373                    target: LOG_TEST,
374                    gw_send = %gw_send.ln.ln_type(),
375                    gw_receive = %gw_receive.ln.ln_type(),
376                    "Testing ecash payment",
377                );
378
379                let fed_id = federation.calculate_federation_id();
380                let prev_send_ecash_balance = gw_send.client().ecash_balance(fed_id.clone()).await?;
381                let prev_receive_ecash_balance = gw_receive.client().ecash_balance(fed_id.clone()).await?;
382                let ecash = gw_send.client().send_ecash(fed_id.clone(), 500_000).await?;
383                gw_receive.client().receive_ecash(ecash).await?;
384                let after_send_ecash_balance = gw_send.client().ecash_balance(fed_id.clone()).await?;
385                almost_equal(
386                    prev_send_ecash_balance - 500_000,
387                    after_send_ecash_balance,
388                    if util::supports_mint_v2() { 2_000 } else { 512 },
389                )
390                .expect("Balances were not almost equal");
391
392                poll_with_timeout(
393                    "receive ecash balance",
394                    Duration::from_secs(30),
395                    || async {
396                        let balance = gw_receive.client().ecash_balance(fed_id.clone()).await
397                            .map_err(ControlFlow::Break)?;
398                        almost_equal(prev_receive_ecash_balance + 500_000, balance, 2_000)
399                            .map_err(|e| ControlFlow::Continue(anyhow::anyhow!(e)))
400                    },
401                )
402                .await?;
403            }
404
405            info!(target: LOG_TEST, "Testing payments between gateways...");
406            for (gw_send, gw_receive) in gateway_matrix.clone() {
407                info!(
408                    target: LOG_TEST,
409                    gw_send = %gw_send.ln.ln_type(),
410                    gw_receive = %gw_receive.ln.ln_type(),
411                    "Testing lightning payment",
412                );
413
414                let invoice = gw_receive.client().create_invoice(1_000_000).await?;
415                gw_send.client().pay_invoice(invoice).await?;
416            }
417
418            let start = now() - Duration::from_mins(5);
419            let end = now() + Duration::from_mins(5);
420            info!(target: LOG_TEST, "Verifying list of transactions");
421            let lnd_transactions = gw_lnd.client().list_transactions(start, end).await?;
422            // One inbound and one outbound transaction
423            assert_eq!(lnd_transactions.len(), 2);
424
425            let ldk_transactions = gw_ldk.client().list_transactions(start, end).await?;
426            assert_eq!(ldk_transactions.len(), 2);
427
428            // Verify that transactions are filtered by time
429            let start = now() - Duration::from_mins(10);
430            let end = now() - Duration::from_mins(5);
431            let lnd_transactions = gw_lnd.client().list_transactions(start, end).await?;
432            assert_eq!(lnd_transactions.len(), 0);
433
434            info!(target: LOG_TEST, "Testing paying Bolt12 Offers...");
435            let offer_with_amount = gw_ldk_second.client().create_offer(Some(Amount::from_msats(10_000_000))).await?;
436            gw_ldk.client().pay_offer(offer_with_amount, None).await?;
437            assert!(get_transaction(gw_ldk_second, PaymentKind::Bolt12Offer, Amount::from_msats(10_000_000), PaymentStatus::Succeeded).await.is_some());
438
439            let offer_without_amount = gw_ldk.client().create_offer(None).await?;
440            gw_ldk_second.client().pay_offer(offer_without_amount.clone(), Some(Amount::from_msats(5_000_000))).await?;
441            assert!(get_transaction(gw_ldk, PaymentKind::Bolt12Offer, Amount::from_msats(5_000_000), PaymentStatus::Succeeded).await.is_some());
442
443            // Cannot pay an offer without an amount without specifying an amount
444            gw_ldk_second.client().pay_offer(offer_without_amount.clone(), None).await.expect_err("Cannot pay amountless offer without specifying an amount");
445
446            // Verify we can pay the offer again
447            gw_ldk_second.client().pay_offer(offer_without_amount, Some(Amount::from_msats(3_000_000))).await?;
448            assert!(get_transaction(gw_ldk, PaymentKind::Bolt12Offer, Amount::from_msats(3_000_000), PaymentStatus::Succeeded).await.is_some());
449
450            // `set-channel-fees` was added in 0.12.0-alpha for both the gateway
451            // API and the CLI. Skip the test against any older gateway/CLI binary
452            // to keep this test backwards-compatible with prior releases.
453            let gateway_cli_version = util::GatewayCli::version_or_default().await;
454            let all_gateways_support_fees = gateways
455                .iter()
456                .all(|gw| gw.gatewayd_version >= *VERSION_0_12_0_ALPHA);
457            if gateway_cli_version >= *VERSION_0_12_0_ALPHA && all_gateways_support_fees {
458                info!(target: LOG_TEST, "Testing updating channel fees on both gateways...");
459                for gw in &gateways {
460                    let channels = gw.client().list_channels().await?;
461                    let channel = channels
462                        .into_iter()
463                        .find(|c| c.funding_outpoint.is_some())
464                        .with_context(|| {
465                            format!(
466                                "{} gateway has no channel with a known funding outpoint",
467                                gw.ln.ln_type(),
468                            )
469                        })?;
470                    let funding_outpoint = channel.funding_outpoint.expect("filtered above");
471
472                    // Pick values that are unlikely to collide with any backend default.
473                    let new_base_fee_msat = 12_345u64;
474                    let new_parts_per_million = 678u64;
475
476                    gw.client()
477                        .set_channel_fees(
478                            funding_outpoint,
479                            new_base_fee_msat,
480                            new_parts_per_million,
481                        )
482                        .await?;
483
484                    // Both backends report local config synchronously, but poll briefly
485                    // in case the LND policy update needs a moment to be visible to
486                    // `fee_report`.
487                    poll_with_timeout(
488                        "channel fees reflect updated values",
489                        Duration::from_secs(15),
490                        || async {
491                            let updated = gw
492                                .client()
493                                .list_channels()
494                                .await
495                                .map_err(ControlFlow::Continue)?
496                                .into_iter()
497                                .find(|c| c.funding_outpoint == Some(funding_outpoint))
498                                .ok_or_else(|| {
499                                    ControlFlow::Break(anyhow::anyhow!(
500                                        "channel disappeared after fee update"
501                                    ))
502                                })?;
503                            if updated.base_fee_msat == Some(new_base_fee_msat)
504                                && updated.parts_per_million == Some(new_parts_per_million)
505                            {
506                                Ok(())
507                            } else {
508                                Err(ControlFlow::Continue(anyhow::anyhow!(
509                                    "{} gateway still reports base={:?}, ppm={:?}",
510                                    gw.ln.ln_type(),
511                                    updated.base_fee_msat,
512                                    updated.parts_per_million,
513                                )))
514                            }
515                        },
516                    )
517                    .await?;
518                }
519            } else {
520                info!(
521                    target: LOG_TEST,
522                    gateway_cli_version = %gateway_cli_version,
523                    "Skipping set-channel-fees test (requires gateway >= 0.12.0-alpha)"
524                );
525            }
526
527            info!(target: LOG_TEST, "Pegging-out gateways...");
528            federation
529                .pegout_gateways(500_000_000, gateways.clone())
530                .await?;
531
532            info!(target: LOG_TEST, "Testing only admin can send onchain...");
533            let send_result = gw_lnd.client().with_password("secondbest").send_onchain(dev_fed.bitcoind().await?, BitcoinAmountOrAll::All, 10).await;
534            assert!(send_result.is_err(), "Only admins can send onchain");
535
536            info!(target: LOG_TEST, "Testing sending onchain...");
537            let bitcoind = dev_fed.bitcoind().await?;
538            for gw in &gateways {
539                let txid = gw
540                    .client()
541                    .send_onchain(dev_fed.bitcoind().await?, BitcoinAmountOrAll::All, 10)
542                    .await?;
543                bitcoind.poll_get_transaction(txid).await?;
544            }
545
546            info!(target: LOG_TEST, "Testing closing all channels...");
547
548            // Gracefully close one of LND's channel's
549            let gw_ldk_pubkey = gw_ldk.client().lightning_pubkey().await?;
550            gw_lnd.client().close_channel(gw_ldk_pubkey, false).await?;
551
552            // Force close remaining channels on every gateway and wait
553            for gw in &gateways {
554                gw.client()
555                    .close_all_channels(true, Duration::from_secs(30))
556                    .await?;
557            }
558
559            Ok(())
560        })
561        .await
562}
563
564async fn esplora_test() -> anyhow::Result<()> {
565    let args = cli::CommonArgs::parse_from::<_, ffi::OsString>(vec![]);
566    let (process_mgr, task_group) = cli::setup(args).await?;
567    cleanup_on_exit(
568        async {
569            info!("Spawning bitcoind...");
570            let bitcoind = Bitcoind::new(&process_mgr, false).await?;
571            info!("Spawning esplora...");
572            let _esplora = Esplora::new(&process_mgr, bitcoind).await?;
573            let network = bitcoin::Network::from_str(&process_mgr.globals.FM_GATEWAY_NETWORK)
574                .expect("Could not parse network");
575            let esplora_port = process_mgr.globals.FM_PORT_ESPLORA.to_string();
576            let esplora = default_esplora_server(network, Some(esplora_port));
577            unsafe {
578                std::env::remove_var("FM_BITCOIND_URL");
579                std::env::set_var("FM_ESPLORA_URL", esplora.url.to_string());
580            }
581            info!("Spawning ldk gateway...");
582            let ldk = Gatewayd::new(
583                &process_mgr,
584                LightningNode::Ldk {
585                    name: "gateway-ldk-esplora".to_string(),
586                    gw_port: process_mgr.globals.FM_PORT_GW_LDK,
587                    ldk_port: process_mgr.globals.FM_PORT_LDK,
588                    metrics_port: process_mgr.globals.FM_PORT_GW_LDK_METRICS,
589                },
590                0,
591            )
592            .await?;
593
594            info!("Waiting for ldk gatewy to be ready...");
595            poll("Waiting for LDK to be ready", || async {
596                let info = ldk
597                    .client()
598                    .get_info()
599                    .await
600                    .map_err(ControlFlow::Continue)?;
601                let state: String = serde_json::from_value(info["gateway_state"].clone())
602                    .expect("Could not get gateway state");
603                if state == "Running" {
604                    Ok(())
605                } else {
606                    Err(ControlFlow::Continue(anyhow::anyhow!(
607                        "Gateway not running"
608                    )))
609                }
610            })
611            .await?;
612
613            ldk.client().get_ln_onchain_address().await?;
614            info!(target:LOG_TEST, "ldk gateway successfully spawned and connected to esplora");
615            Ok(())
616        },
617        task_group,
618    )
619    .await?;
620    Ok(())
621}
622
623async fn get_transaction(
624    gateway: &Gatewayd,
625    kind: PaymentKind,
626    amount: Amount,
627    status: PaymentStatus,
628) -> Option<PaymentDetails> {
629    let transactions = gateway
630        .client()
631        .list_transactions(
632            now() - Duration::from_mins(5),
633            now() + Duration::from_mins(5),
634        )
635        .await
636        .ok()?;
637    transactions.into_iter().find(|details| {
638        details.payment_kind == kind && details.amount == amount && details.status == status
639    })
640}