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