@@ -66,8 +66,8 @@ func TestEngineExecution(t *testing.T) {
6666 genesisStateRoot := common .HexToHash (GENESIS_STATEROOT )
6767 rollkitGenesisStateRoot := genesisStateRoot [:]
6868
69- t . Run ( "Build chain" , func ( tt * testing. T ) {
70- jwtSecret := setupTestRethEngine (tt )
69+ {
70+ jwtSecret := setupTestRethEngine (t )
7171
7272 executionClient , err := NewEngineExecutionClient (
7373 TEST_ETH_URL ,
@@ -86,7 +86,7 @@ func TestEngineExecution(t *testing.T) {
8686 require .NotZero (t , gasLimit )
8787
8888 prevStateRoot := rollkitGenesisStateRoot
89- lastHeight , lastHash , lastTxs := checkLatestBlock (tt , ctx )
89+ lastHeight , lastHash , lastTxs := checkLatestBlock (t , ctx )
9090
9191 for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
9292 nTxs := int (blockHeight ) + 10
@@ -104,97 +104,98 @@ func TestEngineExecution(t *testing.T) {
104104 time .Sleep (1000 * time .Millisecond )
105105
106106 payload , err := executionClient .GetTxs (ctx )
107- require .NoError (tt , err )
108- require .Lenf (tt , payload , nTxs , "expected %d transactions, got %d" , nTxs , len (payload ))
107+ require .NoError (t , err )
108+ require .Lenf (t , payload , nTxs , "expected %d transactions, got %d" , nTxs , len (payload ))
109109
110110 allPayloads = append (allPayloads , payload )
111111
112112 // Check latest block before execution
113- beforeHeight , beforeHash , beforeTxs := checkLatestBlock (tt , ctx )
114- require .Equal (tt , lastHeight , beforeHeight , "Latest block height should match" )
115- require .Equal (tt , lastHash .Hex (), beforeHash .Hex (), "Latest block hash should match" )
116- require .Equal (tt , lastTxs , beforeTxs , "Number of transactions should match" )
113+ beforeHeight , beforeHash , beforeTxs := checkLatestBlock (t , ctx )
114+ require .Equal (t , lastHeight , beforeHeight , "Latest block height should match" )
115+ require .Equal (t , lastHash .Hex (), beforeHash .Hex (), "Latest block hash should match" )
116+ require .Equal (t , lastTxs , beforeTxs , "Number of transactions should match" )
117117
118118 newStateRoot , maxBytes , err := executionClient .ExecuteTxs (ctx , payload , blockHeight , time .Now (), prevStateRoot )
119- require .NoError (tt , err )
119+ require .NoError (t , err )
120120 if nTxs > 0 {
121- require .NotZero (tt , maxBytes )
121+ require .NotZero (t , maxBytes )
122122 }
123123
124124 err = executionClient .SetFinal (ctx , blockHeight )
125- require .NoError (tt , err )
125+ require .NoError (t , err )
126126
127127 // Check latest block after execution
128- lastHeight , lastHash , lastTxs = checkLatestBlock (tt , ctx )
129- require .Equal (tt , blockHeight , lastHeight , "Latest block height should match" )
130- require .NotEmpty (tt , lastHash .Hex (), "Latest block hash should not be empty" )
131- require .GreaterOrEqual (tt , lastTxs , 0 , "Number of transactions should be non-negative" )
128+ lastHeight , lastHash , lastTxs = checkLatestBlock (t , ctx )
129+ require .Equal (t , blockHeight , lastHeight , "Latest block height should match" )
130+ require .NotEmpty (t , lastHash .Hex (), "Latest block hash should not be empty" )
131+ require .GreaterOrEqual (t , lastTxs , 0 , "Number of transactions should be non-negative" )
132132
133133 if nTxs == 0 {
134- require .Equal (tt , prevStateRoot , newStateRoot )
134+ require .Equal (t , prevStateRoot , newStateRoot )
135135 } else {
136- require .NotEqual (tt , prevStateRoot , newStateRoot )
136+ require .NotEqual (t , prevStateRoot , newStateRoot )
137137 }
138138 prevStateRoot = newStateRoot
139139 }
140- })
141140
142- if t .Failed () {
143- return
141+ if t .Failed () {
142+ return
143+ }
144144 }
145145
146146 // start new container and try to sync
147+ {
148+ jwtSecret := setupTestRethEngine (t )
147149
148- jwtSecret := setupTestRethEngine (t )
149-
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 )
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 )
158158
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 )
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 )
165165
166- prevStateRoot := rollkitGenesisStateRoot
167- lastHeight , lastHash , lastTxs := checkLatestBlock (t , ctx )
166+ prevStateRoot := rollkitGenesisStateRoot
167+ lastHeight , lastHash , lastTxs := checkLatestBlock (t , ctx )
168168
169- for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
170- payload := allPayloads [blockHeight - 1 ]
169+ for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
170+ payload := allPayloads [blockHeight - 1 ]
171171
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" )
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" )
177177
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- }
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+ }
186186
187- err = executionClient .SetFinal (ctx , blockHeight )
188- require .NoError (t , err )
187+ err = executionClient .SetFinal (ctx , blockHeight )
188+ require .NoError (t , err )
189189
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" )
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" )
195195
196- prevStateRoot = newStateRoot
197- fmt .Println ("all good blockheight" , blockHeight )
196+ prevStateRoot = newStateRoot
197+ fmt .Println ("all good blockheight" , blockHeight )
198+ }
198199 }
199200}
200201
0 commit comments