Introduce mockable ChainSync object for testing (#12480)

* Introduce mockable `ChainSync` object for testing

`mockall` allows to mock `ChainSync` and to verify that the calls made
to `ChaiSync` are firstly executed at all, that they're executed in
correct order and with correct parameters.

This allows to verify, e.g., that delegating calls directly to
`ChainSync` from `NetworkService` still calls the correct functions with
correct arguments even if `Protocol` middleman is removed.

* Add Cargo.lock

* Fix tests

* Update client/network/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update Cargo.lock

* Fix clippy and documentation

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: parity-processbot <>
This commit is contained in:
Aaro Altonen
2022-10-13 12:37:09 +03:00
committed by GitHub
parent b0b2b6799c
commit 09164dbced
8 changed files with 546 additions and 23 deletions
+8 -6
View File
@@ -269,12 +269,14 @@ pub trait ChainSync<Block: BlockT>: Send {
);
/// Get an iterator over all scheduled justification requests.
fn justification_requests(
&mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + '_>;
fn justification_requests<'a>(
&'a mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + 'a>;
/// Get an iterator over all block requests of all peers.
fn block_requests(&mut self) -> Box<dyn Iterator<Item = (&PeerId, BlockRequest<Block>)> + '_>;
fn block_requests<'a>(
&'a mut self,
) -> Box<dyn Iterator<Item = (PeerId, BlockRequest<Block>)> + 'a>;
/// Get a state request, if any.
fn state_request(&mut self) -> Option<(PeerId, OpaqueStateRequest)>;
@@ -359,9 +361,9 @@ pub trait ChainSync<Block: BlockT>: Send {
///
/// If [`PollBlockAnnounceValidation::ImportHeader`] is returned, then the caller MUST try to
/// import passed header (call `on_block_data`). The network request isn't sent in this case.
fn poll_block_announce_validation(
fn poll_block_announce_validation<'a>(
&mut self,
cx: &mut std::task::Context,
cx: &mut std::task::Context<'a>,
) -> Poll<PollBlockAnnounceValidation<Block::Header>>;
/// Call when a peer has disconnected.