@@ -18,6 +18,7 @@ package tests
1818
1919import (
2020 "fmt"
21+ "math/big"
2122
2223 "github.com/ethereum/go-ethereum/common"
2324 "github.com/ethereum/go-ethereum/common/hexutil"
@@ -65,11 +66,11 @@ func (tt *TransactionTest) validateFork(fork *ttFork) error {
6566 return nil
6667}
6768
68- func (tt * TransactionTest ) Run (config * params. ChainConfig ) error {
69+ func (tt * TransactionTest ) Run () error {
6970 if err := tt .validate (); err != nil {
7071 return err
7172 }
72- validateTx := func (rlpData hexutil.Bytes , signer types.Signer , isHomestead , isIstanbul , isShanghai bool ) (sender common.Address , hash common.Hash , requiredGas uint64 , err error ) {
73+ validateTx := func (rlpData hexutil.Bytes , signer types.Signer , rules * params. Rules ) (sender common.Address , hash common.Hash , requiredGas uint64 , err error ) {
7374 tx := new (types.Transaction )
7475 if err = tx .UnmarshalBinary (rlpData ); err != nil {
7576 return
@@ -79,62 +80,75 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
7980 return
8081 }
8182 // Intrinsic gas
82- requiredGas , err = core .IntrinsicGas (tx .Data (), tx .AccessList (), tx .SetCodeAuthorizations (), tx .To () == nil , isHomestead , isIstanbul , isShanghai )
83+ requiredGas , err = core .IntrinsicGas (tx .Data (), tx .AccessList (), tx .SetCodeAuthorizations (), tx .To () == nil , rules . IsHomestead , rules . IsIstanbul , rules . IsShanghai )
8384 if err != nil {
8485 return
8586 }
8687 if requiredGas > tx .Gas () {
8788 return sender , hash , 0 , fmt .Errorf ("insufficient gas ( %d < %d )" , tx .Gas (), requiredGas )
8889 }
90+
91+ if rules .IsPrague {
92+ var floorDataGas uint64
93+ floorDataGas , err = core .FloorDataGas (tx .Data ())
94+ if err != nil {
95+ return
96+ }
97+ if tx .Gas () < floorDataGas {
98+ return sender , hash , 0 , fmt .Errorf ("%w: have %d, want %d" , core .ErrFloorDataGas , tx .Gas (), floorDataGas )
99+ }
100+ }
89101 hash = tx .Hash ()
90102 return sender , hash , requiredGas , nil
91103 }
92104 for _ , testcase := range []struct {
93- name string
94- signer types.Signer
95- fork * ttFork
96- isHomestead bool
97- isIstanbul bool
98- isShanghai bool
105+ name string
106+ isMerge bool
99107 }{
100- {"Frontier" , types. FrontierSigner {}, tt . Result [ "Frontier" ], false , false , false },
101- {"Homestead" , types. HomesteadSigner {}, tt . Result [ "Homestead" ], true , false , false },
102- {"EIP150" , types. HomesteadSigner {}, tt . Result [ "EIP150" ], true , false , false },
103- {"EIP158" , types . NewEIP155Signer ( config . ChainID ), tt . Result [ "EIP158" ], true , false , false },
104- {"Byzantium" , types . NewEIP155Signer ( config . ChainID ), tt . Result [ "Byzantium" ], true , false , false },
105- {"Constantinople" , types . NewEIP155Signer ( config . ChainID ), tt . Result [ "Constantinople" ], true , false , false },
106- {"Istanbul" , types . NewEIP155Signer ( config . ChainID ), tt . Result [ "Istanbul" ], true , true , false },
107- {"Berlin" , types . NewEIP2930Signer ( config . ChainID ), tt . Result [ "Berlin" ], true , true , false },
108- {"London" , types . NewLondonSigner ( config . ChainID ), tt . Result [ "London" ], true , true , false },
109- {"Paris" , types . NewLondonSigner ( config . ChainID ), tt . Result [ "Paris" ], true , true , false },
110- {"Shanghai" , types . NewLondonSigner ( config . ChainID ), tt . Result [ "Shanghai" ], true , true , true },
111- {"Cancun" , types . NewCancunSigner ( config . ChainID ), tt . Result [ "Cancun" ], true , true , true },
112- {"Prague" , types . NewPragueSigner ( config . ChainID ), tt . Result [ "Prague" ], true , true , true },
108+ {"Frontier" , false },
109+ {"Homestead" , false },
110+ {"EIP150" , false },
111+ {"EIP158" , false },
112+ {"Byzantium" , false },
113+ {"Constantinople" , false },
114+ {"Istanbul" , false },
115+ {"Berlin" , false },
116+ {"London" , false },
117+ {"Paris" , true },
118+ {"Shanghai" , true },
119+ {"Cancun" , true },
120+ {"Prague" , true },
113121 } {
114- if testcase .fork == nil {
122+ expected := tt .Result [testcase .name ]
123+ if expected == nil {
115124 continue
116125 }
117- sender , hash , gas , err := validateTx (tt .Txbytes , testcase .signer , testcase .isHomestead , testcase .isIstanbul , testcase .isShanghai )
126+ config , ok := Forks [testcase .name ]
127+ if ! ok || config == nil {
128+ return UnsupportedForkError {Name : testcase .name }
129+ }
130+ var (
131+ rules = config .Rules (new (big.Int ), testcase .isMerge , 0 )
132+ signer = types .MakeSigner (config , new (big.Int ), 0 )
133+ )
134+ sender , hash , gas , err := validateTx (tt .Txbytes , signer , & rules )
118135 if err != nil {
119- if testcase . fork .Hash != nil {
120- return fmt .Errorf ("unexpected error: %v" , err )
136+ if expected .Hash != nil {
137+ return fmt .Errorf ("unexpected error fork %s : %v" , testcase . name , err )
121138 }
122139 continue
123140 }
124- if testcase .fork .Exception != nil {
125- return fmt .Errorf ("expected error %v, got none (%v)" , * testcase .fork .Exception , err )
126- }
127- if common .Hash (* testcase .fork .Hash ) != hash {
128- return fmt .Errorf ("hash mismatch: got %x, want %x" , hash , common .Hash (* testcase .fork .Hash ))
141+ if expected .Exception != nil {
142+ return fmt .Errorf ("expected error %v, got none (%v), fork %s" , * expected .Exception , err , testcase .name )
129143 }
130- if common .Address ( * testcase . fork . Sender ) != sender {
131- return fmt .Errorf ("sender mismatch: got %x, want %x" , sender , testcase . fork . Sender )
144+ if common .Hash ( * expected . Hash ) != hash {
145+ return fmt .Errorf ("hash mismatch: got %x, want %x" , hash , common . Hash ( * expected . Hash ) )
132146 }
133- if hash != common .Hash ( * testcase . fork . Hash ) {
134- return fmt .Errorf ("hash mismatch: got %x, want %x" , hash , testcase . fork . Hash )
147+ if common .Address ( * expected . Sender ) != sender {
148+ return fmt .Errorf ("sender mismatch: got %x, want %x" , sender , expected . Sender )
135149 }
136- if uint64 (testcase . fork .IntrinsicGas ) != gas {
137- return fmt .Errorf ("intrinsic gas mismatch: got %d, want %d" , gas , uint64 (testcase . fork .IntrinsicGas ))
150+ if uint64 (expected .IntrinsicGas ) != gas {
151+ return fmt .Errorf ("intrinsic gas mismatch: got %d, want %d" , gas , uint64 (expected .IntrinsicGas ))
138152 }
139153 }
140154 return nil
0 commit comments