prysm-pulse/slasher/detection/proposals/detector_test.go
Victor Farazdagi 9bf80219c9
Applies assertion funcs to slasher/* tests (#6998)
* slasher/beaconclient tests
* slasher/db/kv tests
* Merge branch 'master' into apply-testutils-assertions-to-slasher
* fix build
* slasher/detection tests
* rest of the tests
* misc tests
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Update slasher/db/kv/spanner_test.go

Co-authored-by: Shay Zluf <thezluf@gmail.com>
* Update slasher/node/node_test.go

Co-authored-by: Shay Zluf <thezluf@gmail.com>
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
* Update slasher/db/kv/spanner_test.go
* Merge refs/heads/master into apply-testutils-assertions-to-slasher
2020-08-18 12:41:25 +00:00

76 lines
2.1 KiB
Go

package proposals
import (
"context"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/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{})
func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) {
type testStruct struct {
name string
blk *ethpb.SignedBeaconBlockHeader
incomingBlk *ethpb.SignedBeaconBlockHeader
slashing *ethpb.ProposerSlashing
}
blk1slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
require.NoError(t, err)
blk2slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
require.NoError(t, err)
blk1slot1, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0)+1, 0)
require.NoError(t, err)
blk1epoch1, err := testDetect.SignedBlockHeader(testDetect.StartSlot(1), 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)
})
}
}