@@ -119,6 +119,59 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
119119 ( wallet, tx1. compute_txid ( ) )
120120}
121121
122+ /// Return a fake wallet that has only reused outputs for testing.
123+ ///
124+ /// The wallet contains two transactions with one output each, both paying to the same common
125+ /// script. The common script is derived from the first unused external address.
126+ pub fn get_wallet_with_only_reused_outputs (
127+ descriptor : & str ,
128+ change_descriptor : Option < & str > ,
129+ ) -> ( Wallet , ( Txid , Txid ) ) {
130+ // Create an empty wallet.
131+ let params = if let Some ( change_desc) = change_descriptor {
132+ Wallet :: create ( descriptor. to_string ( ) , change_desc. to_string ( ) )
133+ } else {
134+ Wallet :: create_single ( descriptor. to_string ( ) )
135+ } ;
136+
137+ let mut wallet = params
138+ . network ( Network :: Regtest )
139+ . create_wallet_no_persist ( )
140+ . expect ( "descriptors must be valid" ) ;
141+
142+ // Derive a common external address to be reused.
143+ let common_addr = wallet. next_unused_address ( KeychainKind :: External ) . address ;
144+ let common_script = common_addr. script_pubkey ( ) ;
145+
146+ // Fabricate transaction 1 with one output paying to the common script.
147+ let tx1 = Transaction {
148+ version : transaction:: Version :: ONE ,
149+ lock_time : absolute:: LockTime :: ZERO ,
150+ input : vec ! [ ] , // No inputs since it's fabricated.
151+ output : vec ! [ TxOut {
152+ value: Amount :: from_sat( 500_000 ) ,
153+ script_pubkey: common_script. clone( ) ,
154+ } ] ,
155+ } ;
156+
157+ // Fabricate transaction 2 with one output paying to the common script.
158+ let tx2 = Transaction {
159+ version : transaction:: Version :: ONE ,
160+ lock_time : absolute:: LockTime :: ZERO ,
161+ input : vec ! [ ] ,
162+ output : vec ! [ TxOut {
163+ value: Amount :: from_sat( 100_000 ) ,
164+ script_pubkey: common_script,
165+ } ] ,
166+ } ;
167+
168+ // Insert these fabricated transactions into the wallet.
169+ insert_tx ( & mut wallet, tx1. clone ( ) ) ;
170+ insert_tx ( & mut wallet, tx2. clone ( ) ) ;
171+
172+ ( wallet, ( tx1. compute_txid ( ) , tx2. compute_txid ( ) ) )
173+ }
174+
122175/// Return a fake wallet that appears to be funded for testing.
123176///
124177/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
0 commit comments