]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add test_static_spendable_outputs_justice_tx_revoked_commitment_tx
authorAntoine Riard <ariard@student.42.fr>
Mon, 5 Nov 2018 02:17:33 +0000 (02:17 +0000)
committerAntoine Riard <ariard@student.42.fr>
Tue, 20 Nov 2018 01:42:55 +0000 (20:42 -0500)
src/ln/channelmanager.rs

index 916399023cdeeaf99e2a69557720979a453b84a0..2fe0ec3837c72107ac26cf6128e53587318945b6 100644 (file)
@@ -7781,4 +7781,36 @@ mod tests {
                let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
                check_spends!(spend_tx, node_txn[0].clone());
        }
+
+       #[test]
+       fn test_static_spendable_outputs_justice_tx_revoked_commitment_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
+               let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.iter().next().unwrap().1.last_local_commitment_txn.clone();
+               assert_eq!(revoked_local_txn[0].input.len(), 1);
+               assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
+
+               claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
+
+               let  header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 3);
+               assert_eq!(node_txn.pop().unwrap(), node_txn[0]);
+               assert_eq!(node_txn[0].input.len(), 2);
+               check_spends!(node_txn[0], revoked_local_txn[0].clone());
+
+               let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
+               check_spends!(spend_tx, node_txn[0].clone());
+       }
 }