| 
 | 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::get_monitor as get_monitor_0_1;  | 
 | 14 | +use lightning_0_1::ln::functional_test_utils as lightning_0_1_utils;  | 
 | 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 | +}  | 
0 commit comments