@@ -395,3 +395,69 @@ impl BlockHashRef for LocalBlockchain {
395
395
. ok_or ( BlockchainError :: UnknownBlockNumber )
396
396
}
397
397
}
398
+
399
+ #[ cfg( test) ]
400
+ mod tests {
401
+ use edr_eth:: { AccountInfo , HashMap } ;
402
+ use revm:: primitives:: { Account , AccountStatus } ;
403
+
404
+ use super :: * ;
405
+ use crate :: state:: IrregularState ;
406
+
407
+ #[ test]
408
+ fn compute_state_after_reserve ( ) -> anyhow:: Result < ( ) > {
409
+ let address1 = Address :: random ( ) ;
410
+ let accounts = vec ! [ (
411
+ address1,
412
+ AccountInfo {
413
+ balance: U256 :: from( 1_000_000_000u64 ) ,
414
+ ..AccountInfo :: default ( )
415
+ } ,
416
+ ) ] ;
417
+
418
+ let genesis_diff = accounts
419
+ . iter ( )
420
+ . map ( |( address, info) | {
421
+ (
422
+ * address,
423
+ Account {
424
+ info : info. clone ( ) ,
425
+ storage : HashMap :: new ( ) ,
426
+ status : AccountStatus :: Created | AccountStatus :: Touched ,
427
+ } ,
428
+ )
429
+ } )
430
+ . collect :: < HashMap < _ , _ > > ( )
431
+ . into ( ) ;
432
+
433
+ let mut blockchain = LocalBlockchain :: new (
434
+ genesis_diff,
435
+ 123 ,
436
+ SpecId :: SHANGHAI ,
437
+ 6_000_000 ,
438
+ None ,
439
+ Some ( B256 :: random ( ) ) ,
440
+ None ,
441
+ Some ( BlobGas :: default ( ) ) ,
442
+ Some ( B256 :: random ( ) ) ,
443
+ )
444
+ . unwrap ( ) ;
445
+
446
+ let irregular_state = IrregularState :: default ( ) ;
447
+ let expected = blockchain. state_at_block_number ( 0 , irregular_state. state_overrides ( ) ) ?;
448
+
449
+ blockchain. reserve_blocks ( 1_000_000_000 , 1 ) ?;
450
+
451
+ let actual =
452
+ blockchain. state_at_block_number ( 1_000_000_000 , irregular_state. state_overrides ( ) ) ?;
453
+
454
+ assert_eq ! ( actual. state_root( ) . unwrap( ) , expected. state_root( ) . unwrap( ) ) ;
455
+
456
+ for ( address, expected) in accounts {
457
+ let actual_account = actual. basic ( address) ?. expect ( "account should exist" ) ;
458
+ assert_eq ! ( actual_account, expected) ;
459
+ }
460
+
461
+ Ok ( ( ) )
462
+ }
463
+ }
0 commit comments