@@ -237,7 +237,7 @@ impl<D> Peer<D> {
237237 where F : FnMut ( BlockBuilder < Block , PeersFullClient , substrate_test_runtime_client:: Backend > ) -> Block
238238 {
239239 let best_hash = self . client . info ( ) . best_hash ;
240- self . generate_blocks_at ( BlockId :: Hash ( best_hash) , count, origin, edit_block)
240+ self . generate_blocks_at ( BlockId :: Hash ( best_hash) , count, origin, edit_block, false )
241241 }
242242
243243 /// Add blocks to the peer -- edit the block before adding. The chain will
@@ -247,7 +247,8 @@ impl<D> Peer<D> {
247247 at : BlockId < Block > ,
248248 count : usize ,
249249 origin : BlockOrigin ,
250- mut edit_block : F
250+ mut edit_block : F ,
251+ headers_only : bool ,
251252 ) -> H256 where F : FnMut ( BlockBuilder < Block , PeersFullClient , substrate_test_runtime_client:: Backend > ) -> Block {
252253 let full_client = self . client . as_full ( )
253254 . expect ( "blocks could only be generated by full clients" ) ;
@@ -272,7 +273,7 @@ impl<D> Peer<D> {
272273 origin,
273274 header. clone ( ) ,
274275 None ,
275- Some ( block. extrinsics )
276+ if headers_only { None } else { Some ( block. extrinsics ) } ,
276277 ) . unwrap ( ) ;
277278 let cache = if let Some ( cache) = cache {
278279 cache. into_iter ( ) . collect ( )
@@ -294,28 +295,46 @@ impl<D> Peer<D> {
294295 self . push_blocks_at ( BlockId :: Hash ( best_hash) , count, with_tx)
295296 }
296297
298+ /// Push blocks to the peer (simplified: with or without a TX)
299+ pub fn push_headers ( & mut self , count : usize ) -> H256 {
300+ let best_hash = self . client . info ( ) . best_hash ;
301+ self . generate_tx_blocks_at ( BlockId :: Hash ( best_hash) , count, false , true )
302+ }
303+
297304 /// Push blocks to the peer (simplified: with or without a TX) starting from
298305 /// given hash.
299306 pub fn push_blocks_at ( & mut self , at : BlockId < Block > , count : usize , with_tx : bool ) -> H256 {
307+ self . generate_tx_blocks_at ( at, count, with_tx, false )
308+ }
309+
310+ /// Push blocks/headers to the peer (simplified: with or without a TX) starting from
311+ /// given hash.
312+ fn generate_tx_blocks_at ( & mut self , at : BlockId < Block > , count : usize , with_tx : bool , headers_only : bool ) -> H256 {
300313 let mut nonce = 0 ;
301314 if with_tx {
302- self . generate_blocks_at ( at, count, BlockOrigin :: File , |mut builder| {
303- let transfer = Transfer {
304- from : AccountKeyring :: Alice . into ( ) ,
305- to : AccountKeyring :: Alice . into ( ) ,
306- amount : 1 ,
307- nonce,
308- } ;
309- builder. push ( transfer. into_signed_tx ( ) ) . unwrap ( ) ;
310- nonce = nonce + 1 ;
311- builder. build ( ) . unwrap ( ) . block
312- } )
315+ self . generate_blocks_at (
316+ at,
317+ count,
318+ BlockOrigin :: File , |mut builder| {
319+ let transfer = Transfer {
320+ from : AccountKeyring :: Alice . into ( ) ,
321+ to : AccountKeyring :: Alice . into ( ) ,
322+ amount : 1 ,
323+ nonce,
324+ } ;
325+ builder. push ( transfer. into_signed_tx ( ) ) . unwrap ( ) ;
326+ nonce = nonce + 1 ;
327+ builder. build ( ) . unwrap ( ) . block
328+ } ,
329+ headers_only
330+ )
313331 } else {
314332 self . generate_blocks_at (
315333 at,
316334 count,
317335 BlockOrigin :: File ,
318336 |builder| builder. build ( ) . unwrap ( ) . block ,
337+ headers_only,
319338 )
320339 }
321340 }
@@ -748,13 +767,37 @@ pub trait TestNetFactory: Sized {
748767 Async :: Ready ( ( ) )
749768 }
750769
770+ /// Polls the testnet until theres' no activiy of any kind.
771+ ///
772+ /// Must be executed in a task context.
773+ fn poll_until_idle ( & mut self ) -> Async < ( ) > {
774+ self . poll ( ) ;
775+
776+ for peer in self . peers ( ) . iter ( ) {
777+ if peer. is_major_syncing ( ) || peer. network . num_queued_blocks ( ) != 0 {
778+ return Async :: NotReady
779+ }
780+ if peer. network . num_sync_requests ( ) != 0 {
781+ return Async :: NotReady
782+ }
783+ }
784+ Async :: Ready ( ( ) )
785+ }
786+
751787 /// Blocks the current thread until we are sync'ed.
752788 ///
753789 /// Calls `poll_until_sync` repeatedly with the runtime passed as parameter.
754790 fn block_until_sync ( & mut self , runtime : & mut tokio:: runtime:: current_thread:: Runtime ) {
755791 runtime. block_on ( futures:: future:: poll_fn :: < ( ) , ( ) , _ > ( || Ok ( self . poll_until_sync ( ) ) ) ) . unwrap ( ) ;
756792 }
757793
794+ /// Blocks the current thread until there are no pending packets.
795+ ///
796+ /// Calls `poll_until_idle` repeatedly with the runtime passed as parameter.
797+ fn block_until_idle ( & mut self , runtime : & mut tokio:: runtime:: current_thread:: Runtime ) {
798+ runtime. block_on ( futures:: future:: poll_fn :: < ( ) , ( ) , _ > ( || Ok ( self . poll_until_idle ( ) ) ) ) . unwrap ( ) ;
799+ }
800+
758801 /// Polls the testnet. Processes all the pending actions and returns `NotReady`.
759802 fn poll ( & mut self ) {
760803 self . mut_peers ( |peers| {
0 commit comments