github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/operations/attester_slashing.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 v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" 11 iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface" 12 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 13 "github.com/prysmaticlabs/prysm/proto/interfaces" 14 "github.com/prysmaticlabs/prysm/shared/testutil" 15 "github.com/prysmaticlabs/prysm/shared/testutil/require" 16 "github.com/prysmaticlabs/prysm/spectest/utils" 17 ) 18 19 // RunAttesterSlashingTest executes "operations/attester_slashing" tests. 20 func RunAttesterSlashingTest(t *testing.T, config string) { 21 require.NoError(t, utils.SetConfig(t, config)) 22 testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/attester_slashing/pyspec_tests") 23 for _, folder := range testFolders { 24 t.Run(folder.Name(), func(t *testing.T) { 25 folderPath := path.Join(testsFolderPath, folder.Name()) 26 attSlashingFile, err := testutil.BazelFileBytes(folderPath, "attester_slashing.ssz_snappy") 27 require.NoError(t, err) 28 attSlashingSSZ, err := snappy.Decode(nil /* dst */, attSlashingFile) 29 require.NoError(t, err, "Failed to decompress") 30 attSlashing := ðpb.AttesterSlashing{} 31 require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal") 32 33 body := ðpb.BeaconBlockBody{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}} 34 RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b interfaces.SignedBeaconBlock) (iface.BeaconState, error) { 35 return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), v.SlashValidator) 36 }) 37 }) 38 } 39 }