@@ -230,6 +230,45 @@ fn inflation_in_1_year() {
230230 } ) ;
231231}
232232
233+ #[ test]
234+ fn inflation_start_large_kusama_block ( ) {
235+ new_test_ext ( ) . execute_with ( || {
236+ // Total issuance = 1_000_000_000
237+ let initial_issuance: u64 = 1_000_000_000 ;
238+ let start_block: u64 = 10457457 ;
239+ let _ = <Balances as Currency < _ > >:: deposit_creating ( & 1234 , initial_issuance) ;
240+ assert_eq ! ( Balances :: free_balance( 1234 ) , initial_issuance) ;
241+ MockBlockNumberProvider :: set ( start_block) ;
242+
243+ // Start inflation as sudo
244+ assert_ok ! ( Inflation :: start_inflation(
245+ RawOrigin :: Root . into( ) ,
246+ start_block
247+ ) ) ;
248+
249+ // Go through all the block inflations for year 1,
250+ // total issuance will be updated accordingly
251+ // Inflation is set to start in block 1, so first iteration is block 101
252+ for block in ( 101 ..YEAR ) . step_by ( 100 ) {
253+ MockBlockNumberProvider :: set ( start_block + block) ;
254+ Inflation :: on_initialize ( 0 ) ;
255+ }
256+ assert_eq ! (
257+ initial_issuance + ( FIRST_YEAR_BLOCK_INFLATION * ( YEAR / 100 ) ) ,
258+ <Balances as Currency <_>>:: total_issuance( )
259+ ) ;
260+
261+ MockBlockNumberProvider :: set ( start_block + YEAR + 1 ) ;
262+ Inflation :: on_initialize ( 0 ) ;
263+ let block_inflation_year_2 = block_inflation ! ( ) ;
264+ // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
265+ let expecter_year_2_inflation: u64 = ( initial_issuance
266+ + FIRST_YEAR_BLOCK_INFLATION * YEAR / 100 )
267+ * 933 * 100 / ( 10000 * YEAR ) ;
268+ assert_eq ! ( block_inflation_year_2 / 10 , expecter_year_2_inflation / 10 ) ; // divide by 10 for approx. equality
269+ } ) ;
270+ }
271+
233272#[ test]
234273fn inflation_after_year_10_is_flat ( ) {
235274 new_test_ext ( ) . execute_with ( || {
0 commit comments