mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* Add basic PathElement * Add ssz_type.go * Add basic sszInfo * Add containerInfo * Add basic analyzer without analyzing list/vector * Add analyzer for homogeneous collection types * Add offset/length calculator * Add testutil package in encoding/ssz/query * Add first round trip test for IndexedAttestationElectra * Go mod tidy * Add Print function for debugging purpose * Add changelog * Add testonly flag for testutil package & Nit for nogo * Apply reviews from Radek * Replace fastssz with prysmaticlabs one * Add proto/ssz_query package for testing purpose * Update encoding/ssz/query tests to decouple with beacon types * Use require.* instead of assert.* * Fix import name for proto ssz_query package * Remove uint8/uint16 and some byte arrays in FixedTestContainer * Add newline for files * Fix comment about byte array in ssz_query.proto --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package testutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v6/encoding/ssz/query"
|
|
"github.com/OffchainLabs/prysm/v6/testing/require"
|
|
ssz "github.com/prysmaticlabs/fastssz"
|
|
)
|
|
|
|
func RunStructTest(t *testing.T, spec TestSpec) {
|
|
t.Run(spec.Name, func(t *testing.T) {
|
|
info, err := query.AnalyzeObject(spec.Type)
|
|
require.NoError(t, err)
|
|
|
|
testInstance := spec.Instance
|
|
marshaller, ok := testInstance.(ssz.Marshaler)
|
|
require.Equal(t, true, ok, "Test instance must implement ssz.Marshaler, got %T", testInstance)
|
|
|
|
marshalledData, err := marshaller.MarshalSSZ()
|
|
require.NoError(t, err)
|
|
|
|
for _, pathTest := range spec.PathTests {
|
|
t.Run(pathTest.Path, func(t *testing.T) {
|
|
path, err := query.ParsePath(pathTest.Path)
|
|
require.NoError(t, err)
|
|
|
|
_, offset, length, err := query.CalculateOffsetAndLength(info, path)
|
|
require.NoError(t, err)
|
|
|
|
expectedRawBytes := marshalledData[offset : offset+length]
|
|
rawBytes, err := marshalAny(pathTest.Expected)
|
|
require.NoError(t, err, "Marshalling expected value should not return an error")
|
|
require.DeepEqual(t, expectedRawBytes, rawBytes, "Extracted value should match expected")
|
|
})
|
|
}
|
|
})
|
|
}
|