2023-03-02 15:42:11 +00:00
|
|
|
package consensustests
|
2023-02-17 14:13:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
|
|
|
)
|
|
|
|
|
2023-03-02 15:42:11 +00:00
|
|
|
func finalityTestFunction(context testContext) error {
|
|
|
|
testState, err := decodeStateFromFile(context, "pre.ssz_snappy")
|
2023-02-17 14:13:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-02 15:42:11 +00:00
|
|
|
expectedState, err := decodeStateFromFile(context, "post.ssz_snappy")
|
2023-02-17 14:13:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-02 15:42:11 +00:00
|
|
|
blocks, err := testBlocks(context)
|
2023-02-17 14:13:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
transistor := transition.New(testState, &clparams.MainnetBeaconConfig, nil, false)
|
|
|
|
startSlot := testState.Slot()
|
|
|
|
for _, block := range blocks {
|
|
|
|
if err := transistor.TransitionState(block); err != nil {
|
|
|
|
return fmt.Errorf("cannot transition state: %s. slot=%d. start_slot=%d", err, block.Block.Slot, startSlot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expectedRoot, err := expectedState.HashSSZ()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
haveRoot, err := testState.HashSSZ()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if haveRoot != expectedRoot {
|
2023-02-17 23:00:07 +00:00
|
|
|
return fmt.Errorf("mismatching state roots")
|
2023-02-17 14:13:00 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|