mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Fix happy path test
Poll bob swarm to send encsig after calling send message3. Comment out unimplmented wait for transaction finality trait. Dial alice.
This commit is contained in:
parent
fa243e2fd7
commit
47c3ddc6f7
@ -142,10 +142,10 @@ where
|
||||
.await
|
||||
.context("Failed to find lock Bitcoin tx")?;
|
||||
|
||||
// We saw the transaction in the mempool, waiting for it to be confirmed.
|
||||
bitcoin_wallet
|
||||
.wait_for_transaction_finality(lock_bitcoin_txid)
|
||||
.await;
|
||||
// // We saw the transaction in the mempool, waiting for it to be confirmed.
|
||||
// bitcoin_wallet
|
||||
// .wait_for_transaction_finality(lock_bitcoin_txid)
|
||||
// .await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -235,8 +235,8 @@ where
|
||||
.broadcast_signed_transaction(redeem_tx)
|
||||
.await?;
|
||||
|
||||
// TODO(Franck): Not sure if we wait for finality here or just mined
|
||||
bitcoin_wallet.wait_for_transaction_finality(tx_id).await;
|
||||
// // TODO(Franck): Not sure if we wait for finality here or just mined
|
||||
// bitcoin_wallet.wait_for_transaction_finality(tx_id).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -370,7 +370,8 @@ where
|
||||
.broadcast_signed_transaction(punish_tx)
|
||||
.await?;
|
||||
|
||||
bitcoin_wallet.wait_for_transaction_finality(txid).await;
|
||||
// todo: enable this once trait is implemented
|
||||
// bitcoin_wallet.wait_for_transaction_finality(txid).await;
|
||||
|
||||
Ok(txid)
|
||||
}
|
||||
|
@ -3,24 +3,25 @@ use crate::{
|
||||
Cmd, Rsp, SwapAmounts,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use libp2p::core::Multiaddr;
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use std::sync::Arc;
|
||||
use tokio::{stream::StreamExt, sync::mpsc};
|
||||
|
||||
use xmr_btc::bob::State2;
|
||||
|
||||
pub async fn negotiate<R>(
|
||||
state0: xmr_btc::bob::State0,
|
||||
amounts: SwapAmounts,
|
||||
swarm: &mut Swarm,
|
||||
addr: Multiaddr,
|
||||
mut rng: R,
|
||||
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
||||
) -> Result<(SwapAmounts, State2)>
|
||||
where
|
||||
R: RngCore + CryptoRng + Send,
|
||||
{
|
||||
// todo: dial the swarm outside
|
||||
// libp2p::Swarm::dial_addr(&mut swarm, addr)?;
|
||||
libp2p::Swarm::dial_addr(swarm, addr)?;
|
||||
|
||||
let alice = match swarm.next().await {
|
||||
OutEvent::ConnectionEstablished(alice) => alice,
|
||||
other => panic!("unexpected event: {:?}", other),
|
||||
|
@ -5,9 +5,10 @@ use crate::{
|
||||
};
|
||||
use anyhow::Result;
|
||||
use async_recursion::async_recursion;
|
||||
use libp2p::PeerId;
|
||||
use libp2p::{core::Multiaddr, PeerId};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use std::sync::Arc;
|
||||
use tracing::debug;
|
||||
use uuid::Uuid;
|
||||
use xmr_btc::bob::{self};
|
||||
|
||||
@ -18,6 +19,7 @@ pub enum BobState {
|
||||
state0: bob::State0,
|
||||
amounts: SwapAmounts,
|
||||
peer_id: PeerId,
|
||||
addr: Multiaddr,
|
||||
},
|
||||
Negotiated(bob::State2, PeerId),
|
||||
BtcLocked(bob::State3, PeerId),
|
||||
@ -50,11 +52,13 @@ where
|
||||
state0,
|
||||
amounts,
|
||||
peer_id,
|
||||
addr,
|
||||
} => {
|
||||
let (swap_amounts, state2) = negotiate(
|
||||
state0,
|
||||
amounts,
|
||||
&mut swarm,
|
||||
addr,
|
||||
&mut rng,
|
||||
bitcoin_wallet.clone(),
|
||||
)
|
||||
@ -118,6 +122,17 @@ where
|
||||
// should happen in this arm?
|
||||
swarm.send_message3(alice_peer_id.clone(), tx_redeem_encsig);
|
||||
|
||||
// Sadly we have to poll the swarm to get make sure the message is sent?
|
||||
// FIXME: Having to wait for Alice's response here is a big problem, because
|
||||
// we're stuck if she doesn't send her response back. I believe this is
|
||||
// currently necessary, so we may have to rework this and/or how we use libp2p
|
||||
match swarm.next().await {
|
||||
OutEvent::Message3 => {
|
||||
debug!("Got Message3 empty response");
|
||||
}
|
||||
other => panic!("unexpected event: {:?}", other),
|
||||
};
|
||||
|
||||
swap(
|
||||
BobState::EncSigSent(state, alice_peer_id),
|
||||
swarm,
|
||||
|
@ -179,8 +179,6 @@ async fn simple_swap_happy_path() {
|
||||
));
|
||||
let bob_xmr_wallet = Arc::new(swap::monero::Wallet(monero.wallet("bob").unwrap().client()));
|
||||
|
||||
// let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
|
||||
// let punish_address = redeem_address.clone();
|
||||
let amounts = SwapAmounts {
|
||||
btc,
|
||||
xmr: xmr_btc::monero::Amount::from_piconero(xmr),
|
||||
@ -201,7 +199,8 @@ async fn simple_swap_happy_path() {
|
||||
v_a,
|
||||
}
|
||||
};
|
||||
let alice_swarm = alice::new_swarm(alice_multiaddr, alice_transport, alice_behaviour).unwrap();
|
||||
let alice_swarm =
|
||||
alice::new_swarm(alice_multiaddr.clone(), alice_transport, alice_behaviour).unwrap();
|
||||
let alice_swap = alice::swap::swap(
|
||||
alice_state,
|
||||
alice_swarm,
|
||||
@ -227,6 +226,7 @@ async fn simple_swap_happy_path() {
|
||||
state0,
|
||||
amounts,
|
||||
peer_id: alice_peer_id,
|
||||
addr: alice_multiaddr,
|
||||
};
|
||||
let bob_swarm = bob::new_swarm(bob_transport, bob_behaviour).unwrap();
|
||||
let bob_swap = bob::swap::swap(
|
||||
|
Loading…
Reference in New Issue
Block a user