mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 01:32:18 +00:00
b030771174
* first version * cli context * fix service * starting change to ccache * ristretto cache * added test * test on evict * remove evict test * test onevict * comment for exported flag * update all span maps on load * fix setup db * span cache added to help flags * start save cache on exit * save cache to db before close * comment fix * fix flags * setup db new * nishant feedback * workspace cr * lint fix * fix calls * start db * fix test * Update slasher/db/db.go Co-Authored-By: Nishant Das <nishdas93@gmail.com> * add flag * nishant feedback * export Config * fix imports * fix imports * fix imports * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * remove mod print Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Nishant Das <nish1993@hotmail.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
136 lines
3.5 KiB
Go
136 lines
3.5 KiB
Go
package db
|
|
|
|
import (
|
|
"flag"
|
|
"reflect"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func TestStore_AttesterSlashingNilBucket(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
as := ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello")}}
|
|
has, _, err := db.HasAttesterSlashing(as)
|
|
if err != nil {
|
|
t.Fatalf("HasAttesterSlashing should not return error: %v", err)
|
|
}
|
|
if has {
|
|
t.Fatal("HasAttesterSlashing should return false")
|
|
}
|
|
|
|
p, err := db.AttesterSlashings(SlashingStatus(Active))
|
|
if err != nil {
|
|
t.Fatalf("failed to get attester slashing: %v", err)
|
|
}
|
|
if p == nil || len(p) != 0 {
|
|
t.Fatalf("get should return empty attester slashing array for a non existent key")
|
|
}
|
|
}
|
|
|
|
func TestStore_SaveAttesterSlashing(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
tests := []struct {
|
|
ss SlashingStatus
|
|
as *ethpb.AttesterSlashing
|
|
}{
|
|
{
|
|
ss: Active,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello")}},
|
|
},
|
|
{
|
|
ss: Included,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello2")}},
|
|
},
|
|
{
|
|
ss: Reverted,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello3")}},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
err := db.SaveAttesterSlashing(tt.ss, tt.as)
|
|
if err != nil {
|
|
t.Fatalf("save attester slashing failed: %v", err)
|
|
}
|
|
|
|
attesterSlashings, err := db.AttesterSlashings(tt.ss)
|
|
if err != nil {
|
|
t.Fatalf("failed to get attester slashings: %v", err)
|
|
}
|
|
|
|
if attesterSlashings == nil || !reflect.DeepEqual(attesterSlashings[0], tt.as) {
|
|
t.Fatalf("attester slashing: %v should be part of attester slashings response: %v", tt.as, attesterSlashings)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func TestStore_UpdateAttesterSlashingStatus(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
tests := []struct {
|
|
ss SlashingStatus
|
|
as *ethpb.AttesterSlashing
|
|
}{
|
|
{
|
|
ss: Active,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello")}},
|
|
},
|
|
{
|
|
ss: Active,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello2")}},
|
|
},
|
|
{
|
|
ss: Active,
|
|
as: ðpb.AttesterSlashing{Attestation_1: ðpb.IndexedAttestation{Signature: []byte("hello3")}},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
err := db.SaveAttesterSlashing(tt.ss, tt.as)
|
|
if err != nil {
|
|
t.Fatalf("save attester slashing failed: %v", err)
|
|
}
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
has, st, err := db.HasAttesterSlashing(tt.as)
|
|
if err != nil {
|
|
t.Fatalf("failed to get attester slashing: %v", err)
|
|
}
|
|
if !has {
|
|
t.Fatalf("failed to find attester slashing: %v", tt.as)
|
|
}
|
|
if st != tt.ss {
|
|
t.Fatalf("failed to find attester slashing with the correct status: %v", tt.as)
|
|
}
|
|
|
|
err = db.SaveAttesterSlashing(SlashingStatus(Included), tt.as)
|
|
has, st, err = db.HasAttesterSlashing(tt.as)
|
|
if err != nil {
|
|
t.Fatalf("failed to get attester slashing: %v", err)
|
|
}
|
|
if !has {
|
|
t.Fatalf("failed to find attester slashing: %v", tt.as)
|
|
}
|
|
if st != Included {
|
|
t.Fatalf("failed to find attester slashing with the correct status: %v", tt.as)
|
|
}
|
|
|
|
}
|
|
|
|
}
|