github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/operations/deposit.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  // RunDepositTest executes "operations/deposit" tests.
    19  func RunDepositTest(t *testing.T, config string) {
    20  	require.NoError(t, utils.SetConfig(t, config))
    21  	testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/deposit/pyspec_tests")
    22  	for _, folder := range testFolders {
    23  		t.Run(folder.Name(), func(t *testing.T) {
    24  			folderPath := path.Join(testsFolderPath, folder.Name())
    25  			depositFile, err := testutil.BazelFileBytes(folderPath, "deposit.ssz_snappy")
    26  			require.NoError(t, err)
    27  			depositSSZ, err := snappy.Decode(nil /* dst */, depositFile)
    28  			require.NoError(t, err, "Failed to decompress")
    29  			deposit := &ethpb.Deposit{}
    30  			require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal")
    31  
    32  			body := &ethpb.BeaconBlockBody{Deposits: []*ethpb.Deposit{deposit}}
    33  			processDepositsFunc := func(ctx context.Context, s iface.BeaconState, b interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
    34  				return blocks.ProcessDeposits(ctx, s, b.Block().Body().Deposits())
    35  			}
    36  			RunBlockOperationTest(t, folderPath, body, processDepositsFunc)
    37  		})
    38  	}
    39  }