mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-04 15:55:04 -04:00
Make lock-tx id available in redeem/punish state to be able to assert exact fees
This commit is contained in:
parent
317b251302
commit
8615aaed6e
6 changed files with 63 additions and 30 deletions
|
@ -45,13 +45,6 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||
let bob = bob_harness.recover_bob_from_db().await;
|
||||
assert!(matches!(bob.state, BobState::BtcLocked {..}));
|
||||
|
||||
// TODO: make lock-tx-id available in final states
|
||||
let lock_tx_id = if let BobState::BtcLocked(state3) = bob_state {
|
||||
state3.tx_lock_id()
|
||||
} else {
|
||||
panic!("Bob in unexpected state");
|
||||
};
|
||||
|
||||
let bob_state = bob::swap(
|
||||
bob.state,
|
||||
bob.event_loop_handle,
|
||||
|
@ -64,7 +57,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
bob_harness.assert_punished(bob_state, lock_tx_id).await;
|
||||
bob_harness.assert_punished(bob_state).await;
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
|
|
@ -363,10 +363,23 @@ impl BobHarness {
|
|||
}
|
||||
|
||||
pub async fn assert_redeemed(&self, state: BobState) {
|
||||
assert!(matches!(state, BobState::XmrRedeemed));
|
||||
let lock_tx_id = if let BobState::XmrRedeemed(state6) = state {
|
||||
state6.tx_lock_id()
|
||||
} else {
|
||||
panic!("Bob in unexpected state");
|
||||
};
|
||||
|
||||
let lock_tx_bitcoin_fee = self
|
||||
.bitcoin_wallet
|
||||
.transaction_fee(lock_tx_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let btc_balance_after_swap = self.bitcoin_wallet.as_ref().balance().await.unwrap();
|
||||
assert!(btc_balance_after_swap <= self.starting_balances.btc - self.swap_amounts.btc);
|
||||
assert_eq!(
|
||||
btc_balance_after_swap,
|
||||
self.starting_balances.btc - self.swap_amounts.btc - lock_tx_bitcoin_fee
|
||||
);
|
||||
|
||||
// Ensure that Bob's balance is refreshed as we use a newly created wallet
|
||||
self.monero_wallet.as_ref().inner.refresh().await.unwrap();
|
||||
|
@ -409,8 +422,12 @@ impl BobHarness {
|
|||
assert_eq!(xmr_balance_after_swap, self.starting_balances.xmr);
|
||||
}
|
||||
|
||||
pub async fn assert_punished(&self, state: BobState, lock_tx_id: ::bitcoin::Txid) {
|
||||
assert!(matches!(state, BobState::BtcPunished));
|
||||
pub async fn assert_punished(&self, state: BobState) {
|
||||
let lock_tx_id = if let BobState::BtcPunished(state6) = state {
|
||||
state6.tx_lock_id()
|
||||
} else {
|
||||
panic!("Bob in unexpected state");
|
||||
};
|
||||
|
||||
let lock_tx_bitcoin_fee = self
|
||||
.bitcoin_wallet
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue