@@ -917,7 +917,56 @@ mod test_online {
917917 "proven_amount should equal the funded UTXO value: {result}"
918918 ) ;
919919 }
920+
921+ // `create_dns_tx` with a plain `--to` recipient
922+ #[ cfg( feature = "dns_payment" ) ]
923+ #[ test]
924+ fn test_create_dns_tx_plain_recipient ( ) {
925+ use bdk_wallet:: bitcoin:: Psbt ;
926+ let ( cli, mut cmd_init, env) = setup_online_wallet ( ) ;
927+ cmd_init. assert ( ) . success ( ) ;
928+ fund_and_sync_wallet ( & cli, & env) ;
929+
930+ let psbt_b64 = run_wallet_json (
931+ & cli,
932+ & [ "create_dns_tx" , "--to" , & format ! ( "{RECIPIENT}:20000" ) ] ,
933+ ) [ "psbt" ]
934+ . as_str ( )
935+ . expect ( "create_dns_tx: missing 'psbt'" )
936+ . to_string ( ) ;
937+
938+ let psbt: Psbt = psbt_b64
939+ . parse ( )
940+ . expect ( "create_dns_tx returned an invalid PSBT" ) ;
941+ assert ! (
942+ psbt. unsigned_tx
943+ . output
944+ . iter( )
945+ . any( |o| o. value. to_sat( ) == 20_000 ) ,
946+ "expected the 20_000 sat recipient output"
947+ ) ;
948+ }
949+
950+ // With neither `--to` nor `--to_dns`, the command errors.
951+ #[ cfg( feature = "dns_payment" ) ]
952+ #[ test]
953+ fn test_create_dns_tx_requires_recipient ( ) {
954+ let ( cli, mut cmd_init, _env) = setup_online_wallet ( ) ;
955+ cmd_init. assert ( ) . success ( ) ;
956+
957+ let out = cli
958+ . wallet_cmd ( & [ "--wallet" , WALLET_NAME , "create_dns_tx" ] )
959+ . output ( )
960+ . unwrap ( ) ;
961+ assert ! ( !out. status. success( ) , "should fail with no recipients" ) ;
962+ assert ! (
963+ String :: from_utf8_lossy( & out. stderr) . contains( "Either --to or --to_dns" ) ,
964+ "expected recipient-required error, got: {}" ,
965+ String :: from_utf8_lossy( & out. stderr)
966+ ) ;
967+ }
920968}
969+
921970#[ cfg( feature = "esplora" ) ]
922971mod test_esplora {
923972 use crate :: common:: BdkCli ;
0 commit comments