@@ -1772,6 +1772,20 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1772
1772
let idx_and_scripts = txouts. iter ( ) . map ( |o| ( o. 0 , o. 1 . script_pubkey . clone ( ) ) ) . collect ( ) ;
1773
1773
self . outputs_to_watch . insert ( txid. clone ( ) , idx_and_scripts) . is_none ( )
1774
1774
} ) ;
1775
+ #[ cfg( test) ]
1776
+ {
1777
+ // If we see a transaction for which we registered outputs previously,
1778
+ // make sure the registered scriptpubkey at the expected index match
1779
+ // the actual transaction output one. We failed this case before #653.
1780
+ for tx in & txn_matched {
1781
+ if let Some ( outputs) = self . get_outputs_to_watch ( ) . get ( & tx. txid ( ) ) {
1782
+ for idx_and_script in outputs. iter ( ) {
1783
+ assert ! ( ( idx_and_script. 0 as usize ) < tx. output. len( ) ) ;
1784
+ assert_eq ! ( tx. output[ idx_and_script. 0 as usize ] . script_pubkey, idx_and_script. 1 ) ;
1785
+ }
1786
+ }
1787
+ }
1788
+ }
1775
1789
watch_outputs
1776
1790
}
1777
1791
@@ -1821,6 +1835,21 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1821
1835
if let Some ( outputs) = self . get_outputs_to_watch ( ) . get ( & input. previous_output . txid ) {
1822
1836
for ( idx, _script_pubkey) in outputs. iter ( ) {
1823
1837
if * idx == input. previous_output . vout {
1838
+ #[ cfg( test) ]
1839
+ {
1840
+ // If the witness is empty this transaction is a dummy one expressely
1841
+ // passed to test parsing code robustness. Return true to test downstream
1842
+ // monitoring code.
1843
+ if input. witness . last ( ) . is_none ( ) { return true ; }
1844
+ // If the expected script is a known type, check that the witness
1845
+ // appears to be spending the correct type (ie that the match would
1846
+ // actually succeed in BIP 158/159-style filters).
1847
+ if _script_pubkey. is_v0_p2wsh ( ) {
1848
+ assert_eq ! ( & bitcoin:: Address :: p2wsh( & Script :: from( input. witness. last( ) . unwrap( ) . clone( ) ) , bitcoin:: Network :: Bitcoin ) . script_pubkey( ) , _script_pubkey) ;
1849
+ } else if _script_pubkey. is_v0_p2wpkh ( ) {
1850
+ assert_eq ! ( & bitcoin:: Address :: p2wpkh( & bitcoin:: PublicKey :: from_slice( & input. witness. last( ) . unwrap( ) ) . unwrap( ) , bitcoin:: Network :: Bitcoin ) . unwrap( ) . script_pubkey( ) , _script_pubkey) ;
1851
+ } else { panic ! ( ) ; }
1852
+ }
1824
1853
return true ;
1825
1854
}
1826
1855
}
0 commit comments