@@ -264,3 +264,155 @@ mod test_config {
264264 assert_eq ! ( config[ "int_descriptor" ] . as_str( ) . unwrap( ) , int_desc) ;
265265 }
266266}
267+
268+ #[ cfg( feature = "rpc" ) ]
269+ mod test_offline {
270+ use super :: * ;
271+ use assert_cmd:: Command ;
272+ use serde_json:: Value ;
273+
274+ static WALLET_NAME : & str = "test_config_wallet" ;
275+
276+ /// Helper to spin up a sandboxed CLI with the generated descriptors
277+ fn setup_wallet_config ( ) -> ( BdkCli , Command ) {
278+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
279+ let cli = BdkCli :: new ( "regtest" , Some ( temp_dir. path ( ) . to_path_buf ( ) ) ) ;
280+
281+ // generate descriptors
282+ let desc = cli
283+ . cmd ( "descriptor" , & [ "--type" , "tr" ] )
284+ . output ( )
285+ . expect ( "Command to generate descriptors failed" ) ;
286+
287+ let desc_values: Value =
288+ serde_json:: from_slice ( & desc. stdout ) . expect ( "Invalid JSON from output descriptor" ) ;
289+
290+ let pub_desc = & desc_values[ "public_descriptors" ] ;
291+
292+ let ext_desc = pub_desc[ "external" ] . as_str ( ) . unwrap ( ) ;
293+ let int_desc = pub_desc[ "internal" ] . as_str ( ) . unwrap ( ) ;
294+ let client_type = "rpc" ;
295+ let db: & str = "sqlite" ;
296+ let url = "http://localhost:18443" ;
297+
298+ let mut cmd_init = cli. build_base_cmd ( ) ;
299+ cmd_init
300+ . arg ( "wallet" )
301+ . arg ( "--wallet" )
302+ . arg ( WALLET_NAME )
303+ . arg ( "config" )
304+ . arg ( "--ext-descriptor" )
305+ . arg ( ext_desc)
306+ . arg ( "--int-descriptor" )
307+ . arg ( int_desc)
308+ . arg ( "--client-type" )
309+ . arg ( client_type)
310+ . arg ( "--database-type" )
311+ . arg ( db)
312+ . arg ( "--url" )
313+ . arg ( url) ;
314+ ( cli, cmd_init)
315+ }
316+
317+ #[ test]
318+ fn test_new_and_unused_address ( ) {
319+ let ( cli, mut cmd_init) = setup_wallet_config ( ) ;
320+ cmd_init. assert ( ) . success ( ) ;
321+
322+ // new address
323+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "new_address" ] )
324+ . assert ( )
325+ . success ( )
326+ . stdout ( predicate:: str:: contains ( "\" address\" :" ) ) ;
327+
328+ // `unused-address`
329+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "unused_address" ] )
330+ . assert ( )
331+ . success ( )
332+ . stdout ( predicate:: str:: contains ( "\" address\" :" ) ) ;
333+ }
334+
335+ #[ test]
336+ fn test_empty_wallet_balances_and_lists ( ) {
337+ let ( cli, mut cmd_init) = setup_wallet_config ( ) ;
338+ cmd_init. assert ( ) . success ( ) ;
339+
340+ // balance
341+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "balance" ] )
342+ . assert ( )
343+ . success ( )
344+ . stdout ( predicate:: str:: contains ( "\" total\" :" ) )
345+ . stdout ( predicate:: str:: contains ( "\" trusted_pending\" :" ) )
346+ . stdout ( predicate:: str:: contains ( "\" untrusted_pending\" :" ) )
347+ . stdout ( predicate:: str:: contains ( "\" immature\" :" ) )
348+ . stdout ( predicate:: str:: contains ( "\" confirmed\" :" ) ) ;
349+
350+ // Unspent UTXOs
351+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "unspent" ] )
352+ . assert ( )
353+ . success ( )
354+ . stdout ( predicate:: str:: contains ( "[]" ) ) ;
355+
356+ // Transactions
357+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "transactions" ] )
358+ . assert ( )
359+ . success ( )
360+ . stdout ( predicate:: str:: contains ( "[]" ) ) ;
361+ }
362+
363+ #[ test]
364+ fn test_policies_and_public_descriptor ( ) {
365+ let ( cli, mut cmd_init) = setup_wallet_config ( ) ;
366+ cmd_init. assert ( ) . success ( ) ;
367+
368+ // Policies
369+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "policies" ] )
370+ . assert ( )
371+ . success ( )
372+ . stdout ( predicate:: str:: contains ( "\" external\" :" ) )
373+ . stdout ( predicate:: str:: contains ( "\" internal\" :" ) ) ;
374+
375+ // Public Descriptor
376+ cli. wallet_cmd ( & [ "--wallet" , WALLET_NAME , "public_descriptor" ] )
377+ . assert ( )
378+ . success ( )
379+ . stdout ( predicate:: str:: contains ( "external" ) )
380+ . stdout ( predicate:: str:: contains ( "internal" ) ) ;
381+ }
382+
383+ #[ test]
384+ fn test_create_tx_insufficient_funds ( ) {
385+ let ( cli, mut cmd_init) = setup_wallet_config ( ) ;
386+ cmd_init. assert ( ) . success ( ) ;
387+
388+ // create transaction
389+ cli. wallet_cmd ( & [
390+ "--wallet" ,
391+ WALLET_NAME ,
392+ "create_tx" ,
393+ "--to" ,
394+ "tb1p4tp4l6glyr2gs94neqcpr5gha7344nfyznfkc8szkreflscsdkgqsdent4:1000" ,
395+ ] )
396+ . assert ( )
397+ . failure ( )
398+ . stderr ( predicate:: str:: contains ( "Insufficient" ) ) ;
399+ }
400+
401+ #[ test]
402+ fn test_combine_psbt_invalid_input ( ) {
403+ let ( cli, mut cmd_init) = setup_wallet_config ( ) ;
404+ cmd_init. assert ( ) . success ( ) ;
405+
406+ // Invalid create-tx.
407+ cli. wallet_cmd ( & [
408+ "--wallet" ,
409+ WALLET_NAME ,
410+ "combine_psbt" ,
411+ "invalid_psbt" ,
412+ "another_invalid_psbt" ,
413+ ] )
414+ . assert ( )
415+ . failure ( )
416+ . stderr ( predicate:: str:: contains ( "Invalid" ) ) ;
417+ }
418+ }
0 commit comments