File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -662,3 +662,52 @@ def test_worst_selfdestruct_created(
662
662
post = post ,
663
663
tx = code_tx ,
664
664
)
665
+
666
+
667
+ @pytest .mark .valid_from ("Cancun" )
668
+ @pytest .mark .parametrize ("value_bearing" , [True , False ])
669
+ def test_worst_selfdestruct_initcode (
670
+ state_test : StateTestFiller ,
671
+ pre : Alloc ,
672
+ value_bearing : bool ,
673
+ ):
674
+ """Test running a block with as many SELFDESTRUCTs as possible executed in initcode."""
675
+ env = Environment ()
676
+ pre .fund_address (env .fee_recipient , 1 )
677
+
678
+ # code = Op.SELFDESTRUCT(Op.COINBASE)
679
+ initcode = 0x41FF
680
+ code = (
681
+ Op .MSTORE (0 , initcode )
682
+ + While (
683
+ body = Op .POP (
684
+ Op .CALL (
685
+ address = Op .CREATE (
686
+ value = 1 if value_bearing else 0 ,
687
+ offset = 30 ,
688
+ size = 2 ,
689
+ )
690
+ )
691
+ ),
692
+ # Stop before we run out of gas for the whole tx execution.
693
+ # The value was found by trial-error rounded to the next 1000 multiple.
694
+ condition = Op .GT (Op .GAS , 10_000 ),
695
+ )
696
+ + Op .SSTORE (0 , 42 ) # Done for successful tx execution assertion below.
697
+ )
698
+ # The 0 storage slot is initialize to avoid creation costs in SSTORE above.
699
+ code_addr = pre .deploy_contract (code = code , balance = 100_000 , storage = {0 : 1 })
700
+ code_tx = Transaction (
701
+ to = code_addr ,
702
+ gas_limit = env .gas_limit ,
703
+ gas_price = 10 ,
704
+ sender = pre .fund_eoa (),
705
+ )
706
+
707
+ post = {code_addr : Account (storage = {0 : 42 })} # Check for successful execution.
708
+ state_test (
709
+ env = env ,
710
+ pre = pre ,
711
+ post = post ,
712
+ tx = code_tx ,
713
+ )
You can’t perform that action at this time.
0 commit comments