Skip to content

Commit 96be037

Browse files
rajarshimaitraSanthoshAngulurisaikishore222
committed
Apply blockchain test changes
Apply the new `make_blockchain_test` macro to run the blockchain tests for rpc, electrum and esplora blockchain. Co-authored-by: SanthoshAnguluri <santhoshanguluri15@gmail.com> Co-authored-by: saikishore222 <saikishore.chsk@gmail.com>
1 parent 8c6911c commit 96be037

File tree

3 files changed

+156
-30
lines changed

3 files changed

+156
-30
lines changed

src/blockchain/electrum.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,53 @@ mod test {
337337

338338
use super::*;
339339
use crate::database::MemoryDatabase;
340+
use crate::make_blockchain_tests;
340341
use crate::testutils::blockchain_tests::TestClient;
341342
use crate::testutils::configurable_blockchain_tests::ConfigurableBlockchainTester;
342343
use crate::wallet::{AddressIndex, Wallet};
344+
use electrum_client::Client;
343345

344-
crate::bdk_blockchain_tests! {
345-
fn test_instance(test_client: &TestClient) -> ElectrumBlockchain {
346-
ElectrumBlockchain::from(Client::new(&test_client.electrsd.electrum_url).unwrap())
347-
}
346+
fn init_blockchain(test_client: &TestClient) -> ElectrumBlockchain {
347+
ElectrumBlockchain::from(Client::new(&test_client.electrsd.electrum_url).unwrap())
348348
}
349349

350+
make_blockchain_tests![
351+
init_blockchain,
352+
tests(
353+
test_sync_simple,
354+
test_sync_stop_gap_20,
355+
test_sync_before_and_after_receive,
356+
test_sync_multiple_outputs_same_tx,
357+
test_sync_receive_multi,
358+
test_sync_address_reuse,
359+
test_sync_receive_rbf_replaced,
360+
test_sync_reorg_block,
361+
test_sync_after_send,
362+
test_sync_address_index_should_not_decrement,
363+
test_sync_address_index_should_increment,
364+
test_sync_double_receive,
365+
test_sync_many_sends_to_a_single_address,
366+
test_update_confirmation_time_after_generate,
367+
test_sync_outgoing_from_scratch,
368+
test_sync_long_change_chain,
369+
test_sync_bump_fee_basic,
370+
test_sync_bump_fee_remove_change,
371+
test_sync_bump_fee_add_input_simple,
372+
test_sync_bump_fee_add_input_no_change,
373+
test_add_data,
374+
test_sync_receive_coinbase,
375+
test_send_to_bech32m_addr,
376+
test_tx_chain,
377+
test_double_spend,
378+
test_send_receive_pkh,
379+
test_taproot_script_spend,
380+
test_sign_taproot_core_keyspend_psbt,
381+
test_sign_taproot_core_scriptspend2_psbt,
382+
test_sign_taproot_core_scriptspend3_psbt,
383+
test_get_block_hash,
384+
)
385+
];
386+
350387
fn get_factory() -> (TestClient, Arc<ElectrumBlockchain>) {
351388
let test_client = TestClient::default();
352389

src/blockchain/esplora/mod.rs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,61 @@ 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

154+
#[cfg(feature = "test-esplora")]
162155
#[cfg(test)]
163-
mod test {
156+
pub mod test {
164157
use super::*;
158+
use crate::make_blockchain_tests;
159+
use crate::testutils::blockchain_tests::TestClient;
160+
161+
fn init_blockchain(test_client: &TestClient) -> EsploraBlockchain {
162+
EsploraBlockchain::new(
163+
&format!(
164+
"http://{}",
165+
test_client.electrsd.esplora_url.as_ref().unwrap()
166+
),
167+
20,
168+
)
169+
}
170+
171+
make_blockchain_tests![
172+
init_blockchain,
173+
tests(
174+
test_sync_simple,
175+
test_sync_stop_gap_20,
176+
test_sync_before_and_after_receive,
177+
test_sync_multiple_outputs_same_tx,
178+
test_sync_receive_multi,
179+
test_sync_address_reuse,
180+
test_sync_receive_rbf_replaced,
181+
test_sync_after_send,
182+
test_sync_address_index_should_not_decrement,
183+
test_sync_address_index_should_increment,
184+
test_sync_double_receive,
185+
test_sync_many_sends_to_a_single_address,
186+
test_update_confirmation_time_after_generate,
187+
test_sync_outgoing_from_scratch,
188+
test_sync_long_change_chain,
189+
test_sync_bump_fee_basic,
190+
test_sync_bump_fee_remove_change,
191+
test_sync_bump_fee_add_input_simple,
192+
test_sync_bump_fee_add_input_no_change,
193+
test_add_data,
194+
test_sync_receive_coinbase,
195+
test_send_to_bech32m_addr,
196+
test_tx_chain,
197+
test_double_spend,
198+
test_send_receive_pkh,
199+
test_taproot_key_spend,
200+
test_taproot_script_spend,
201+
test_sign_taproot_core_keyspend_psbt,
202+
test_sign_taproot_core_scriptspend2_psbt,
203+
test_sign_taproot_core_scriptspend3_psbt,
204+
test_get_block_hash,
205+
)
206+
];
165207

166208
#[test]
167209
fn feerate_parsing() {

src/blockchain/rpc.rs

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -870,32 +870,79 @@ impl BlockchainFactory for RpcBlockchainFactory {
870870

871871
#[cfg(test)]
872872
#[cfg(any(feature = "test-rpc", feature = "test-rpc-legacy"))]
873-
mod test {
873+
pub mod test {
874874
use super::*;
875-
use crate::{
876-
descriptor::{into_wallet_descriptor_checked, AsDerived},
877-
testutils::blockchain_tests::TestClient,
878-
wallet::utils::SecpCtx,
879-
};
875+
use crate::descriptor::into_wallet_descriptor_checked;
876+
use crate::descriptor::AsDerived;
877+
use crate::make_blockchain_tests;
878+
use crate::testutils::blockchain_tests::TestClient;
879+
use crate::wallet::utils::SecpCtx;
880880

881881
use bitcoin::{Address, Network};
882882
use bitcoincore_rpc::RpcApi;
883883
use log::LevelFilter;
884884
use miniscript::DescriptorTrait;
885885

886-
crate::bdk_blockchain_tests! {
887-
fn test_instance(test_client: &TestClient) -> RpcBlockchain {
888-
let config = RpcConfig {
889-
url: test_client.bitcoind.rpc_url(),
890-
auth: Auth::Cookie { file: test_client.bitcoind.params.cookie_file.clone() },
891-
network: Network::Regtest,
892-
wallet_name: format!("client-wallet-test-{}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() ),
893-
sync_params: None,
894-
};
895-
RpcBlockchain::from_config(&config).unwrap()
896-
}
886+
pub fn init_blockchain(test_client: &TestClient) -> RpcBlockchain {
887+
let config = RpcConfig {
888+
url: test_client.bitcoind.rpc_url(),
889+
auth: Auth::Cookie {
890+
file: test_client.bitcoind.params.cookie_file.clone(),
891+
},
892+
network: Network::Regtest,
893+
wallet_name: format!(
894+
"client-wallet-test-{}",
895+
std::time::SystemTime::now()
896+
.duration_since(std::time::UNIX_EPOCH)
897+
.unwrap()
898+
.as_nanos()
899+
),
900+
sync_params: Some(RpcSyncParams::default()),
901+
};
902+
RpcBlockchain::from_config(&config).unwrap()
897903
}
898904

905+
make_blockchain_tests![
906+
init_blockchain,
907+
tests(
908+
test_sync_simple,
909+
test_sync_stop_gap_20,
910+
test_sync_before_and_after_receive,
911+
test_sync_multiple_outputs_same_tx,
912+
test_sync_receive_multi,
913+
test_sync_address_reuse,
914+
test_sync_receive_rbf_replaced,
915+
test_sync_after_send,
916+
test_sync_address_index_should_not_decrement,
917+
test_sync_address_index_should_increment,
918+
test_sync_double_receive,
919+
test_sync_many_sends_to_a_single_address,
920+
test_update_confirmation_time_after_generate,
921+
test_sync_outgoing_from_scratch,
922+
test_sync_long_change_chain,
923+
test_sync_bump_fee_basic,
924+
test_sync_bump_fee_add_input_simple,
925+
test_sync_bump_fee_add_input_no_change,
926+
test_sync_receive_coinbase,
927+
test_double_spend,
928+
test_tx_chain,
929+
test_get_block_hash,
930+
)
931+
];
932+
933+
#[cfg(not(feature = "test-rpc-legacy"))]
934+
make_blockchain_tests![
935+
init_blockchain,
936+
tests(
937+
test_send_to_bech32m_addr,
938+
test_taproot_key_spend,
939+
test_taproot_script_spend,
940+
test_sign_taproot_core_keyspend_psbt,
941+
test_sign_taproot_core_scriptspend2_psbt,
942+
test_sign_taproot_core_scriptspend3_psbt,
943+
)
944+
];
945+
899946
fn get_factory() -> (TestClient, RpcBlockchainFactory) {
900947
let test_client = TestClient::default();
901948

0 commit comments

Comments
 (0)