Skip to content

Commit 36bdbb9

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 6d81b3e commit 36bdbb9

File tree

4 files changed

+115
-35
lines changed

4 files changed

+115
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test-blockchains = ["bitcoincore-rpc", "electrum-client"]
9191
test-electrum = ["electrum", "electrsd/electrs_0_8_10", "electrsd/bitcoind_22_0", "test-blockchains"]
9292
test-rpc = ["rpc", "electrsd/electrs_0_8_10", "electrsd/bitcoind_22_0", "test-blockchains"]
9393
test-rpc-legacy = ["rpc", "electrsd/electrs_0_8_10", "electrsd/bitcoind_0_20_0", "test-blockchains"]
94-
test-esplora = ["electrsd/legacy", "electrsd/esplora_a33e97e1", "electrsd/bitcoind_22_0", "test-blockchains"]
94+
test-esplora = ["use-esplora-ureq", "electrsd/legacy", "electrsd/esplora_a33e97e1", "electrsd/bitcoind_22_0", "test-blockchains"]
9595
test-md-docs = ["electrum"]
9696

9797
[dev-dependencies]

src/blockchain/electrum.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,43 @@ mod test {
328328

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

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-
}
335+
make_blockchain_tests![
336+
blockchain BlockchainType::ElectrumBlockchain,
337+
tests (
338+
test_sync_simple,
339+
test_sync_stop_gap_20,
340+
test_sync_before_and_after_receive,
341+
test_sync_multiple_outputs_same_tx,
342+
test_sync_receive_multi,
343+
test_sync_address_reuse,
344+
test_sync_receive_rbf_replaced,
345+
test_sync_reorg_block,
346+
test_sync_after_send,
347+
test_sync_double_receive,
348+
test_sync_many_sends_to_a_single_address,
349+
test_update_confirmation_time_after_generate,
350+
test_sync_outgoing_from_scratch,
351+
test_sync_long_change_chain,
352+
test_sync_bump_fee_basic,
353+
test_sync_bump_fee_remove_change,
354+
test_sync_bump_fee_add_input_simple,
355+
test_sync_bump_fee_add_input_no_change,
356+
test_add_data,
357+
test_sync_receive_coinbase,
358+
test_send_to_bech32m_addr,
359+
test_tx_chain,
360+
test_double_spend,
361+
test_send_receive_pkh,
362+
test_taproot_script_spend,
363+
test_sign_taproot_core_keyspend_psbt,
364+
test_sign_taproot_core_scriptspend2_psbt,
365+
test_sign_taproot_core_scriptspend3_psbt,
366+
)
367+
];
340368

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

src/blockchain/esplora/mod.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,48 @@ 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+
use crate::make_blockchain_tests;
158+
use crate::testutils::blockchain_tests::BlockchainType;
159+
160+
#[cfg(feature = "test-esplora")]
161+
make_blockchain_tests![
162+
blockchain BlockchainType::EsploraBlockchain,
163+
tests (
164+
test_sync_simple,
165+
test_sync_stop_gap_20,
166+
test_sync_before_and_after_receive,
167+
test_sync_multiple_outputs_same_tx,
168+
test_sync_receive_multi,
169+
test_sync_address_reuse,
170+
test_sync_receive_rbf_replaced,
171+
test_sync_after_send,
172+
test_sync_double_receive,
173+
test_sync_many_sends_to_a_single_address,
174+
test_update_confirmation_time_after_generate,
175+
test_sync_outgoing_from_scratch,
176+
test_sync_long_change_chain,
177+
test_sync_bump_fee_basic,
178+
test_sync_bump_fee_remove_change,
179+
test_sync_bump_fee_add_input_simple,
180+
test_sync_bump_fee_add_input_no_change,
181+
test_add_data,
182+
test_sync_receive_coinbase,
183+
test_send_to_bech32m_addr,
184+
test_tx_chain,
185+
test_double_spend,
186+
test_send_receive_pkh,
187+
test_taproot_key_spend,
188+
test_taproot_script_spend,
189+
test_sign_taproot_core_keyspend_psbt,
190+
test_sign_taproot_core_scriptspend2_psbt,
191+
test_sign_taproot_core_scriptspend3_psbt,
192+
)
193+
];
165194

166195
#[test]
167196
fn feerate_parsing() {

src/blockchain/rpc.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -861,31 +861,54 @@ 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::make_blockchain_tests;
867+
use crate::testutils::blockchain_tests::BlockchainType;
868+
use crate::testutils::blockchain_tests::TestClient;
871869

872870
use bitcoin::{Address, Network};
873871
use bitcoincore_rpc::RpcApi;
874872
use log::LevelFilter;
875873
use miniscript::DescriptorTrait;
876874

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-
}
875+
make_blockchain_tests![
876+
blockchain BlockchainType::RpcBlockchain,
877+
tests (
878+
test_sync_simple,
879+
test_sync_stop_gap_20,
880+
test_sync_before_and_after_receive,
881+
test_sync_multiple_outputs_same_tx,
882+
test_sync_receive_multi,
883+
test_sync_address_reuse,
884+
test_sync_receive_rbf_replaced,
885+
test_sync_after_send,
886+
test_sync_double_receive,
887+
test_sync_many_sends_to_a_single_address,
888+
test_update_confirmation_time_after_generate,
889+
test_sync_outgoing_from_scratch,
890+
test_sync_long_change_chain,
891+
test_sync_bump_fee_basic,
892+
test_sync_bump_fee_add_input_simple,
893+
test_sync_bump_fee_add_input_no_change,
894+
test_sync_receive_coinbase,
895+
test_double_spend,
896+
test_tx_chain
897+
)
898+
];
899+
900+
#[cfg(not(feature = "test-rpc-legacy"))]
901+
make_blockchain_tests![
902+
blockchain BlockchainType::RpcBlockchain,
903+
tests (
904+
test_send_to_bech32m_addr,
905+
test_taproot_key_spend,
906+
test_taproot_script_spend,
907+
test_sign_taproot_core_keyspend_psbt,
908+
test_sign_taproot_core_scriptspend2_psbt,
909+
test_sign_taproot_core_scriptspend3_psbt
910+
)
911+
];
889912

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

0 commit comments

Comments
 (0)