|
| 1 | +// This file is Copyright its original authors, visible in version control history. |
| 2 | +// |
| 3 | +// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
| 5 | +// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in |
| 6 | +// accordance with one or both of these licenses. |
| 7 | + |
| 8 | +#![cfg(hrn_tests)] |
| 9 | + |
| 10 | +mod common; |
| 11 | + |
| 12 | +use bitcoin::Amount; |
| 13 | +use common::{ |
| 14 | + expect_channel_ready_event, expect_payment_successful_event, generate_blocks_and_wait, |
| 15 | + open_channel, premine_and_distribute_funds, setup_bitcoind_and_electrsd, setup_two_nodes, |
| 16 | + TestChainSource, |
| 17 | +}; |
| 18 | +use ldk_node::payment::UnifiedPaymentResult; |
| 19 | +use ldk_node::Event; |
| 20 | +use lightning::ln::channelmanager::PaymentId; |
| 21 | + |
| 22 | +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] |
| 23 | +async fn unified_send_to_hrn() { |
| 24 | + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); |
| 25 | + let chain_source = TestChainSource::Esplora(&electrsd); |
| 26 | + |
| 27 | + let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false); |
| 28 | + |
| 29 | + let address_a = node_a.onchain_payment().new_address().unwrap(); |
| 30 | + let premined_sats = 5_000_000; |
| 31 | + |
| 32 | + premine_and_distribute_funds( |
| 33 | + &bitcoind.client, |
| 34 | + &electrsd.client, |
| 35 | + vec![address_a], |
| 36 | + Amount::from_sat(premined_sats), |
| 37 | + ) |
| 38 | + .await; |
| 39 | + |
| 40 | + node_a.sync_wallets().unwrap(); |
| 41 | + open_channel(&node_a, &node_b, 4_000_000, true, &electrsd).await; |
| 42 | + generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await; |
| 43 | + |
| 44 | + node_a.sync_wallets().unwrap(); |
| 45 | + node_b.sync_wallets().unwrap(); |
| 46 | + |
| 47 | + expect_channel_ready_event!(node_a, node_b.node_id()); |
| 48 | + expect_channel_ready_event!(node_b, node_a.node_id()); |
| 49 | + |
| 50 | + // Sleep until we broadcast a node announcement. |
| 51 | + while node_b.status().latest_node_announcement_broadcast_timestamp.is_none() { |
| 52 | + std::thread::sleep(std::time::Duration::from_millis(10)); |
| 53 | + } |
| 54 | + |
| 55 | + let test_offer = node_b.bolt12_payment().receive(1000000, "test offer", None, None).unwrap(); |
| 56 | + |
| 57 | + // Sleep one more sec to make sure the node announcement propagates. |
| 58 | + std::thread::sleep(std::time::Duration::from_secs(1)); |
| 59 | + |
| 60 | + let hrn_str = "matt@mattcorallo.com"; |
| 61 | + |
| 62 | + let offer_payment_id: PaymentId = |
| 63 | + match node_a.unified_payment().send(&hrn_str, Some(1000000), None, &test_offer).await { |
| 64 | + Ok(UnifiedPaymentResult::Bolt12 { payment_id }) => { |
| 65 | + println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id); |
| 66 | + payment_id |
| 67 | + }, |
| 68 | + Ok(UnifiedPaymentResult::Bolt11 { payment_id: _ }) => { |
| 69 | + panic!("Expected Bolt12 payment but got Bolt11"); |
| 70 | + }, |
| 71 | + Ok(UnifiedPaymentResult::Onchain { txid: _ }) => { |
| 72 | + panic!("Expected Bolt12 payment but got On-chain transaction"); |
| 73 | + }, |
| 74 | + Err(e) => { |
| 75 | + panic!("Expected Bolt12 payment but got error: {:?}", e); |
| 76 | + }, |
| 77 | + }; |
| 78 | + |
| 79 | + expect_payment_successful_event!(node_a, Some(offer_payment_id), None); |
| 80 | +} |
0 commit comments