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

     1  package operations
     2  
     3  import (
     4  	"context"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/golang/snappy"
     9  	"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
    10  	iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
    11  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    12  	"github.com/prysmaticlabs/prysm/proto/interfaces"
    13  	"github.com/prysmaticlabs/prysm/shared/testutil"
    14  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    15  	"github.com/prysmaticlabs/prysm/spectest/utils"
    16  )
    17  
    18  // RunVoluntaryExitTest executes "operations/voluntary_exit" tests.
    19  func RunVoluntaryExitTest(t *testing.T, config string) {
    20  	require.NoError(t, utils.SetConfig(t, config))
    21  	testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/voluntary_exit/pyspec_tests")
    22  	for _, folder := range testFolders {
    23  		t.Run(folder.Name(), func(t *testing.T) {
    24  			folderPath := path.Join(testsFolderPath, folder.Name())
    25  			exitFile, err := testutil.BazelFileBytes(folderPath, "voluntary_exit.ssz_snappy")
    26  			require.NoError(t, err)
    27  			exitSSZ, err := snappy.Decode(nil /* dst */, exitFile)
    28  			require.NoError(t, err, "Failed to decompress")
    29  			voluntaryExit := &ethpb.SignedVoluntaryExit{}
    30  			require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")
    31  
    32  			body := &ethpb.BeaconBlockBody{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}}
    33  			RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
    34  				return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits())
    35  			})
    36  		})
    37  	}
    38  }