@@ -6,11 +6,10 @@ use polimec_common::assets::AcceptedFundingAsset;
6
6
7
7
// general chain interactions
8
8
impl <
9
- T : Config + pallet_balances:: Config < Balance = Balance > ,
9
+ T : Config + pallet_balances:: Config < Balance = Balance > + cumulus_pallet_parachain_system :: Config ,
10
10
AllPalletsWithoutSystem : OnFinalize < BlockNumberFor < T > > + OnIdle < BlockNumberFor < T > > + OnInitialize < BlockNumberFor < T > > ,
11
- BNProvider : BlockNumberProvider < BlockNumber = frame_system:: pallet_prelude:: BlockNumberFor < T > > ,
12
11
RuntimeEvent : From < Event < T > > + TryInto < Event < T > > + Parameter + Member + IsType < <T as frame_system:: Config >:: RuntimeEvent > ,
13
- > Instantiator < T , AllPalletsWithoutSystem , BNProvider , RuntimeEvent >
12
+ > Instantiator < T , AllPalletsWithoutSystem , RuntimeEvent >
14
13
{
15
14
pub fn new ( ext : OptionalExternalities ) -> Self {
16
15
Self { ext, nonce : RefCell :: new ( 0u64 ) , _marker : PhantomData }
@@ -145,13 +144,13 @@ impl<
145
144
}
146
145
147
146
pub fn current_block ( & mut self ) -> BlockNumberFor < T > {
148
- self . execute ( || BNProvider :: current_block_number ( ) )
147
+ self . execute ( || < T as Config > :: BlockNumberProvider :: current_block_number ( ) )
149
148
}
150
149
151
150
pub fn advance_time ( & mut self , amount : BlockNumberFor < T > ) {
152
151
self . execute ( || {
153
152
for _block in 0u32 ..amount. saturated_into ( ) {
154
- let mut current_block = BNProvider :: current_block_number ( ) ;
153
+ let mut current_block = < T as Config > :: BlockNumberProvider :: current_block_number ( ) ;
155
154
156
155
<AllPalletsWithoutSystem as OnFinalize < BlockNumberFor < T > > >:: on_finalize ( current_block) ;
157
156
<frame_system:: Pallet < T > as OnFinalize < BlockNumberFor < T > > >:: on_finalize ( current_block) ;
@@ -160,24 +159,26 @@ impl<
160
159
<frame_system:: Pallet < T > as OnIdle < BlockNumberFor < T > > >:: on_idle ( current_block, Weight :: MAX ) ;
161
160
162
161
current_block += One :: one ( ) ;
163
- println ! ( "Advancing block to {}" , current_block) ;
164
- // frame_system::Pallet::<T>::set_block_number(current_block);
165
- BNProvider :: set_block_number ( current_block) ;
162
+ frame_system:: Pallet :: < T > :: set_block_number ( current_block) ;
166
163
167
- let current_block = BNProvider :: current_block_number ( ) ;
168
- println ! ( "Executing on_initialize for block {}" , current_block) ;
169
164
<frame_system:: Pallet < T > as OnInitialize < BlockNumberFor < T > > >:: on_initialize ( current_block) ;
170
165
<AllPalletsWithoutSystem as OnInitialize < BlockNumberFor < T > > >:: on_initialize ( current_block) ;
171
166
}
172
- } )
167
+ } ) ;
168
+
169
+ let current_block = self . current_block ( ) ;
170
+ // in case we are relying on parachain system
171
+ self . set_relay_chain_block_number ( current_block + amount) ;
173
172
}
174
173
175
174
pub fn jump_to_block ( & mut self , block : BlockNumberFor < T > ) {
176
175
let current_block = self . current_block ( ) ;
177
- println ! ( "Jumping from block {} to block {}" , current_block, block) ;
178
176
if block > current_block {
179
- // self.execute(|| frame_system::Pallet::<T>::set_block_number(block - One::one()));
180
- self . execute ( || BNProvider :: set_block_number ( block - One :: one ( ) ) ) ;
177
+ self . execute ( || {
178
+ frame_system:: Pallet :: < T > :: set_block_number ( block - One :: one ( ) ) ;
179
+ } ) ;
180
+ self . set_relay_chain_block_number ( block - One :: one ( ) ) ;
181
+
181
182
self . advance_time ( One :: one ( ) ) ;
182
183
} else {
183
184
// panic!("Cannot jump to a block in the present or past")
@@ -223,15 +224,38 @@ impl<
223
224
} ) ;
224
225
}
225
226
}
227
+
228
+ /// NOTE: this is a workaround function to advance relaychain's block number, since
229
+ /// `<T as Config>::BlockNumberProvider::set_block_number` is not working in tests
230
+ ///
231
+ /// It is cloned version of the above trait function implementation in [`cumulus_pallet_parachain_system::RelaychainDataProvider`]
232
+ ///
233
+ /// TODO: remove this function once the issue is fixed
234
+ pub fn set_relay_chain_block_number ( & mut self , to : BlockNumberFor < T > ) {
235
+ use cumulus_pallet_parachain_system:: ValidationData ;
236
+ use cumulus_primitives_core:: PersistedValidationData ;
237
+
238
+ self . execute ( || {
239
+ let mut validation_data = ValidationData :: < T > :: get ( ) . unwrap_or_else ( ||
240
+ // PersistedValidationData does not impl default in non-std
241
+ PersistedValidationData {
242
+ parent_head : vec ! [ ] . into ( ) ,
243
+ relay_parent_number : Default :: default ( ) ,
244
+ max_pov_size : Default :: default ( ) ,
245
+ relay_parent_storage_root : Default :: default ( ) ,
246
+ } ) ;
247
+ validation_data. relay_parent_number = to. saturated_into ( ) ;
248
+ ValidationData :: < T > :: put ( validation_data)
249
+ } ) ;
250
+ }
226
251
}
227
252
228
253
// assertions
229
254
impl <
230
- T : Config + pallet_balances:: Config < Balance = Balance > ,
255
+ T : Config + pallet_balances:: Config < Balance = Balance > + cumulus_pallet_parachain_system :: Config ,
231
256
AllPalletsWithoutSystem : OnFinalize < BlockNumberFor < T > > + OnIdle < BlockNumberFor < T > > + OnInitialize < BlockNumberFor < T > > ,
232
- BNProvider : BlockNumberProvider < BlockNumber = frame_system:: pallet_prelude:: BlockNumberFor < T > > ,
233
257
RuntimeEvent : From < Event < T > > + TryInto < Event < T > > + Parameter + Member + IsType < <T as frame_system:: Config >:: RuntimeEvent > ,
234
- > Instantiator < T , AllPalletsWithoutSystem , BNProvider , RuntimeEvent >
258
+ > Instantiator < T , AllPalletsWithoutSystem , RuntimeEvent >
235
259
{
236
260
pub fn test_ct_created_for ( & mut self , project_id : ProjectId ) {
237
261
self . execute ( || {
@@ -335,11 +359,10 @@ impl<
335
359
336
360
// project chain interactions
337
361
impl <
338
- T : Config + pallet_balances:: Config < Balance = Balance > ,
362
+ T : Config + pallet_balances:: Config < Balance = Balance > + cumulus_pallet_parachain_system :: Config ,
339
363
AllPalletsWithoutSystem : OnFinalize < BlockNumberFor < T > > + OnIdle < BlockNumberFor < T > > + OnInitialize < BlockNumberFor < T > > ,
340
- BNProvider : BlockNumberProvider < BlockNumber = frame_system:: pallet_prelude:: BlockNumberFor < T > > ,
341
364
RuntimeEvent : From < Event < T > > + TryInto < Event < T > > + Parameter + Member + IsType < <T as frame_system:: Config >:: RuntimeEvent > ,
342
- > Instantiator < T , AllPalletsWithoutSystem , BNProvider , RuntimeEvent >
365
+ > Instantiator < T , AllPalletsWithoutSystem , RuntimeEvent >
343
366
{
344
367
pub fn get_issuer ( & mut self , project_id : ProjectId ) -> AccountIdOf < T > {
345
368
self . execute ( || ProjectsDetails :: < T > :: get ( project_id) . unwrap ( ) . issuer_account )
0 commit comments