From b89db6d614b582d3e8f6325baef5ea4448c8c413 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 14 Sep 2018 10:47:13 +0200 Subject: [PATCH] utxonursery: assert empty database --- utxonursery_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/utxonursery_test.go b/utxonursery_test.go index c0a47d5b..b37bb1ed 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/lightningnetwork/lnd/channeldb" "io/ioutil" + "math" "reflect" "sync" "testing" @@ -515,7 +516,8 @@ func (ctx *nurseryTestContext) finish() { select { case <-signalChan: 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. @@ -530,6 +532,25 @@ func (ctx *nurseryTestContext) finish() { ctx.t.Fatalf("unexpected transactions published") 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 {