prysm-pulse/slasher/detection/proposals/detector_test.go
Raul Jordan 5aac06f04e
Move EthereumAPIs Into Prysm (#8968)
* begin move

* use same import path

* imports

* regen protos

* regen

* no rename

* generate ssz

* gaz

* fmt

* edit build file

* imports

* modify

* remove generated files

* remove protos

* edit imports in prysm

* beacon chain all builds

* edit script

* add generated pbs

* add replace rules

* license for ethereumapis protos

* change visibility

* fmt

* update build files to gaz ignore

* use proper form

* edit imports

* wrap block

* revert scripts

* revert go mod
2021-06-02 18:49:52 -05:00

81 lines
2.2 KiB
Go

package proposals
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing"
"github.com/prysmaticlabs/prysm/slasher/detection/proposals/iface"
testDetect "github.com/prysmaticlabs/prysm/slasher/detection/testing"
)
var _ iface.ProposalsDetector = (*ProposeDetector)(nil)
func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) {
type testStruct struct {
name string
blk *ethpb.SignedBeaconBlockHeader
incomingBlk *ethpb.SignedBeaconBlockHeader
slashing *ethpb.ProposerSlashing
}
s0, err := helpers.StartSlot(0)
require.NoError(t, err)
blk1slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
blk2slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
blk1slot1, err := testDetect.SignedBlockHeader(s0+1, 0)
require.NoError(t, err)
s1, err := helpers.StartSlot(1)
require.NoError(t, err)
blk1epoch1, err := testDetect.SignedBlockHeader(s1, 0)
require.NoError(t, err)
tests := []testStruct{
{
name: "same block sig dont slash",
blk: blk1slot0,
incomingBlk: blk1slot0,
slashing: nil,
},
{
name: "block from different epoch dont slash",
blk: blk1slot0,
incomingBlk: blk1epoch1,
slashing: nil,
},
{
name: "different sig from different slot dont slash",
blk: blk1slot0,
incomingBlk: blk1slot1,
slashing: nil,
},
{
name: "different sig from same slot slash",
blk: blk1slot0,
incomingBlk: blk2slot0,
slashing: &ethpb.ProposerSlashing{Header_1: blk2slot0, Header_2: blk1slot0},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
db := testDB.SetupSlasherDB(t, false)
ctx := context.Background()
sd := &ProposeDetector{
slasherDB: db,
}
require.NoError(t, sd.slasherDB.SaveBlockHeader(ctx, tt.blk))
res, err := sd.DetectDoublePropose(ctx, tt.incomingBlk)
require.NoError(t, err)
assert.DeepEqual(t, tt.slashing, res)
})
}
}