Skip to content

Commit 708a5cc

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 5ad0440 commit 708a5cc

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

ci/ci-tests.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cargo check --verbose --color always
3232
# When the workspace members change, make sure to update the list here as well
3333
# as in `Cargo.toml`.
3434
WORKSPACE_MEMBERS=(
35-
lightning
35+
lightning@0.2.0+git
3636
lightning-types
3737
lightning-block-sync
3838
lightning-invoice
@@ -74,14 +74,14 @@ cargo test -p lightning-custom-message --verbose --color always
7474
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
7575

7676
echo -e "\n\nTest backtrace-debug builds"
77-
cargo test -p lightning --verbose --color always --features backtrace
77+
cargo test -p lightning@0.2.0+git --verbose --color always --features backtrace
7878

7979
echo -e "\n\nTesting no_std builds"
8080
for DIR in lightning-invoice lightning-rapid-gossip-sync lightning-liquidity; do
8181
cargo test -p $DIR --verbose --color always --no-default-features
8282
done
8383

84-
cargo test -p lightning --verbose --color always --no-default-features
84+
cargo test -p lightning@0.2.0+git --verbose --color always --no-default-features
8585

8686
echo -e "\n\nTesting c_bindings builds"
8787
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
@@ -96,11 +96,11 @@ done
9696
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
9797
# disable doctests in `c_bindings` so we skip doctests entirely here.
9898
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
99-
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --lib --bins --tests
99+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning@0.2.0+git --verbose --color always --no-default-features --lib --bins --tests
100100

101101
echo -e "\n\nTesting other crate-specific builds"
102102
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
103-
RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose --color always --no-default-features --features=std
103+
RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning@0.2.0+git --verbose --color always --no-default-features --features=std
104104
# This one only works for lightning-invoice
105105
# check that compile with no_std and serde works in lightning-invoice
106106
cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde
@@ -127,8 +127,8 @@ if [ -f "$(which arm-none-eabi-gcc)" ]; then
127127
fi
128128

129129
echo -e "\n\nTest cfg-flag builds"
130-
RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
130+
RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning@0.2.0+git
131131
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
132-
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
132+
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning@0.2.0+git
133133
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
134-
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
134+
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning@0.2.0+git

lightning/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ libm = { version = "0.2", default-features = false }
5151
[dev-dependencies]
5252
regex = "1.5.6"
5353
lightning-types = { version = "0.3.0", path = "../lightning-types", features = ["_test_utils"] }
54+
lightning_0_1 = { package = "lightning", version = "0.1.1", features = ["_test_utils"] }
5455

5556
[dev-dependencies.bitcoin]
5657
version = "0.32.2"

lightning/src/ln/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,8 @@ mod offers_tests;
9797
#[cfg(test)]
9898
#[allow(unused_mut)]
9999
mod dual_funding_tests;
100+
#[cfg(test)]
101+
#[allow(unused_mut)]
102+
mod upgrade_downgrade_tests;
100103

101104
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 crate::ln::functional_test_utils::*;
18+
use crate::types::payment::PaymentPreimage;
19+
20+
#[test]
21+
fn simple_upgrade() {
22+
// Tests a simple case of upgrading from LDK 0.1 with a pending payment
23+
let (node_a, node_b, mon_a, mon_b, preimage);
24+
{
25+
let chanmon_cfgs = lightning_0_1_utils::create_chanmon_cfgs(2);
26+
let node_cfgs = lightning_0_1_utils::create_node_cfgs(2, &chanmon_cfgs);
27+
let node_chanmgrs = lightning_0_1_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None]);
28+
let nodes = lightning_0_1_utils::create_network(2, &node_cfgs, &node_chanmgrs);
29+
30+
let chan_id = lightning_0_1_utils::create_announced_chan_between_nodes(&nodes, 0, 1).2;
31+
32+
let payment_preimage = lightning_0_1_utils::route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
33+
preimage = PaymentPreimage(payment_preimage.0.0);
34+
35+
node_a = nodes[0].node.encode();
36+
node_b = nodes[1].node.encode();
37+
mon_a = get_monitor_0_1!(nodes[0], chan_id).encode();
38+
mon_b = get_monitor_0_1!(nodes[1], chan_id).encode();
39+
}
40+
41+
// Create a dummy node to reload over with the 0.1 state
42+
43+
let mut chanmon_cfgs = create_chanmon_cfgs(2);
44+
45+
// Our TestChannelSigner will fail as we're jumping ahead, so disable its state-based checks
46+
chanmon_cfgs[0].keys_manager.disable_all_state_policy_checks = true;
47+
chanmon_cfgs[1].keys_manager.disable_all_state_policy_checks = true;
48+
49+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
50+
let (persister_a, persister_b, chain_monitor_a, chain_monitor_b);
51+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
52+
let (node_deser_a, node_deser_b);
53+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
54+
55+
reload_node!(nodes[0], test_default_channel_config(), &node_a, &[&mon_a], persister_a, chain_monitor_a, node_deser_a);
56+
reload_node!(nodes[1], test_default_channel_config(), &node_b, &[&mon_b], persister_b, chain_monitor_b, node_deser_b);
57+
58+
reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
59+
60+
claim_payment(&nodes[0], &[&nodes[1]], preimage);
61+
}

0 commit comments

Comments
 (0)