From 622eac38d55b0e8e7a509e0203f2cd6f7a6d63ef Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Wed, 5 Feb 2025 08:25:58 +0100 Subject: [PATCH] Use a stub preimage --- src/swaps/bitcoin.rs | 13 +++---------- src/swaps/liquid.rs | 7 ++----- tests/regtest.rs | 35 ++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/swaps/bitcoin.rs b/src/swaps/bitcoin.rs index 7ce80cc..454639f 100644 --- a/src/swaps/bitcoin.rs +++ b/src/swaps/bitcoin.rs @@ -1208,19 +1208,12 @@ impl BtcSwapTx { /// The `preimage` is only required when calculating the claim tx size. /// Use this before calling drain to help calculate the absolute fees. /// Multiply the size by the fee_rate to get the absolute fees. - pub fn size( - &self, - keys: &Keypair, - preimage: Option<&Preimage>, - is_cooperative: bool, - ) -> Result { + pub fn size(&self, keys: &Keypair, is_cooperative: bool) -> Result { let dummy_abs_fee = 1; let tx = match self.kind { SwapTxKind::Claim => { - let Some(preimage) = preimage else { - return Err(Error::Protocol("No preimage provided.".to_string())); - }; - self.create_claim(keys, preimage, dummy_abs_fee, is_cooperative)? + let preimage = Preimage::from_vec([0; 32].to_vec())?; + self.create_claim(keys, &preimage, dummy_abs_fee, is_cooperative)? } SwapTxKind::Refund => self.create_refund(keys, dummy_abs_fee, is_cooperative)?, }; diff --git a/src/swaps/liquid.rs b/src/swaps/liquid.rs index fcdf614..1ce9379 100644 --- a/src/swaps/liquid.rs +++ b/src/swaps/liquid.rs @@ -1268,17 +1268,14 @@ impl LBtcSwapTx { pub fn size( &self, keys: &Keypair, - preimage: Option<&Preimage>, is_cooperative: bool, is_discount_ct: bool, ) -> Result { let dummy_abs_fee = 1; let tx = match self.kind { SwapTxKind::Claim => { - let Some(preimage) = preimage else { - return Err(Error::Protocol("No preimage provided.".to_string())); - }; - self.create_claim(keys, preimage, dummy_abs_fee, is_cooperative)? + let preimage = Preimage::from_vec([0; 32].to_vec())?; + self.create_claim(keys, &preimage, dummy_abs_fee, is_cooperative)? } SwapTxKind::Refund => self.create_refund(keys, dummy_abs_fee, is_cooperative)?, }; diff --git a/tests/regtest.rs b/tests/regtest.rs index f19a7e8..5d98c79 100644 --- a/tests/regtest.rs +++ b/tests/regtest.rs @@ -109,15 +109,13 @@ fn prepare_btc_claim() -> ( #[test] fn btc_reverse_claim_size() { - let (_test_framework, _scan_request, swap_tx, preimage, recvr_keypair, _utxos) = + let (_test_framework, _scan_request, swap_tx, _preimage, recvr_keypair, _utxos) = prepare_btc_claim(); - let coop_claim_tx_size = swap_tx.size(&recvr_keypair, Some(&preimage), true).unwrap(); + let coop_claim_tx_size = swap_tx.size(&recvr_keypair, true).unwrap(); assert_eq!(coop_claim_tx_size, 84); - let non_coop_claim_tx_size = swap_tx - .size(&recvr_keypair, Some(&preimage), false) - .unwrap(); + let non_coop_claim_tx_size = swap_tx.size(&recvr_keypair, false).unwrap(); assert_eq!(non_coop_claim_tx_size, 140); } @@ -277,10 +275,10 @@ fn prepare_btc_refund() -> ( fn btc_submarine_refund_size() { let (_test_framework, _scan_request, swap_tx, sender_keypair, _utxos) = prepare_btc_refund(); - let coop_refund_tx_size = swap_tx.size(&sender_keypair, None, true).unwrap(); + let coop_refund_tx_size = swap_tx.size(&sender_keypair, true).unwrap(); assert_eq!(coop_refund_tx_size, 84); - let non_coop_refund_tx_size = swap_tx.size(&sender_keypair, None, false).unwrap(); + let non_coop_refund_tx_size = swap_tx.size(&sender_keypair, false).unwrap(); assert_eq!(non_coop_refund_tx_size, 126); } @@ -441,17 +439,20 @@ fn prepare_lbtc_claim() -> ( #[test] fn lbtc_reverse_claim_size() { - let (_test_framework, swap_tx, preimage, recvr_keypair, _blinding_keypair, _swap_addrs, _utxos) = - prepare_lbtc_claim(); + let ( + _test_framework, + swap_tx, + _preimage, + recvr_keypair, + _blinding_keypair, + _swap_addrs, + _utxos, + ) = prepare_lbtc_claim(); - let coop_claim_tx_size = swap_tx - .size(&recvr_keypair, Some(&preimage), true, true) - .unwrap(); + let coop_claim_tx_size = swap_tx.size(&recvr_keypair, true, true).unwrap(); assert_eq!(coop_claim_tx_size, 165); - let non_coop_claim_tx_size = swap_tx - .size(&recvr_keypair, Some(&preimage), false, true) - .unwrap(); + let non_coop_claim_tx_size = swap_tx.size(&recvr_keypair, false, true).unwrap(); assert_eq!(non_coop_claim_tx_size, 221); } @@ -590,10 +591,10 @@ fn lbtc_submarine_refund_size() { let (_test_framework, swap_tx, sender_keypair, _blinding_keypair, _swap_addrs, _utxos) = prepare_lbtc_refund(); - let coop_refund_tx_size = swap_tx.size(&sender_keypair, None, true, true).unwrap(); + let coop_refund_tx_size = swap_tx.size(&sender_keypair, true, true).unwrap(); assert_eq!(coop_refund_tx_size, 165); - let non_coop_refund_tx_size = swap_tx.size(&sender_keypair, None, false, true).unwrap(); + let non_coop_refund_tx_size = swap_tx.size(&sender_keypair, false, true).unwrap(); assert_eq!(non_coop_refund_tx_size, 207); }