From aa6a41221652bd375dc68402a61c5330ea3a3712 Mon Sep 17 00:00:00 2001 From: Dario Anongba Varela Date: Fri, 13 Dec 2024 10:42:41 +0100 Subject: [PATCH] improve test Co-authored-by: River Kanies --- tests/esplora.rs | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/tests/esplora.rs b/tests/esplora.rs index 74667b2..5baf6b1 100644 --- a/tests/esplora.rs +++ b/tests/esplora.rs @@ -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() { @@ -33,23 +31,13 @@ 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(); @@ -57,11 +45,18 @@ async fn test_esplora_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); }