Skip to content

Commit 0d0549c

Browse files
committed
rpc_api: Create new transactions manually in raw_transaction test.
1 parent 99cea81 commit 0d0549c

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/client/rpc_api.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -191,42 +191,34 @@ mod tests {
191191
use crate::test_common;
192192
use bitcoin::{hashes::Hash, Amount, Network, OutPoint, ScriptBuf, TxIn, TxOut, Txid, Witness};
193193

194-
/// Tests `send_raw_transaction` and `get_raw_transaction`.
194+
/// Tests raw transaction operations, using `send_raw_transaction` and
195+
/// `get_raw_transaction`.
195196
#[test]
196197
#[ignore = "raw_transaction not working"]
197198
fn raw_transaction() {
198199
let rpc = Client::new("", bitcoincore_rpc::Auth::None).unwrap();
199200

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;
205203

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(),
213208
};
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);
214214
let txout = TxOut {
215215
value: Amount::from_sat(0x1F),
216-
script_pubkey: address.assume_checked().script_pubkey(),
216+
script_pubkey: address.script_pubkey(),
217217
};
218218
let inserted_tx1 = test_common::create_transaction(vec![txin], vec![txout]);
219219
rpc.send_raw_transaction(&inserted_tx1).unwrap();
220220

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());
230222
let txout = TxOut {
231223
value: Amount::from_sat(0x45),
232224
script_pubkey: test_common::get_temp_address().script_pubkey(),

0 commit comments

Comments
 (0)