@@ -4,15 +4,15 @@ use std::sync::Arc;
44
55use anyhow:: Context ;
66use assert_matches:: assert_matches;
7- use bdk_chain:: { BlockId , ChainPosition , ConfirmationBlockTime } ;
7+ use bdk_chain:: { BlockId , ChainPosition , ConfirmationBlockTime , TxUpdate } ;
88use bdk_wallet:: coin_selection:: { self , LargestFirstCoinSelection } ;
99use bdk_wallet:: descriptor:: { calc_checksum, DescriptorError , IntoWalletDescriptor } ;
1010use bdk_wallet:: error:: CreateTxError ;
1111use bdk_wallet:: psbt:: PsbtUtils ;
1212use bdk_wallet:: signer:: { SignOptions , SignerError } ;
1313use bdk_wallet:: test_utils:: * ;
1414use bdk_wallet:: tx_builder:: AddForeignUtxoError ;
15- use bdk_wallet:: { AddressInfo , Balance , ChangeSet , Wallet , WalletPersister , WalletTx } ;
15+ use bdk_wallet:: { AddressInfo , Balance , ChangeSet , Update , Wallet , WalletPersister , WalletTx } ;
1616use bdk_wallet:: { KeychainKind , LoadError , LoadMismatch , LoadWithPersistError } ;
1717use bitcoin:: constants:: { ChainHash , COINBASE_MATURITY } ;
1818use bitcoin:: hashes:: Hash ;
@@ -4239,3 +4239,52 @@ fn test_tx_builder_is_send_safe() {
42394239 let ( mut wallet, _txid) = get_funded_wallet_wpkh ( ) ;
42404240 let _box: Box < dyn Send + Sync > = Box :: new ( wallet. build_tx ( ) ) ;
42414241}
4242+
4243+ #[ test]
4244+ fn test_wallet_transactions_relevant ( ) {
4245+ let ( mut test_wallet, _txid) = get_funded_wallet_wpkh ( ) ;
4246+ let relevant_tx_count_before = test_wallet. transactions ( ) . count ( ) ;
4247+ let full_tx_count_before = test_wallet. tx_graph ( ) . full_txs ( ) . count ( ) ;
4248+ let chain_tip = test_wallet. local_chain ( ) . tip ( ) . block_id ( ) ;
4249+ let canonical_tx_count_before = test_wallet
4250+ . tx_graph ( )
4251+ . list_canonical_txs ( test_wallet. local_chain ( ) , chain_tip)
4252+ . count ( ) ;
4253+
4254+ // add not relevant transaction to test wallet
4255+ let ( other_external_desc, other_internal_desc) = get_test_tr_single_sig_xprv_and_change_desc ( ) ;
4256+ let ( other_wallet, other_txid) = get_funded_wallet ( other_internal_desc, other_external_desc) ;
4257+ let other_tx_node = other_wallet. get_tx ( other_txid) . unwrap ( ) . tx_node ;
4258+ let other_tx_confirmationblocktime = other_tx_node. anchors . iter ( ) . last ( ) . unwrap ( ) ;
4259+ let other_tx_update = TxUpdate {
4260+ txs : vec ! [ other_tx_node. tx] ,
4261+ txouts : Default :: default ( ) ,
4262+ anchors : [ ( * other_tx_confirmationblocktime, other_txid) ] . into ( ) ,
4263+ seen_ats : [ ( other_txid, other_tx_confirmationblocktime. confirmation_time ) ] . into ( ) ,
4264+ } ;
4265+ let test_wallet_update = Update {
4266+ last_active_indices : Default :: default ( ) ,
4267+ tx_update : other_tx_update,
4268+ chain : None ,
4269+ } ;
4270+ test_wallet. apply_update ( test_wallet_update) . unwrap ( ) ;
4271+
4272+ // verify transaction from other wallet was added but is not it relevant transactions list.
4273+ let relevant_tx_count_after = test_wallet. transactions ( ) . count ( ) ;
4274+ let full_tx_count_after = test_wallet. tx_graph ( ) . full_txs ( ) . count ( ) ;
4275+ let canonical_tx_count_after = test_wallet
4276+ . tx_graph ( )
4277+ . list_canonical_txs ( test_wallet. local_chain ( ) , chain_tip)
4278+ . count ( ) ;
4279+
4280+ assert_eq ! ( relevant_tx_count_before, relevant_tx_count_after) ;
4281+ assert ! ( !test_wallet
4282+ . transactions( )
4283+ . any( |wallet_tx| wallet_tx. tx_node. txid == other_txid) ) ;
4284+ assert ! ( test_wallet
4285+ . tx_graph( )
4286+ . list_canonical_txs( test_wallet. local_chain( ) , chain_tip)
4287+ . any( |wallet_tx| wallet_tx. tx_node. txid == other_txid) ) ;
4288+ assert ! ( full_tx_count_before < full_tx_count_after) ;
4289+ assert ! ( canonical_tx_count_before < canonical_tx_count_after) ;
4290+ }
0 commit comments