@@ -6,6 +6,8 @@ package core
66import (
77 "fmt"
88 "math/big"
9+ "os"
10+ "path/filepath"
911 "slices"
1012 "testing"
1113
@@ -139,6 +141,30 @@ func copyMemDB(db ethdb.Database) (ethdb.Database, error) {
139141 return newDB , nil
140142}
141143
144+ // This copies all files from a flat directory [src] to a new temporary directory and returns
145+ // the path to the new directory.
146+ func copyFlatDir (t * testing.T , src string ) string {
147+ t .Helper ()
148+ if src == "" {
149+ return ""
150+ }
151+
152+ dst := t .TempDir ()
153+ ents , err := os .ReadDir (src )
154+ require .NoError (t , err )
155+
156+ for _ , e := range ents {
157+ require .False (t , e .IsDir (), "expected flat directory" )
158+ name := e .Name ()
159+ data , err := os .ReadFile (filepath .Join (src , name ))
160+ require .NoError (t , err )
161+ info , err := e .Info ()
162+ require .NoError (t , err )
163+ require .NoError (t , os .WriteFile (filepath .Join (dst , name ), data , info .Mode ().Perm ()))
164+ }
165+ return dst
166+ }
167+
142168// checkBlockChainState creates a new BlockChain instance and checks that exporting each block from
143169// genesis to last accepted from the original instance yields the same last accepted block and state
144170// root.
@@ -205,7 +231,8 @@ func checkBlockChainState(
205231 if err != nil {
206232 t .Fatal (err )
207233 }
208- restartedChain , err := create (originalDB , gspec , lastAcceptedBlock .Hash (), oldChainDataDir )
234+ newChainDataDir := copyFlatDir (t , oldChainDataDir )
235+ restartedChain , err := create (originalDB , gspec , lastAcceptedBlock .Hash (), newChainDataDir )
209236 if err != nil {
210237 t .Fatal (err )
211238 }
0 commit comments