mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-28 06:07:17 +00:00
c8685d256c
* Add v1 as import alias * Update helpers.go * More * Update skip_slot_cache_test.go Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package sanity
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/golang/snappy"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
|
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"github.com/prysmaticlabs/prysm/spectest/utils"
|
|
"google.golang.org/protobuf/proto"
|
|
"gopkg.in/d4l3k/messagediff.v1"
|
|
)
|
|
|
|
func init() {
|
|
state.SkipSlotCache.Disable()
|
|
}
|
|
|
|
// RunSlotProcessingTests executes "sanity/slots" tests.
|
|
func RunSlotProcessingTests(t *testing.T, config string) {
|
|
require.NoError(t, utils.SetConfig(t, config))
|
|
|
|
testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "sanity/slots/pyspec_tests")
|
|
|
|
for _, folder := range testFolders {
|
|
t.Run(folder.Name(), func(t *testing.T) {
|
|
preBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz_snappy")
|
|
require.NoError(t, err)
|
|
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
|
|
require.NoError(t, err, "Failed to decompress")
|
|
base := &pb.BeaconState{}
|
|
require.NoError(t, base.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
|
beaconState, err := v1.InitializeFromProto(base)
|
|
require.NoError(t, err)
|
|
|
|
file, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "slots.yaml")
|
|
require.NoError(t, err)
|
|
fileStr := string(file)
|
|
slotsCount, err := strconv.Atoi(fileStr[:len(fileStr)-5])
|
|
require.NoError(t, err)
|
|
|
|
postBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "post.ssz_snappy")
|
|
require.NoError(t, err)
|
|
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
|
require.NoError(t, err, "Failed to decompress")
|
|
postBeaconState := &pb.BeaconState{}
|
|
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
|
postState, err := state.ProcessSlots(context.Background(), beaconState, beaconState.Slot().Add(uint64(slotsCount)))
|
|
require.NoError(t, err)
|
|
|
|
pbState, err := v1.ProtobufBeaconState(postState.CloneInnerState())
|
|
require.NoError(t, err)
|
|
if !proto.Equal(pbState, postBeaconState) {
|
|
diff, _ := messagediff.PrettyDiff(beaconState, postBeaconState)
|
|
t.Fatalf("Post state does not match expected. Diff between states %s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|