Skip to content

Commit b53f6e6

Browse files
committed
Add a simple test of upgrading from LDK 0.1
One major hole in our test coverage historically has been tests covering upgrades or downgrades across LDK versions. Luckily, these aren't particularly hard to write as cargo lets us depend on previous versions of the `lightning` crate directly, which we can use in tests. Here we add a simple initial test of upgrading from LDK 0.1 while there's a pending payment to be claimed.
1 parent 3b08fea commit b53f6e6

File tree

7 files changed

+101
-3
lines changed

7 files changed

+101
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ members = [
2121

2222
exclude = [
2323
"lightning-transaction-sync",
24+
"lightning-tests",
2425
"ext-functional-test-demo",
2526
"no-std-check",
2627
"msrv-no-dev-deps-check",

ci/ci-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ for DIR in "${WORKSPACE_MEMBERS[@]}"; do
5757
cargo doc -p "$DIR" --document-private-items
5858
done
5959

60+
echo -e "\n\nTesting upgrade from prior versions of LDK"
61+
pushd lightning-tests
62+
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
63+
cargo test
64+
popd
65+
6066
echo -e "\n\nChecking and testing Block Sync Clients with features"
6167

6268
cargo test -p lightning-block-sync --verbose --color always --features rest-client

lightning-tests/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "lightning-tests"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
license = "MIT OR Apache-2.0"
6+
repository = "https://github.com/lightningdevkit/rust-lightning/"
7+
description = "Tests for LDK crates"
8+
edition = "2021"
9+
10+
[features]
11+
12+
[dependencies]
13+
lightning-types = { version = "0.3.0", path = "../lightning-types", features = ["_test_utils"] }
14+
lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false }
15+
lightning-macros = { version = "0.2", path = "../lightning-macros" }
16+
lightning = { version = "0.2", path = "../lightning", features = ["_test_utils"] }
17+
lightning_0_1 = { package = "lightning", version = "0.1.1", features = ["_test_utils"] }
18+
19+
bitcoin = { version = "0.32.2", default-features = false }
20+
21+
[dev-dependencies]

lightning-tests/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[cfg_attr(test, macro_use)]
2+
extern crate lightning;
3+
4+
#[cfg(all(test, not(taproot)))]
5+
pub mod upgrade_downgrade_tests;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Tests which test upgrading from previous versions of LDK or downgrading to previous versions of
11+
//! LDK.
12+
13+
use lightning_0_1::ln::functional_test_utils as lightning_0_1_utils;
14+
use lightning_0_1::get_monitor as get_monitor_0_1;
15+
use lightning_0_1::util::ser::Writeable;
16+
17+
use lightning::ln::functional_test_utils::*;
18+
19+
use lightning_types::payment::PaymentPreimage;
20+
21+
#[test]
22+
fn simple_upgrade() {
23+
// Tests a simple case of upgrading from LDK 0.1 with a pending payment
24+
let (node_a_ser, node_b_ser, mon_a_ser, mon_b_ser, preimage);
25+
{
26+
let chanmon_cfgs = lightning_0_1_utils::create_chanmon_cfgs(2);
27+
let node_cfgs = lightning_0_1_utils::create_node_cfgs(2, &chanmon_cfgs);
28+
let node_chanmgrs = lightning_0_1_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None]);
29+
let nodes = lightning_0_1_utils::create_network(2, &node_cfgs, &node_chanmgrs);
30+
31+
let chan_id = lightning_0_1_utils::create_announced_chan_between_nodes(&nodes, 0, 1).2;
32+
33+
let payment_preimage =
34+
lightning_0_1_utils::route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
35+
preimage = PaymentPreimage(payment_preimage.0 .0);
36+
37+
node_a_ser = nodes[0].node.encode();
38+
node_b_ser = nodes[1].node.encode();
39+
mon_a_ser = get_monitor_0_1!(nodes[0], chan_id).encode();
40+
mon_b_ser = get_monitor_0_1!(nodes[1], chan_id).encode();
41+
}
42+
43+
// Create a dummy node to reload over with the 0.1 state
44+
45+
let mut chanmon_cfgs = create_chanmon_cfgs(2);
46+
47+
// Our TestChannelSigner will fail as we're jumping ahead, so disable its state-based checks
48+
chanmon_cfgs[0].keys_manager.disable_all_state_policy_checks = true;
49+
chanmon_cfgs[1].keys_manager.disable_all_state_policy_checks = true;
50+
51+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
52+
let (persister_a, persister_b, chain_mon_a, chain_mon_b);
53+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
54+
let (node_a, node_b);
55+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
56+
57+
let config = test_default_channel_config();
58+
let a_mons = &[&mon_a_ser[..]];
59+
reload_node!(nodes[0], config.clone(), &node_a_ser, a_mons, persister_a, chain_mon_a, node_a);
60+
reload_node!(nodes[1], config, &node_b_ser, &[&mon_b_ser], persister_b, chain_mon_b, node_b);
61+
62+
reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
63+
64+
claim_payment(&nodes[0], &[&nodes[1]], preimage);
65+
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ pub fn _reload_node<'a, 'b, 'c>(node: &'a Node<'a, 'b, 'c>, default_config: User
11971197
node_deserialized
11981198
}
11991199

1200-
#[cfg(any(test, feature = "_externalize_tests"))]
1200+
#[macro_export]
12011201
macro_rules! reload_node {
12021202
($node: expr, $new_config: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => {
12031203
let chanman_encoded = $chanman_encoded;

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ where
13131313
}
13141314
}
13151315

1316-
#[cfg(any(test, feature = "_externalize_tests"))]
1317-
pub(crate) fn set_offers_handler(&mut self, offers_handler: OMH) {
1316+
#[cfg(any(test, feature = "_test_utils"))]
1317+
pub fn set_offers_handler(&mut self, offers_handler: OMH) {
13181318
self.offers_handler = offers_handler;
13191319
}
13201320

0 commit comments

Comments
 (0)