Skip to content

Commit

Permalink
tests: test that ldk node can send onion message
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Sep 7, 2023
1 parent 14e43a6 commit b3e4248
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
38 changes: 34 additions & 4 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {

Check failure on line 15 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / LNDK Rust Build

missing field `ldk_storage_dir_path` in initializer of `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 {

Check failure on line 26 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / LNDK Rust Build

missing field `ldk_storage_dir_path` in initializer of `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) {
Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -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<u8> = vec![72, 101, 108, 108, 111];
let res = ldk1.send_onion_message(vec![node_id_2], 65, data).await;
assert!(res.is_ok());
}

0 comments on commit b3e4248

Please sign in to comment.