Skip to content

Commit 5ea933b

Browse files
committed
test: Add tests for dns payment instn feature
1 parent 01c273d commit 5ea933b

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/handlers/online.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct FullScanCommand {
8383
/// Stop searching addresses for transactions after finding an unused gap of this length.
8484
#[arg(env = "STOP_GAP", long = "scan-stop-gap", default_value = "20")]
8585
stop_gap: usize,
86-
// #[clap(long, default_value = "5")]
86+
#[clap(long, default_value = "5")]
8787
pub parallel_request: usize,
8888
}
8989

tests/integration/online.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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")]
922971
mod test_esplora {
923972
use crate::common::BdkCli;

0 commit comments

Comments
 (0)