Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add a mock version of network ops
  • Loading branch information
rphmeier committed Mar 11, 2020
commit aafc9031556267e0a8c3bfd6c9b163efabc6946c
30 changes: 30 additions & 0 deletions network/src/protocol/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@
//! Tests for the protocol.

use super::*;
use parking_lot::Mutex;

struct MockNetworkOps {
recorded: Arc<Mutex<Recorded>>,
}

struct Recorded {
peer_reputations: HashMap<PeerId, i32>,
notifications: Vec<(PeerId, Message)>,
}

impl NetworkServiceOps for MockNetworkOps {
fn report_peer(&self, peer: PeerId, value: sc_network::ReputationChange) {
let mut recorded = self.recorded.lock();
let total_rep = recorded.peer_reputations.entry(peer).or_insert(0);

*total_rep = total_rep.saturating_add(value.value);
}

fn write_notification(
&self,
peer: PeerId,
engine_id: ConsensusEngineId,
notification: Vec<u8>,
) {
assert_eq!(engine_id, POLKADOT_ENGINE_ID);
let message = Message::decode(&mut &notification[..]).expect("invalid notification");
self.recorded.lock().notifications.push((peer, message));
}
}

#[test]
fn router_inner_drop_sends_worker_message() {
Expand Down