2024-09-21 00:37:06 +00:00
|
|
|
#![expect(unused_crate_dependencies, reason = "external test module")]
|
|
|
|
|
2024-05-02 22:58:22 +00:00
|
|
|
use tower::{Service, ServiceExt};
|
|
|
|
|
|
|
|
use cuprate_helper::network::Network;
|
2024-09-21 00:37:06 +00:00
|
|
|
use cuprate_test_utils::monerod::monerod;
|
2024-06-24 01:30:47 +00:00
|
|
|
use cuprate_wire::{common::PeerSupportFlags, protocol::GetObjectsRequest, BasicNodeData};
|
2024-05-02 22:58:22 +00:00
|
|
|
|
2024-06-24 01:30:47 +00:00
|
|
|
use cuprate_p2p_core::{
|
2024-07-04 20:05:22 +00:00
|
|
|
client::{handshaker::HandshakerBuilder, ConnectRequest, Connector},
|
2024-05-02 22:58:22 +00:00
|
|
|
protocol::{PeerRequest, PeerResponse},
|
2024-07-04 20:05:22 +00:00
|
|
|
ClearNet, ProtocolRequest, ProtocolResponse,
|
2024-05-02 22:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#[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,
|
|
|
|
};
|
|
|
|
|
2024-07-04 20:05:22 +00:00
|
|
|
let handshaker = HandshakerBuilder::<ClearNet>::new(our_basic_node_data).build();
|
2024-05-02 22:58:22 +00:00
|
|
|
|
|
|
|
let mut connector = Connector::new(handshaker);
|
|
|
|
|
|
|
|
let mut connected_peer = connector
|
|
|
|
.ready()
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.call(ConnectRequest {
|
|
|
|
addr: monerod.p2p_addr(),
|
2024-07-04 20:05:22 +00:00
|
|
|
permit: None,
|
2024-05-02 22:58:22 +00:00
|
|
|
})
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 20:05:22 +00:00
|
|
|
let PeerResponse::Protocol(ProtocolResponse::GetObjects(obj)) = connected_peer
|
2024-05-02 22:58:22 +00:00
|
|
|
.ready()
|
|
|
|
.await
|
|
|
|
.unwrap()
|
2024-07-04 20:05:22 +00:00
|
|
|
.call(PeerRequest::Protocol(ProtocolRequest::GetObjects(
|
|
|
|
GetObjectsRequest {
|
|
|
|
blocks: hex::decode(
|
|
|
|
"418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3",
|
|
|
|
)
|
2024-05-02 22:58:22 +00:00
|
|
|
.unwrap()
|
|
|
|
.try_into()
|
|
|
|
.unwrap(),
|
2024-07-04 20:05:22 +00:00
|
|
|
pruned: false,
|
|
|
|
},
|
|
|
|
)))
|
2024-05-02 22:58:22 +00:00
|
|
|
.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);
|
|
|
|
}
|