mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-29 03:56:33 -05:00
Make it easier to create a bitcoin::Wallet for testing
Forcing the user to create an implementation of `EstimateFeeRate` every time they want to create a wallet for testing is tedious and leads to duplicated code. The implementation for tests is rarely dynamic and thus can be simplified to static arguments. This also allows us to provide convenience constructors to make tests that don't care about fees less distracting by reducing the number of constants that are floating around.
This commit is contained in:
parent
baf5a0896e
commit
51316d8183
3 changed files with 51 additions and 71 deletions
|
|
@ -265,10 +265,8 @@ pub struct NotThreeWitnesses(usize);
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bitcoin::wallet::EstimateFeeRate;
|
||||
use crate::env::{GetConfig, Regtest};
|
||||
use crate::protocol::{alice, bob};
|
||||
use bdk::FeeRate;
|
||||
use rand::rngs::OsRng;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
@ -317,21 +315,10 @@ mod tests {
|
|||
assert_eq!(expired_timelock, ExpiredTimelocks::Punish)
|
||||
}
|
||||
|
||||
struct StaticFeeRate {}
|
||||
impl EstimateFeeRate for StaticFeeRate {
|
||||
fn estimate_feerate(&self, _target_block: usize) -> Result<FeeRate> {
|
||||
Ok(FeeRate::default_min_relay_fee())
|
||||
}
|
||||
|
||||
fn min_relay_fee(&self) -> Result<bitcoin::Amount> {
|
||||
Ok(bitcoin::Amount::from_sat(1_000))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn calculate_transaction_weights() {
|
||||
let alice_wallet = Wallet::new_funded(Amount::ONE_BTC.as_sat(), StaticFeeRate {});
|
||||
let bob_wallet = Wallet::new_funded(Amount::ONE_BTC.as_sat(), StaticFeeRate {});
|
||||
let alice_wallet = Wallet::new_funded_default_fees(Amount::ONE_BTC.as_sat());
|
||||
let bob_wallet = Wallet::new_funded_default_fees(Amount::ONE_BTC.as_sat());
|
||||
let spending_fee = Amount::from_sat(1_000);
|
||||
let btc_amount = Amount::from_sat(500_000);
|
||||
let xmr_amount = crate::monero::Amount::from_piconero(10000);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue