@@ -8,6 +8,7 @@ use integration_test::{Node, NodeExt as _, Wallet};
88use node:: client:: client_sync;
99use node:: vtype:: * ; // All the version specific types.
1010use node:: mtype;
11+ use node:: { Input , Output } ;
1112
1213#[ test]
1314#[ cfg( not( feature = "v25_and_below" ) ) ]
@@ -246,17 +247,67 @@ fn blockchain__get_difficulty__modelled() {
246247}
247248
248249#[ test]
249- #[ cfg( feature = "TODO" ) ]
250250fn blockchain__get_mempool_ancestors__modelled ( ) {
251- // We can probably get away with not testing this because it returns the same type as
252- // `getmempoolentry` which is tested below (for verbose=true). For verbose=false it
253- // just returns a txid.
251+ let node = Node :: with_wallet ( Wallet :: Default , & [ ] ) ;
252+ node. fund_wallet ( ) ;
253+ let ( _address, parent_txid) = node. create_mempool_transaction ( ) ;
254+ let child_txid = create_child_spending_parent ( & node, parent_txid) ;
255+
256+ let json: GetMempoolAncestors =
257+ node. client . get_mempool_ancestors ( child_txid) . expect ( "getmempoolancestors" ) ;
258+ let model: Result < mtype:: GetMempoolAncestors , _ > = json. into_model ( ) ;
259+ let ancestors = model. unwrap ( ) ;
260+
261+ assert ! ( ancestors. 0 . contains( & parent_txid) ) ;
262+ }
263+
264+ #[ test]
265+ fn blockchain__get_mempool_ancestors_verbose__modelled ( ) {
266+ let node = Node :: with_wallet ( Wallet :: Default , & [ ] ) ;
267+ node. fund_wallet ( ) ;
268+ let ( _address, parent_txid) = node. create_mempool_transaction ( ) ;
269+ let child_txid = create_child_spending_parent ( & node, parent_txid) ;
270+
271+ let json: GetMempoolAncestorsVerbose = node
272+ . client
273+ . get_mempool_ancestors_verbose ( child_txid)
274+ . expect ( "getmempoolancestors verbose" ) ;
275+ let model: Result < mtype:: GetMempoolAncestorsVerbose , _ > = json. into_model ( ) ;
276+ let ancestors = model. unwrap ( ) ;
277+
278+ assert ! ( ancestors. 0 . contains_key( & parent_txid) ) ;
254279}
255280
256281#[ test]
257- #[ cfg( feature = "TODO" ) ]
258282fn blockchain__get_mempool_descendants__modelled ( ) {
259- // Same justification as for `blockchain__get_mempool_ancestors__modelled`
283+ let node = Node :: with_wallet ( Wallet :: Default , & [ ] ) ;
284+ node. fund_wallet ( ) ;
285+ let ( _address, parent_txid) = node. create_mempool_transaction ( ) ;
286+ let child_txid = create_child_spending_parent ( & node, parent_txid) ;
287+
288+ let json: GetMempoolDescendants =
289+ node. client . get_mempool_descendants ( parent_txid) . expect ( "getmempooldescendants" ) ;
290+ let model: Result < mtype:: GetMempoolDescendants , _ > = json. into_model ( ) ;
291+ let descendants = model. unwrap ( ) ;
292+
293+ assert ! ( descendants. 0 . contains( & child_txid) ) ;
294+ }
295+
296+ #[ test]
297+ fn blockchain__get_mempool_descendants_verbose__modelled ( ) {
298+ let node = Node :: with_wallet ( Wallet :: Default , & [ ] ) ;
299+ node. fund_wallet ( ) ;
300+ let ( _address, parent_txid) = node. create_mempool_transaction ( ) ;
301+ let child_txid = create_child_spending_parent ( & node, parent_txid) ;
302+
303+ let json: GetMempoolDescendantsVerbose = node
304+ . client
305+ . get_mempool_descendants_verbose ( parent_txid)
306+ . expect ( "getmempooldescendants verbose" ) ;
307+ let model: Result < mtype:: GetMempoolDescendantsVerbose , _ > = json. into_model ( ) ;
308+ let descendants = model. unwrap ( ) ;
309+
310+ assert ! ( descendants. 0 . contains_key( & child_txid) ) ;
260311}
261312
262313#[ test]
@@ -476,3 +527,29 @@ fn verify_tx_out_proof(node: &Node) -> Result<(), client_sync::Error> {
476527
477528 Ok ( ( ) )
478529}
530+
531+ /// Create and broadcast a child transaction spending vout 0 of the given parent mempool txid.
532+ /// Returns the child's txid.
533+ fn create_child_spending_parent ( node : & Node , parent_txid : bitcoin:: Txid ) -> bitcoin:: Txid {
534+ let inputs = vec ! [ Input { txid: parent_txid, vout: 0 , sequence: None } ] ;
535+ let spend_address = node. client . new_address ( ) . expect ( "newaddress" ) ;
536+ let outputs = vec ! [ Output :: new( spend_address, bitcoin:: Amount :: from_sat( 100_000 ) ) ] ;
537+
538+ let raw: CreateRawTransaction =
539+ node. client . create_raw_transaction ( & inputs, & outputs) . expect ( "createrawtransaction" ) ;
540+ let unsigned = raw. transaction ( ) . expect ( "raw.transaction" ) ;
541+
542+ let funded: FundRawTransaction =
543+ node. client . fund_raw_transaction ( & unsigned) . expect ( "fundrawtransaction" ) ;
544+ let funded_tx = funded. transaction ( ) . expect ( "funded.transaction" ) ;
545+
546+ let signed: SignRawTransaction = node
547+ . client
548+ . sign_raw_transaction_with_wallet ( & funded_tx)
549+ . expect ( "signrawtransactionwithwallet" ) ;
550+ let model = signed. into_model ( ) . expect ( "SignRawTransactionWithWallet into model" ) ;
551+ let child_txid = model. tx . compute_txid ( ) ;
552+ let _ = node. client . send_raw_transaction ( & model. tx ) . expect ( "sendrawtransaction" ) ;
553+
554+ child_txid
555+ }
0 commit comments