Implement traits Receive{BitcoinRedeemEncsig, TransferProof}

Unfortunately, I had to put the wrap the swarm in Alice's `Network`
struct in an `Arc<Mutex<T>>` in order to be able to use `backoff` to
control the retry mechanism. This is because the stream of events
cannot be turned into a `SharedFuture` (unlike Bob's).

It would be good to find an alternative solution.
This commit is contained in:
Lucas Soriano del Pino 2020-10-27 17:18:19 +11:00
parent a4e4c27bee
commit 3f43581da7
3 changed files with 65 additions and 25 deletions

View file

@ -168,7 +168,7 @@ async fn swap_as_alice(
}
async fn swap_as_bob(
network: BobNetwork,
network: Arc<Mutex<BobNetwork>>,
mut sender: Sender<EncryptedSignature>,
monero_wallet: Arc<harness::wallet::monero::Wallet>,
bitcoin_wallet: Arc<harness::wallet::bitcoin::Wallet>,
@ -274,11 +274,9 @@ async fn on_chain_happy_path() {
let (alice_network, bob_sender) = Network::<EncryptedSignature>::new();
let (bob_network, alice_sender) = Network::<TransferProof>::new();
let alice_network = Arc::new(Mutex::new(alice_network));
try_join(
swap_as_alice(
alice_network,
Arc::new(Mutex::new(alice_network)),
alice_sender,
alice_monero_wallet.clone(),
alice_bitcoin_wallet.clone(),
@ -286,7 +284,7 @@ async fn on_chain_happy_path() {
alice,
),
swap_as_bob(
bob_network,
Arc::new(Mutex::new(bob_network)),
bob_sender,
bob_monero_wallet.clone(),
bob_bitcoin_wallet.clone(),
@ -367,11 +365,9 @@ async fn on_chain_both_refund_if_alice_never_redeems() {
let (alice_network, bob_sender) = Network::<EncryptedSignature>::new();
let (bob_network, alice_sender) = Network::<TransferProof>::new();
let alice_network = Arc::new(Mutex::new(alice_network));
try_join(
swap_as_alice(
alice_network,
Arc::new(Mutex::new(alice_network)),
alice_sender,
alice_monero_wallet.clone(),
alice_bitcoin_wallet.clone(),
@ -382,7 +378,7 @@ async fn on_chain_both_refund_if_alice_never_redeems() {
alice,
),
swap_as_bob(
bob_network,
Arc::new(Mutex::new(bob_network)),
bob_sender,
bob_monero_wallet.clone(),
bob_bitcoin_wallet.clone(),
@ -464,10 +460,8 @@ async fn on_chain_alice_punishes_if_bob_never_acts_after_fund() {
let (alice_network, bob_sender) = Network::<EncryptedSignature>::new();
let (bob_network, alice_sender) = Network::<TransferProof>::new();
let alice_network = Arc::new(Mutex::new(alice_network));
let alice_swap = swap_as_alice(
alice_network,
Arc::new(Mutex::new(alice_network)),
alice_sender,
alice_monero_wallet.clone(),
alice_bitcoin_wallet.clone(),
@ -475,7 +469,7 @@ async fn on_chain_alice_punishes_if_bob_never_acts_after_fund() {
alice,
);
let bob_swap = swap_as_bob(
bob_network,
Arc::new(Mutex::new(bob_network)),
bob_sender,
bob_monero_wallet.clone(),
bob_bitcoin_wallet.clone(),