Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
Co-authored-by: River Kanies <[email protected]>
  • Loading branch information
darioAnongba and riverKanies committed Dec 13, 2024
1 parent d9d7197 commit aa6a412
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions tests/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@

extern crate wasm_bindgen_test;

use bdk_wallet::bip39::Mnemonic;
use bdk_wasm::{
bitcoin::{EsploraClient, Wallet},
set_panic_hook,
types::{AddressType, KeychainKind, Network},
types::{KeychainKind, Network},
};
use js_sys::Date;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

const STOP_GAP: usize = 5;
const PARALLEL_REQUESTS: usize = 1;
const NETWORK: Network = Network::Testnet;
const ADDRESS_TYPE: AddressType = AddressType::P2wpkh;
const MNEMONIC: &str = "journey embrace permit coil indoor stereo welcome maid movie easy clock spider tent slush bright luxury awake waste legal modify awkward answer acid goose";
const NETWORK: Network = Network::Signet;
const EXTERNAL_DESC: &str = "wpkh([aafa6322/84'/1'/0']tpubDCfvzhCuifJtWDVdrBcPvZU7U5uyixL7QULk8hXA7KjqiNnry9Te1nwm7yStqenPCQhy5MwzxKkLBD2GmKNgvMYqXgo53iYqQ7Vu4vQbN2N/0/*)#mlua264t";
const INTERNAL_DESC: &str = "wpkh([aafa6322/84'/1'/0']tpubDCfvzhCuifJtWDVdrBcPvZU7U5uyixL7QULk8hXA7KjqiNnry9Te1nwm7yStqenPCQhy5MwzxKkLBD2GmKNgvMYqXgo53iYqQ7Vu4vQbN2N/1/*)#2teuh09n";

#[wasm_bindgen_test]
async fn test_esplora_client() {
Expand All @@ -33,35 +31,32 @@ async fn test_esplora_client() {
Network::Regtest => "https://localhost:3000",
};

let seed = Mnemonic::parse(MNEMONIC).unwrap().to_seed("");
let mut wallet = Wallet::from_seed(&seed, NETWORK, ADDRESS_TYPE).expect("wallet");
let mut wallet =
Wallet::from_descriptors(NETWORK, EXTERNAL_DESC.to_string(), INTERNAL_DESC.to_string()).expect("wallet");
let mut blockchain_client = EsploraClient::new(esplora_url).expect("esplora_client");

let block_height = wallet.latest_checkpoint().height();
assert_eq!(block_height, 0);

let full_scan_request = wallet.start_full_scan();
let update = blockchain_client
.full_scan(full_scan_request, STOP_GAP, PARALLEL_REQUESTS)
.await
.expect("full_scan");
wallet.apply_update(update).expect("full_scan apply_update_at");

let fullscan_block_height = wallet.latest_checkpoint().height();
assert!(fullscan_block_height > 0);

wallet.reveal_addresses_to(KeychainKind::External, 5);

let sync_request = wallet.start_sync_with_revealed_spks();
let update = blockchain_client
.sync(sync_request, PARALLEL_REQUESTS)
.await
.expect("sync");
wallet
.apply_update_at(update, Some((Date::now() / 1000.0) as u64))
.expect("sync apply_update_at");
wallet.apply_update(update).expect("sync apply_update");

// TODO: Find a better way to assert that the sync was successful
let sync_block_height = wallet.latest_checkpoint().height();
assert!(sync_block_height >= fullscan_block_height);
assert!(sync_block_height > block_height);

let full_scan_request = wallet.start_full_scan();
let update = blockchain_client
.full_scan(full_scan_request, STOP_GAP, PARALLEL_REQUESTS)
.await
.expect("full_scan");
wallet.apply_update(update).expect("full_scan apply_update");

let balance = wallet.balance();
assert!(balance.total().to_sat() > 0);
}

0 comments on commit aa6a412

Please sign in to comment.