From 16a321f6c50fc258001896bad891f28e941e283b Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 24 Aug 2018 04:05:18 -0700 Subject: [PATCH] chainntnfs/bitcoind: initialize with height hint cache --- chainntnfs/bitcoindnotify/bitcoind_test.go | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/chainntnfs/bitcoindnotify/bitcoind_test.go b/chainntnfs/bitcoindnotify/bitcoind_test.go index c3f863ba..6447630d 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_test.go +++ b/chainntnfs/bitcoindnotify/bitcoind_test.go @@ -3,6 +3,7 @@ package bitcoindnotify import ( + "io/ioutil" "testing" "time" @@ -10,14 +11,37 @@ import ( "github.com/btcsuite/btcd/integration/rpctest" "github.com/btcsuite/btcwallet/chain" "github.com/lightningnetwork/lnd/chainntnfs" + "github.com/lightningnetwork/lnd/channeldb" ) +func initHintCache(t *testing.T) *chainntnfs.HeightHintCache { + t.Helper() + + tempDir, err := ioutil.TempDir("", "kek") + if err != nil { + t.Fatalf("unable to create temp dir: %v", err) + } + db, err := channeldb.Open(tempDir) + if err != nil { + t.Fatalf("unable to create db: %v", err) + } + hintCache, err := chainntnfs.NewHeightHintCache(db) + if err != nil { + t.Fatalf("unable to create hint cache: %v", err) + } + + return hintCache +} + // setUpNotifier is a helper function to start a new notifier backed by a // bitcoind driver. -func setUpNotifier(t *testing.T, bitcoindConn *chain.BitcoindConn) *BitcoindNotifier { +func setUpNotifier(t *testing.T, bitcoindConn *chain.BitcoindConn, + spendHintCache chainntnfs.SpendHintCache, + confirmHintCache chainntnfs.ConfirmHintCache) *BitcoindNotifier { + t.Helper() - notifier := New(bitcoindConn) + notifier := New(bitcoindConn, spendHintCache, confirmHintCache) if err := notifier.Start(); err != nil { t.Fatalf("unable to start notifier: %v", err) } @@ -70,7 +94,9 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) { ) defer cleanUp() - notifier := setUpNotifier(t, bitcoindConn) + hintCache := initHintCache(t) + + notifier := setUpNotifier(t, bitcoindConn, hintCache, hintCache) defer notifier.Stop() syncNotifierWithMiner(t, notifier, miner) @@ -136,7 +162,9 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) { ) defer cleanUp() - notifier := setUpNotifier(t, bitcoindConn) + hintCache := initHintCache(t) + + notifier := setUpNotifier(t, bitcoindConn, hintCache, hintCache) defer notifier.Stop() // Since the node has its txindex disabled, we fall back to scanning the