Skip to content

Commit

Permalink
Remove electrsd block_header_subscribe, and electrsd trigger, simplif…
Browse files Browse the repository at this point in the history
…y wait_for_block
  • Loading branch information
notmandatory committed Jun 4, 2022
1 parent b273c9c commit b2c7b35
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/testutils/blockchain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl TestClient {
fn wait_for_tx(&mut self, txid: Txid, monitor_script: &Script) {
// wait for electrs to index the tx
exponential_backoff_poll(|| {
self.electrsd.trigger().unwrap();
trace!("wait_for_tx {}", txid);

self.electrsd
Expand All @@ -63,18 +62,11 @@ impl TestClient {
}

fn wait_for_block(&mut self, min_height: usize) {
self.electrsd.client.block_headers_subscribe().unwrap();

loop {
let header = exponential_backoff_poll(|| {
self.electrsd.trigger().unwrap();
self.electrsd.client.ping().unwrap();
self.electrsd.client.block_headers_pop().unwrap()
});
if header.height >= min_height {
break;
}
}
exponential_backoff_poll(|| {
let found_header = self.electrsd.client.block_header(min_height).ok();
debug!("waiting for block header min_height {}", min_height);
found_header
});
}

pub fn receive(&mut self, meta_tx: TestIncomingTx) -> Txid {
Expand Down Expand Up @@ -242,8 +234,6 @@ impl TestClient {
let block_hex: String = serialize(&block).to_hex();
debug!("generated block hex: {}", block_hex);

self.electrsd.client.block_headers_subscribe().unwrap();

let submit_result: serde_json::Value =
self.call("submitblock", &[block_hex.into()]).unwrap();
debug!("submitblock: {:?}", submit_result);
Expand All @@ -270,8 +260,6 @@ impl TestClient {
}

pub fn invalidate(&mut self, num_blocks: u64) {
self.electrsd.client.block_headers_subscribe().unwrap();

let best_hash = self.get_best_block_hash().unwrap();
let initial_height = self.get_block_info(&best_hash).unwrap().height;

Expand Down Expand Up @@ -566,7 +554,7 @@ macro_rules! bdk_blockchain_tests {

// FIXME: I would like this to be cfg_attr(not(feature = "test-esplora"), ignore) but it
// doesn't work for some reason.
#[cfg(not(feature = "esplora"))]
#[cfg(not(any(feature = "esplora", feature = "electrum")))]
#[test]
fn test_sync_reorg_block() {
let (wallet, blockchain, descriptors, mut test_client) = init_single_sig();
Expand All @@ -589,10 +577,11 @@ macro_rules! bdk_blockchain_tests {
test_client.invalidate(1);

wallet.sync(&blockchain, SyncOptions::default()).unwrap();

debug!("after wallet.sync");
assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance after invalidate");

let list_tx_item = &wallet.list_transactions(false).unwrap()[0];
debug!("after wallet.list_transactions");
assert_eq!(list_tx_item.txid, txid, "incorrect txid after invalidate");
assert_eq!(list_tx_item.confirmation_time, None, "incorrect confirmation time after invalidate");
}
Expand Down

0 comments on commit b2c7b35

Please sign in to comment.