mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 03:22:18 +00:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package consensustests
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
"github.com/ledgerwatch/erigon/cl/utils"
|
|
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
|
)
|
|
|
|
func decodeStateFromFile(context testContext, filepath string) (*state.BeaconState, error) {
|
|
sszSnappy, err := os.ReadFile(filepath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
testState := state.New(&clparams.MainnetBeaconConfig)
|
|
if err := utils.DecodeSSZSnappyWithVersion(testState, sszSnappy, int(context.version)); err != nil {
|
|
return nil, err
|
|
}
|
|
return testState, nil
|
|
}
|
|
|
|
func testBlocks(context testContext) ([]*cltypes.SignedBeaconBlock, error) {
|
|
i := 0
|
|
blocks := []*cltypes.SignedBeaconBlock{}
|
|
var err error
|
|
for {
|
|
var blockBytes []byte
|
|
blockBytes, err = os.ReadFile(fmt.Sprintf("blocks_%d.ssz_snappy", i))
|
|
if err != nil {
|
|
break
|
|
}
|
|
blk := &cltypes.SignedBeaconBlock{}
|
|
if err = utils.DecodeSSZSnappyWithVersion(blk, blockBytes, int(context.version)); err != nil {
|
|
return nil, err
|
|
}
|
|
blocks = append(blocks, blk)
|
|
i++
|
|
}
|
|
if os.IsNotExist(err) {
|
|
err = nil
|
|
}
|
|
return blocks, err
|
|
}
|