erigon-pulse/cl/spectest/consensus_tests/forks.go
a 436493350e
Sentinel refactor (#8296)
1. changes sentinel to use an http-like interface

2. moves hexutil, crypto/blake2b, metrics packages to erigon-lib
2023-10-22 01:17:18 +02:00

50 lines
1.2 KiB
Go

package consensus_tests
import (
"fmt"
"github.com/ledgerwatch/erigon/spectest"
"io/fs"
"os"
"testing"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var ForksFork = spectest.HandlerFunc(func(t *testing.T, root fs.FS, c spectest.TestCase) (err error) {
preState, err := spectest.ReadBeaconState(root, c.Version()-1, spectest.PreSsz)
require.NoError(t, err)
postState, err := spectest.ReadBeaconState(root, c.Version(), spectest.PostSsz)
expectedError := os.IsNotExist(err)
if !expectedError {
require.NoError(t, err)
}
switch preState.Version() {
case clparams.Phase0Version:
err = preState.UpgradeToAltair()
case clparams.AltairVersion:
err = preState.UpgradeToBellatrix()
case clparams.BellatrixVersion:
err = preState.UpgradeToCapella()
case clparams.CapellaVersion:
err = preState.UpgradeToDeneb()
default:
err = spectest.ErrHandlerNotImplemented(fmt.Sprintf("block state %v", preState.Version()))
}
if expectedError {
assert.Error(t, err)
}
haveRoot, err := preState.HashSSZ()
assert.NoError(t, err)
expectedRoot, err := postState.HashSSZ()
assert.NoError(t, err)
assert.EqualValues(t, haveRoot, expectedRoot, "state root")
return nil
})