mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Validate blobs feature (#12574)
This commit is contained in:
19
testing/spectest/general/deneb/kzg/BUILD.bazel
Normal file
19
testing/spectest/general/deneb/kzg/BUILD.bazel
Normal file
@@ -0,0 +1,19 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_test")
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["verify_blob_kzg_proof_batch_test.go"],
|
||||
data = [
|
||||
"@consensus_spec_tests_general//:test_data",
|
||||
],
|
||||
tags = ["spectest"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/kzg:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/spectest/utils:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,73 @@
|
||||
package kzg
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
kzgPrysm "github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain/kzg"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/utils"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
||||
)
|
||||
|
||||
type KZGTestDataInput struct {
|
||||
Blobs []string `json:"blobs"`
|
||||
Commitments []string `json:"commitments"`
|
||||
Proofs []string `json:"proofs"`
|
||||
}
|
||||
|
||||
type KZGTestData struct {
|
||||
Input KZGTestDataInput `json:"input"`
|
||||
Output bool `json:"output"`
|
||||
}
|
||||
|
||||
func TestVerifyBlobKZGProofBatch(t *testing.T) {
|
||||
require.NoError(t, kzgPrysm.Start())
|
||||
testFolders, testFolderPath := utils.TestFolders(t, "general", "deneb", "kzg/verify_blob_kzg_proof_batch/small")
|
||||
if len(testFolders) == 0 {
|
||||
t.Fatalf("No test folders found for %s/%s/%s", "general", "deneb", "kzg/verify_blob_kzg_proof_batch/small")
|
||||
}
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
|
||||
require.NoError(t, err)
|
||||
test := &KZGTestData{}
|
||||
require.NoError(t, yaml.Unmarshal(file, test))
|
||||
var sidecars []*ethpb.BlobSidecar
|
||||
blobs := test.Input.Blobs
|
||||
commitments := test.Input.Commitments
|
||||
proofs := test.Input.Proofs
|
||||
if len(proofs) != len(blobs) {
|
||||
require.Equal(t, false, test.Output)
|
||||
return
|
||||
}
|
||||
var kzgs [][]byte
|
||||
// Need separate loops to test length checks in
|
||||
// `IsDataAvailable`
|
||||
for i, blob := range blobs {
|
||||
blobBytes, err := hex.DecodeString(blob[2:])
|
||||
require.NoError(t, err)
|
||||
proofBytes, err := hex.DecodeString(proofs[i][2:])
|
||||
require.NoError(t, err)
|
||||
sidecar := ðpb.BlobSidecar{
|
||||
Blob: blobBytes,
|
||||
KzgProof: proofBytes,
|
||||
}
|
||||
sidecars = append(sidecars, sidecar)
|
||||
}
|
||||
for _, commitment := range commitments {
|
||||
commitmentBytes, err := hex.DecodeString(commitment[2:])
|
||||
require.NoError(t, err)
|
||||
kzgs = append(kzgs, commitmentBytes)
|
||||
}
|
||||
if test.Output {
|
||||
require.NoError(t, kzgPrysm.IsDataAvailable(kzgs, sidecars))
|
||||
} else {
|
||||
require.NotNil(t, kzgPrysm.IsDataAvailable(kzgs, sidecars))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user