Skip to content

Commit

Permalink
Rename TestNode::message
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Oct 9, 2023
1 parent 2451247 commit ee5bb1d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 64 deletions.
2 changes: 1 addition & 1 deletion p2p/src/sync/tests/ban_scores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn receive_header_with_invalid_parent_block(#[case] seed: Seed) {
])))
.await;

let (adjusted_peer_id, ban_score_delta) = node.adjust_peer_score_event().await;
let (adjusted_peer_id, ban_score_delta) = node.receive_adjust_peer_score_event().await;
assert_eq!(adjusted_peer_id, peer.get_id());
assert_eq!(ban_score_delta, 100);

Expand Down
22 changes: 11 additions & 11 deletions p2p/src/sync/tests/block_announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn single_header_with_unknown_prev_block_v1(#[case] seed: Seed) {
// that the event is caught even if it's late; the first one just allows the test to fail
// faster if the event is not late.
node.assert_no_peer_manager_event().await;
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert!(matches!(message, SyncMessage::HeaderListRequest(_)));
node.assert_no_peer_manager_event().await;
Expand Down Expand Up @@ -191,7 +191,7 @@ async fn single_header_with_unknown_prev_block_with_intermittent_connected_heade
peer.send_headers(vec![block_2.header().clone()]).await;

node.assert_no_peer_manager_event().await;
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert!(matches!(message, SyncMessage::HeaderListRequest(_)));
node.assert_no_peer_manager_event().await;
Expand All @@ -200,7 +200,7 @@ async fn single_header_with_unknown_prev_block_with_intermittent_connected_heade
peer.send_headers(vec![block_11.header().clone()]).await;

node.assert_no_peer_manager_event().await;
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert!(matches!(message, SyncMessage::BlockListRequest(_)));
node.assert_no_peer_manager_event().await;
Expand All @@ -211,7 +211,7 @@ async fn single_header_with_unknown_prev_block_with_intermittent_connected_heade
peer.send_headers(vec![block_2.header().clone()]).await;

node.assert_no_peer_manager_event().await;
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert!(matches!(message, SyncMessage::HeaderListRequest(_)));
node.assert_no_peer_manager_event().await;
Expand Down Expand Up @@ -287,7 +287,7 @@ async fn invalid_timestamp() {
.clone()])))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -337,7 +337,7 @@ async fn invalid_consensus_data() {
.clone()])))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -429,7 +429,7 @@ async fn valid_block(#[case] seed: Seed) {
.clone()])))
.await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert_eq!(
message,
Expand Down Expand Up @@ -484,7 +484,7 @@ async fn best_known_header_is_considered(#[case] seed: Seed) {
.await;

log::debug!("Expecting initial header response");
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert_eq!(
message,
Expand All @@ -506,7 +506,7 @@ async fn best_known_header_is_considered(#[case] seed: Seed) {
.await;

log::debug!("Expecting first announcement");
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert_eq!(
message,
Expand Down Expand Up @@ -534,7 +534,7 @@ async fn best_known_header_is_considered(#[case] seed: Seed) {
.await;

log::debug!("Expecting second announcement");
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert_eq!(
message,
Expand All @@ -558,7 +558,7 @@ async fn best_known_header_is_considered(#[case] seed: Seed) {
.await;

log::debug!("Expecting third announcement");
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(sent_to, peer.get_id());
assert_eq!(
message,
Expand Down
10 changes: 5 additions & 5 deletions p2p/src/sync/tests/block_list_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn max_block_count_in_request_exceeded(#[case] seed: Seed) {
peer.send_message(SyncMessage::BlockListRequest(BlockListRequest::new(blocks)))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -114,7 +114,7 @@ async fn unknown_blocks(#[case] seed: Seed) {
)))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(score, expected_score);
node.assert_no_event().await;
Expand Down Expand Up @@ -157,7 +157,7 @@ async fn valid_request(#[case] seed: Seed) {
.await;

for block in blocks {
let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
assert_eq!(
message,
Expand Down Expand Up @@ -205,7 +205,7 @@ async fn request_same_block_twice(#[case] seed: Seed) {
])))
.await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
assert_eq!(
message,
Expand All @@ -221,7 +221,7 @@ async fn request_same_block_twice(#[case] seed: Seed) {
])))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down
22 changes: 11 additions & 11 deletions p2p/src/sync/tests/block_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn unrequested_block(#[case] seed: Seed) {

peer.send_message(SyncMessage::BlockResponse(BlockResponse::new(block))).await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -100,7 +100,7 @@ async fn valid_response(#[case] seed: Seed) {
let headers = blocks.iter().map(|b| b.header().clone()).collect();
peer.send_message(SyncMessage::HeaderList(HeaderList::new(headers))).await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
let ids = blocks.iter().map(|b| b.get_id()).collect();
assert_eq!(
Expand All @@ -117,7 +117,7 @@ async fn valid_response(#[case] seed: Seed) {

// A peer would request headers after the last block.
assert!(matches!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderListRequest(HeaderListRequest { .. })
));

Expand Down Expand Up @@ -183,15 +183,15 @@ async fn disconnect(#[case] seed: Seed) {
.clone()])))
.await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
assert_eq!(
message,
SyncMessage::BlockListRequest(BlockListRequest::new(vec![block.get_id()]))
);

tokio::time::sleep(Duration::from_millis(300)).await;
node.assert_disconnect_peer_event(peer.get_id()).await;
node.receive_disconnect_peer_event(peer.get_id()).await;

node.join_subsystem_manager().await;
})
Expand Down Expand Up @@ -262,7 +262,7 @@ async fn slow_response(#[case] seed: Seed) {
.clone()])))
.await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
assert_eq!(
message,
Expand All @@ -277,7 +277,7 @@ async fn slow_response(#[case] seed: Seed) {
.await;

assert!(matches!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderListRequest(HeaderListRequest { .. })
));

Expand Down Expand Up @@ -349,7 +349,7 @@ async fn invalidated_block(#[case] seed: Seed) {
// The node sends HeaderList.
let initial_blocks_headers = initial_blocks.iter().map(|b| b.header().clone()).collect();
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderList(HeaderList::new(initial_blocks_headers))
);

Expand All @@ -362,11 +362,11 @@ async fn invalidated_block(#[case] seed: Seed) {

// The node sends block responses.
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::BlockResponse(BlockResponse::new(initial_blocks[0].clone()))
);
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::BlockResponse(BlockResponse::new(initial_blocks[1].clone()))
);

Expand Down Expand Up @@ -394,7 +394,7 @@ async fn invalidated_block(#[case] seed: Seed) {

// The node should send the new tip update
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderList(HeaderList::new(vec![new_header.clone()]))
);

Expand Down
10 changes: 5 additions & 5 deletions p2p/src/sync/tests/header_list_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn max_locator_size_exceeded(#[case] seed: Seed) {
)))
.await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -110,7 +110,7 @@ async fn valid_request(#[case] seed: Seed) {
)))
.await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
let headers = match message {
SyncMessage::HeaderList(l) => l.into_headers(),
Expand Down Expand Up @@ -201,7 +201,7 @@ async fn allow_peer_to_ignore_header_requests_when_asking_for_blocks(

// The node should send the header list.
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderList(HeaderList::new(headers)),
);

Expand All @@ -221,7 +221,7 @@ async fn allow_peer_to_ignore_header_requests_when_asking_for_blocks(

// The node should send the block.
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::BlockResponse(BlockResponse::new(block)),
);
}
Expand Down Expand Up @@ -293,7 +293,7 @@ async fn respond_with_empty_header_list_when_in_ibd(#[case] protocol_version: Pr

// The node should send an empty header list.
assert_eq!(
node.message().await.1,
node.get_sent_message().await.1,
SyncMessage::HeaderList(HeaderList::new(Vec::new())),
);

Expand Down
10 changes: 5 additions & 5 deletions p2p/src/sync/tests/header_list_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn header_count_limit_exceeded(#[case] seed: Seed) {
.collect();
peer.send_message(SyncMessage::HeaderList(HeaderList::new(headers))).await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -104,7 +104,7 @@ async fn unordered_headers(#[case] seed: Seed) {

peer.send_message(SyncMessage::HeaderList(HeaderList::new(headers))).await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn disconnected_headers(#[case] seed: Seed) {

peer.send_message(SyncMessage::HeaderList(HeaderList::new(headers))).await;

let (adjusted_peer, score) = node.adjust_peer_score_event().await;
let (adjusted_peer, score) = node.receive_adjust_peer_score_event().await;
assert_eq!(peer.get_id(), adjusted_peer);
assert_eq!(
score,
Expand Down Expand Up @@ -185,7 +185,7 @@ async fn valid_headers(#[case] seed: Seed) {
let headers = blocks.iter().map(|b| b.header().clone()).collect();
peer.send_message(SyncMessage::HeaderList(HeaderList::new(headers))).await;

let (sent_to, message) = node.message().await;
let (sent_to, message) = node.get_sent_message().await;
assert_eq!(peer.get_id(), sent_to);
assert_eq!(
message,
Expand Down Expand Up @@ -239,7 +239,7 @@ async fn disconnect() {
let peer = node.connect_peer(PeerId::new(), protocol_version).await;

tokio::time::sleep(Duration::from_millis(300)).await;
node.assert_disconnect_peer_event(peer.get_id()).await;
node.receive_disconnect_peer_event(peer.get_id()).await;

node.join_subsystem_manager().await;
})
Expand Down
Loading

0 comments on commit ee5bb1d

Please sign in to comment.