]> Untitled Git - bdk-cli/commitdiff
test: Add tests for dns payment instn feature
authorVihiga Tyonum <withtvpeter@gmail.com>
Wed, 8 Jul 2026 18:55:23 +0000 (19:55 +0100)
committerVihiga Tyonum <withtvpeter@gmail.com>
Wed, 8 Jul 2026 21:49:32 +0000 (22:49 +0100)
src/handlers/online.rs
tests/integration/online.rs

index 2aa2ffca8b68f2a79f990756d69ca969b52dbbd5..f2900cbca08ac5ec8d0af84ab3632ec5b9b5b903 100644 (file)
@@ -83,7 +83,7 @@ pub struct FullScanCommand {
     /// Stop searching addresses for transactions after finding an unused gap of this length.
     #[arg(env = "STOP_GAP", long = "scan-stop-gap", default_value = "20")]
     stop_gap: usize,
-    // #[clap(long, default_value = "5")]
+    #[clap(long, default_value = "5")]
     pub parallel_request: usize,
 }
 
index 7f370583cd1f39700143bf84f27ccea0589ea57b..0ba166d540da0e398017f0f3a7028978923b4085 100644 (file)
@@ -917,7 +917,56 @@ mod test_online {
             "proven_amount should equal the funded UTXO value: {result}"
         );
     }
+
+    // `create_dns_tx` with a plain `--to` recipient
+    #[cfg(feature = "dns_payment")]
+    #[test]
+    fn test_create_dns_tx_plain_recipient() {
+        use bdk_wallet::bitcoin::Psbt;
+        let (cli, mut cmd_init, env) = setup_online_wallet();
+        cmd_init.assert().success();
+        fund_and_sync_wallet(&cli, &env);
+
+        let psbt_b64 = run_wallet_json(
+            &cli,
+            &["create_dns_tx", "--to", &format!("{RECIPIENT}:20000")],
+        )["psbt"]
+            .as_str()
+            .expect("create_dns_tx: missing 'psbt'")
+            .to_string();
+
+        let psbt: Psbt = psbt_b64
+            .parse()
+            .expect("create_dns_tx returned an invalid PSBT");
+        assert!(
+            psbt.unsigned_tx
+                .output
+                .iter()
+                .any(|o| o.value.to_sat() == 20_000),
+            "expected the 20_000 sat recipient output"
+        );
+    }
+
+    // With neither `--to` nor `--to_dns`, the command errors.
+    #[cfg(feature = "dns_payment")]
+    #[test]
+    fn test_create_dns_tx_requires_recipient() {
+        let (cli, mut cmd_init, _env) = setup_online_wallet();
+        cmd_init.assert().success();
+
+        let out = cli
+            .wallet_cmd(&["--wallet", WALLET_NAME, "create_dns_tx"])
+            .output()
+            .unwrap();
+        assert!(!out.status.success(), "should fail with no recipients");
+        assert!(
+            String::from_utf8_lossy(&out.stderr).contains("Either --to or --to_dns"),
+            "expected recipient-required error, got: {}",
+            String::from_utf8_lossy(&out.stderr)
+        );
+    }
 }
+
 #[cfg(feature = "esplora")]
 mod test_esplora {
     use crate::common::BdkCli;