@@ -10,7 +10,6 @@ import (
1010 "os"
1111 "path/filepath"
1212 "strings"
13- "sync"
1413 "testing"
1514 "time"
1615
@@ -67,8 +66,8 @@ func TestEngineExecution(t *testing.T) {
6766 genesisStateRoot := common .HexToHash (GENESIS_STATEROOT )
6867 rollkitGenesisStateRoot := genesisStateRoot [:]
6968
70- t .Run ("build phase " , func (t * testing.T ) {
71- jwtSecret := setupTestRethEngine (t , "jwttoken" )
69+ t .Run ("Build chain " , func (tt * testing.T ) {
70+ jwtSecret := setupTestRethEngine (tt )
7271
7372 executionClient , err := NewEngineExecutionClient (
7473 TEST_ETH_URL ,
@@ -87,7 +86,7 @@ func TestEngineExecution(t *testing.T) {
8786 require .NotZero (t , gasLimit )
8887
8988 prevStateRoot := rollkitGenesisStateRoot
90- lastHeight , lastHash , lastTxs := checkLatestBlock (t , ctx )
89+ lastHeight , lastHash , lastTxs := checkLatestBlock (tt , ctx )
9190
9291 for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
9392 nTxs := int (blockHeight ) + 10
@@ -105,47 +104,48 @@ func TestEngineExecution(t *testing.T) {
105104 time .Sleep (1000 * time .Millisecond )
106105
107106 payload , err := executionClient .GetTxs (ctx )
108- require .NoError (t , err )
109- require .Lenf (t , payload , nTxs , "expected %d transactions, got %d" , nTxs , len (payload ))
107+ require .NoError (tt , err )
108+ require .Lenf (tt , payload , nTxs , "expected %d transactions, got %d" , nTxs , len (payload ))
110109
111110 allPayloads = append (allPayloads , payload )
112111
113112 // Check latest block before execution
114- beforeHeight , beforeHash , beforeTxs := checkLatestBlock (t , ctx )
115- require .Equal (t , lastHeight , beforeHeight , "Latest block height should match" )
116- require .Equal (t , lastHash .Hex (), beforeHash .Hex (), "Latest block hash should match" )
117- require .Equal (t , lastTxs , beforeTxs , "Number of transactions should match" )
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" )
118117
119118 newStateRoot , maxBytes , err := executionClient .ExecuteTxs (ctx , payload , blockHeight , time .Now (), prevStateRoot )
120- require .NoError (t , err )
119+ require .NoError (tt , err )
121120 if nTxs > 0 {
122- require .NotZero (t , maxBytes )
121+ require .NotZero (tt , maxBytes )
123122 }
124123
125124 err = executionClient .SetFinal (ctx , blockHeight )
126- require .NoError (t , err )
125+ require .NoError (tt , err )
127126
128127 // Check latest block after execution
129- lastHeight , lastHash , lastTxs = checkLatestBlock (t , ctx )
130- require .Equal (t , blockHeight , lastHeight , "Latest block height should match" )
131- require .NotEmpty (t , lastHash .Hex (), "Latest block hash should not be empty" )
132- require .GreaterOrEqual (t , lastTxs , 0 , "Number of transactions should be non-negative" )
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" )
133132
134133 if nTxs == 0 {
135- require .Equal (t , prevStateRoot , newStateRoot )
134+ require .Equal (tt , prevStateRoot , newStateRoot )
136135 } else {
137- require .NotEqual (t , prevStateRoot , newStateRoot )
136+ require .NotEqual (tt , prevStateRoot , newStateRoot )
138137 }
139138 prevStateRoot = newStateRoot
140139 }
141140 })
141+
142142 if t .Failed () {
143143 return
144144 }
145145
146146 // start new container and try to sync
147- t .Run ("sync phase " , func (t * testing.T ) {
148- jwtSecret := setupTestRethEngine (t , "jwttoken2" )
147+ t .Run ("Sync chain " , func (tt * testing.T ) {
148+ jwtSecret := setupTestRethEngine (t )
149149
150150 executionClient , err := NewEngineExecutionClient (
151151 TEST_ETH_URL ,
@@ -164,34 +164,36 @@ func TestEngineExecution(t *testing.T) {
164164 require .NotZero (t , gasLimit )
165165
166166 prevStateRoot := rollkitGenesisStateRoot
167- lastHeight , lastHash , lastTxs := checkLatestBlock (t , ctx )
167+ lastHeight , lastHash , lastTxs := checkLatestBlock (tt , ctx )
168168
169169 for blockHeight := initialHeight ; blockHeight <= 10 ; blockHeight ++ {
170170 payload := allPayloads [blockHeight - 1 ]
171171
172172 // 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" )
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" )
177177
178178 newStateRoot , maxBytes , err := executionClient .ExecuteTxs (ctx , payload , blockHeight , time .Now (), prevStateRoot )
179179 require .NoError (t , err )
180180 if len (payload ) > 0 {
181- require .NotZero (t , maxBytes )
182- require .NotEqual (t , prevStateRoot , newStateRoot )
181+ require .NotZero (tt , maxBytes )
182+ }
183+ if len (payload ) == 0 {
184+ require .Equal (tt , prevStateRoot , newStateRoot )
183185 } else {
184- require .Equal ( t , prevStateRoot , newStateRoot )
186+ require .NotEqual ( tt , prevStateRoot , newStateRoot )
185187 }
186188
187189 err = executionClient .SetFinal (ctx , blockHeight )
188- require .NoError (t , err )
190+ require .NoError (tt , err )
189191
190192 // 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" )
193+ lastHeight , lastHash , lastTxs = checkLatestBlock (tt , ctx )
194+ require .Equal (tt , blockHeight , lastHeight , "Latest block height should match" )
195+ require .NotEmpty (tt , lastHash .Hex (), "Latest block hash should not be empty" )
196+ require .GreaterOrEqual (tt , lastTxs , 0 , "Number of transactions should be non-negative" )
195197
196198 prevStateRoot = newStateRoot
197199 fmt .Println ("all good blockheight" , blockHeight )
@@ -253,23 +255,16 @@ func generateJWTSecret() (string, error) {
253255 return hex .EncodeToString (jwtSecret ), nil
254256}
255257
256- // Global mutex to serialize Docker Compose operations
257- var dockerMutex sync.Mutex
258-
259258// setupTestRethEngine starts a reth container using docker-compose and returns the JWT secret
260- func setupTestRethEngine (t * testing.T , jp string ) string {
259+ func setupTestRethEngine (t * testing.T ) string {
261260 t .Helper ()
262261
263- // Serialize Docker Compose operations
264- dockerMutex .Lock ()
265- defer dockerMutex .Unlock ()
266-
267262 // Get absolute path to docker directory
268263 dockerPath , err := filepath .Abs (DOCKER_PATH )
269264 require .NoError (t , err )
270265
271266 // Create JWT directory if it doesn't exist
272- jwtPath := filepath .Join (dockerPath , jp )
267+ jwtPath := filepath .Join (dockerPath , "jwttoken" )
273268 err = os .MkdirAll (jwtPath , 0750 ) // More permissive directory permissions
274269 require .NoError (t , err )
275270
@@ -397,9 +392,9 @@ func TestSubmitTransaction(t *testing.T) {
397392 lastNonce , err = rpcClient .NonceAt (ctx , address , new (big.Int ).SetUint64 (height ))
398393 require .NoError (t , err )
399394
400- for s := 0 ; s < 15 ; s ++ {
395+ for s := 0 ; s < 30 ; s ++ {
401396 startTime := time .Now ()
402- for i := 0 ; i < 50 ; i ++ {
397+ for i := 0 ; i < 5000 ; i ++ {
403398 tx := getRandomTransaction (t , 22000 )
404399 submitTransaction (t , tx )
405400 }
0 commit comments