2023-02-17 23:00:07 +00:00
|
|
|
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 {
|
2023-02-24 21:07:32 +00:00
|
|
|
err = transistor.TransitionState(block)
|
2023-02-17 23:00:07 +00:00
|
|
|
if err != nil {
|
2023-02-24 21:07:32 +00:00
|
|
|
break
|
2023-02-17 23:00:07 +00:00
|
|
|
}
|
2023-02-24 21:07:32 +00:00
|
|
|
}
|
|
|
|
// Deal with transition error
|
|
|
|
if expectedError && err == nil {
|
|
|
|
return fmt.Errorf("expected error")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
if expectedError {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
2023-02-17 23:00:07 +00:00
|
|
|
}
|
|
|
|
expectedRoot, err := expectedState.HashSSZ()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
haveRoot, err := testState.HashSSZ()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if haveRoot != expectedRoot {
|
2023-02-24 21:07:32 +00:00
|
|
|
return fmt.Errorf("mismatching state roots")
|
2023-02-17 23:00:07 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|