From b3e4248786e9b0b82fbcb51ee3fd2bcaf59de6ac Mon Sep 17 00:00:00 2001 From: Orbital Date: Thu, 7 Sep 2023 16:45:16 -0500 Subject: [PATCH] tests: test that ldk node can send onion message --- tests/common/mod.rs | 38 ++++++++++++++++++++++++++++++++++---- tests/integration_tests.rs | 13 ++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index ab226377..4c56516a 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,13 +1,43 @@ #![allow(dead_code)] pub mod ldk_node; +use crate::common::ldk_node::config::LdkUserInfo; -use bitcoincore_rpc::{bitcoin::Network, json, RpcApi}; +use bitcoin::network::constants::Network; +use bitcoincore_rpc::{bitcoin::Network as BitcoindNetwork, json, RpcApi}; use bitcoind::{get_available_port, BitcoinD, Conf}; +use ldk_node::node_api::Node as LdkNode; use tempfile::{tempdir, TempDir}; -pub async fn setup_test_infrastructure() -> (BitcoinD, TempDir) { - setup_bitcoind().await +pub async fn setup_test_infrastructure(test_name: &str) -> (BitcoinD, TempDir, LdkNode, LdkNode) { + let (bitcoind, bitcoind_dir) = setup_bitcoind().await; + let connect_params = bitcoind.params.get_cookie_values().unwrap(); + let ldk1_config = LdkUserInfo { + bitcoind_rpc_username: connect_params.0.clone().unwrap(), + bitcoind_rpc_password: connect_params.1.clone().unwrap(), + bitcoind_rpc_host: String::from("localhost"), + bitcoind_rpc_port: bitcoind.params.rpc_socket.port(), + ldk_announced_listen_addr: Vec::new(), + ldk_peer_listening_port: get_available_port().unwrap(), + ldk_announced_node_name: [0; 32], + network: Network::Regtest, + }; + + let ldk2_config = LdkUserInfo { + bitcoind_rpc_username: connect_params.0.unwrap(), + bitcoind_rpc_password: connect_params.1.unwrap(), + bitcoind_rpc_host: String::from("localhost"), + bitcoind_rpc_port: bitcoind.params.rpc_socket.port(), + ldk_announced_listen_addr: Vec::new(), + ldk_peer_listening_port: get_available_port().unwrap(), + ldk_announced_node_name: [0; 32], + network: Network::Regtest, + }; + + let ldk1 = ldk_node::start_ldk(ldk1_config, test_name).await; + let ldk2 = ldk_node::start_ldk(ldk2_config, test_name).await; + + (bitcoind, bitcoind_dir, ldk1, ldk2) } pub async fn setup_bitcoind() -> (BitcoinD, TempDir) { @@ -28,7 +58,7 @@ pub async fn setup_bitcoind() -> (BitcoinD, TempDir) { .client .get_new_address(None, Some(json::AddressType::Bech32)) .unwrap(); - let address = address.require_network(Network::Regtest).unwrap(); + let address = address.require_network(BitcoindNetwork::Regtest).unwrap(); bitcoind.client.generate_to_address(101, &address).unwrap(); (bitcoind, bitcoind_dir) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index b3fce12c..f65ad7f4 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,6 +1,13 @@ mod common; -#[tokio::test] -async fn test_ldk_onion_messages() { - let (_bitcoind, _bitcoin_dir) = common::setup_test_infrastructure().await; +#[tokio::test(flavor = "multi_thread")] +async fn test_ldk_send_onion_message() { + let test_name = "send_onion_message"; + let (_bitcoind, _bitcoin_dir, ldk1, ldk2) = common::setup_test_infrastructure(test_name).await; + let (node_id_2, node_addr_2) = ldk2.get_node_info(); + ldk1.connect_to_peer(node_id_2, node_addr_2).await.unwrap(); + + let data: Vec = vec![72, 101, 108, 108, 111]; + let res = ldk1.send_onion_message(vec![node_id_2], 65, data).await; + assert!(res.is_ok()); }