@@ -191,42 +191,34 @@ mod tests {
191
191
use crate :: test_common;
192
192
use bitcoin:: { hashes:: Hash , Amount , Network , OutPoint , ScriptBuf , TxIn , TxOut , Txid , Witness } ;
193
193
194
- /// Tests `send_raw_transaction` and `get_raw_transaction`.
194
+ /// Tests raw transaction operations, using `send_raw_transaction` and
195
+ /// `get_raw_transaction`.
195
196
#[ test]
196
197
#[ ignore = "raw_transaction not working" ]
197
198
fn raw_transaction ( ) {
198
199
let rpc = Client :: new ( "" , bitcoincore_rpc:: Auth :: None ) . unwrap ( ) ;
199
200
200
- // Get some BTC.
201
- let address = rpc. get_new_address ( None , None ) . unwrap ( ) ;
202
- rpc. generate_to_address ( 101 , address. assume_checked_ref ( ) )
203
- . unwrap ( ) ;
204
- let prev_tx = rpc. ledger . _get_transactions ( ) . get ( 0 ) . unwrap ( ) . to_owned ( ) ;
201
+ // Create and address for the user.
202
+ let address = rpc. ledger . generate_address ( ) . address ;
205
203
206
- // Insert raw transactions to Bitcoin.
207
- let txin = TxIn {
208
- previous_output : OutPoint {
209
- txid : prev_tx. compute_txid ( ) ,
210
- vout : 0 ,
211
- } ,
212
- ..Default :: default ( )
204
+ // Get some funds.
205
+ let txout = TxOut {
206
+ value : Amount :: from_sat ( 100_000_000 ) ,
207
+ script_pubkey : address. script_pubkey ( ) ,
213
208
} ;
209
+ let tx = test_common:: create_transaction ( vec ! [ ] , vec ! [ txout] ) ;
210
+ let txid = rpc. ledger . add_transaction_unconditionally ( tx) . unwrap ( ) ;
211
+
212
+ // Create a new raw transactions that is valid.
213
+ let txin = test_common:: create_txin ( txid) ;
214
214
let txout = TxOut {
215
215
value : Amount :: from_sat ( 0x1F ) ,
216
- script_pubkey : address. assume_checked ( ) . script_pubkey ( ) ,
216
+ script_pubkey : address. script_pubkey ( ) ,
217
217
} ;
218
218
let inserted_tx1 = test_common:: create_transaction ( vec ! [ txin] , vec ! [ txout] ) ;
219
219
rpc. send_raw_transaction ( & inserted_tx1) . unwrap ( ) ;
220
220
221
- let txin = TxIn {
222
- previous_output : OutPoint {
223
- txid : inserted_tx1. compute_txid ( ) ,
224
- vout : 0 ,
225
- } ,
226
- sequence : bitcoin:: transaction:: Sequence :: ENABLE_RBF_NO_LOCKTIME ,
227
- script_sig : ScriptBuf :: default ( ) ,
228
- witness : Witness :: new ( ) ,
229
- } ;
221
+ let txin = test_common:: create_txin ( inserted_tx1. compute_txid ( ) ) ;
230
222
let txout = TxOut {
231
223
value : Amount :: from_sat ( 0x45 ) ,
232
224
script_pubkey : test_common:: get_temp_address ( ) . script_pubkey ( ) ,
0 commit comments