chainntnfs/btcdnotify: initialize with height hint cache

This commit is contained in:
Conner Fromknecht 2018-08-24 04:05:46 -07:00
parent 16a321f6c5
commit ecc91305ac
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -3,18 +3,41 @@
package btcdnotify
import (
"io/ioutil"
"testing"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/integration/rpctest"
"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 btcd
// driver.
func setUpNotifier(t *testing.T, h *rpctest.Harness) *BtcdNotifier {
hintCache := initHintCache(t)
rpcCfg := h.RPCConfig()
notifier, err := New(&rpcCfg)
notifier, err := New(&rpcCfg, hintCache, hintCache)
if err != nil {
t.Fatalf("unable to create notifier: %v", err)
}