Compare commits

...

1 Commits

Author SHA1 Message Date
Bastin
0949baeac5 add lc data collection spec tests 2025-09-24 13:58:36 -04:00
7 changed files with 136 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ go_test(
"altair__fork__upgrade_to_altair_test.go",
"altair__fork_transition__transition_test.go",
"altair__forkchoice__forkchoice_test.go",
"altair__light_client__data_collection_test.go",
"altair__light_client__single_merkle_proof_test.go",
"altair__light_client__update_ranking_test.go",
"altair__operations__attestation_test.go",

View File

@@ -0,0 +1,12 @@
package minimal
import (
"testing"
"github.com/OffchainLabs/prysm/v6/runtime/version"
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/light_client"
)
func TestMinimal_Altair_LightClient_DataCollection(t *testing.T) {
light_client.RunLightClientDataCollectionTests(t, "minimal", version.Altair)
}

View File

@@ -7,6 +7,6 @@ import (
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/light_client"
)
func TestMainnet_Altair_LightClient_SingleMerkleProof(t *testing.T) {
func TestMinimal_Altair_LightClient_SingleMerkleProof(t *testing.T) {
light_client.RunLightClientSingleMerkleProofTests(t, "minimal", version.Altair)
}

View File

@@ -7,6 +7,6 @@ import (
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/light_client"
)
func TestMainnet_Altair_LightClient_UpdateRanking(t *testing.T) {
func TestMinimal_Altair_LightClient_UpdateRanking(t *testing.T) {
light_client.RunLightClientUpdateRankingTests(t, "minimal", version.Altair)
}

View File

@@ -4,7 +4,9 @@ go_library(
name = "go_default_library",
testonly = True,
srcs = [
"data_collection.go",
"single_merkle_proof.go",
"types.go",
"update_ranking.go",
],
importpath = "github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/light_client",

View File

@@ -0,0 +1,80 @@
package light_client
import (
"context"
"fmt"
"path"
"testing"
"github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain"
"github.com/OffchainLabs/prysm/v6/beacon-chain/core/helpers"
state_native "github.com/OffchainLabs/prysm/v6/beacon-chain/state/state-native"
"github.com/OffchainLabs/prysm/v6/consensus-types/blocks"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v6/runtime/version"
"github.com/OffchainLabs/prysm/v6/testing/require"
"github.com/OffchainLabs/prysm/v6/testing/spectest/utils"
"github.com/OffchainLabs/prysm/v6/testing/util"
"github.com/golang/snappy"
)
// RunLightClientDataCollectionTests executes "light_client/data_collection/pyspec_tests/light_client_data_collection" tests.
func RunLightClientDataCollectionTests(t *testing.T, config string, v int) {
require.NoError(t, utils.SetConfig(t, config))
_, testsFolderPath := utils.TestFolders(t, config, version.String(v), "light_client/data_collection/pyspec_tests/")
testTypes, err := util.BazelListDirectories(testsFolderPath)
require.NoError(t, err)
if len(testTypes) == 0 {
t.Fatalf("No test types found for %s", testsFolderPath)
}
if testTypes[0] != "light_client_data_collection" {
t.Fatalf("Expected test type 'light_client_data_collection', got %s", testTypes[0])
}
_, testsFolderPath = utils.TestFolders(t, config, version.String(v), "light_client/data_collection/pyspec_tests/light_client_data_collection")
helpers.ClearCache()
t.Run("data collection", func(t *testing.T) {
runLightClientDataCollectionTest(t, testsFolderPath, v)
})
}
func runLightClientDataCollectionTest(t *testing.T, testFolderPath string, v int) {
stepsFile, err := util.BazelFileBytes(path.Join(testFolderPath, "steps.yaml"))
require.NoError(t, err)
var steps []Step
require.NoError(t, utils.UnmarshalYaml(stepsFile, &steps))
preBeaconStateFile, err := util.BazelFileBytes(path.Join(testFolderPath, "initial_state.ssz_snappy"))
require.NoError(t, err)
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
require.NoError(t, err, "Failed to decompress")
beaconStateBase := &ethpb.BeaconStateAltair{}
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
beaconState, err := state_native.InitializeFromProtoAltair(beaconStateBase)
require.NoError(t, err)
service, err := blockchain.NewService(context.Background(), blockchain.WithFinalizedStateAtStartUp(beaconState))
require.NoError(t, err)
for _, step := range steps {
if step.NewBlock != nil && step.NewHead == nil {
fmt.Println("block")
blkFile, err := util.BazelFileBytes(path.Join(testFolderPath, step.NewBlock.Data))
require.NoError(t, err)
blockSSZ, err := snappy.Decode(nil /* dst */, blkFile)
require.NoError(t, err, "Failed to decompress")
block := &ethpb.SignedBeaconBlockAltair{}
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
wsb, err := blocks.NewSignedBeaconBlock(block)
require.NoError(t, err)
} else if step.NewHead != nil && step.NewBlock == nil {
fmt.Println("head")
} else {
t.Fatalf("Unexpected step")
}
}
}

View File

@@ -0,0 +1,39 @@
package light_client
type Step struct {
NewBlock *DataEntry `json:"new_block"`
NewHead *HeadEntry `json:"new_head"`
}
type DataEntry struct {
ForkDigest string `json:"fork_digest"`
Data string `json:"data"`
}
type HeadEntry struct {
HeadBlockRoot string `json:"head_block_root"`
Checks *ChecksEntry `json:"checks"`
}
type ChecksEntry struct {
LatestFinalizedCheckpoint EpochRoot `json:"latest_finalized_checkpoint"`
LatestFinalityUpdate DataEntry `json:"latest_finality_update"`
LatestOptimisticUpdate DataEntry `json:"latest_optimistic_update"`
Bootstraps []*BootstrapEntry `json:"bootstraps"`
BestUpdates []*BestUpdatesEntry `json:"best_updates"`
}
type BestUpdatesEntry struct {
Period int `json:"period"`
Update DataEntry `json:"update"`
}
type BootstrapEntry struct {
BlockRoot string `json:"block_root"`
Bootstrap DataEntry `json:"bootstrap"`
}
type EpochRoot struct {
Epoch int `json:"epoch"`
Root string `json:"root"`
}