@@ -27,11 +27,15 @@ use sr_primitives::{
2727 transaction_validity:: { TransactionValidity , ValidTransaction } ,
2828} ;
2929
30- struct TestApi ;
30+ struct TestApi {
31+ pub modifier : Box < dyn Fn ( & mut ValidTransaction ) + Send + Sync > ,
32+ }
3133
3234impl TestApi {
3335 fn default ( ) -> Self {
34- TestApi
36+ TestApi {
37+ modifier : Box :: new ( |_| { } ) ,
38+ }
3539 }
3640}
3741
@@ -54,14 +58,18 @@ impl txpool::ChainApi for TestApi {
5458 } ;
5559 let provides = vec ! [ vec![ uxt. transfer( ) . nonce as u8 ] ] ;
5660
61+ let mut validity = ValidTransaction {
62+ priority : 1 ,
63+ requires,
64+ provides,
65+ longevity : 64 ,
66+ propagate : true ,
67+ } ;
68+
69+ ( self . modifier ) ( & mut validity) ;
70+
5771 futures:: future:: ready ( Ok (
58- Ok ( ValidTransaction {
59- priority : 1 ,
60- requires,
61- provides,
62- longevity : 64 ,
63- propagate : true ,
64- } )
72+ Ok ( validity)
6573 ) )
6674 }
6775
@@ -181,3 +189,34 @@ fn should_ban_invalid_transactions() {
181189 // then
182190 block_on ( pool. submit_one ( & BlockId :: number ( 0 ) , uxt. clone ( ) ) ) . unwrap_err ( ) ;
183191}
192+
193+ #[ test]
194+ fn should_correctly_prune_transactions_providing_more_than_one_tag ( ) {
195+ let mut api = TestApi :: default ( ) ;
196+ api. modifier = Box :: new ( |v : & mut ValidTransaction | {
197+ v. provides . push ( vec ! [ 155 ] ) ;
198+ } ) ;
199+ let pool = Pool :: new ( Default :: default ( ) , api) ;
200+ let xt = uxt ( Alice , 209 ) ;
201+ block_on ( pool. submit_one ( & BlockId :: number ( 0 ) , xt. clone ( ) ) ) . expect ( "1. Imported" ) ;
202+ assert_eq ! ( pool. status( ) . ready, 1 ) ;
203+
204+ // remove the transaction that just got imported.
205+ block_on ( pool. prune_tags ( & BlockId :: number ( 1 ) , vec ! [ vec![ 209 ] ] , vec ! [ ] ) ) . expect ( "1. Pruned" ) ;
206+ assert_eq ! ( pool. status( ) . ready, 0 ) ;
207+ // it's re-imported to future
208+ assert_eq ! ( pool. status( ) . future, 1 ) ;
209+
210+ // so now let's insert another transaction that also provides the 155
211+ let xt = uxt ( Alice , 211 ) ;
212+ block_on ( pool. submit_one ( & BlockId :: number ( 2 ) , xt. clone ( ) ) ) . expect ( "2. Imported" ) ;
213+ assert_eq ! ( pool. status( ) . ready, 1 ) ;
214+ assert_eq ! ( pool. status( ) . future, 1 ) ;
215+ let pending: Vec < _ > = pool. ready ( ) . map ( |a| a. data . transfer ( ) . nonce ) . collect ( ) ;
216+ assert_eq ! ( pending, vec![ 211 ] ) ;
217+
218+ // prune it and make sure the pool is empty
219+ block_on ( pool. prune_tags ( & BlockId :: number ( 3 ) , vec ! [ vec![ 155 ] ] , vec ! [ ] ) ) . expect ( "2. Pruned" ) ;
220+ assert_eq ! ( pool. status( ) . ready, 0 ) ;
221+ assert_eq ! ( pool. status( ) . future, 2 ) ;
222+ }
0 commit comments