Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change the meaning of the `fee_amount` field inside `CoinSelectionResult`: from now on the `fee_amount` will represent only the fees asociated with the utxos in the `selected` field of `CoinSelectionResult`.
- New `RpcBlockchain` implementation with various fixes.
- Return balance in separate categories, namely `confirmed`, `trusted_pending`, `untrusted_pending` & `immature`.
- Transform testing macros into functions. For both Database and Blockchain tests.
- Move testing macros and functions into their own module inside `testutils/helpers.rs`.

## [v0.20.0] - [v0.19.0]

Expand Down
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
60 changes: 51 additions & 9 deletions src/blockchain/esplora/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,61 @@ impl_error!(std::num::ParseIntError, Parsing, EsploraError);
impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError);
impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError);

#[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 {
pub 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]
fn feerate_parsing() {
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
60 changes: 16 additions & 44 deletions src/database/keyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ mod test {

use sled::{Db, Tree};

use crate::run_tests_with_init;

static mut COUNT: usize = 0;

lazy_static! {
Expand Down Expand Up @@ -448,48 +450,18 @@ mod test {
}
}

#[test]
fn test_script_pubkey() {
crate::database::test::test_script_pubkey(get_tree());
}

#[test]
fn test_batch_script_pubkey() {
crate::database::test::test_batch_script_pubkey(get_tree());
}

#[test]
fn test_iter_script_pubkey() {
crate::database::test::test_iter_script_pubkey(get_tree());
}

#[test]
fn test_del_script_pubkey() {
crate::database::test::test_del_script_pubkey(get_tree());
}

#[test]
fn test_utxo() {
crate::database::test::test_utxo(get_tree());
}

#[test]
fn test_raw_tx() {
crate::database::test::test_raw_tx(get_tree());
}

#[test]
fn test_tx() {
crate::database::test::test_tx(get_tree());
}

#[test]
fn test_last_index() {
crate::database::test::test_last_index(get_tree());
}

#[test]
fn test_sync_time() {
crate::database::test::test_sync_time(get_tree());
}
run_tests_with_init![
@init get_tree(),
@tests(
test_script_pubkey,
test_batch_script_pubkey,
test_iter_script_pubkey,
test_del_script_pubkey,
test_utxo,
test_raw_tx,
test_tx,
test_last_index,
test_sync_time
)
];
}
Loading