Skip to content

Commit 3c44d6b

Browse files
authored
Merge pull request #248 from TheBlueMatt/2018-11-monitor-test-split
Split up channel_monitor_network_test a little bit
2 parents 2be7c5d + 44f56f8 commit 3c44d6b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/ln/channelmanager.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,7 +5708,13 @@ mod tests {
57085708
get_announce_close_broadcast_events(&nodes, 3, 4);
57095709
assert_eq!(nodes[3].node.list_channels().len(), 0);
57105710
assert_eq!(nodes[4].node.list_channels().len(), 0);
5711+
}
5712+
5713+
#[test]
5714+
fn test_justice_tx() {
5715+
// Test justice txn built on revoked HTLC-Success tx, against both sides
57115716

5717+
let nodes = create_network(2);
57125718
// Create some new channels:
57135719
let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1);
57145720

@@ -5747,6 +5753,45 @@ mod tests {
57475753
test_revoked_htlc_claim_txn_broadcast(&nodes[1], node_txn[1].clone());
57485754
}
57495755
get_announce_close_broadcast_events(&nodes, 0, 1);
5756+
5757+
assert_eq!(nodes[0].node.list_channels().len(), 0);
5758+
assert_eq!(nodes[1].node.list_channels().len(), 0);
5759+
5760+
// We test justice_tx build by A on B's revoked HTLC-Success tx
5761+
// Create some new channels:
5762+
let chan_6 = create_announced_chan_between_nodes(&nodes, 0, 1);
5763+
5764+
// A pending HTLC which will be revoked:
5765+
let payment_preimage_4 = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
5766+
// Get the will-be-revoked local txn from B
5767+
let revoked_local_txn = nodes[1].node.channel_state.lock().unwrap().by_id.iter().next().unwrap().1.last_local_commitment_txn.clone();
5768+
assert_eq!(revoked_local_txn.len(), 1); // Only commitment tx
5769+
assert_eq!(revoked_local_txn[0].input.len(), 1);
5770+
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_6.3.txid());
5771+
assert_eq!(revoked_local_txn[0].output.len(), 2); // Only HTLC and output back to A are present
5772+
// Revoke the old state
5773+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_4);
5774+
{
5775+
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
5776+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
5777+
{
5778+
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
5779+
assert_eq!(node_txn.len(), 3);
5780+
assert_eq!(node_txn.pop().unwrap(), node_txn[0]); // An outpoint registration will result in a 2nd block_connected
5781+
assert_eq!(node_txn[0].input.len(), 1); // We claim the received HTLC output
5782+
5783+
check_spends!(node_txn[0], revoked_local_txn[0].clone());
5784+
node_txn.swap_remove(0);
5785+
}
5786+
test_txn_broadcast(&nodes[0], &chan_6, None, HTLCType::NONE);
5787+
5788+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
5789+
let node_txn = test_txn_broadcast(&nodes[1], &chan_6, Some(revoked_local_txn[0].clone()), HTLCType::SUCCESS);
5790+
header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
5791+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![node_txn[1].clone()] }, 1);
5792+
test_revoked_htlc_claim_txn_broadcast(&nodes[0], node_txn[1].clone());
5793+
}
5794+
get_announce_close_broadcast_events(&nodes, 0, 1);
57505795
assert_eq!(nodes[0].node.list_channels().len(), 0);
57515796
assert_eq!(nodes[1].node.list_channels().len(), 0);
57525797
}

0 commit comments

Comments
 (0)