Skip to content

Commit

Permalink
Apply blockchain test changes
Browse files Browse the repository at this point in the history
Apply the new `make_blockchain_test` macro to run the blockchain tests
for rpc, electrum and esplora blockchain.

Co-authored-by: SanthoshAnguluri <[email protected]>
Co-authored-by: saikishore222 <[email protected]>
  • Loading branch information
3 people committed Oct 10, 2022
1 parent 037d84d commit 63dd109
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 30 deletions.
45 changes: 41 additions & 4 deletions src/blockchain/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,53 @@ mod test {

use super::*;
use crate::database::MemoryDatabase;
use crate::make_blockchain_tests;
use crate::testutils::blockchain_tests::TestClient;
use crate::testutils::configurable_blockchain_tests::ConfigurableBlockchainTester;
use crate::wallet::{AddressIndex, Wallet};
use electrum_client::Client;

crate::bdk_blockchain_tests! {
fn test_instance(test_client: &TestClient) -> ElectrumBlockchain {
ElectrumBlockchain::from(Client::new(&test_client.electrsd.electrum_url).unwrap())
}
fn init_blockchain(test_client: &TestClient) -> ElectrumBlockchain {
ElectrumBlockchain::from(Client::new(&test_client.electrsd.electrum_url).unwrap())
}

make_blockchain_tests![
init_blockchain,
tests(
test_sync_simple,
test_sync_stop_gap_20,
test_sync_before_and_after_receive,
test_sync_multiple_outputs_same_tx,
test_sync_receive_multi,
test_sync_address_reuse,
test_sync_receive_rbf_replaced,
test_sync_reorg_block,
test_sync_after_send,
test_sync_address_index_should_not_decrement,
test_sync_address_index_should_increment,
test_sync_double_receive,
test_sync_many_sends_to_a_single_address,
test_update_confirmation_time_after_generate,
test_sync_outgoing_from_scratch,
test_sync_long_change_chain,
test_sync_bump_fee_basic,
test_sync_bump_fee_remove_change,
test_sync_bump_fee_add_input_simple,
test_sync_bump_fee_add_input_no_change,
test_add_data,
test_sync_receive_coinbase,
test_send_to_bech32m_addr,
test_tx_chain,
test_double_spend,
test_send_receive_pkh,
test_taproot_script_spend,
test_sign_taproot_core_keyspend_psbt,
test_sign_taproot_core_scriptspend2_psbt,
test_sign_taproot_core_scriptspend3_psbt,
test_get_block_hash,
)
];

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

Expand Down
61 changes: 52 additions & 9 deletions src/blockchain/esplora/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,63 @@ impl From<esplora_client::BlockTime> for crate::BlockTime {
}
}

#[cfg(test)]
#[cfg(feature = "test-esplora")]
crate::bdk_blockchain_tests! {
fn test_instance(test_client: &TestClient) -> EsploraBlockchain {
EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), 20)
}
}

const DEFAULT_CONCURRENT_REQUESTS: u8 = 4;

#[cfg(feature = "test-esplora")]
#[cfg(test)]
mod test {
use super::*;
use crate::make_blockchain_tests;
use crate::testutils::blockchain_tests::TestClient;

fn init_blockchain(test_client: &TestClient) -> EsploraBlockchain {
EsploraBlockchain::new(
&format!(
"http://{}",
test_client.electrsd.esplora_url.as_ref().unwrap()
),
20,
)
}

make_blockchain_tests![
init_blockchain,
tests(
test_sync_simple,
test_sync_stop_gap_20,
test_sync_before_and_after_receive,
test_sync_multiple_outputs_same_tx,
test_sync_receive_multi,
test_sync_address_reuse,
test_sync_receive_rbf_replaced,
test_sync_after_send,
test_sync_address_index_should_not_decrement,
test_sync_address_index_should_increment,
test_sync_double_receive,
test_sync_many_sends_to_a_single_address,
test_update_confirmation_time_after_generate,
test_sync_outgoing_from_scratch,
test_sync_long_change_chain,
test_sync_bump_fee_basic,
test_sync_bump_fee_remove_change,
test_sync_bump_fee_add_input_simple,
test_sync_bump_fee_add_input_no_change,
test_add_data,
test_sync_receive_coinbase,
test_send_to_bech32m_addr,
test_tx_chain,
test_double_spend,
test_send_receive_pkh,
test_taproot_key_spend,
test_taproot_script_spend,
test_sign_taproot_core_keyspend_psbt,
test_sign_taproot_core_scriptspend2_psbt,
test_sign_taproot_core_scriptspend3_psbt,
test_get_block_hash,
)
];

#[test]
#[cfg(feature = "test-esplora")]
fn test_esplora_with_variable_configs() {
use super::*;

Expand Down
81 changes: 64 additions & 17 deletions src/blockchain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,32 +870,79 @@ impl BlockchainFactory for RpcBlockchainFactory {

#[cfg(test)]
#[cfg(any(feature = "test-rpc", feature = "test-rpc-legacy"))]
mod test {
pub mod test {
use super::*;
use crate::{
descriptor::{into_wallet_descriptor_checked, AsDerived},
testutils::blockchain_tests::TestClient,
wallet::utils::SecpCtx,
};
use crate::descriptor::into_wallet_descriptor_checked;
use crate::descriptor::AsDerived;
use crate::make_blockchain_tests;
use crate::testutils::blockchain_tests::TestClient;
use crate::wallet::utils::SecpCtx;

use bitcoin::{Address, Network};
use bitcoincore_rpc::RpcApi;
use log::LevelFilter;
use miniscript::DescriptorTrait;

crate::bdk_blockchain_tests! {
fn test_instance(test_client: &TestClient) -> RpcBlockchain {
let config = RpcConfig {
url: test_client.bitcoind.rpc_url(),
auth: Auth::Cookie { file: test_client.bitcoind.params.cookie_file.clone() },
network: Network::Regtest,
wallet_name: format!("client-wallet-test-{}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() ),
sync_params: None,
};
RpcBlockchain::from_config(&config).unwrap()
}
pub fn init_blockchain(test_client: &TestClient) -> RpcBlockchain {
let config = RpcConfig {
url: test_client.bitcoind.rpc_url(),
auth: Auth::Cookie {
file: test_client.bitcoind.params.cookie_file.clone(),
},
network: Network::Regtest,
wallet_name: format!(
"client-wallet-test-{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
),
sync_params: Some(RpcSyncParams::default()),
};
RpcBlockchain::from_config(&config).unwrap()
}

make_blockchain_tests![
init_blockchain,
tests(
test_sync_simple,
test_sync_stop_gap_20,
test_sync_before_and_after_receive,
test_sync_multiple_outputs_same_tx,
test_sync_receive_multi,
test_sync_address_reuse,
test_sync_receive_rbf_replaced,
test_sync_after_send,
test_sync_address_index_should_not_decrement,
test_sync_address_index_should_increment,
test_sync_double_receive,
test_sync_many_sends_to_a_single_address,
test_update_confirmation_time_after_generate,
test_sync_outgoing_from_scratch,
test_sync_long_change_chain,
test_sync_bump_fee_basic,
test_sync_bump_fee_add_input_simple,
test_sync_bump_fee_add_input_no_change,
test_sync_receive_coinbase,
test_double_spend,
test_tx_chain,
test_get_block_hash,
)
];

#[cfg(not(feature = "test-rpc-legacy"))]
make_blockchain_tests![
init_blockchain,
tests(
test_send_to_bech32m_addr,
test_taproot_key_spend,
test_taproot_script_spend,
test_sign_taproot_core_keyspend_psbt,
test_sign_taproot_core_scriptspend2_psbt,
test_sign_taproot_core_scriptspend3_psbt,
)
];

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

Expand Down

0 comments on commit 63dd109

Please sign in to comment.