Skip to content

Commit

Permalink
Use the correct dust limit. Add test. Fix existing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Martin committed Mar 13, 2023
1 parent 3397fa6 commit 7f921fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ impl TransactionBuilder {
}

fn select_outgoing(mut self) -> Result<Self> {
let dust_limit = self.recipient.script_pubkey().dust_value().to_sat();
let dust_limit = self
.unused_change_addresses
.last()
.unwrap()
.script_pubkey()
.dust_value()
.to_sat();
for (inscribed_satpoint, inscription_id) in self.inscriptions.iter().rev() {
if self.outgoing.outpoint == inscribed_satpoint.outpoint
&& self.outgoing.offset != inscribed_satpoint.offset
Expand Down
28 changes: 25 additions & 3 deletions tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn send_does_not_use_inscribed_sats_as_cardinal_utxos() {
}

#[test]
fn do_not_accidentally_send_an_inscription() {
fn do_not_send_within_dust_limit_of_an_inscription() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);

Expand All @@ -182,16 +182,38 @@ fn do_not_accidentally_send_an_inscription() {
};

CommandBuilder::new(format!(
"wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {output}:55"
"wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {output}:329"
))
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr(format!(
"error: cannot send {output}:55 without also sending inscription {inscription} at {output}:0\n"
"error: cannot send {output}:329 without also sending inscription {inscription} at {output}:0\n"
))
.run();
}

#[test]
fn can_send_after_dust_limit_from_an_inscription() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);

let Inscribe { reveal, .. } = inscribe(&rpc_server);

rpc_server.mine_blocks(1);

let output = OutPoint {
txid: reveal,
vout: 0,
};

CommandBuilder::new(format!(
"wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {output}:330"
))
.rpc_server(&rpc_server)
.stdout_regex("[[:xdigit:]]{64}\n")
.run();
}

#[test]
fn inscriptions_cannot_be_sent_by_satpoint() {
let rpc_server = test_bitcoincore_rpc::spawn();
Expand Down

0 comments on commit 7f921fb

Please sign in to comment.