erigon-pulse/cmd/caplin-regression/regression/reader.go
2023-06-07 20:01:32 +02:00

55 lines
1.4 KiB
Go

package regression
import (
"io/fs"
"io/ioutil"
"path"
"path/filepath"
"sort"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/utils"
)
func (r *RegressionTester) readStartingState() (*state.BeaconState, error) {
stateFile, err := ioutil.ReadFile(path.Join(r.testDirectory, regressionPath, startingStatePath))
if err != nil {
return nil, err
}
s := state.New(&clparams.MainnetBeaconConfig)
if err := utils.DecodeSSZSnappy(s, stateFile, int(clparams.CapellaVersion)); err != nil {
return nil, err
}
return s, nil
}
func (r *RegressionTester) initBlocks() error {
r.blockList = nil
if err := filepath.Walk(filepath.Join(r.testDirectory, regressionPath, signedBeaconBlockPath), func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info == nil || info.IsDir() || info.Name() != "data.bin" {
return nil
}
f, err := ioutil.ReadFile(path)
if err != nil {
return err
}
b := new(cltypes.SignedBeaconBlock)
if err := utils.DecodeSSZSnappy(b, f, int(clparams.CapellaVersion)); err != nil {
return err
}
r.blockList = append(r.blockList, b)
return nil
}); err != nil {
return err
}
sort.Slice(r.blockList, func(i, j int) bool {
return r.blockList[i].Block.Slot < r.blockList[j].Block.Slot
})
return nil
}