mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
b5c4dc2a75
* init-sync updates * slasher/db/kv tests * beacon-chain/rpc/beacon tests * update kv_test * beacon-chain/rpc-validator tests updated * slasher/db/kv - remove teardown method * beacon-chain/sync tests updated * beacon-chain/db/kv tests updated * beacon-chain/blockchain tests updated * beacon-chain/state/stategen tests updated * beacon-chain/powchain updates * updates rest of slasher tests * validator/db tests * rest of the tests * minor comments update * gazelle * Merge refs/heads/master into teardowndb-to-cleanup
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestArchivedPointIndexRoot_CanSaveRetrieve(t *testing.T) {
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
i1 := uint64(100)
|
|
r1 := [32]byte{'A'}
|
|
|
|
received := db.ArchivedPointRoot(ctx, i1)
|
|
if r1 == received {
|
|
t.Fatal("Should not have been saved")
|
|
}
|
|
|
|
if err := db.SaveArchivedPointRoot(ctx, r1, i1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
received = db.ArchivedPointRoot(ctx, i1)
|
|
if r1 != received {
|
|
t.Error("Should have been saved")
|
|
}
|
|
}
|
|
|
|
func TestLastArchivedPoint_CanRetrieve(t *testing.T) {
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
i, err := db.LastArchivedIndex(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if i != 0 {
|
|
t.Error("Did not get correct index")
|
|
}
|
|
|
|
if err := db.SaveArchivedPointRoot(ctx, [32]byte{'A'}, 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := db.SaveArchivedPointRoot(ctx, [32]byte{'B'}, 3); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := db.SaveLastArchivedIndex(ctx, 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if db.LastArchivedIndexRoot(ctx) != [32]byte{'A'} {
|
|
t.Error("Did not get wanted root")
|
|
}
|
|
|
|
if err := db.SaveLastArchivedIndex(ctx, 3); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if db.LastArchivedIndexRoot(ctx) != [32]byte{'B'} {
|
|
t.Error("Did not get wanted root")
|
|
}
|
|
|
|
i, err = db.LastArchivedIndex(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if i != 3 {
|
|
t.Error("Did not get correct index")
|
|
}
|
|
}
|