github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/operations/attestation.go (about)

     1  package operations
     2  
     3  import (
     4  	"path"
     5  	"testing"
     6  
     7  	"github.com/golang/snappy"
     8  	"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
     9  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    10  	"github.com/prysmaticlabs/prysm/shared/testutil"
    11  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    12  	"github.com/prysmaticlabs/prysm/spectest/utils"
    13  )
    14  
    15  // RunAttestationTest executes "operations/attestation" tests.
    16  func RunAttestationTest(t *testing.T, config string) {
    17  	require.NoError(t, utils.SetConfig(t, config))
    18  	testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/attestation/pyspec_tests")
    19  	for _, folder := range testFolders {
    20  		t.Run(folder.Name(), func(t *testing.T) {
    21  			folderPath := path.Join(testsFolderPath, folder.Name())
    22  			attestationFile, err := testutil.BazelFileBytes(folderPath, "attestation.ssz_snappy")
    23  			require.NoError(t, err)
    24  			attestationSSZ, err := snappy.Decode(nil /* dst */, attestationFile)
    25  			require.NoError(t, err, "Failed to decompress")
    26  			att := &ethpb.Attestation{}
    27  			require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")
    28  
    29  			body := &ethpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{att}}
    30  			RunBlockOperationTest(t, folderPath, body, blocks.ProcessAttestations)
    31  		})
    32  	}
    33  }