mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 01:32:18 +00:00
1d3a9983cc
* Move block interface next to pb * Update fuzz build bazel * Move interface to /proto/interface and wrapper next to generated pb * Fix fuzz build bazel * Add //proto/eth/v1alpha1/wrapper Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
86 lines
3.3 KiB
Go
86 lines
3.3 KiB
Go
package finality
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/golang/snappy"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
|
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper"
|
|
"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()
|
|
}
|
|
|
|
type Config struct {
|
|
BlocksCount int `json:"blocks_count"`
|
|
}
|
|
|
|
// RunFinalityTest executes finality spec tests.
|
|
func RunFinalityTest(t *testing.T, config string) {
|
|
require.NoError(t, utils.SetConfig(t, config))
|
|
|
|
testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "finality/finality/pyspec_tests")
|
|
for _, folder := range testFolders {
|
|
t.Run(folder.Name(), func(t *testing.T) {
|
|
helpers.ClearCache()
|
|
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")
|
|
beaconStateBase := &pb.BeaconState{}
|
|
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
|
beaconState, err := v1.InitializeFromProto(beaconStateBase)
|
|
require.NoError(t, err)
|
|
|
|
file, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml")
|
|
require.NoError(t, err)
|
|
|
|
metaYaml := &Config{}
|
|
require.NoError(t, utils.UnmarshalYaml(file, metaYaml), "Failed to Unmarshal")
|
|
|
|
var processedState iface.BeaconState
|
|
var ok bool
|
|
for i := 0; i < metaYaml.BlocksCount; i++ {
|
|
filename := fmt.Sprintf("blocks_%d.ssz_snappy", i)
|
|
blockFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), filename)
|
|
require.NoError(t, err)
|
|
blockSSZ, err := snappy.Decode(nil /* dst */, blockFile)
|
|
require.NoError(t, err, "Failed to decompress")
|
|
block := ðpb.SignedBeaconBlock{}
|
|
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
|
|
processedState, err = state.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
|
|
require.NoError(t, err)
|
|
beaconState, ok = processedState.(*v1.BeaconState)
|
|
require.Equal(t, true, ok)
|
|
}
|
|
|
|
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")
|
|
pbState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
|
require.NoError(t, err)
|
|
if !proto.Equal(pbState, postBeaconState) {
|
|
diff, _ := messagediff.PrettyDiff(beaconState.InnerStateUnsafe(), postBeaconState)
|
|
t.Log(diff)
|
|
t.Fatal("Post state does not match expected")
|
|
}
|
|
})
|
|
}
|
|
}
|