Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Oct 8, 2023
2 parents 932364e + 1c8a9a8 commit 92e088e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions mm2src/mm2_main/src/ordermatch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,14 +1662,10 @@ fn pubkey_and_secret_for_test(passphrase: &str) -> (String, [u8; 32]) {
(pubkey, secret)
}

fn p2p_context_mock() -> (mpsc::Sender<AdexBehaviourCmd>, mpsc::Receiver<AdexBehaviourCmd>) {
fn init_p2p_context(ctx: &MmArc) -> (mpsc::Sender<AdexBehaviourCmd>, mpsc::Receiver<AdexBehaviourCmd>) {
let (cmd_tx, cmd_rx) = mpsc::channel(10);
let cmd_sender = cmd_tx.clone();
P2PContext::fetch_from_mm_arc.mock_safe(move |_| {
MockResult::Return(Arc::new(P2PContext {
cmd_tx: PaMutex::new(cmd_sender.clone()),
}))
});
let p2p_context = P2PContext::new(cmd_tx.clone());
p2p_context.store_to_mm_arc(ctx);
(cmd_tx, cmd_rx)
}

Expand Down Expand Up @@ -1775,7 +1771,7 @@ fn test_request_and_fill_orderbook() {
const ORDERS_NUMBER: usize = 10;

let (ctx, _pubkey, _secret) = make_ctx_for_tests();
let (_, mut cmd_rx) = p2p_context_mock();
let (_, mut cmd_rx) = init_p2p_context(&ctx);

let other_pubkeys: Vec<(String, [u8; 32])> = (0..PUBKEYS_NUMBER)
.map(|idx| {
Expand Down Expand Up @@ -1927,9 +1923,10 @@ fn test_process_order_keep_alive_requested_from_peer() {
let ordermatch_ctx = Arc::new(OrdermatchContext::default());
let ordermatch_ctx_clone = ordermatch_ctx.clone();
OrdermatchContext::from_ctx.mock_safe(move |_| MockResult::Return(Ok(ordermatch_ctx_clone.clone())));
let (_, mut cmd_rx) = p2p_context_mock();
let (ctx, pubkey, secret) = make_ctx_for_tests();
let (_, mut cmd_rx) = init_p2p_context(&ctx);
let uuid = new_uuid();
let peer = PeerId::random().to_string();
Expand Down Expand Up @@ -2048,7 +2045,7 @@ fn test_process_get_order_request() {
#[test]
fn test_subscribe_to_ordermatch_topic_not_subscribed() {
let (ctx, _pubkey, _secret) = make_ctx_for_tests();
let (_, mut cmd_rx) = p2p_context_mock();
let (_, mut cmd_rx) = init_p2p_context(&ctx);
spawn(async move {
match cmd_rx.next().await.unwrap() {
Expand Down Expand Up @@ -2092,7 +2089,7 @@ fn test_subscribe_to_ordermatch_topic_not_subscribed() {
#[test]
fn test_subscribe_to_ordermatch_topic_subscribed_not_filled() {
let (ctx, _pubkey, _secret) = make_ctx_for_tests();
let (_, mut cmd_rx) = p2p_context_mock();
let (_, mut cmd_rx) = init_p2p_context(&ctx);
{
let ordermatch_ctx = OrdermatchContext::from_ctx(&ctx).unwrap();
Expand Down Expand Up @@ -2144,7 +2141,7 @@ fn test_subscribe_to_ordermatch_topic_subscribed_not_filled() {
#[test]
fn test_subscribe_to_ordermatch_topic_subscribed_filled() {
let (ctx, _pubkey, _secret) = make_ctx_for_tests();
let (_, mut cmd_rx) = p2p_context_mock();
let (_, mut cmd_rx) = init_p2p_context(&ctx);
// enough time has passed for the orderbook to be filled
let subscribed_at = now_ms() / 1000 - ORDERBOOK_REQUESTING_TIMEOUT - 1;
Expand Down Expand Up @@ -2174,6 +2171,7 @@ fn test_subscribe_to_ordermatch_topic_subscribed_filled() {
assert_eq!(actual, expected);
}
*/

#[test]
fn test_taker_request_can_match_with_maker_pubkey() {
let coin = TestCoin::default().into();
Expand Down
3 changes: 0 additions & 3 deletions mm2src/mm2_net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@ gstuff = { version = "0.7", features = ["nightly"] }
rustls = { version = "0.20", default-features = false }
tokio = { version = "1.20" }
tokio-rustls = { version = "0.23", default-features = false }

[dev-dependencies]
mocktopus = "0.8.0"
10 changes: 0 additions & 10 deletions mm2src/mm2_net/src/p2p.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use mm2_core::mm_ctx::MmArc;
use mm2_libp2p::behaviours::atomicdex::AdexCmdTx;
#[cfg(test)] use mocktopus::macros::*;
use parking_lot::Mutex;
use std::sync::Arc;

Expand All @@ -9,15 +8,6 @@ pub struct P2PContext {
pub cmd_tx: Mutex<AdexCmdTx>,
}

// `mockable` violates these
#[allow(
clippy::forget_ref,
clippy::forget_copy,
clippy::swap_ptr_to_ref,
clippy::forget_non_drop,
clippy::let_unit_value
)]
#[cfg_attr(test, mockable)]
impl P2PContext {
pub fn new(cmd_tx: AdexCmdTx) -> Self {
P2PContext {
Expand Down

0 comments on commit 92e088e

Please sign in to comment.