From c316ea5244f3d3184d8ada07e9af0b3a1f506172 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 3 Feb 2021 16:20:59 +1100 Subject: [PATCH] Upgrade toolchain Needed to use libp2p-async-await --- monero-harness/rustfmt.toml | 2 +- monero-harness/src/image.rs | 15 ++++++--------- rust-toolchain | 2 +- rustfmt.toml | 2 +- swap/src/bitcoin/wallet.rs | 3 +-- swap/src/config/seed.rs | 2 +- swap/src/protocol/alice/swap.rs | 4 +--- swap/tests/happy_path_restart_alice.rs | 4 ++-- swap/tests/happy_path_restart_bob_after_comm.rs | 4 ++-- ..._path_restart_bob_after_lock_proof_received.rs | 8 +++++--- swap/tests/happy_path_restart_bob_before_comm.rs | 4 ++-- swap/tests/punish.rs | 4 ++-- swap/tests/refund_restart_alice.rs | 5 ++--- swap/tests/refund_restart_alice_cancelled.rs | 5 ++--- swap/tests/testutils/mod.rs | 10 ++-------- 15 files changed, 31 insertions(+), 43 deletions(-) diff --git a/monero-harness/rustfmt.toml b/monero-harness/rustfmt.toml index 100f5106..d973e35c 100644 --- a/monero-harness/rustfmt.toml +++ b/monero-harness/rustfmt.toml @@ -1,7 +1,7 @@ edition = "2018" condense_wildcard_suffixes = true format_macro_matchers = true -merge_imports = true +imports_granularity = "Crate" use_field_init_shorthand = true format_code_in_doc_comments = true normalize_comments = true diff --git a/monero-harness/src/image.rs b/monero-harness/src/image.rs index a491a345..81cc8723 100644 --- a/monero-harness/src/image.rs +++ b/monero-harness/src/image.rs @@ -303,14 +303,11 @@ impl IntoIterator for Args { type IntoIter = ::std::vec::IntoIter; fn into_iter(self) -> ::IntoIter { - let mut args = Vec::new(); - - args.push("/bin/bash".into()); - args.push("-c".into()); - - let cmd = format!("{} ", self.image_args.args()); - args.push(cmd); - - args.into_iter() + vec![ + "/bin/bash".to_string(), + "-c".to_string(), + format!("{} ", self.image_args.args()), + ] + .into_iter() } } diff --git a/rust-toolchain b/rust-toolchain index a66b2431..97e6da5f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-08-13 +nightly-2021-01-31 diff --git a/rustfmt.toml b/rustfmt.toml index 100f5106..d973e35c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,7 +1,7 @@ edition = "2018" condense_wildcard_suffixes = true format_macro_matchers = true -merge_imports = true +imports_granularity = "Crate" use_field_init_shorthand = true format_code_in_doc_comments = true normalize_comments = true diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 793394ae..584fe5cc 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -157,8 +157,7 @@ impl TransactionBlockHeight for Wallet { .await .map_err(|_| backoff::Error::Transient(Error::Io))?; - let block_height = - block_height.ok_or_else(|| backoff::Error::Transient(Error::NotYetMined))?; + let block_height = block_height.ok_or(backoff::Error::Transient(Error::NotYetMined))?; Result::<_, backoff::Error>::Ok(block_height) }) diff --git a/swap/src/config/seed.rs b/swap/src/config/seed.rs index 371225e3..ef6382f7 100644 --- a/swap/src/config/seed.rs +++ b/swap/src/config/seed.rs @@ -17,7 +17,7 @@ impl Seed { Ok(Seed(seed::Seed::random()?)) } - pub fn from_file_or_generate(data_dir: &PathBuf) -> Result { + pub fn from_file_or_generate(data_dir: &Path) -> Result { let file_path_buf = data_dir.join("seed.pem"); let file_path = Path::new(&file_path_buf); diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 0cbcac28..beb17e91 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -247,9 +247,7 @@ async fn run_until_internal( .await; match publishded_redeem_tx { - Ok(_) => { - AliceState::BtcRedeemed - } + Ok(_) => AliceState::BtcRedeemed, Err(e) => { bail!("Waiting for Bitcoin transaction finality failed with {}! The redeem transaction was published, but it is not ensured that the transaction was included! You're screwed.", e) } diff --git a/swap/tests/happy_path_restart_alice.rs b/swap/tests/happy_path_restart_alice.rs index fe38a09d..fbf2515c 100644 --- a/swap/tests/happy_path_restart_alice.rs +++ b/swap/tests/happy_path_restart_alice.rs @@ -15,10 +15,10 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() { let alice_state = alice::run_until(alice_swap, is_encsig_learned) .await .unwrap(); - assert!(matches!(alice_state, AliceState::EncSigLearned {..})); + assert!(matches!(alice_state, AliceState::EncSigLearned { .. })); let alice_swap = ctx.stop_and_resume_alice_from_db(alice_join_handle).await; - assert!(matches!(alice_swap.state, AliceState::EncSigLearned {..})); + assert!(matches!(alice_swap.state, AliceState::EncSigLearned { .. })); let alice_state = alice::run(alice_swap).await.unwrap(); diff --git a/swap/tests/happy_path_restart_bob_after_comm.rs b/swap/tests/happy_path_restart_bob_after_comm.rs index 09024be6..87a3b861 100644 --- a/swap/tests/happy_path_restart_bob_after_comm.rs +++ b/swap/tests/happy_path_restart_bob_after_comm.rs @@ -14,10 +14,10 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() { let bob_state = bob::run_until(bob_swap, is_encsig_sent).await.unwrap(); - assert!(matches!(bob_state, BobState::EncSigSent {..})); + assert!(matches!(bob_state, BobState::EncSigSent { .. })); let bob_swap = ctx.stop_and_resume_bob_from_db(bob_join_handle).await; - assert!(matches!(bob_swap.state, BobState::EncSigSent {..})); + assert!(matches!(bob_swap.state, BobState::EncSigSent { .. })); let bob_state = bob::run(bob_swap).await.unwrap(); diff --git a/swap/tests/happy_path_restart_bob_after_lock_proof_received.rs b/swap/tests/happy_path_restart_bob_after_lock_proof_received.rs index e742fbed..7101c0ab 100644 --- a/swap/tests/happy_path_restart_bob_after_lock_proof_received.rs +++ b/swap/tests/happy_path_restart_bob_after_lock_proof_received.rs @@ -16,11 +16,13 @@ async fn given_bob_restarts_after_lock_proof_received_resume_swap() { .await .unwrap(); - assert!(matches!(bob_state, BobState::XmrLockProofReceived {..})); + assert!(matches!(bob_state, BobState::XmrLockProofReceived { .. })); let bob_swap = ctx.stop_and_resume_bob_from_db(bob_join_handle).await; - assert!(matches!(bob_swap.state, BobState::XmrLockProofReceived - {..})); + assert!(matches!( + bob_swap.state, + BobState::XmrLockProofReceived { .. } + )); let bob_state = bob::run(bob_swap).await.unwrap(); diff --git a/swap/tests/happy_path_restart_bob_before_comm.rs b/swap/tests/happy_path_restart_bob_before_comm.rs index 06306cca..fd5f8979 100644 --- a/swap/tests/happy_path_restart_bob_before_comm.rs +++ b/swap/tests/happy_path_restart_bob_before_comm.rs @@ -14,10 +14,10 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { let bob_state = bob::run_until(bob_swap, is_xmr_locked).await.unwrap(); - assert!(matches!(bob_state, BobState::XmrLocked {..})); + assert!(matches!(bob_state, BobState::XmrLocked { .. })); let bob_swap = ctx.stop_and_resume_bob_from_db(bob_join_handle).await; - assert!(matches!(bob_swap.state, BobState::XmrLocked {..})); + assert!(matches!(bob_swap.state, BobState::XmrLocked { .. })); let bob_state = bob::run(bob_swap).await.unwrap(); diff --git a/swap/tests/punish.rs b/swap/tests/punish.rs index 7da44631..61de0577 100644 --- a/swap/tests/punish.rs +++ b/swap/tests/punish.rs @@ -16,7 +16,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() { let bob_state = bob::run_until(bob_swap, is_btc_locked).await.unwrap(); - assert!(matches!(bob_state, BobState::BtcLocked {..})); + assert!(matches!(bob_state, BobState::BtcLocked { .. })); let alice_state = alice_handle.await.unwrap(); ctx.assert_alice_punished(alice_state.unwrap()).await; @@ -24,7 +24,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() { // Restart Bob after Alice punished to ensure Bob transitions to // punished and does not run indefinitely let bob_swap = ctx.stop_and_resume_bob_from_db(bob_join_handle).await; - assert!(matches!(bob_swap.state, BobState::BtcLocked {..})); + assert!(matches!(bob_swap.state, BobState::BtcLocked { .. })); let bob_state = bob::run(bob_swap).await.unwrap(); diff --git a/swap/tests/refund_restart_alice.rs b/swap/tests/refund_restart_alice.rs index 475212f3..5af2c7a0 100644 --- a/swap/tests/refund_restart_alice.rs +++ b/swap/tests/refund_restart_alice.rs @@ -15,8 +15,7 @@ async fn given_alice_restarts_after_xmr_is_locked_refund_swap() { let bob_handle = tokio::spawn(bob); let alice_state = alice::run_until(alice_swap, is_xmr_locked).await.unwrap(); - assert!(matches!(alice_state, - AliceState::XmrLocked {..})); + assert!(matches!(alice_state, AliceState::XmrLocked { .. })); // Alice does not act, Bob refunds let bob_state = bob_handle.await.unwrap(); @@ -24,7 +23,7 @@ async fn given_alice_restarts_after_xmr_is_locked_refund_swap() { // Once bob has finished Alice is restarted and refunds as well let alice_swap = ctx.stop_and_resume_alice_from_db(alice_join_handle).await; - assert!(matches!(alice_swap.state, AliceState::XmrLocked {..})); + assert!(matches!(alice_swap.state, AliceState::XmrLocked { .. })); let alice_state = alice::run(alice_swap).await.unwrap(); diff --git a/swap/tests/refund_restart_alice_cancelled.rs b/swap/tests/refund_restart_alice_cancelled.rs index 116c1fd4..129887a1 100644 --- a/swap/tests/refund_restart_alice_cancelled.rs +++ b/swap/tests/refund_restart_alice_cancelled.rs @@ -22,7 +22,7 @@ async fn given_alice_restarts_after_enc_sig_learned_and_bob_already_cancelled_re .await .unwrap(); assert!( - matches!(alice_state, AliceState::EncSigLearned {..}), + matches!(alice_state, AliceState::EncSigLearned { .. }), "Alice state is not EncSigLearned: {:?}", alice_state ); @@ -34,8 +34,7 @@ async fn given_alice_restarts_after_enc_sig_learned_and_bob_already_cancelled_re // Once bob has finished Alice is restarted and refunds as well let alice_swap = ctx.stop_and_resume_alice_from_db(alice_join_handle).await; assert!( - matches!(alice_swap.state, AliceState::EncSigLearned - {..}), + matches!(alice_swap.state, AliceState::EncSigLearned { .. }), "Alice state is not EncSigLearned: {:?}", alice_state ); diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index 1d435958..847af388 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -478,17 +478,11 @@ pub mod alice_run_until { use swap::protocol::alice::AliceState; pub fn is_xmr_locked(state: &AliceState) -> bool { - matches!( - state, - AliceState::XmrLocked{..} - ) + matches!(state, AliceState::XmrLocked { .. }) } pub fn is_encsig_learned(state: &AliceState) -> bool { - matches!( - state, - AliceState::EncSigLearned{..} - ) + matches!(state, AliceState::EncSigLearned { .. }) } }