2023-09-26 11:34:41 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-07-03 09:59:21 +00:00
|
|
|
"github.com/cerc-io/eth-testing/chains/premerge2"
|
2023-09-26 11:34:41 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-07-03 09:59:21 +00:00
|
|
|
FixtureNodePaths = premerge2.Block1_StateNodePaths
|
|
|
|
FixtureLeafKeys = premerge2.Block1_StateNodeLeafKeys
|
2023-09-26 11:34:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func OpenFixtureTrie(t *testing.T, height uint64) (state.Trie, ethdb.Database) {
|
2024-07-03 09:59:21 +00:00
|
|
|
data := premerge2.ChainData
|
2024-07-04 09:06:18 +00:00
|
|
|
edb, err := rawdb.Open(rawdb.OpenOptions{
|
|
|
|
Directory: data.ChainData,
|
|
|
|
AncientsDirectory: data.Ancient,
|
|
|
|
Namespace: t.Name(),
|
|
|
|
Cache: 1024,
|
|
|
|
Handles: 256,
|
|
|
|
ReadOnly: true,
|
|
|
|
})
|
2023-09-26 11:34:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
hash := rawdb.ReadCanonicalHash(edb, height)
|
|
|
|
header := rawdb.ReadHeader(edb, hash, height)
|
|
|
|
if header == nil {
|
|
|
|
t.Fatalf("unable to read canonical header at height %d", height)
|
|
|
|
}
|
|
|
|
sdb := state.NewDatabase(edb)
|
|
|
|
tree, err := sdb.OpenTrie(header.Root)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return tree, edb
|
|
|
|
}
|