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