Skip to content

Commit 7e5d395

Browse files
rajarshimaitrasaikishore222SanthoshAnguluri
committed
Apply Blockchain test refactor
Add esplora-ureq into the test-esplora feature. Eslora tests won't run without them. Co-authored-by: saikishore222 <saikishore.chsk@gmail.com> Co-authored-by: SanthoshAnguluri <santhoshanguluri15@gmail.com>
1 parent 13e0b06 commit 7e5d395

File tree

3 files changed

+128
-33
lines changed

3 files changed

+128
-33
lines changed

src/blockchain/electrum.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,47 @@ mod test {
328328

329329
use super::*;
330330
use crate::database::MemoryDatabase;
331-
use crate::testutils::blockchain_tests::TestClient;
331+
use crate::make_blockchain_tests;
332+
use crate::testutils::blockchain_tests::{BlockchainType, TestClient};
332333
use crate::testutils::configurable_blockchain_tests::ConfigurableBlockchainTester;
333334
use crate::wallet::{AddressIndex, Wallet};
334335

335-
crate::bdk_blockchain_tests! {
336-
fn test_instance(test_client: &TestClient) -> ElectrumBlockchain {
337-
ElectrumBlockchain::from(Client::new(&test_client.electrsd.electrum_url).unwrap())
338-
}
339-
}
336+
make_blockchain_tests![
337+
blockchain BlockchainType::ElectrumBlockchain,
338+
tests (
339+
test_sync_simple,
340+
test_sync_stop_gap_20,
341+
test_sync_before_and_after_receive,
342+
test_sync_multiple_outputs_same_tx,
343+
test_sync_receive_multi,
344+
test_sync_address_reuse,
345+
test_sync_receive_rbf_replaced,
346+
test_sync_reorg_block,
347+
test_sync_after_send,
348+
test_sync_address_index_should_not_decrement,
349+
test_sync_address_index_should_increment,
350+
test_sync_double_receive,
351+
test_sync_many_sends_to_a_single_address,
352+
test_update_confirmation_time_after_generate,
353+
test_sync_outgoing_from_scratch,
354+
test_sync_long_change_chain,
355+
test_sync_bump_fee_basic,
356+
test_sync_bump_fee_remove_change,
357+
test_sync_bump_fee_add_input_simple,
358+
test_sync_bump_fee_add_input_no_change,
359+
test_add_data,
360+
test_sync_receive_coinbase,
361+
test_send_to_bech32m_addr,
362+
test_tx_chain,
363+
test_double_spend,
364+
test_send_receive_pkh,
365+
test_taproot_script_spend,
366+
test_sign_taproot_core_keyspend_psbt,
367+
test_sign_taproot_core_scriptspend2_psbt,
368+
test_sign_taproot_core_scriptspend3_psbt,
369+
test_get_block_hash,
370+
)
371+
];
340372

341373
fn get_factory() -> (TestClient, Arc<ElectrumBlockchain>) {
342374
let test_client = TestClient::default();

src/blockchain/esplora/mod.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,53 @@ impl_error!(std::num::ParseIntError, Parsing, EsploraError);
149149
impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError);
150150
impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError);
151151

152-
#[cfg(test)]
153-
#[cfg(feature = "test-esplora")]
154-
crate::bdk_blockchain_tests! {
155-
fn test_instance(test_client: &TestClient) -> EsploraBlockchain {
156-
EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), 20)
157-
}
158-
}
159-
160152
const DEFAULT_CONCURRENT_REQUESTS: u8 = 4;
161153

162154
#[cfg(test)]
163-
mod test {
155+
pub mod test {
164156
use super::*;
157+
#[cfg(feature = "test-esplora")]
158+
use crate::make_blockchain_tests;
159+
#[cfg(feature = "test-esplora")]
160+
use crate::testutils::blockchain_tests::BlockchainType;
161+
162+
#[cfg(feature = "test-esplora")]
163+
make_blockchain_tests![
164+
blockchain BlockchainType::EsploraBlockchain,
165+
tests (
166+
test_sync_simple,
167+
test_sync_stop_gap_20,
168+
test_sync_before_and_after_receive,
169+
test_sync_multiple_outputs_same_tx,
170+
test_sync_receive_multi,
171+
test_sync_address_reuse,
172+
test_sync_receive_rbf_replaced,
173+
test_sync_after_send,
174+
test_sync_address_index_should_not_decrement,
175+
test_sync_address_index_should_increment,
176+
test_sync_double_receive,
177+
test_sync_many_sends_to_a_single_address,
178+
test_update_confirmation_time_after_generate,
179+
test_sync_outgoing_from_scratch,
180+
test_sync_long_change_chain,
181+
test_sync_bump_fee_basic,
182+
test_sync_bump_fee_remove_change,
183+
test_sync_bump_fee_add_input_simple,
184+
test_sync_bump_fee_add_input_no_change,
185+
test_add_data,
186+
test_sync_receive_coinbase,
187+
test_send_to_bech32m_addr,
188+
test_tx_chain,
189+
test_double_spend,
190+
test_send_receive_pkh,
191+
test_taproot_key_spend,
192+
test_taproot_script_spend,
193+
test_sign_taproot_core_keyspend_psbt,
194+
test_sign_taproot_core_scriptspend2_psbt,
195+
test_sign_taproot_core_scriptspend3_psbt,
196+
test_get_block_hash,
197+
)
198+
];
165199

166200
#[test]
167201
fn feerate_parsing() {

src/blockchain/rpc.rs

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -861,31 +861,60 @@ impl BlockchainFactory for RpcBlockchainFactory {
861861

862862
#[cfg(test)]
863863
#[cfg(any(feature = "test-rpc", feature = "test-rpc-legacy"))]
864-
mod test {
864+
pub mod test {
865865
use super::*;
866-
use crate::{
867-
descriptor::{into_wallet_descriptor_checked, AsDerived},
868-
testutils::blockchain_tests::TestClient,
869-
wallet::utils::SecpCtx,
870-
};
866+
use crate::descriptor::into_wallet_descriptor_checked;
867+
use crate::descriptor::AsDerived;
868+
use crate::make_blockchain_tests;
869+
use crate::testutils::blockchain_tests::BlockchainType;
870+
use crate::testutils::blockchain_tests::TestClient;
871+
use crate::wallet::utils::SecpCtx;
871872

872873
use bitcoin::{Address, Network};
873874
use bitcoincore_rpc::RpcApi;
874875
use log::LevelFilter;
875876
use miniscript::DescriptorTrait;
876877

877-
crate::bdk_blockchain_tests! {
878-
fn test_instance(test_client: &TestClient) -> RpcBlockchain {
879-
let config = RpcConfig {
880-
url: test_client.bitcoind.rpc_url(),
881-
auth: Auth::Cookie { file: test_client.bitcoind.params.cookie_file.clone() },
882-
network: Network::Regtest,
883-
wallet_name: format!("client-wallet-test-{}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() ),
884-
sync_params: None,
885-
};
886-
RpcBlockchain::from_config(&config).unwrap()
887-
}
888-
}
878+
make_blockchain_tests![
879+
blockchain BlockchainType::RpcBlockchain,
880+
tests (
881+
test_sync_simple,
882+
test_sync_stop_gap_20,
883+
test_sync_before_and_after_receive,
884+
test_sync_multiple_outputs_same_tx,
885+
test_sync_receive_multi,
886+
test_sync_address_reuse,
887+
test_sync_receive_rbf_replaced,
888+
test_sync_after_send,
889+
test_sync_address_index_should_not_decrement,
890+
test_sync_address_index_should_increment,
891+
test_sync_double_receive,
892+
test_sync_many_sends_to_a_single_address,
893+
test_update_confirmation_time_after_generate,
894+
test_sync_outgoing_from_scratch,
895+
test_sync_long_change_chain,
896+
test_sync_bump_fee_basic,
897+
test_sync_bump_fee_add_input_simple,
898+
test_sync_bump_fee_add_input_no_change,
899+
test_sync_receive_coinbase,
900+
test_double_spend,
901+
test_tx_chain,
902+
test_get_block_hash,
903+
)
904+
];
905+
906+
#[cfg(not(feature = "test-rpc-legacy"))]
907+
make_blockchain_tests![
908+
blockchain BlockchainType::RpcBlockchain,
909+
tests (
910+
test_send_to_bech32m_addr,
911+
test_taproot_key_spend,
912+
test_taproot_script_spend,
913+
test_sign_taproot_core_keyspend_psbt,
914+
test_sign_taproot_core_scriptspend2_psbt,
915+
test_sign_taproot_core_scriptspend3_psbt,
916+
)
917+
];
889918

890919
fn get_factory() -> (TestClient, RpcBlockchainFactory) {
891920
let test_client = TestClient::default();

0 commit comments

Comments
 (0)