utxonursery: assert empty database

This commit is contained in:
Joost Jager 2018-09-14 10:47:13 +02:00
parent b5da791271
commit b89db6d614
No known key found for this signature in database
GPG Key ID: AE6B0D042C8E38D9

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"io/ioutil" "io/ioutil"
"math"
"reflect" "reflect"
"sync" "sync"
"testing" "testing"
@ -515,7 +516,8 @@ func (ctx *nurseryTestContext) finish() {
select { select {
case <-signalChan: case <-signalChan:
case <-time.After(time.Second): case <-time.After(time.Second):
ctx.t.Fatalf("lingering goroutines detected after test is finished") ctx.t.Fatalf("lingering goroutines detected after test " +
"is finished")
} }
// Restore waitgroup state to what it was before. // Restore waitgroup state to what it was before.
@ -530,6 +532,25 @@ func (ctx *nurseryTestContext) finish() {
ctx.t.Fatalf("unexpected transactions published") ctx.t.Fatalf("unexpected transactions published")
default: default:
} }
// Assert that the database is empty. All channels removed and height
// index cleared.
nurseryChannels, err := ctx.nursery.cfg.Store.ListChannels()
if err != nil {
ctx.t.Fatal(err)
}
if len(nurseryChannels) > 0 {
ctx.t.Fatalf("Expected all channels to be removed from store")
}
activeHeights, err := ctx.nursery.cfg.Store.HeightsBelowOrEqual(
math.MaxUint32)
if err != nil {
ctx.t.Fatal(err)
}
if len(activeHeights) > 0 {
ctx.t.Fatalf("Expected height index to be empty")
}
} }
func createOutgoingRes(onLocalCommitment bool) *lnwallet.OutgoingHtlcResolution { func createOutgoingRes(onLocalCommitment bool) *lnwallet.OutgoingHtlcResolution {