cuprate/p2p/p2p-core/tests/sending_receiving.rs
hinto-janai 4b93dbec4c
Some checks failed
CI / fmt (push) Waiting to run
CI / typo (push) Waiting to run
CI / ci (macos-latest, stable, bash) (push) Waiting to run
CI / ci (ubuntu-latest, stable, bash) (push) Waiting to run
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Waiting to run
Audit / audit (push) Has been cancelled
Deny / audit (push) Has been cancelled
workspace: enforce crate/directory naming scheme (#164)
* rename all directories and crates

* fix all `use`

* fix doc link

* `dandelion/` -> `dandelion-tower/`

* fix epee-encoding test

* fix `json-rpc`

* fix pruning

* crate import fixes

* fix leftover merge conflicts

* fix `epee-encoding`
2024-06-24 02:30:47 +01:00

78 lines
2 KiB
Rust

use std::sync::Arc;
use tokio::sync::Semaphore;
use tower::{Service, ServiceExt};
use cuprate_helper::network::Network;
use cuprate_wire::{common::PeerSupportFlags, protocol::GetObjectsRequest, BasicNodeData};
use cuprate_p2p_core::{
client::{ConnectRequest, Connector, HandShaker},
network_zones::ClearNet,
protocol::{PeerRequest, PeerResponse},
};
use cuprate_test_utils::monerod::monerod;
mod utils;
use utils::*;
#[tokio::test]
async fn get_single_block_from_monerod() {
let semaphore = Arc::new(Semaphore::new(10));
let permit = semaphore.acquire_owned().await.unwrap();
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 = HandShaker::<ClearNet, _, _, _, _, _>::new(
DummyAddressBook,
DummyPeerSyncSvc,
DummyCoreSyncSvc,
DummyPeerRequestHandlerSvc,
|_| futures::stream::pending(),
our_basic_node_data,
);
let mut connector = Connector::new(handshaker);
let mut connected_peer = connector
.ready()
.await
.unwrap()
.call(ConnectRequest {
addr: monerod.p2p_addr(),
permit,
})
.await
.unwrap();
let PeerResponse::GetObjects(obj) = connected_peer
.ready()
.await
.unwrap()
.call(PeerRequest::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);
}