mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
5e939378d0
* Ignore latest messages in fork choice prior to latest justified * Make sure Compact Committee Roots isn't changed by process_final_updates * WIP add attestation bitfields length to match committee length * Begin work on updating spec tests to 0.8.2 * WIP set up for new spec test structure * Fix slashings * Get mainnet tests mostly passing for attestations and attester slashings * Fix process attestation test * Undo change * Complete spec tests for all operations Still need sanity block tests * Fix BLS sigs * Reduce amount of reused code in core/blocks/spectests/ * Fix tests * Update block sanity tests to 0.8.2 * Update epoch spec tests to 0.8.2 * Clean up all tests and fix shuffling/epoch tests * WIP update bls tests to 0.8.2 * WIP update bls tests to 0.8.3 * Finish BLS spectest update to 0.8.3 * Fix shuffling spec tests * Fix more tests * Update proto ssz spec tests to 0.8.3 * Attempt to fix PrevEpochFFGDataMismatches test * Goimports * Fix documentation * fix test * Use custom general spec tests * Reduce code footprint * Remove unneeded minimal skip * Fix for comments * Fix for comments * Fix test * Small fixes * Cleanup block spec tests a bit * Undo change * fix validator * Fix validator tests * Run gazelle * Fix error output for epoch spec tests
145 lines
3.8 KiB
Go
145 lines
3.8 KiB
Go
package testing
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"errors"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
// SSZRoots --
|
|
type SSZRoots struct {
|
|
Root string `json:"root"`
|
|
SigningRoot string `json:"signing_root"`
|
|
}
|
|
|
|
func runSSZStaticTests(t *testing.T, config string) {
|
|
if err := spectest.SetConfig(config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
testFolders, _ := testutil.TestFolders(t, config, "ssz_static")
|
|
for _, folder := range testFolders {
|
|
innerPath := path.Join("ssz_static", folder.Name(), "ssz_random")
|
|
innerTestFolders, innerTestsFolderPath := testutil.TestFolders(t, config, innerPath)
|
|
|
|
for _, innerFolder := range innerTestFolders {
|
|
t.Run(path.Join(folder.Name(), innerFolder.Name()), func(t *testing.T) {
|
|
serializedBytes, err := testutil.BazelFileBytes(innerTestsFolderPath, innerFolder.Name(), "serialized.ssz")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
object, err := UnmarshalledSSZ(serializedBytes, folder.Name())
|
|
if err != nil {
|
|
t.Fatalf("Could not unmarshall serialized SSZ: %v", err)
|
|
}
|
|
|
|
rootsYamlFile, err := testutil.BazelFileBytes(innerTestsFolderPath, innerFolder.Name(), "roots.yaml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rootsYaml := &SSZRoots{}
|
|
if err := testutil.UnmarshalYaml(rootsYamlFile, rootsYaml); err != nil {
|
|
t.Fatalf("Failed to Unmarshal: %v", err)
|
|
}
|
|
|
|
root, err := ssz.HashTreeRoot(object)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rootBytes, err := hex.DecodeString(rootsYaml.Root[2:])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(root[:], rootBytes) {
|
|
t.Fatalf(
|
|
"Did not receive expected hash tree root, received: %#x, expected: %#x",
|
|
root[:],
|
|
rootBytes,
|
|
)
|
|
}
|
|
|
|
if rootsYaml.SigningRoot == "" {
|
|
return
|
|
}
|
|
signingRoot, err := ssz.SigningRoot(object)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
signingRootBytes, err := hex.DecodeString(rootsYaml.SigningRoot[2:])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(signingRoot[:], signingRootBytes) {
|
|
t.Fatalf(
|
|
"Did not receive expected signing root, received: %#x, expected: %#x",
|
|
signingRoot[:],
|
|
signingRootBytes,
|
|
)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func UnmarshalledSSZ(serializedBytes []byte, folderName string) (interface{}, error) {
|
|
var obj interface{}
|
|
switch folderName {
|
|
case "Attestation":
|
|
obj = ðpb.Attestation{}
|
|
case "AttestationData":
|
|
obj = ðpb.AttestationData{}
|
|
case "AttestationDataAndCustodyBit":
|
|
obj = &pb.AttestationDataAndCustodyBit{}
|
|
case "AttesterSlashing":
|
|
obj = ðpb.AttesterSlashing{}
|
|
case "BeaconBlock":
|
|
obj = ðpb.BeaconBlock{}
|
|
case "BeaconBlockBody":
|
|
obj = ðpb.BeaconBlockBody{}
|
|
case "BeaconBlockHeader":
|
|
obj = ðpb.BeaconBlockHeader{}
|
|
case "BeaconState":
|
|
obj = &pb.BeaconState{}
|
|
case "Checkpoint":
|
|
obj = ðpb.Checkpoint{}
|
|
case "CompactCommittee":
|
|
obj = &pb.CompactCommittee{}
|
|
case "Crosslink":
|
|
obj = ðpb.Crosslink{}
|
|
case "Deposit":
|
|
obj = ðpb.Deposit{}
|
|
case "DepositData":
|
|
obj = ðpb.Deposit_Data{}
|
|
case "Eth1Data":
|
|
obj = ðpb.Eth1Data{}
|
|
case "Fork":
|
|
obj = &pb.Fork{}
|
|
case "HistoricalBatch":
|
|
obj = &pb.HistoricalBatch{}
|
|
case "IndexedAttestation":
|
|
obj = ðpb.IndexedAttestation{}
|
|
case "PendingAttestation":
|
|
obj = &pb.PendingAttestation{}
|
|
case "ProposerSlashing":
|
|
obj = ðpb.ProposerSlashing{}
|
|
case "Transfer":
|
|
obj = ðpb.Transfer{}
|
|
case "Validator":
|
|
obj = ðpb.Validator{}
|
|
case "VoluntaryExit":
|
|
obj = ðpb.VoluntaryExit{}
|
|
default:
|
|
return nil, errors.New("type not found")
|
|
}
|
|
err := ssz.Unmarshal(serializedBytes, obj)
|
|
return obj, err
|
|
}
|