Skip to content

Commit d12d1a7

Browse files
Fix rpc and esplora blockchain test failures
Co-authored-by: saikishore222 <saikishore.chsk@gmail.com>
1 parent 27046cb commit d12d1a7

File tree

4 files changed

+52
-84
lines changed

4 files changed

+52
-84
lines changed

src/blockchain/electrum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ mod test {
338338
}
339339

340340
make_blockchain_tests![
341-
@type BlockchainType::ElectrumBlockchain,
342-
@tests (
341+
blockchain BlockchainType::ElectrumBlockchain,
342+
tests (
343343
test_sync_simple,
344344
test_sync_stop_gap_20,
345345
test_sync_before_and_after_receive,

src/blockchain/esplora/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,15 @@ pub mod test {
168168

169169
#[cfg(feature = "test-esplora")]
170170
make_blockchain_tests![
171-
@type BlockchainType::EsploraBlockchain,
172-
@tests (
171+
blockchain BlockchainType::EsploraBlockchain,
172+
tests (
173173
test_sync_simple,
174174
test_sync_stop_gap_20,
175175
test_sync_before_and_after_receive,
176176
test_sync_multiple_outputs_same_tx,
177177
test_sync_receive_multi,
178178
test_sync_address_reuse,
179179
test_sync_receive_rbf_replaced,
180-
test_sync_reorg_block,
181180
test_sync_after_send,
182181
test_sync_double_receive,
183182
test_sync_many_sends_to_a_single_address,

src/blockchain/rpc.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ pub mod test {
589589
}
590590

591591
make_blockchain_tests![
592-
@type BlockchainType::RpcBlockchain,
593-
@tests (
592+
blockchain BlockchainType::RpcBlockchain,
593+
tests (
594594
test_sync_simple,
595595
test_sync_stop_gap_20,
596596
test_sync_before_and_after_receive,
@@ -608,9 +608,16 @@ pub mod test {
608608
test_sync_bump_fee_add_input_simple,
609609
test_sync_bump_fee_add_input_no_change,
610610
test_sync_receive_coinbase,
611-
test_send_to_bech32m_addr,
612611
test_double_spend,
613-
test_tx_chain,
612+
test_tx_chain
613+
)
614+
];
615+
616+
#[cfg(not(feature = "test-rpc-legacy"))]
617+
make_blockchain_tests![
618+
blockchain BlockchainType::RpcBlockchain,
619+
tests (
620+
test_send_to_bech32m_addr,
614621
test_taproot_key_spend,
615622
test_taproot_script_spend,
616623
test_sign_taproot_core_keyspend_psbt,

src/testutils/blockchain_tests.rs

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -413,37 +413,8 @@ pub mod test {
413413
TaprootScriptSpend3,
414414
}
415415

416-
fn init_wallet(
417-
ty: WalletType,
418-
chain_type: BlockchainType,
419-
) -> (
420-
Wallet<MemoryDatabase>,
421-
AnyBlockchain,
422-
(String, Option<String>),
423-
TestClient,
424-
) {
425-
let _ = env_logger::try_init();
426-
427-
let descriptors = match ty {
428-
WalletType::WpkhSingleSig => testutils! {
429-
@descriptors ( "wpkh(Alice)" ) ( "wpkh(Alice)" ) ( @keys ( "Alice" => (@generate_xprv "/44'/0'/0'/0/*", "/44'/0'/0'/1/*") ) )
430-
},
431-
WalletType::TaprootKeySpend => testutils! {
432-
@descriptors ( "tr(Alice)" ) ( "tr(Alice)" ) ( @keys ( "Alice" => (@generate_xprv "/44'/0'/0'/0/*", "/44'/0'/0'/1/*") ) )
433-
},
434-
WalletType::TaprootScriptSpend => testutils! {
435-
@descriptors ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( @keys ( "Key" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Script" => (@generate_xprv "/0/*", "/1/*") ) )
436-
},
437-
WalletType::TaprootScriptSpend2 => testutils! {
438-
@descriptors ( "tr(Alice,pk(Bob))" ) ( "tr(Alice,pk(Bob))" ) ( @keys ( "Alice" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Bob" => (@generate_xprv "/0/*", "/1/*") ) )
439-
},
440-
WalletType::TaprootScriptSpend3 => testutils! {
441-
@descriptors ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( @keys ( "Alice" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Bob" => (@generate_xprv "/0/*", "/1/*"), "Carol" => (@generate_xprv "/0/*", "/1/*") ) )
442-
},
443-
};
444-
445-
let test_client = TestClient::default();
446-
let blockchain: AnyBlockchain = match chain_type {
416+
fn get_blockchain(test_client: &TestClient, chain_type: BlockchainType) -> AnyBlockchain {
417+
match chain_type {
447418
#[cfg(any(feature = "test-rpc", feature = "test-rpc-legacy"))]
448419
BlockchainType::RpcBlockchain => {
449420
let config = RpcConfig {
@@ -481,7 +452,40 @@ pub mod test {
481452
electrum_client::new(&test_client.electrsd.electrum_url).unwrap(),
482453
)))
483454
}
455+
}
456+
}
457+
458+
fn init_wallet(
459+
ty: WalletType,
460+
chain_type: BlockchainType,
461+
) -> (
462+
Wallet<MemoryDatabase>,
463+
AnyBlockchain,
464+
(String, Option<String>),
465+
TestClient,
466+
) {
467+
let _ = env_logger::try_init();
468+
469+
let descriptors = match ty {
470+
WalletType::WpkhSingleSig => testutils! {
471+
@descriptors ( "wpkh(Alice)" ) ( "wpkh(Alice)" ) ( @keys ( "Alice" => (@generate_xprv "/44'/0'/0'/0/*", "/44'/0'/0'/1/*") ) )
472+
},
473+
WalletType::TaprootKeySpend => testutils! {
474+
@descriptors ( "tr(Alice)" ) ( "tr(Alice)" ) ( @keys ( "Alice" => (@generate_xprv "/44'/0'/0'/0/*", "/44'/0'/0'/1/*") ) )
475+
},
476+
WalletType::TaprootScriptSpend => testutils! {
477+
@descriptors ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( @keys ( "Key" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Script" => (@generate_xprv "/0/*", "/1/*") ) )
478+
},
479+
WalletType::TaprootScriptSpend2 => testutils! {
480+
@descriptors ( "tr(Alice,pk(Bob))" ) ( "tr(Alice,pk(Bob))" ) ( @keys ( "Alice" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Bob" => (@generate_xprv "/0/*", "/1/*") ) )
481+
},
482+
WalletType::TaprootScriptSpend3 => testutils! {
483+
@descriptors ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( @keys ( "Alice" => (@literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788"), "Bob" => (@generate_xprv "/0/*", "/1/*"), "Carol" => (@generate_xprv "/0/*", "/1/*") ) )
484+
},
484485
};
486+
487+
let test_client = TestClient::default();
488+
let blockchain: AnyBlockchain = get_blockchain(&test_client, chain_type);
485489
let wallet = get_wallet_from_descriptors(&descriptors);
486490

487491
// rpc need to call import_multi before receiving any tx, otherwise will not see tx in the mempool
@@ -491,49 +495,6 @@ pub mod test {
491495
(wallet, blockchain, descriptors, test_client)
492496
}
493497

494-
fn get_blockchain(test_client: &TestClient, chain_type: BlockchainType) -> AnyBlockchain {
495-
let blockchain: AnyBlockchain = match chain_type {
496-
#[cfg(any(feature = "test-rpc", feature = "test-rpc-legacy"))]
497-
BlockchainType::RpcBlockchain => {
498-
let config = RpcConfig {
499-
url: test_client.bitcoind.rpc_url(),
500-
auth: Auth::Cookie {
501-
file: test_client.bitcoind.params.cookie_file.clone(),
502-
},
503-
network: Network::Regtest,
504-
wallet_name: format!(
505-
"client-wallet-test-{}",
506-
std::time::SystemTime::now()
507-
.duration_since(std::time::UNIX_EPOCH)
508-
.unwrap()
509-
.as_nanos()
510-
),
511-
skip_blocks: None,
512-
};
513-
AnyBlockchain::Rpc(Box::new(RpcBlockchain::from_config(&config).unwrap()))
514-
}
515-
516-
#[cfg(feature = "test-esplora")]
517-
BlockchainType::EsploraBlockchain => {
518-
AnyBlockchain::Esplora(Box::new(EsploraBlockchain::new(
519-
&format!(
520-
"http://{}",
521-
test_client.electrsd.esplora_url.as_ref().unwrap()
522-
),
523-
20,
524-
)))
525-
}
526-
527-
#[cfg(feature = "test-electrum")]
528-
BlockchainType::ElectrumBlockchain => {
529-
AnyBlockchain::Electrum(Box::new(ElectrumBlockchain::from(
530-
electrum_client::new(&test_client.electrsd.electrum_url).unwrap(),
531-
)))
532-
}
533-
};
534-
blockchain
535-
}
536-
537498
fn init_single_sig(
538499
chain_type: BlockchainType,
539500
) -> (
@@ -1822,10 +1783,11 @@ pub mod test {
18221783
assert_eq!(finalized, true);
18231784
}
18241785
}
1786+
18251787
#[macro_export]
18261788
#[doc(hidden)]
18271789
macro_rules! make_blockchain_tests {
1828-
(@type $chain_type:expr, @tests ( $($x:tt) , + $(,)? )) => {
1790+
(blockchain $chain_type:expr, tests ( $($x:tt) , + $(,)? )) => {
18291791
$(
18301792
#[test]
18311793
fn $x()

0 commit comments

Comments
 (0)