2018-11-28 09:02:35 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestSaveCleanedFinalizedSlot_OK(t *testing.T) {
|
2018-11-28 09:02:35 +00:00
|
|
|
db := setupDB(t)
|
|
|
|
defer teardownDB(t, db)
|
|
|
|
|
|
|
|
slot := uint64(100)
|
|
|
|
if err := db.SaveCleanedFinalizedSlot(slot); err != nil {
|
|
|
|
t.Errorf("failed to save cleaned finalized slot %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 09:34:11 +00:00
|
|
|
func TestCleanedFinalizedSlot_NotFound(t *testing.T) {
|
2018-11-28 09:02:35 +00:00
|
|
|
db := setupDB(t)
|
|
|
|
defer teardownDB(t, db)
|
|
|
|
|
|
|
|
var slot uint64
|
2019-01-21 09:34:11 +00:00
|
|
|
slot, err := db.CleanedFinalizedSlot()
|
2018-11-28 09:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error("got DB error when reading cleaned finalized slot")
|
|
|
|
}
|
|
|
|
if slot != 0 {
|
|
|
|
t.Error("expect 0 if DB doesn't have last cleaned finalized slot")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestCleanedFinalizedSlot_OK(t *testing.T) {
|
2018-11-28 09:02:35 +00:00
|
|
|
db := setupDB(t)
|
|
|
|
defer teardownDB(t, db)
|
|
|
|
|
|
|
|
slot := uint64(100)
|
|
|
|
if err := db.SaveCleanedFinalizedSlot(slot); err != nil {
|
|
|
|
t.Fatalf("failed to save cleaned finalized slot %v", err)
|
|
|
|
}
|
|
|
|
|
2019-01-21 09:34:11 +00:00
|
|
|
readSlot, err := db.CleanedFinalizedSlot()
|
2018-11-28 09:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to read cleaned finalized slot from DB %v", err)
|
|
|
|
}
|
|
|
|
if readSlot != slot {
|
|
|
|
t.Error("got wrong result when reading cleaned finalized slot from DB")
|
|
|
|
}
|
|
|
|
}
|