2020-03-02 07:55:38 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArchivedPointIndexRoot_CanSaveRetrieve(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
defer teardownDB(t, db)
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 19:07:07 +00:00
|
|
|
func TestLastArchivedPoint_CanRetrieve(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
defer teardownDB(t, db)
|
|
|
|
ctx := context.Background()
|
2020-04-11 20:54:19 +00:00
|
|
|
i, err := db.LastArchivedIndex(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if i != 0 {
|
|
|
|
t.Error("Did not get correct index")
|
|
|
|
}
|
|
|
|
|
2020-03-16 19:07:07 +00:00
|
|
|
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")
|
|
|
|
}
|
2020-04-11 20:54:19 +00:00
|
|
|
|
|
|
|
i, err = db.LastArchivedIndex(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if i != 3 {
|
|
|
|
t.Error("Did not get correct index")
|
|
|
|
}
|
2020-03-16 19:07:07 +00:00
|
|
|
}
|