spend: reword warning messages

This commit is contained in:
jp1ac4 2024-03-28 10:58:49 +00:00
parent 8078a2791a
commit 5d6ca97e4c
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B
3 changed files with 51 additions and 13 deletions

View File

@ -1571,7 +1571,14 @@ mod tests {
); );
assert_eq!(tx.output[0].value.to_sat(), 95_000); assert_eq!(tx.output[0].value.to_sat(), 95_000);
// change = 100_000 - 95_000 - /* fee without change */ 127 - /* extra fee for change output */ 43 = 4830 // change = 100_000 - 95_000 - /* fee without change */ 127 - /* extra fee for change output */ 43 = 4830
assert_eq!(warnings, vec!["Change amount of 4830 sats added to fee as it was too small to create a transaction output."]); assert_eq!(
warnings,
vec![
"Dust UTXO. The minimal change output allowed by Liana is 5000 sats. \
Instead of creating a change of 4830 sats, it was added to the \
transaction fee. Select a larger input to avoid this from happening."
]
);
// Increase the target value by the change amount and the warning will disappear. // Increase the target value by the change amount and the warning will disappear.
*destinations.get_mut(&dummy_addr).unwrap() = 95_000 + 4_830; *destinations.get_mut(&dummy_addr).unwrap() = 95_000 + 4_830;
@ -1622,7 +1629,14 @@ mod tests {
panic!("expect successful spend creation") panic!("expect successful spend creation")
}; };
// Message uses "sat" instead of "sats" when value is 1. // Message uses "sat" instead of "sats" when value is 1.
assert_eq!(warnings, vec!["Change amount of 1 sat added to fee as it was too small to create a transaction output."]); assert_eq!(
warnings,
vec![
"Dust UTXO. The minimal change output allowed by Liana is 5000 sats. \
Instead of creating a change of 1 sat, it was added to the \
transaction fee. Select a larger input to avoid this from happening."
]
);
// Now decrease the target value so that we have enough for a change output. // Now decrease the target value so that we have enough for a change output.
*destinations.get_mut(&dummy_addr).unwrap() = *destinations.get_mut(&dummy_addr).unwrap() =
@ -1651,7 +1665,14 @@ mod tests {
} else { } else {
panic!("expect successful spend creation") panic!("expect successful spend creation")
}; };
assert_eq!(warnings, vec!["Change amount of 4999 sats added to fee as it was too small to create a transaction output."]); assert_eq!(
warnings,
vec![
"Dust UTXO. The minimal change output allowed by Liana is 5000 sats. \
Instead of creating a change of 4999 sats, it was added to the \
transaction fee. Select a larger input to avoid this from happening."
]
);
// Now if we mark the coin as spent, we won't create another Spend transaction containing // Now if we mark the coin as spent, we won't create another Spend transaction containing
// it. // it.

View File

@ -551,15 +551,20 @@ impl fmt::Display for CreateSpendWarning {
match self { match self {
CreateSpendWarning::ChangeAddedToFee(amt) => write!( CreateSpendWarning::ChangeAddedToFee(amt) => write!(
f, f,
"Change amount of {} sat{} added to fee as it was too small to create a transaction output.", "Dust UTXO. The minimal change output allowed by Liana is {} sats. \
Instead of creating a change of {} sat{}, it was added to the \
transaction fee. Select a larger input to avoid this from happening.",
DUST_OUTPUT_SATS,
amt, amt,
if *amt > 1 {"s"} else {""}, if *amt > 1 { "s" } else { "" },
), ),
CreateSpendWarning::AdditionalFeeForAncestors(amt) => write!( CreateSpendWarning::AdditionalFeeForAncestors(amt) => write!(
f, f,
"An additional fee of {} sat{} has been added to pay for ancestors at the target feerate.", "CPFP: an unconfirmed input was selected. The current transaction fee \
was increased by {} sat{} to make the average feerate of both the input \
and current transaction equal to the selected feerate.",
amt, amt,
if *amt > 1 {"s"} else {""}, if *amt > 1 { "s" } else { "" },
), ),
} }
} }

View File

@ -141,7 +141,9 @@ def test_coin_marked_spent(lianad, bitcoind):
assert len(res["warnings"]) == 1 assert len(res["warnings"]) == 1
assert ( assert (
res["warnings"][0] res["warnings"][0]
== f"Change amount of {change_amount} sats added to fee as it was too small to create a transaction output." == "Dust UTXO. The minimal change output allowed by Liana is 5000 sats. "
f"Instead of creating a change of {change_amount} sats, it was added to the "
"transaction fee. Select a larger input to avoid this from happening."
) )
# Spend the third coin to an address of ours, no change # Spend the third coin to an address of ours, no change
@ -158,7 +160,9 @@ def test_coin_marked_spent(lianad, bitcoind):
assert len(res["warnings"]) == 1 assert len(res["warnings"]) == 1
assert ( assert (
res["warnings"][0] res["warnings"][0]
== f"Change amount of {change_amount} sats added to fee as it was too small to create a transaction output." == "Dust UTXO. The minimal change output allowed by Liana is 5000 sats. "
f"Instead of creating a change of {change_amount} sats, it was added to the "
"transaction fee. Select a larger input to avoid this from happening."
) )
# Spend the fourth coin to an address of ours, with change # Spend the fourth coin to an address of ours, with change
@ -194,7 +198,9 @@ def test_coin_marked_spent(lianad, bitcoind):
assert len(res["warnings"]) == 1 assert len(res["warnings"]) == 1
assert ( assert (
res["warnings"][0] res["warnings"][0]
== f"An additional fee of {additional_fee} sats has been added to pay for ancestors at the target feerate." == "CPFP: an unconfirmed input was selected. The current transaction fee "
f"was increased by {additional_fee} sats to make the average feerate of "
"both the input and current transaction equal to the selected feerate."
) )
# All the spent coins must have been detected as such # All the spent coins must have been detected as such
@ -346,7 +352,9 @@ def test_coin_selection(lianad, bitcoind):
assert len(spend_res_2["warnings"]) == 1 assert len(spend_res_2["warnings"]) == 1
assert ( assert (
spend_res_2["warnings"][0] spend_res_2["warnings"][0]
== f"An additional fee of {additional_fee} sats has been added to pay for ancestors at the target feerate." == "CPFP: an unconfirmed input was selected. The current transaction fee "
f"was increased by {additional_fee} sats to make the average feerate of "
"both the input and current transaction equal to the selected feerate."
) )
# Try 3 sat/vb: # Try 3 sat/vb:
@ -366,7 +374,9 @@ def test_coin_selection(lianad, bitcoind):
assert len(spend_res_2["warnings"]) == 1 assert len(spend_res_2["warnings"]) == 1
assert ( assert (
spend_res_2["warnings"][0] spend_res_2["warnings"][0]
== f"An additional fee of {additional_fee} sats has been added to pay for ancestors at the target feerate." == "CPFP: an unconfirmed input was selected. The current transaction fee "
f"was increased by {additional_fee} sats to make the average feerate of "
"both the input and current transaction equal to the selected feerate."
) )
# 2 sat/vb is same feerate as ancestor and we have no warnings: # 2 sat/vb is same feerate as ancestor and we have no warnings:
@ -416,7 +426,9 @@ def test_coin_selection(lianad, bitcoind):
assert len(spend_res_3["warnings"]) == 1 assert len(spend_res_3["warnings"]) == 1
assert ( assert (
spend_res_3["warnings"][0] spend_res_3["warnings"][0]
== f"An additional fee of {additional_fee} sats has been added to pay for ancestors at the target feerate." == "CPFP: an unconfirmed input was selected. The current transaction fee "
f"was increased by {additional_fee} sats to make the average feerate of "
"both the input and current transaction equal to the selected feerate."
) )
spend_psbt_3 = PSBT.from_base64(spend_res_3["psbt"]) spend_psbt_3 = PSBT.from_base64(spend_res_3["psbt"])
spend_txid_3 = sign_and_broadcast_psbt(lianad, spend_psbt_3) spend_txid_3 = sign_and_broadcast_psbt(lianad, spend_psbt_3)