github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/operations/proposer_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 // RunProposerSlashingTest executes "operations/proposer_slashing" tests. 20 func RunProposerSlashingTest(t *testing.T, config string) { 21 require.NoError(t, utils.SetConfig(t, config)) 22 testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "operations/proposer_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 proposerSlashingFile, err := testutil.BazelFileBytes(folderPath, "proposer_slashing.ssz_snappy") 27 require.NoError(t, err) 28 proposerSlashingSSZ, err := snappy.Decode(nil /* dst */, proposerSlashingFile) 29 require.NoError(t, err, "Failed to decompress") 30 proposerSlashing := ðpb.ProposerSlashing{} 31 require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal") 32 33 body := ðpb.BeaconBlockBody{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}} 34 RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b interfaces.SignedBeaconBlock) (iface.BeaconState, error) { 35 return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), v.SlashValidator) 36 }) 37 }) 38 } 39 }