mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
82de66bb90
* first version of the watchtower api * service files * Begin work on grpc server * More changes to server * REnames and mock setup * working test * merge * double propose detection test * nishant review * todo change * gaz * fix service * gaz * remove unused import * gaz * resolve circular dependency * resolve circular dependency 2nd try * remove package * fix package * fix test * added tests * gaz * remove status check * gaz * remove context * remove context * change var name * moved to rpc dir * gaz * remove server code * gaz * slasher server * visibility change * pb * service update * gaz * slasher grpc server * making it work * setup db and start * gaz * service flags fixes * grpc service running * go imports * remove new initializer * gaz * remove feature flags * change back SetupSlasherDB * fix SetupSlasherDB calls * define err * fix bad merge * fix test * fix imports * fix imports * fix imports * add cancel * comment stop * fix cancel issue * remove unneeded code * bring back bad merge that removed TODO * fixed slasher to be runable again * wait for channel close * gaz * small test * flags fix * fix flag order * remove flag
168 lines
3.9 KiB
Go
168 lines
3.9 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/slasher/db"
|
|
)
|
|
|
|
func TestServer_IsSlashableBlock(t *testing.T) {
|
|
dbs := db.SetupSlasherDB(t)
|
|
defer db.TeardownSlasherDB(t, dbs)
|
|
ctx := context.Background()
|
|
slasherServer := &Server{
|
|
SlasherDb: dbs,
|
|
}
|
|
psr := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 1,
|
|
StateRoot: []byte("A"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
psr2 := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 1,
|
|
StateRoot: []byte("B"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
|
|
if _, err := slasherServer.IsSlashableBlock(ctx, psr); err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
sr, err := slasherServer.IsSlashableBlock(ctx, psr2)
|
|
if err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
want := ðpb.ProposerSlashing{
|
|
ProposerIndex: psr.ValidatorIndex,
|
|
Header_1: psr2.BlockHeader,
|
|
Header_2: psr.BlockHeader,
|
|
}
|
|
|
|
if len(sr.ProposerSlashing) != 1 {
|
|
t.Errorf("Should return 1 slashaing proof: %v", sr)
|
|
}
|
|
if !proto.Equal(sr.ProposerSlashing[0], want) {
|
|
t.Errorf("wanted slashing proof: %v got: %v", want, sr.ProposerSlashing[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestServer_IsNotSlashableBlock(t *testing.T) {
|
|
dbs := db.SetupSlasherDB(t)
|
|
defer db.TeardownSlasherDB(t, dbs)
|
|
|
|
slasherServer := &Server{
|
|
SlasherDb: dbs,
|
|
}
|
|
psr := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 1,
|
|
StateRoot: []byte("A"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
psr2 := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 65,
|
|
StateRoot: []byte("B"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
ctx := context.Background()
|
|
|
|
if _, err := slasherServer.IsSlashableBlock(ctx, psr); err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
sr, err := slasherServer.IsSlashableBlock(ctx, psr2)
|
|
if err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
|
|
if len(sr.ProposerSlashing) != 0 {
|
|
t.Errorf("Should return 0 slashaing proof: %v", sr)
|
|
}
|
|
|
|
}
|
|
|
|
func TestServer_DoubleBlock(t *testing.T) {
|
|
dbs := db.SetupSlasherDB(t)
|
|
defer db.TeardownSlasherDB(t, dbs)
|
|
ctx := context.Background()
|
|
slasherServer := &Server{
|
|
ctx: ctx,
|
|
SlasherDb: dbs,
|
|
}
|
|
psr := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 1,
|
|
StateRoot: []byte("A"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
|
|
if _, err := slasherServer.IsSlashableBlock(ctx, psr); err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
sr, err := slasherServer.IsSlashableBlock(ctx, psr)
|
|
if err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
|
|
if len(sr.ProposerSlashing) != 0 {
|
|
t.Errorf("Should return 0 slashaing proof: %v", sr)
|
|
}
|
|
|
|
}
|
|
|
|
func TestServer_SameEpochDifferentSlotSlashable(t *testing.T) {
|
|
dbs := db.SetupSlasherDB(t)
|
|
defer db.TeardownSlasherDB(t, dbs)
|
|
ctx := context.Background()
|
|
slasherServer := &Server{
|
|
ctx: ctx,
|
|
SlasherDb: dbs,
|
|
}
|
|
psr := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 1,
|
|
StateRoot: []byte("A"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
psr2 := ðpb.ProposerSlashingRequest{
|
|
BlockHeader: ðpb.BeaconBlockHeader{
|
|
Slot: 63,
|
|
StateRoot: []byte("B"),
|
|
},
|
|
ValidatorIndex: 1,
|
|
}
|
|
want := ðpb.ProposerSlashing{
|
|
ProposerIndex: psr.ValidatorIndex,
|
|
Header_1: psr2.BlockHeader,
|
|
Header_2: psr.BlockHeader,
|
|
}
|
|
|
|
if _, err := slasherServer.IsSlashableBlock(ctx, psr); err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
sr, err := slasherServer.IsSlashableBlock(ctx, psr2)
|
|
if err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
|
|
if len(sr.ProposerSlashing) != 1 {
|
|
t.Errorf("Should return 1 slashaing proof: %v", sr)
|
|
}
|
|
if !proto.Equal(sr.ProposerSlashing[0], want) {
|
|
t.Errorf("wanted slashing proof: %v got: %v", want, sr.ProposerSlashing[0])
|
|
|
|
}
|
|
}
|