mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
multi: move many t.Fatalf calls to require.NoError
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -33,20 +34,14 @@ 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)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp dir")
|
||||
db, err := channeldb.Open(tempDir)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create db: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create db")
|
||||
testCfg := chainntnfs.CacheConfig{
|
||||
QueryDisable: false,
|
||||
}
|
||||
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db.Backend)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create hint cache: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create hint cache")
|
||||
|
||||
return hintCache
|
||||
}
|
||||
@@ -61,9 +56,7 @@ func setUpNotifier(t *testing.T, h *rpctest.Harness) *BtcdNotifier {
|
||||
notifier, err := New(
|
||||
&rpcCfg, chainntnfs.NetParams, hintCache, hintCache, blockCache,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create notifier: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create notifier")
|
||||
if err := notifier.Start(); err != nil {
|
||||
t.Fatalf("unable to start notifier: %v", err)
|
||||
}
|
||||
@@ -90,13 +83,9 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) {
|
||||
var unknownHash chainhash.Hash
|
||||
copy(unknownHash[:], bytes.Repeat([]byte{0x10}, 32))
|
||||
unknownConfReq, err := chainntnfs.NewConfRequest(&unknownHash, testScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create conf request: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create conf request")
|
||||
_, txStatus, err := notifier.historicalConfDetails(unknownConfReq, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
switch txStatus {
|
||||
case chainntnfs.TxNotFoundIndex:
|
||||
@@ -109,22 +98,16 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) {
|
||||
// Now, we'll create a test transaction and attempt to retrieve its
|
||||
// confirmation details.
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(harness)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(harness, txid); err != nil {
|
||||
t.Fatalf("unable to find tx in the mempool: %v", err)
|
||||
}
|
||||
confReq, err := chainntnfs.NewConfRequest(txid, pkScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create conf request: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create conf request")
|
||||
|
||||
// The transaction should be found in the mempool at this point.
|
||||
_, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
// Since it has yet to be included in a block, it should have been found
|
||||
// within the mempool.
|
||||
@@ -142,9 +125,7 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
_, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
// Since the backend node's txindex is enabled and the transaction has
|
||||
// confirmed, we should be able to retrieve it using the txindex.
|
||||
@@ -174,13 +155,9 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) {
|
||||
var unknownHash chainhash.Hash
|
||||
copy(unknownHash[:], bytes.Repeat([]byte{0x10}, 32))
|
||||
unknownConfReq, err := chainntnfs.NewConfRequest(&unknownHash, testScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create conf request: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create conf request")
|
||||
_, txStatus, err := notifier.historicalConfDetails(unknownConfReq, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
switch txStatus {
|
||||
case chainntnfs.TxNotFoundManually:
|
||||
@@ -194,26 +171,18 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) {
|
||||
// confirmation details. We'll note its broadcast height to use as the
|
||||
// height hint when manually scanning the chain.
|
||||
_, currentHeight, err := harness.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve current height")
|
||||
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(harness)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(harness, txid); err != nil {
|
||||
t.Fatalf("unable to find tx in the mempool: %v", err)
|
||||
}
|
||||
confReq, err := chainntnfs.NewConfRequest(txid, pkScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create conf request: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create conf request")
|
||||
|
||||
_, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
// Since it has yet to be included in a block, it should have been found
|
||||
// within the mempool.
|
||||
@@ -231,9 +200,7 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) {
|
||||
_, txStatus, err = notifier.historicalConfDetails(
|
||||
confReq, uint32(currentHeight), uint32(currentHeight)+1,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve historical conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve historical conf details")
|
||||
|
||||
// Since the backend node's txindex is disabled and the transaction has
|
||||
// confirmed, we should be able to find it by falling back to scanning
|
||||
|
Reference in New Issue
Block a user