Skip to main content

soil_network/sync/
mock.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Contains mock implementations of `ChainSync` and 'BlockDownloader'.
8
9use crate::sync::block_relay_protocol::{BlockDownloader as BlockDownloaderT, BlockResponseError};
10
11use futures::channel::oneshot;
12use soil_network::common::sync::message::{BlockData, BlockRequest};
13use soil_network::types::PeerId;
14use soil_network::{ProtocolName, RequestFailure};
15use subsoil::runtime::traits::Block as BlockT;
16
17mockall::mock! {
18	#[derive(Debug)]
19	pub BlockDownloader<Block: BlockT> {}
20
21	#[async_trait::async_trait]
22	impl<Block: BlockT> BlockDownloaderT<Block> for BlockDownloader<Block> {
23		fn protocol_name(&self) -> &ProtocolName;
24
25		async fn download_blocks(
26			&self,
27			who: PeerId,
28			request: BlockRequest<Block>,
29		) -> Result<Result<(Vec<u8>, ProtocolName), RequestFailure>, oneshot::Canceled>;
30		fn block_response_into_blocks(
31			&self,
32			request: &BlockRequest<Block>,
33			response: Vec<u8>,
34		) -> Result<Vec<BlockData<Block>>, BlockResponseError>;
35	}
36}