@@ -4,15 +4,15 @@ use std::sync::Arc;
4
4
5
5
use anyhow:: Context ;
6
6
use assert_matches:: assert_matches;
7
- use bdk_chain:: { BlockId , ChainPosition , ConfirmationBlockTime } ;
7
+ use bdk_chain:: { BlockId , ChainPosition , ConfirmationBlockTime , TxUpdate } ;
8
8
use bdk_wallet:: coin_selection:: { self , LargestFirstCoinSelection } ;
9
9
use bdk_wallet:: descriptor:: { calc_checksum, DescriptorError , IntoWalletDescriptor } ;
10
10
use bdk_wallet:: error:: CreateTxError ;
11
11
use bdk_wallet:: psbt:: PsbtUtils ;
12
12
use bdk_wallet:: signer:: { SignOptions , SignerError } ;
13
13
use bdk_wallet:: test_utils:: * ;
14
14
use 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 } ;
16
16
use bdk_wallet:: { KeychainKind , LoadError , LoadMismatch , LoadWithPersistError } ;
17
17
use bitcoin:: constants:: { ChainHash , COINBASE_MATURITY } ;
18
18
use bitcoin:: hashes:: Hash ;
@@ -4239,3 +4239,52 @@ fn test_tx_builder_is_send_safe() {
4239
4239
let ( mut wallet, _txid) = get_funded_wallet_wpkh ( ) ;
4240
4240
let _box: Box < dyn Send + Sync > = Box :: new ( wallet. build_tx ( ) ) ;
4241
4241
}
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