mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 03:51:20 +00:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
||
|
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
||
|
)
|
||
|
|
||
|
func testSanityFunction() error {
|
||
|
testState, err := decodeStateFromFile("pre.ssz_snappy")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
var expectedError bool
|
||
|
expectedState, err := decodeStateFromFile("post.ssz_snappy")
|
||
|
if os.IsNotExist(err) {
|
||
|
expectedError = true
|
||
|
err = nil
|
||
|
}
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
blocks, err := testBlocks()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
transistor := transition.New(testState, &clparams.MainnetBeaconConfig, nil, false)
|
||
|
for _, block := range blocks {
|
||
|
err := transistor.TransitionState(block)
|
||
|
if expectedError && err == nil {
|
||
|
return fmt.Errorf("expected error")
|
||
|
}
|
||
|
if err != nil {
|
||
|
if expectedError {
|
||
|
return nil
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
}
|
||
|
expectedRoot, err := expectedState.HashSSZ()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
haveRoot, err := testState.HashSSZ()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if haveRoot != expectedRoot {
|
||
|
return fmt.Errorf("mismatching state roots.")
|
||
|
}
|
||
|
return nil
|
||
|
}
|