mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-09-26 03:11:07 -04:00
Inform user if cancel tx is has already been published
Alice and Bob can both submit cancel. A scenario exists where one of them may try and manually cancel but the other party has already published cancel. Log a message to notify the user this has happened. Add reusable function to check error for bitcoin rpc error code
This commit is contained in:
parent
f511ff093c
commit
110a5d2229
4 changed files with 80 additions and 19 deletions
|
@ -4,6 +4,7 @@ use harness::alice_run_until::is_xmr_lock_transaction_sent;
|
|||
use harness::bob_run_until::is_btc_locked;
|
||||
use harness::SlowCancelConfig;
|
||||
use swap::asb::FixedRate;
|
||||
use swap::bitcoin::{parse_rpc_error_code, RpcErrorCode};
|
||||
use swap::protocol::alice::AliceState;
|
||||
use swap::protocol::bob::BobState;
|
||||
use swap::protocol::{alice, bob};
|
||||
|
@ -41,10 +42,10 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors()
|
|||
let error = cli::cancel(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db)
|
||||
.await
|
||||
.unwrap_err();
|
||||
match error.downcast::<bdk::Error>().unwrap() {
|
||||
bdk::Error::Electrum(bdk::electrum_client::Error::Protocol(..)) => (),
|
||||
unexpected => panic!("Failed to cancel due to unexpected error: {}", unexpected),
|
||||
}
|
||||
assert_eq!(
|
||||
parse_rpc_error_code(&error).unwrap(),
|
||||
i64::from(RpcErrorCode::RpcVerifyRejected)
|
||||
);
|
||||
|
||||
ctx.restart_alice().await;
|
||||
let alice_swap = ctx.alice_next_swap().await;
|
||||
|
@ -54,9 +55,13 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors()
|
|||
));
|
||||
|
||||
// Alice tries but fails manual cancel
|
||||
let result =
|
||||
asb::cancel(alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db).await;
|
||||
assert!(result.is_err());
|
||||
let error = asb::cancel(alice_swap.swap_id, alice_swap.bitcoin_wallet, alice_swap.db)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
parse_rpc_error_code(&error).unwrap(),
|
||||
i64::from(RpcErrorCode::RpcVerifyRejected)
|
||||
);
|
||||
|
||||
let (bob_swap, bob_join_handle) = ctx
|
||||
.stop_and_resume_bob_from_db(bob_join_handle, swap_id)
|
||||
|
@ -67,10 +72,10 @@ async fn given_alice_and_bob_manually_cancel_when_timelock_not_expired_errors()
|
|||
let error = cli::refund(bob_swap.id, bob_swap.bitcoin_wallet, bob_swap.db)
|
||||
.await
|
||||
.unwrap_err();
|
||||
match error.downcast::<bdk::Error>().unwrap() {
|
||||
bdk::Error::Electrum(bdk::electrum_client::Error::Protocol(..)) => (),
|
||||
unexpected => panic!("Failed to refund due to unexpected error: {}", unexpected),
|
||||
}
|
||||
assert_eq!(
|
||||
parse_rpc_error_code(&error).unwrap(),
|
||||
i64::from(RpcErrorCode::RpcVerifyError)
|
||||
);
|
||||
|
||||
let (bob_swap, _) = ctx
|
||||
.stop_and_resume_bob_from_db(bob_join_handle, swap_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue