|
1 | | -use std::{thread::sleep, time::Duration}; |
| 1 | +use std::{str::FromStr, thread::sleep, time::Duration}; |
2 | 2 |
|
3 | 3 | use anyhow::Result; |
4 | 4 | use bdk::{ |
5 | | - bitcoin::{psbt::serialize::Serialize, PrivateKey}, |
| 5 | + bitcoin::{psbt::serialize::Serialize, Address, PrivateKey}, |
| 6 | + bitcoincore_rpc::RpcApi, |
6 | 7 | blockchain::{ |
7 | 8 | ConfigurableBlockchain, ElectrumBlockchain, ElectrumBlockchainConfig, |
8 | 9 | }, |
9 | 10 | database::MemoryDatabase, |
10 | 11 | template::P2Wpkh, |
11 | 12 | SyncOptions, Wallet, |
12 | 13 | }; |
13 | | -use reqwest::blocking::Client; |
14 | 14 | use sbtc_cli::commands::{ |
15 | 15 | broadcast::{broadcast_tx, BroadcastArgs}, |
16 | 16 | deposit::{build_deposit_tx, DepositArgs}, |
17 | 17 | }; |
18 | 18 |
|
19 | 19 | use super::{ |
20 | | - bitcoin_client::{electrs_url, generate_blocks}, |
| 20 | + bitcoin_client::{ |
| 21 | + bitcoin_url, client_new, electrs_url, mine_blocks, |
| 22 | + wait_for_tx_confirmation, |
| 23 | + }, |
21 | 24 | KeyType::*, |
22 | 25 | WALLETS, |
23 | 26 | }; |
24 | 27 |
|
25 | 28 | #[test] |
26 | 29 | fn broadcast_deposit() -> Result<()> { |
27 | | - let client = Client::new(); |
| 30 | + let b_client = client_new(bitcoin_url().as_str(), "devnet", "devnet"); |
| 31 | + |
| 32 | + b_client |
| 33 | + .import_address( |
| 34 | + &Address::from_str(WALLETS[1][P2wpkh].address).unwrap(), |
| 35 | + None, |
| 36 | + Some(false), |
| 37 | + ) |
| 38 | + .unwrap(); |
| 39 | + |
28 | 40 | { |
29 | | - generate_blocks(1, &client, WALLETS[0][P2wpkh].address); |
30 | | - generate_blocks(1, &client, WALLETS[1][P2wpkh].address); |
| 41 | + mine_blocks(&b_client, 1, WALLETS[0][P2wpkh].address); |
| 42 | + mine_blocks(&b_client, 1, WALLETS[1][P2wpkh].address); |
31 | 43 | // pads blocks to get rewards. |
32 | | - generate_blocks(100, &client, WALLETS[0][P2wpkh].address); |
| 44 | + mine_blocks(&b_client, 100, WALLETS[0][P2wpkh].address); |
33 | 45 | }; |
34 | 46 |
|
35 | 47 | let electrum_url = electrs_url(); |
36 | 48 |
|
37 | 49 | // suboptimal, replace once we have better events. |
| 50 | + // replace with b_client balance? |
38 | 51 | { |
39 | 52 | let blockchain = |
40 | 53 | ElectrumBlockchain::from_config(&ElectrumBlockchainConfig { |
@@ -88,5 +101,9 @@ fn broadcast_deposit() -> Result<()> { |
88 | 101 | }) |
89 | 102 | .unwrap(); |
90 | 103 |
|
| 104 | + let txid = tx.txid(); |
| 105 | + |
| 106 | + wait_for_tx_confirmation(&b_client, &txid, 1); |
| 107 | + |
91 | 108 | Ok(()) |
92 | 109 | } |
0 commit comments