') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Introduce multi-hop payment test by tnull · Pull Request #157 · lightningdevkit/ldk-node · GitHub
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 82 additions & 17 deletions src/test/functional_tests.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use crate::builder::NodeBuilder;
use crate::io::test_utils::TestSyncStore;
use crate::test::utils::*;
use crate::test::utils::{expect_event, random_config, setup_two_nodes};
use crate::test::utils::{expect_channel_pending_event, expect_event, open_channel, random_config};
use crate::{Error, Event, Node, PaymentDirection, PaymentStatus};

use bitcoin::Amount;
Expand DownExpand Up@@ -86,24 +86,13 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
.unwrap();

assert_eq!(node_a.list_peers().first().unwrap().node_id, node_b.node_id());
expect_event!(node_a, ChannelPending);
let funding_txo_a = expect_channel_pending_event!(node_a, node_b.node_id());
let funding_txo_b = expect_channel_pending_event!(node_b, node_a.node_id());
assert_eq!(funding_txo_a, funding_txo_b);

let funding_txo = match node_b.wait_next_event() {
ref e @ Event::ChannelPending { funding_txo, .. } => {
println!("{} got event {:?}", std::stringify!(node_b), e);
assert_eq!(node_b.next_event().as_ref(), Some(e));
node_b.event_handled();
funding_txo
}
ref e => {
panic!("{} got unexpected event!: {:?}", std::stringify!(node_b), e);
}
};

wait_for_tx(&electrsd, funding_txo.txid);
wait_for_tx(&electrsd, funding_txo_a.txid);

if !allow_0conf {
println!("\n .. generating blocks ..");
generate_blocks_and_wait(&bitcoind, &electrsd, 6);
}

Expand DownExpand Up@@ -276,7 +265,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
expect_event!(node_a, ChannelClosed);
expect_event!(node_b, ChannelClosed);

wait_for_outpoint_spend(&electrsd, funding_txo);
wait_for_outpoint_spend(&electrsd, funding_txo_b);

generate_blocks_and_wait(&bitcoind, &electrsd, 1);
node_a.sync_wallets().unwrap();
Expand DownExpand Up@@ -341,6 +330,82 @@ fn channel_open_fails_when_funds_insufficient() {
);
}

#[test]
fn multi_hop_sending() {
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());

// Setup and fund 5 nodes
let mut nodes = Vec::new();
for _ in 0..5 {
let config = random_config();
let mut builder = NodeBuilder::from_config(config);
builder.set_esplora_server(esplora_url.clone());
let node = builder.build().unwrap();
node.start().unwrap();
nodes.push(node);
}

let addresses = nodes.iter().map(|n| n.new_onchain_address().unwrap()).collect();
let premine_amount_sat = 5_000_000;
premine_and_distribute_funds(
&bitcoind,
&electrsd,
addresses,
Amount::from_sat(premine_amount_sat),
);

for n in &nodes {
n.sync_wallets().unwrap();
assert_eq!(n.spendable_onchain_balance_sats().unwrap(), premine_amount_sat);
assert_eq!(n.next_event(), None);
}

// Setup channel topology:
// (1M:0)- N2 -(1M:0)
// / \
// N0 -(100k:0)-> N1 N4
// \ /
// (1M:0)- N3 -(1M:0)

open_channel(&nodes[0], &nodes[1], 100_000, true, &electrsd);
open_channel(&nodes[1], &nodes[2], 1_000_000, true, &electrsd);
// We need to sync wallets in-between back-to-back channel opens from the same node so BDK
// wallet picks up on the broadcast funding tx and doesn't double-spend itself.
//
// TODO: Remove once fixed in BDK.
nodes[1].sync_wallets().unwrap();
open_channel(&nodes[1], &nodes[3], 1_000_000, true, &electrsd);
open_channel(&nodes[2], &nodes[4], 1_000_000, true, &electrsd);
open_channel(&nodes[3], &nodes[4], 1_000_000, true, &electrsd);

generate_blocks_and_wait(&bitcoind, &electrsd, 6);

for n in &nodes {
n.sync_wallets().unwrap();
}

expect_event!(nodes[0], ChannelReady);
expect_event!(nodes[1], ChannelReady);
expect_event!(nodes[1], ChannelReady);
expect_event!(nodes[1], ChannelReady);
expect_event!(nodes[2], ChannelReady);
expect_event!(nodes[2], ChannelReady);
expect_event!(nodes[3], ChannelReady);
expect_event!(nodes[3], ChannelReady);
expect_event!(nodes[4], ChannelReady);
expect_event!(nodes[4], ChannelReady);

// Sleep a bit for gossip to propagate.
std::thread::sleep(std::time::Duration::from_secs(1));

let invoice = nodes[4].receive_payment(2_500_000, &"asdf", 9217).unwrap();
nodes[0].send_payment(&invoice).unwrap();

expect_event!(nodes[4], PaymentReceived);
expect_event!(nodes[0], PaymentSuccessful);
}

#[test]
fn connect_to_public_testnet_esplora() {
let mut config = random_config();
Expand Down