mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 16:37:39 +00:00
7d0e5a9dc4
* add latest vote map * fix all tests * remove db crud methods * Merge branch 'master' into latestVoteMap * preston's review * Merge branch 'latestVoteMap' of https://github.com/prysmaticlabs/geth-sharding into latestVoteMap
41 lines
939 B
Go
41 lines
939 B
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestStore_ValidatorIndexCRUD(t *testing.T) {
|
|
db := setupDB(t)
|
|
defer teardownDB(t, db)
|
|
validatorIdx := uint64(100)
|
|
pubKey := [48]byte{1, 2, 3, 4}
|
|
ctx := context.Background()
|
|
_, ok, err := db.ValidatorIndex(ctx, pubKey)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if ok {
|
|
t.Fatal("Expected validator index to not exist")
|
|
}
|
|
if err := db.SaveValidatorIndex(ctx, pubKey, validatorIdx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
retrievedIdx, ok, err := db.ValidatorIndex(ctx, pubKey)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !ok {
|
|
t.Fatal("Expected validator index to have been properly retrieved")
|
|
}
|
|
if retrievedIdx != validatorIdx {
|
|
t.Errorf("Wanted %d, received %d", validatorIdx, retrievedIdx)
|
|
}
|
|
if err := db.DeleteValidatorIndex(ctx, pubKey); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if db.HasValidatorIndex(ctx, pubKey) {
|
|
t.Error("Expected validator index to have been deleted from the db")
|
|
}
|
|
}
|