@@ -144,59 +144,58 @@ func TestEngineExecution(t *testing.T) {
144144 }
145145
146146 // start new container and try to sync
147- t .Run ("Sync chain" , func (tt * testing.T ) {
148- jwtSecret := setupTestRethEngine (tt )
149147
150- executionClient , err := NewEngineExecutionClient (
151- TEST_ETH_URL ,
152- TEST_ENGINE_URL ,
153- jwtSecret ,
154- genesisHash ,
155- common.Address {},
156- )
157- require .NoError (tt , err )
148+ jwtSecret := setupTestRethEngine (t )
158149
159- ctx , cancel := context .WithTimeout (context .Background (), 300 * time .Second )
160- defer cancel ()
161- stateRoot , gasLimit , err := executionClient .InitChain (ctx , genesisTime , initialHeight , CHAIN_ID )
162- require .NoError (tt , err )
163- require .Equal (tt , rollkitGenesisStateRoot , stateRoot )
164- require .NotZero (tt , gasLimit )
150+ executionClient , err := NewEngineExecutionClient (
151+ TEST_ETH_URL ,
152+ TEST_ENGINE_URL ,
153+ jwtSecret ,
154+ genesisHash ,
155+ common.Address {},
156+ )
157+ require .NoError (t , err )
165158
166- prevStateRoot := rollkitGenesisStateRoot
167- lastHeight , lastHash , lastTxs := checkLatestBlock (tt , ctx )
159+ ctx , cancel := context .WithTimeout (context .Background (), 300 * time .Second )
160+ defer cancel ()
161+ stateRoot , gasLimit , err := executionClient .InitChain (ctx , genesisTime , initialHeight , CHAIN_ID )
162+ require .NoError (t , err )
163+ require .Equal (t , rollkitGenesisStateRoot , stateRoot )
164+ require .NotZero (t , gasLimit )
168165
169- for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
170- payload := allPayloads [ blockHeight - 1 ]
166+ prevStateRoot := rollkitGenesisStateRoot
167+ lastHeight , lastHash , lastTxs := checkLatestBlock ( t , ctx )
171168
172- // Check latest block before execution
173- beforeHeight , beforeHash , beforeTxs := checkLatestBlock (tt , ctx )
174- require .Equal (tt , lastHeight , beforeHeight , "Latest block height should match" )
175- require .Equal (tt , lastHash .Hex (), beforeHash .Hex (), "Latest block hash should match" )
176- require .Equal (tt , lastTxs , beforeTxs , "Number of transactions should match" )
169+ for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
170+ payload := allPayloads [blockHeight - 1 ]
177171
178- newStateRoot , maxBytes , err := executionClient .ExecuteTxs (ctx , payload , blockHeight , time .Now (), prevStateRoot )
179- require .NoError (tt , err )
180- if len (payload ) > 0 {
181- require .NotZero (tt , maxBytes )
182- require .NotEqual (tt , prevStateRoot , newStateRoot )
183- } else {
184- require .Equal (tt , prevStateRoot , newStateRoot )
185- }
172+ // Check latest block before execution
173+ beforeHeight , beforeHash , beforeTxs := checkLatestBlock (t , ctx )
174+ require .Equal (t , lastHeight , beforeHeight , "Latest block height should match" )
175+ require .Equal (t , lastHash .Hex (), beforeHash .Hex (), "Latest block hash should match" )
176+ require .Equal (t , lastTxs , beforeTxs , "Number of transactions should match" )
186177
187- err = executionClient .SetFinal (ctx , blockHeight )
188- require .NoError (tt , err )
178+ newStateRoot , maxBytes , err := executionClient .ExecuteTxs (ctx , payload , blockHeight , time .Now (), prevStateRoot )
179+ require .NoError (t , err )
180+ if len (payload ) > 0 {
181+ require .NotZero (t , maxBytes )
182+ require .NotEqual (t , prevStateRoot , newStateRoot )
183+ } else {
184+ require .Equal (t , prevStateRoot , newStateRoot )
185+ }
189186
190- // Check latest block after execution
191- lastHeight , lastHash , lastTxs = checkLatestBlock (tt , ctx )
192- require .Equal (tt , blockHeight , lastHeight , "Latest block height should match" )
193- require .NotEmpty (tt , lastHash .Hex (), "Latest block hash should not be empty" )
194- require .GreaterOrEqual (tt , lastTxs , 0 , "Number of transactions should be non-negative" )
187+ err = executionClient .SetFinal (ctx , blockHeight )
188+ require .NoError (t , err )
195189
196- prevStateRoot = newStateRoot
197- fmt .Println ("all good blockheight" , blockHeight )
198- }
199- })
190+ // Check latest block after execution
191+ lastHeight , lastHash , lastTxs = checkLatestBlock (t , ctx )
192+ require .Equal (t , blockHeight , lastHeight , "Latest block height should match" )
193+ require .NotEmpty (t , lastHash .Hex (), "Latest block hash should not be empty" )
194+ require .GreaterOrEqual (t , lastTxs , 0 , "Number of transactions should be non-negative" )
195+
196+ prevStateRoot = newStateRoot
197+ fmt .Println ("all good blockheight" , blockHeight )
198+ }
200199}
201200
202201// createEthClient creates an Ethereum client for checking block information
0 commit comments