cuprate/p2p/p2p-core/tests/sending_receiving.rs
Boog900 d5c8eba1d8
Some checks failed
Deny / audit (push) Has been cancelled
Doc / build (push) Has been cancelled
Audit / audit (push) Has been cancelled
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Doc / deploy (push) Has been cancelled
P2P: API Improvements (#168)
* start handshaker builder

* finish builder

* remove borsh requirement

* fix poll_ready :/

* add more docs to builder

* more docs

* fix clippy

* merge fixes

* fix doc test

* fix imports

* cargo fmt

* split `PeerRequest` and `PeerResponse` enums up.

This splits them both into a protocol and admin enum

* add request handler file

* integrate request handler into connection

* fix docs

* doc updates

* add more docs

* fix docs

* misc changes

* review fixes

* fix merge

* add dummy file

* fix docs

* Update p2p/dandelion-tower/src/router.rs

* fix docs
2024-07-04 21:05:22 +01:00

66 lines
1.8 KiB
Rust

use tower::{Service, ServiceExt};
use cuprate_helper::network::Network;
use cuprate_wire::{common::PeerSupportFlags, protocol::GetObjectsRequest, BasicNodeData};
use cuprate_p2p_core::{
client::{handshaker::HandshakerBuilder, ConnectRequest, Connector},
protocol::{PeerRequest, PeerResponse},
ClearNet, ProtocolRequest, ProtocolResponse,
};
use cuprate_test_utils::monerod::monerod;
#[tokio::test]
async fn get_single_block_from_monerod() {
let monerod = monerod(["--out-peers=0"]).await;
let our_basic_node_data = BasicNodeData {
my_port: 0,
network_id: Network::Mainnet.network_id(),
peer_id: 87980,
support_flags: PeerSupportFlags::FLUFFY_BLOCKS,
rpc_port: 0,
rpc_credits_per_hash: 0,
};
let handshaker = HandshakerBuilder::<ClearNet>::new(our_basic_node_data).build();
let mut connector = Connector::new(handshaker);
let mut connected_peer = connector
.ready()
.await
.unwrap()
.call(ConnectRequest {
addr: monerod.p2p_addr(),
permit: None,
})
.await
.unwrap();
let PeerResponse::Protocol(ProtocolResponse::GetObjects(obj)) = connected_peer
.ready()
.await
.unwrap()
.call(PeerRequest::Protocol(ProtocolRequest::GetObjects(
GetObjectsRequest {
blocks: hex::decode(
"418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3",
)
.unwrap()
.try_into()
.unwrap(),
pruned: false,
},
)))
.await
.unwrap()
else {
panic!("Client returned wrong response");
};
assert_eq!(obj.blocks.len(), 1);
assert_eq!(obj.missed_ids.len(), 0);
assert_eq!(obj.current_blockchain_height, 1);
}