mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 12:07:17 +00:00
41 lines
936 B
Go
41 lines
936 B
Go
package consensustests
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
|
)
|
|
|
|
func finalityTestFunction(context testContext) error {
|
|
testState, err := decodeStateFromFile(context, "pre.ssz_snappy")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
expectedState, err := decodeStateFromFile(context, "post.ssz_snappy")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
blocks, err := testBlocks(context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
startSlot := testState.Slot()
|
|
for _, block := range blocks {
|
|
if err := transition.TransitionState(testState, block, true); 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 {
|
|
return fmt.Errorf("mismatching state roots")
|
|
}
|
|
return nil
|
|
}
|