multi: move many t.Fatalf calls to require.NoError
This commit is contained in:
1 parent
9e6f0ef46b
commit
9a10c80bcb
92 files changed
+1905
-5565
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -35,20 +36,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
|
||||
}
|
||||
@@ -81,9 +76,7 @@ func syncNotifierWithMiner(t *testing.T, notifier *BitcoindNotifier,
|
||||
t.Helper()
|
||||
|
||||
_, minerHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve miner's current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve miner's current height")
|
||||
|
||||
timeout := time.After(10 * time.Second)
|
||||
for {
|
||||
@@ -139,13 +132,9 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
|
||||
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:
|
||||
@@ -158,22 +147,16 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
|
||||
// Now, we'll create a test transaction, confirm it, and attempt to
|
||||
// retrieve its confirmation details.
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatal(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.
|
||||
@@ -193,9 +176,7 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
|
||||
syncNotifierWithMiner(t, notifier, miner)
|
||||
|
||||
_, 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.
|
||||
@@ -238,16 +219,12 @@ func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) {
|
||||
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")
|
||||
broadcastHeight := syncNotifierWithMiner(t, notifier, miner)
|
||||
_, txStatus, err := notifier.historicalConfDetails(
|
||||
unknownConfReq, uint32(broadcastHeight), uint32(broadcastHeight),
|
||||
)
|
||||
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:
|
||||
@@ -267,9 +244,7 @@ func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) {
|
||||
outpoint, output, privKey := chainntnfs.CreateSpendableOutput(t, miner)
|
||||
spendTx := chainntnfs.CreateSpendTx(t, outpoint, output, privKey)
|
||||
spendTxHash, err := miner.Client.SendRawTransaction(spendTx, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to broadcast tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to broadcast tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, spendTxHash); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
@@ -280,16 +255,12 @@ func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) {
|
||||
// Ensure the notifier and miner are synced to the same height to ensure
|
||||
// we can find the transaction when manually scanning the chain.
|
||||
confReq, err := chainntnfs.NewConfRequest(&outpoint.Hash, output.PkScript)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create conf request: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create conf request")
|
||||
currentHeight := syncNotifierWithMiner(t, notifier, miner)
|
||||
_, txStatus, err = notifier.historicalConfDetails(
|
||||
confReq, uint32(broadcastHeight), uint32(currentHeight),
|
||||
)
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,17 +25,11 @@ func initHintCacheWithConfig(t *testing.T, cfg CacheConfig) *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")
|
||||
hintCache, err := NewHeightHintCache(cfg, 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
|
||||
}
|
||||
@@ -69,9 +63,7 @@ func TestHeightHintCacheConfirms(t *testing.T) {
|
||||
}
|
||||
|
||||
err = hintCache.CommitConfirmHint(height, confRequests...)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to add entries to cache: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to add entries to cache")
|
||||
|
||||
// With the hashes committed, we'll now query the cache to ensure that
|
||||
// we're able to properly retrieve the confirm hints.
|
||||
@@ -130,9 +122,7 @@ func TestHeightHintCacheSpends(t *testing.T) {
|
||||
}
|
||||
|
||||
err = hintCache.CommitSpendHint(height, spendRequests...)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to add entries to cache: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to add entries to cache")
|
||||
|
||||
// With the outpoints committed, we'll now query the cache to ensure
|
||||
// that we're able to properly retrieve the confirm hints.
|
||||
|
||||
@@ -39,17 +39,13 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
|
||||
// We're spending from a coinbase output here, so we use the dedicated
|
||||
// function.
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Now that we have a txid, register a confirmation notification with
|
||||
// the chainntfn source.
|
||||
@@ -64,16 +60,12 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
|
||||
txid, pkScript, numConfs, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Now generate a single block, the transaction should be included which
|
||||
// should trigger a notification event.
|
||||
blockHash, err := miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
select {
|
||||
case confInfo := <-confIntent.Confirmed:
|
||||
@@ -113,17 +105,13 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
|
||||
// Again, we'll begin by creating a fresh transaction, so we can obtain
|
||||
// a fresh txid.
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test addr: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test addr")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
numConfs := uint32(6)
|
||||
var confIntent *chainntnfs.ConfirmationEvent
|
||||
@@ -136,9 +124,7 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
|
||||
txid, pkScript, numConfs, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Now generate a six blocks. The transaction should be included in the
|
||||
// first block, which will be built upon by the other 5 blocks.
|
||||
@@ -167,9 +153,7 @@ func testBatchConfirmationNotification(miner *rpctest.Harness,
|
||||
confIntents := make([]*chainntnfs.ConfirmationEvent, len(confSpread))
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Create a new txid spending miner coins for each confirmation entry
|
||||
// in confSpread, we collect each conf intent into a slice so we can
|
||||
@@ -279,9 +263,7 @@ func testSpendNotification(miner *rpctest.Harness,
|
||||
outpoint, output, privKey := chainntnfs.CreateSpendableOutput(t, miner)
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Now that we have an output index and the pkScript, register for a
|
||||
// spentness notification for the newly created output with multiple
|
||||
@@ -312,9 +294,7 @@ func testSpendNotification(miner *rpctest.Harness,
|
||||
|
||||
// Broadcast our spending transaction.
|
||||
spenderSha, err := miner.Client.SendRawTransaction(spendingTx, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to broadcast tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to broadcast tx")
|
||||
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, spenderSha); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
@@ -354,9 +334,7 @@ func testSpendNotification(miner *rpctest.Harness,
|
||||
outpoint, output.PkScript, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register for spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register for spend ntfn")
|
||||
|
||||
select {
|
||||
case <-spentIntent.Spend:
|
||||
@@ -373,9 +351,7 @@ func testSpendNotification(miner *rpctest.Harness,
|
||||
}
|
||||
|
||||
_, currentHeight, err = miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
for _, c := range spendClients {
|
||||
select {
|
||||
@@ -464,9 +440,7 @@ func testMultiClientConfirmationNotification(miner *rpctest.Harness,
|
||||
// We'd like to test the case of a multiple clients registered to
|
||||
// receive a confirmation notification for the same transaction.
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
@@ -478,9 +452,7 @@ func testMultiClientConfirmationNotification(miner *rpctest.Harness,
|
||||
)
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Register for a conf notification for the above generated txid with
|
||||
// numConfsClients distinct clients.
|
||||
@@ -535,9 +507,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
// spending from a coinbase output here, so we use the dedicated
|
||||
// function.
|
||||
txid3, pkScript3, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid3); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
@@ -548,36 +518,26 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
// that the TXID hasn't already been included in the chain, otherwise the
|
||||
// notification will never be sent.
|
||||
_, err = miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate block")
|
||||
|
||||
txid1, pkScript1, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid1); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
txid2, pkScript2, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid2); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Now generate another block containing txs 1 & 2.
|
||||
blockHash, err := miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate block")
|
||||
|
||||
// Register a confirmation notification with the chainntfn source for tx2,
|
||||
// which is included in the last block. The height hint is the height before
|
||||
@@ -593,9 +553,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
txid1, pkScript1, 1, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
select {
|
||||
case confInfo := <-ntfn1.Confirmed:
|
||||
@@ -639,15 +597,11 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
txid2, pkScript2, 3, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Fully confirm tx3.
|
||||
_, err = miner.Client.Generate(2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate block")
|
||||
|
||||
select {
|
||||
case <-ntfn2.Confirmed:
|
||||
@@ -674,9 +628,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
txid3, pkScript3, 1, uint32(currentHeight-1),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// We'll also register for a confirmation notification with the pkscript
|
||||
// of a different transaction. This notification shouldn't fire since we
|
||||
@@ -685,9 +637,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
ntfn4, err = notifier.RegisterConfirmationsNtfn(
|
||||
txid3, pkScript2, 1, uint32(currentHeight-1),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
select {
|
||||
case <-ntfn3.Confirmed:
|
||||
@@ -725,17 +675,13 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
|
||||
// Create a transaction to be notified about. We'll register for
|
||||
// notifications on this transaction but won't be prompt in checking them
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
numConfs := uint32(3)
|
||||
|
||||
@@ -755,9 +701,7 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
|
||||
txid, pkScript, numConfs, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Generate another 2 blocks, this should dispatch the confirm notification
|
||||
if _, err := miner.Client.Generate(2); err != nil {
|
||||
@@ -768,17 +712,13 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
|
||||
// if the first transaction has confirmed doesn't mean that we shouldn't
|
||||
// be able to see if this transaction confirms first
|
||||
txid, pkScript, err = chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err = miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
numConfs = 1
|
||||
var secondConfIntent *chainntnfs.ConfirmationEvent
|
||||
@@ -791,9 +731,7 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
|
||||
txid, pkScript, numConfs, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
if _, err := miner.Client.Generate(1); err != nil {
|
||||
t.Fatalf("unable to generate blocks: %v", err)
|
||||
@@ -829,16 +767,12 @@ func testSpendBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
outpoint, output, privKey := chainntnfs.CreateSpendableOutput(t, miner)
|
||||
|
||||
_, heightHint, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// We'll then spend this output and broadcast the spend transaction.
|
||||
spendingTx := chainntnfs.CreateSpendTx(t, outpoint, output, privKey)
|
||||
spenderSha, err := miner.Client.SendRawTransaction(spendingTx, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to broadcast tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to broadcast tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, spenderSha); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
@@ -846,18 +780,14 @@ func testSpendBeforeNtfnRegistration(miner *rpctest.Harness,
|
||||
// We create an epoch client we can use to make sure the notifier is
|
||||
// caught up to the mining node's chain.
|
||||
epochClient, err := notifier.RegisterBlockEpochNtfn(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register for block epoch: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register for block epoch")
|
||||
|
||||
// Now we mine an additional block, which should include our spend.
|
||||
if _, err := miner.Client.Generate(1); err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
_, spendHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// checkSpends registers two clients to be notified of a spend that has
|
||||
// already happened. The notifier should dispatch a spend notification
|
||||
@@ -948,9 +878,7 @@ func testCancelSpendNtfn(node *rpctest.Harness,
|
||||
outpoint, output, privKey := chainntnfs.CreateSpendableOutput(t, node)
|
||||
|
||||
_, currentHeight, err := node.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Create two clients that each registered to the spend notification.
|
||||
// We'll cancel the notification for the first client and leave the
|
||||
@@ -984,9 +912,7 @@ func testCancelSpendNtfn(node *rpctest.Harness,
|
||||
|
||||
// Broadcast our spending transaction.
|
||||
spenderSha, err := node.Client.SendRawTransaction(spendingTx, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to broadcast tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to broadcast tx")
|
||||
|
||||
if err := chainntnfs.WaitForMempoolTx(node, spenderSha); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
@@ -1092,9 +1018,7 @@ func testReorgConf(miner *rpctest.Harness,
|
||||
miner2, err := rpctest.New(
|
||||
chainntnfs.NetParams, nil, []string{"--txindex"}, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
if err := miner2.SetUp(false, 0); err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
}
|
||||
@@ -1129,22 +1053,16 @@ func testReorgConf(miner *rpctest.Harness,
|
||||
// We disconnect the two nodes, such that we can start mining on them
|
||||
// individually without the other one learning about the new blocks.
|
||||
err = miner.Client.AddNode(miner2.P2PAddress(), rpcclient.ANRemove)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to remove node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to remove node")
|
||||
|
||||
txid, pkScript, err := chainntnfs.GetTestTxidAndScript(miner)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, currentHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Now that we have a txid, register a confirmation notification with
|
||||
// the chainntfn source.
|
||||
@@ -1159,15 +1077,11 @@ func testReorgConf(miner *rpctest.Harness,
|
||||
txid, pkScript, numConfs, uint32(currentHeight),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Now generate a single block, the transaction should be included.
|
||||
_, err = miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
// Transaction only has one confirmation, and the notification is registered
|
||||
// with 2 confirmations, so we should not be notified yet.
|
||||
@@ -1219,22 +1133,16 @@ func testReorgConf(miner *rpctest.Harness,
|
||||
// Now confirm the transaction on the longest chain and verify that we
|
||||
// receive the notification.
|
||||
tx, err := miner.Client.GetRawTransaction(txid)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get raw tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get raw tx")
|
||||
|
||||
txid, err = miner2.Client.SendRawTransaction(tx.MsgTx(), false)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get send tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get send tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, txid); err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
|
||||
_, err = miner.Client.Generate(3)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
select {
|
||||
case <-confIntent.Confirmed:
|
||||
@@ -1253,9 +1161,7 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
// notification for it.
|
||||
outpoint, output, privKey := chainntnfs.CreateSpendableOutput(t, miner)
|
||||
_, heightHint, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve current height")
|
||||
|
||||
var spendIntent *chainntnfs.SpendEvent
|
||||
if scriptDispatch {
|
||||
@@ -1267,17 +1173,13 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
outpoint, output.PkScript, uint32(heightHint),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register for spend: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register for spend")
|
||||
|
||||
// Set up a new miner that we can use to cause a reorg.
|
||||
miner2, err := rpctest.New(
|
||||
chainntnfs.NetParams, nil, []string{"--txindex"}, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
if err := miner2.SetUp(false, 0); err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
}
|
||||
@@ -1294,13 +1196,9 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
t.Fatalf("unable to sync miners: %v", err)
|
||||
}
|
||||
_, minerHeight1, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get miner1's current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get miner1's current height")
|
||||
_, minerHeight2, err := miner2.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get miner2's current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get miner2's current height")
|
||||
if minerHeight1 != minerHeight2 {
|
||||
t.Fatalf("expected both miners to be on the same height: "+
|
||||
"%v vs %v", minerHeight1, minerHeight2)
|
||||
@@ -1309,17 +1207,13 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
// We disconnect the two nodes, such that we can start mining on them
|
||||
// individually without the other one learning about the new blocks.
|
||||
err = miner.Client.AddNode(miner2.P2PAddress(), rpcclient.ANRemove)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to disconnect miners: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to disconnect miners")
|
||||
|
||||
// Craft the spending transaction for the outpoint created above and
|
||||
// confirm it under the chain of the original miner.
|
||||
spendTx := chainntnfs.CreateSpendTx(t, outpoint, output, privKey)
|
||||
spendTxHash, err := miner.Client.SendRawTransaction(spendTx, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to broadcast spend tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to broadcast spend tx")
|
||||
if err := chainntnfs.WaitForMempoolTx(miner, spendTxHash); err != nil {
|
||||
t.Fatalf("spend tx not relayed to miner: %v", err)
|
||||
}
|
||||
@@ -1328,9 +1222,7 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
t.Fatalf("unable to generate blocks: %v", err)
|
||||
}
|
||||
_, spendHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get spend height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get spend height")
|
||||
|
||||
// We should see a spend notification dispatched with the correct spend
|
||||
// details.
|
||||
@@ -1356,13 +1248,9 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
t.Fatalf("unable to sync miners: %v", err)
|
||||
}
|
||||
_, minerHeight1, err = miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get miner1's current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get miner1's current height")
|
||||
_, minerHeight2, err = miner2.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get miner2's current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to get miner2's current height")
|
||||
if minerHeight1 != minerHeight2 {
|
||||
t.Fatalf("expected both miners to be on the same height: "+
|
||||
"%v vs %v", minerHeight1, minerHeight2)
|
||||
@@ -1391,9 +1279,7 @@ func testReorgSpend(miner *rpctest.Harness,
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
_, spendHeight, err = miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve current height")
|
||||
|
||||
select {
|
||||
case spendDetails := <-spendIntent.Spend:
|
||||
@@ -1416,9 +1302,7 @@ func testCatchUpClientOnMissedBlocks(miner *rpctest.Harness,
|
||||
var wg sync.WaitGroup
|
||||
|
||||
outdatedHash, outdatedHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve current height: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve current height")
|
||||
|
||||
// This function is used by UnsafeStart to ensure all notifications
|
||||
// are fully drained before clients register for notifications.
|
||||
@@ -1432,9 +1316,7 @@ func testCatchUpClientOnMissedBlocks(miner *rpctest.Harness,
|
||||
// client may not receive all historical notifications.
|
||||
bestHeight := outdatedHeight + numBlocks
|
||||
err = notifier.UnsafeStart(bestHeight, nil, bestHeight, generateBlocks)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to unsafe start the notifier: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to unsafe start the notifier")
|
||||
defer notifier.Stop()
|
||||
|
||||
// Create numClients clients whose best known block is 10 blocks behind
|
||||
@@ -1523,9 +1405,7 @@ func testCatchUpOnMissedBlocks(miner *rpctest.Harness,
|
||||
err = notifier.UnsafeStart(
|
||||
bestHeight, nil, bestHeight+numBlocks, generateBlocks,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to unsafe start the notifier: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to unsafe start the notifier")
|
||||
defer notifier.Stop()
|
||||
|
||||
// Create numClients clients who will listen for block notifications.
|
||||
@@ -1622,9 +1502,7 @@ func testCatchUpOnMissedBlocksWithReorg(miner1 *rpctest.Harness,
|
||||
miner2, err := rpctest.New(
|
||||
chainntnfs.NetParams, nil, []string{"--txindex"}, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
if err := miner2.SetUp(false, 0); err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
}
|
||||
@@ -1659,22 +1537,16 @@ func testCatchUpOnMissedBlocksWithReorg(miner1 *rpctest.Harness,
|
||||
// We disconnect the two nodes, such that we can start mining on them
|
||||
// individually without the other one learning about the new blocks.
|
||||
err = miner1.Client.AddNode(miner2.P2PAddress(), rpcclient.ANRemove)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to remove node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to remove node")
|
||||
|
||||
// Now mine on each chain separately
|
||||
blocks, err := miner1.Client.Generate(numBlocks)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
// We generate an extra block on miner 2's chain to ensure it is the
|
||||
// longer chain.
|
||||
_, err = miner2.Client.Generate(numBlocks + 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
// Sync the two chains to ensure they will sync to miner2's chain.
|
||||
if err := rpctest.ConnectNode(miner1, miner2); err != nil {
|
||||
@@ -1717,9 +1589,7 @@ func testCatchUpOnMissedBlocksWithReorg(miner1 *rpctest.Harness,
|
||||
err = notifier.UnsafeStart(
|
||||
nodeHeight1+numBlocks, blocks[numBlocks-1], syncHeight, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to unsafe start the notifier: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Unable to unsafe start the notifier")
|
||||
defer notifier.Stop()
|
||||
|
||||
// Create numClients clients who will listen for block notifications.
|
||||
@@ -1745,9 +1615,7 @@ func testCatchUpOnMissedBlocksWithReorg(miner1 *rpctest.Harness,
|
||||
// Generate a single block, which should trigger the notifier to rewind
|
||||
// to the common ancestor and dispatch notifications from there.
|
||||
_, err = miner2.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate single block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate single block")
|
||||
|
||||
// If the chain backend to the notifier stores information about reorged
|
||||
// blocks, the notifier is able to rewind the chain to the common
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -127,14 +128,10 @@ func CreateSpendableOutput(t *testing.T,
|
||||
// Create a transaction that only has one output, the one destined for
|
||||
// the recipient.
|
||||
pkScript, privKey, err := randPubKeyHashScript()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate pkScript: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate pkScript")
|
||||
output := &wire.TxOut{Value: 2e8, PkScript: pkScript}
|
||||
txid, err := miner.SendOutputsWithoutChange([]*wire.TxOut{output}, 10)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create tx")
|
||||
|
||||
// Mine the transaction to mark the output as spendable.
|
||||
if err := WaitForMempoolTx(miner, txid); err != nil {
|
||||
@@ -161,9 +158,7 @@ func CreateSpendTx(t *testing.T, prevOutPoint *wire.OutPoint,
|
||||
spendingTx, 0, prevOutput.PkScript, txscript.SigHashAll,
|
||||
privKey, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to sign tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to sign tx")
|
||||
spendingTx.TxIn[0].SignatureScript = sigScript
|
||||
|
||||
return spendingTx
|
||||
@@ -181,9 +176,7 @@ func NewMiner(t *testing.T, extraArgs []string, createChain bool,
|
||||
extraArgs = append(extraArgs, trickle)
|
||||
|
||||
node, err := rpctest.New(NetParams, nil, extraArgs, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create backend node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create backend node")
|
||||
if err := node.SetUp(createChain, spendableOutputs); err != nil {
|
||||
node.TearDown()
|
||||
t.Fatalf("unable to set up backend node: %v", err)
|
||||
@@ -204,9 +197,7 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, txindex,
|
||||
t.Helper()
|
||||
|
||||
tempBitcoindDir, err := ioutil.TempDir("", "bitcoind")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp dir")
|
||||
|
||||
rpcPort := rand.Intn(65536-1024) + 1024
|
||||
zmqBlockHost := "ipc:///" + tempBitcoindDir + "/blocks.socket"
|
||||
@@ -289,9 +280,7 @@ func NewNeutrinoBackend(t *testing.T, minerAddr string) (*neutrino.ChainService,
|
||||
t.Helper()
|
||||
|
||||
spvDir, err := ioutil.TempDir("", "neutrino")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp dir")
|
||||
|
||||
dbName := filepath.Join(spvDir, "neutrino.db")
|
||||
spvDatabase, err := walletdb.Create(
|
||||
|
||||
+99
-297
@@ -224,17 +224,13 @@ func TestTxNotifierFutureConfDispatch(t *testing.T) {
|
||||
tx1.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, tx1NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
tx2 := wire.MsgTx{Version: 2}
|
||||
tx2.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, tx2NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// We should not receive any notifications from both transactions
|
||||
// since they have not been included in a block yet.
|
||||
@@ -261,9 +257,7 @@ func TestTxNotifierFutureConfDispatch(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block1.Hash(), 11, block1.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(11); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -323,9 +317,7 @@ func TestTxNotifierFutureConfDispatch(t *testing.T) {
|
||||
// This should confirm tx2.
|
||||
block2 := btcutil.NewBlock(&wire.MsgBlock{})
|
||||
err = n.ConnectTip(block2.Hash(), 12, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(12); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -396,15 +388,11 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) {
|
||||
// starting height so that they are confirmed once registering them.
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, tx1NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, tx2NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
// Update tx1 with its confirmation details. We should only receive one
|
||||
// update since it only requires one confirmation and it already met it.
|
||||
@@ -415,9 +403,7 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) {
|
||||
Tx: &tx1,
|
||||
}
|
||||
err = n.UpdateConfDetails(ntfn1.HistoricalDispatch.ConfRequest, &txConf1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
select {
|
||||
case numConfsLeft := <-ntfn1.Event.Updates:
|
||||
const expected = 0
|
||||
@@ -449,9 +435,7 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) {
|
||||
Tx: &tx2,
|
||||
}
|
||||
err = n.UpdateConfDetails(ntfn2.HistoricalDispatch.ConfRequest, &txConf2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
select {
|
||||
case numConfsLeft := <-ntfn2.Event.Updates:
|
||||
const expected = 1
|
||||
@@ -477,9 +461,7 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block.Hash(), 11, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(11); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -532,9 +514,7 @@ func TestTxNotifierFutureSpendDispatch(t *testing.T) {
|
||||
// outpoint.
|
||||
op := wire.OutPoint{Index: 1}
|
||||
ntfn, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// We should not receive a notification as the outpoint has not been
|
||||
// spent yet.
|
||||
@@ -557,9 +537,7 @@ func TestTxNotifierFutureSpendDispatch(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx},
|
||||
})
|
||||
err = n.ConnectTip(block.Hash(), 11, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(11); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -592,9 +570,7 @@ func TestTxNotifierFutureSpendDispatch(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendOfSpend},
|
||||
})
|
||||
err = n.ConnectTip(block.Hash(), 12, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(12); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -626,21 +602,15 @@ func TestTxNotifierFutureConfDispatchReuseSafe(t *testing.T) {
|
||||
tx1.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
scriptNtfn1, err := n.RegisterConf(nil, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
block := btcutil.NewBlock(&wire.MsgBlock{
|
||||
Transactions: []*wire.MsgTx{&tx1},
|
||||
})
|
||||
currentBlock++
|
||||
err = n.ConnectTip(block.Hash(), currentBlock, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(currentBlock); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -685,21 +655,15 @@ func TestTxNotifierFutureConfDispatchReuseSafe(t *testing.T) {
|
||||
tx2.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
scriptNtfn2, err := n.RegisterConf(nil, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
block2 := btcutil.NewBlock(&wire.MsgBlock{
|
||||
Transactions: []*wire.MsgTx{&tx2},
|
||||
})
|
||||
currentBlock++
|
||||
err = n.ConnectTip(block2.Hash(), currentBlock, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(currentBlock); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -800,9 +764,7 @@ func TestTxNotifierHistoricalSpendDispatch(t *testing.T) {
|
||||
// We'll register for a spend notification of the outpoint and ensure
|
||||
// that a notification isn't dispatched.
|
||||
ntfn, err := n.RegisterSpend(&spentOutpoint, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
select {
|
||||
case <-ntfn.Event.Spend:
|
||||
@@ -817,9 +779,7 @@ func TestTxNotifierHistoricalSpendDispatch(t *testing.T) {
|
||||
err = n.UpdateSpendDetails(
|
||||
ntfn.HistoricalDispatch.SpendRequest, expectedSpendDetails,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
|
||||
// Now that we have the spending details, we should receive a spend
|
||||
// notification. We'll ensure that the details match as intended.
|
||||
@@ -842,9 +802,7 @@ func TestTxNotifierHistoricalSpendDispatch(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendOfSpend},
|
||||
})
|
||||
err = n.ConnectTip(block.Hash(), startingHeight+1, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 1); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -872,9 +830,7 @@ func TestTxNotifierMultipleHistoricalConfRescans(t *testing.T) {
|
||||
// request a historical confirmation rescan as it does not have a
|
||||
// historical view of the chain.
|
||||
ntfn1, err := n.RegisterConf(&chainntnfs.ZeroHash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn1.HistoricalDispatch == nil {
|
||||
t.Fatal("expected to receive historical dispatch request")
|
||||
}
|
||||
@@ -883,9 +839,7 @@ func TestTxNotifierMultipleHistoricalConfRescans(t *testing.T) {
|
||||
// transaction. This should not request a historical confirmation rescan
|
||||
// since the first one is still pending.
|
||||
ntfn2, err := n.RegisterConf(&chainntnfs.ZeroHash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn2.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -898,14 +852,10 @@ func TestTxNotifierMultipleHistoricalConfRescans(t *testing.T) {
|
||||
BlockHeight: startingHeight - 1,
|
||||
}
|
||||
err = n.UpdateConfDetails(ntfn1.HistoricalDispatch.ConfRequest, confDetails)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
|
||||
ntfn3, err := n.RegisterConf(&chainntnfs.ZeroHash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn3.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -928,9 +878,7 @@ func TestTxNotifierMultipleHistoricalSpendRescans(t *testing.T) {
|
||||
// the chain.
|
||||
op := wire.OutPoint{Index: 1}
|
||||
ntfn1, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn1.HistoricalDispatch == nil {
|
||||
t.Fatal("expected to receive historical dispatch request")
|
||||
}
|
||||
@@ -939,9 +887,7 @@ func TestTxNotifierMultipleHistoricalSpendRescans(t *testing.T) {
|
||||
// should not request a historical spend rescan since the first one is
|
||||
// still pending.
|
||||
ntfn2, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn2.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -960,14 +906,10 @@ func TestTxNotifierMultipleHistoricalSpendRescans(t *testing.T) {
|
||||
err = n.UpdateSpendDetails(
|
||||
ntfn1.HistoricalDispatch.SpendRequest, spendDetails,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
|
||||
ntfn3, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if ntfn3.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -1026,9 +968,7 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) {
|
||||
err := n.UpdateConfDetails(
|
||||
confNtfns[0].HistoricalDispatch.ConfRequest, expectedConfDetails,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
|
||||
// With the confirmation details retrieved, each client should now have
|
||||
// been notified of the confirmation.
|
||||
@@ -1047,9 +987,7 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) {
|
||||
// see a historical rescan request and the confirmation notification
|
||||
// should come through immediately.
|
||||
extraConfNtfn, err := n.RegisterConf(&txid, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register conf ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register conf ntfn")
|
||||
if extraConfNtfn.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -1095,9 +1033,7 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) {
|
||||
err = n.UpdateSpendDetails(
|
||||
spendNtfns[0].HistoricalDispatch.SpendRequest, expectedSpendDetails,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
|
||||
// With the spend details retrieved, each client should now have been
|
||||
// notified of the spend.
|
||||
@@ -1116,9 +1052,7 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) {
|
||||
// should not see a historical rescan request and the spend notification
|
||||
// should come through immediately.
|
||||
extraSpendNtfn, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
if extraSpendNtfn.HistoricalDispatch != nil {
|
||||
t.Fatal("received unexpected historical rescan request")
|
||||
}
|
||||
@@ -1146,27 +1080,19 @@ func TestTxNotifierCancelConf(t *testing.T) {
|
||||
tx1.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
tx2 := wire.NewMsgTx(2)
|
||||
tx2.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
ntfn3, err := n.RegisterConf(&tx2Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// This request will have a three block num confs.
|
||||
ntfn4, err := n.RegisterConf(&tx2Hash, testRawScript, 3, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// Extend the chain with a block that will confirm both transactions.
|
||||
// This will queue confirmation notifications to dispatch once their
|
||||
@@ -1185,9 +1111,7 @@ func TestTxNotifierCancelConf(t *testing.T) {
|
||||
ntfn2.Event.Cancel()
|
||||
|
||||
err = n.ConnectTip(block.Hash(), startingHeight+1, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
|
||||
// Cancel the third notification before notifying to ensure its queued
|
||||
// confirmation notification gets removed as well.
|
||||
@@ -1232,9 +1156,7 @@ func TestTxNotifierCancelConf(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block1.Hash(), startingHeight+2, block1.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
|
||||
if err := n.NotifyHeight(startingHeight + 2); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
@@ -1266,9 +1188,7 @@ func TestTxNotifierCancelConf(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block2.Hash(), startingHeight+3, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
|
||||
if err := n.NotifyHeight(startingHeight + 3); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
@@ -1291,15 +1211,11 @@ func TestTxNotifierCancelSpend(t *testing.T) {
|
||||
// canceled.
|
||||
op1 := wire.OutPoint{Index: 1}
|
||||
ntfn1, err := n.RegisterSpend(&op1, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
op2 := wire.OutPoint{Index: 2}
|
||||
ntfn2, err := n.RegisterSpend(&op2, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// Construct the spending details of the outpoint and create a dummy
|
||||
// block containing it.
|
||||
@@ -1326,9 +1242,7 @@ func TestTxNotifierCancelSpend(t *testing.T) {
|
||||
n.CancelSpend(ntfn2.HistoricalDispatch.SpendRequest, 2)
|
||||
|
||||
err = n.ConnectTip(block.Hash(), startingHeight+1, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 1); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1377,42 +1291,30 @@ func TestTxNotifierConfReorg(t *testing.T) {
|
||||
tx1.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, tx1NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
err = n.UpdateConfDetails(ntfn1.HistoricalDispatch.ConfRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to deliver conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to deliver conf details")
|
||||
|
||||
// Tx 2 will be confirmed in block 10 and requires 1 conf.
|
||||
tx2 := wire.MsgTx{Version: 2}
|
||||
tx2.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, tx2NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
err = n.UpdateConfDetails(ntfn2.HistoricalDispatch.ConfRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to deliver conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to deliver conf details")
|
||||
|
||||
// Tx 3 will be confirmed in block 10 and requires 2 confs.
|
||||
tx3 := wire.MsgTx{Version: 3}
|
||||
tx3.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx3Hash := tx3.TxHash()
|
||||
ntfn3, err := n.RegisterConf(&tx3Hash, testRawScript, tx3NumConfs, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register ntfn")
|
||||
|
||||
err = n.UpdateConfDetails(ntfn3.HistoricalDispatch.ConfRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to deliver conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to deliver conf details")
|
||||
|
||||
// Sync chain to block 10. Txs 1 & 2 should be confirmed.
|
||||
block1 := btcutil.NewBlock(&wire.MsgBlock{
|
||||
@@ -1555,17 +1457,13 @@ func TestTxNotifierConfReorg(t *testing.T) {
|
||||
block4 := btcutil.NewBlock(&wire.MsgBlock{})
|
||||
|
||||
err = n.ConnectTip(block3.Hash(), 12, block3.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(12); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
|
||||
err = n.ConnectTip(block4.Hash(), 13, block4.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(13); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1692,14 +1590,10 @@ func TestTxNotifierSpendReorg(t *testing.T) {
|
||||
|
||||
// We'll register for a spend notification for each outpoint above.
|
||||
ntfn1, err := n.RegisterSpend(&op1, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
ntfn2, err := n.RegisterSpend(&op2, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// We'll extend the chain by connecting a new block at tip. This block
|
||||
// will only contain the spending transaction of the first outpoint.
|
||||
@@ -1707,9 +1601,7 @@ func TestTxNotifierSpendReorg(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx1},
|
||||
})
|
||||
err = n.ConnectTip(block1.Hash(), startingHeight+1, block1.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 1); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1737,9 +1629,7 @@ func TestTxNotifierSpendReorg(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx2},
|
||||
})
|
||||
err = n.ConnectTip(block2.Hash(), startingHeight+2, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 2); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1793,9 +1683,7 @@ func TestTxNotifierSpendReorg(t *testing.T) {
|
||||
err = n.ConnectTip(
|
||||
emptyBlock.Hash(), startingHeight+2, emptyBlock.Transactions(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to disconnect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to disconnect block")
|
||||
if err := n.NotifyHeight(startingHeight + 2); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1818,9 +1706,7 @@ func TestTxNotifierSpendReorg(t *testing.T) {
|
||||
err = n.ConnectTip(
|
||||
block2.Hash(), startingHeight+3, block2.Transactions(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 3); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1882,9 +1768,7 @@ func TestTxNotifierSpendReorgMissed(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx},
|
||||
})
|
||||
err := n.ConnectTip(block.Hash(), startingHeight+1, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(startingHeight + 1); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -1892,9 +1776,7 @@ func TestTxNotifierSpendReorgMissed(t *testing.T) {
|
||||
// We register for the spend now and will not get a spend notification
|
||||
// until we call UpdateSpendDetails.
|
||||
ntfn, err := n.RegisterSpend(&op, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend")
|
||||
|
||||
// Assert that the HistoricalDispatch variable is non-nil. We'll use
|
||||
// the SpendRequest member to update the spend details.
|
||||
@@ -1962,17 +1844,13 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
tx1.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx1Hash := tx1.TxHash()
|
||||
ntfn1, err := n.RegisterConf(&tx1Hash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register tx1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register tx1")
|
||||
|
||||
tx2 := wire.MsgTx{Version: 2}
|
||||
tx2.AddTxOut(&wire.TxOut{PkScript: testRawScript})
|
||||
tx2Hash := tx2.TxHash()
|
||||
ntfn2, err := n.RegisterConf(&tx2Hash, testRawScript, 2, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register tx2: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register tx2")
|
||||
|
||||
// Both transactions should not have a height hint set, as RegisterConf
|
||||
// should not alter the cache state.
|
||||
@@ -1998,9 +1876,7 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block1.Hash(), txDummyHeight, block1.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(txDummyHeight); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2026,13 +1902,9 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
// Now, update the conf details reporting that the neither txn was found
|
||||
// in the historical dispatch.
|
||||
err = n.UpdateConfDetails(ntfn1.HistoricalDispatch.ConfRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
err = n.UpdateConfDetails(ntfn2.HistoricalDispatch.ConfRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update conf details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update conf details")
|
||||
|
||||
// We'll create another block that will include the first transaction
|
||||
// and extend the chain.
|
||||
@@ -2041,9 +1913,7 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block2.Hash(), tx1Height, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(tx1Height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2052,18 +1922,14 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
// they should have their height hints updated to the latest block
|
||||
// height.
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn1.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx1Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx1Height, hint)
|
||||
}
|
||||
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn2.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx1Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx2Height, hint)
|
||||
@@ -2076,18 +1942,14 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block3.Hash(), tx2Height, block3.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Failed to connect block")
|
||||
if err := n.NotifyHeight(tx2Height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
|
||||
// The height hint for the first transaction should remain the same.
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn1.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx1Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx1Height, hint)
|
||||
@@ -2096,9 +1958,7 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
// The height hint for the second transaction should now be updated to
|
||||
// reflect its confirmation.
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn2.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx2Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx2Height, hint)
|
||||
@@ -2113,9 +1973,7 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
// This should update the second transaction's height hint within the
|
||||
// cache to the previous height.
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn2.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx1Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx1Height, hint)
|
||||
@@ -2124,9 +1982,7 @@ func TestTxNotifierConfirmHintCache(t *testing.T) {
|
||||
// The first transaction's height hint should remain at the original
|
||||
// confirmation height.
|
||||
hint, err = hintCache.QueryConfirmHint(ntfn2.HistoricalDispatch.ConfRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for hint: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for hint")
|
||||
if hint != tx1Height {
|
||||
t.Fatalf("expected hint %d, got %d",
|
||||
tx1Height, hint)
|
||||
@@ -2158,14 +2014,10 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
// Create two test outpoints and register them for spend notifications.
|
||||
op1 := wire.OutPoint{Index: 1}
|
||||
ntfn1, err := n.RegisterSpend(&op1, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend for op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend for op1")
|
||||
op2 := wire.OutPoint{Index: 2}
|
||||
ntfn2, err := n.RegisterSpend(&op2, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend for op2: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend for op2")
|
||||
|
||||
// Both outpoints should not have a spend hint set upon registration, as
|
||||
// we must first determine whether they have already been spent in the
|
||||
@@ -2188,9 +2040,7 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
err = n.ConnectTip(
|
||||
emptyBlock.Hash(), dummyHeight, emptyBlock.Transactions(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(dummyHeight); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2215,13 +2065,9 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
// calling UpdateSpendDetails. This should allow their spend hints to be
|
||||
// updated upon every block connected/disconnected.
|
||||
err = n.UpdateSpendDetails(ntfn1.HistoricalDispatch.SpendRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
err = n.UpdateSpendDetails(ntfn2.HistoricalDispatch.SpendRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
|
||||
// We'll create a new block that only contains the spending transaction
|
||||
// of the first outpoint.
|
||||
@@ -2234,9 +2080,7 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx1},
|
||||
})
|
||||
err = n.ConnectTip(block1.Hash(), op1Height, block1.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(op1Height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2245,16 +2089,12 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
// the new block being connected due to the first outpoint being spent
|
||||
// at this height, and the second outpoint still being unspent.
|
||||
op1Hint, err := hintCache.QuerySpendHint(ntfn1.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != op1Height {
|
||||
t.Fatalf("expected hint %d, got %d", op1Height, op1Hint)
|
||||
}
|
||||
op2Hint, err := hintCache.QuerySpendHint(ntfn2.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op2: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op2")
|
||||
if op2Hint != op1Height {
|
||||
t.Fatalf("expected hint %d, got %d", op1Height, op2Hint)
|
||||
}
|
||||
@@ -2269,9 +2109,7 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx2},
|
||||
})
|
||||
err = n.ConnectTip(block2.Hash(), op2Height, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(op2Height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2280,16 +2118,12 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
// being spent within the new block. The first outpoint's spend hint
|
||||
// should remain the same as it's already been spent before.
|
||||
op1Hint, err = hintCache.QuerySpendHint(ntfn1.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != op1Height {
|
||||
t.Fatalf("expected hint %d, got %d", op1Height, op1Hint)
|
||||
}
|
||||
op2Hint, err = hintCache.QuerySpendHint(ntfn2.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op2: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op2")
|
||||
if op2Hint != op2Height {
|
||||
t.Fatalf("expected hint %d, got %d", op2Height, op2Hint)
|
||||
}
|
||||
@@ -2305,16 +2139,12 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
|
||||
// included in within the chain. The first outpoint's spend hint should
|
||||
// remain the same.
|
||||
op1Hint, err = hintCache.QuerySpendHint(ntfn1.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != op1Height {
|
||||
t.Fatalf("expected hint %d, got %d", op1Height, op1Hint)
|
||||
}
|
||||
op2Hint, err = hintCache.QuerySpendHint(ntfn2.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op2: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op2")
|
||||
if op2Hint != op1Height {
|
||||
t.Fatalf("expected hint %d, got %d", op1Height, op2Hint)
|
||||
}
|
||||
@@ -2340,9 +2170,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
// Create a test outpoint and register it for spend notifications.
|
||||
op1 := wire.OutPoint{Index: 1}
|
||||
ntfn1, err := n.RegisterSpend(&op1, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend for op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend for op1")
|
||||
|
||||
// A historical rescan should be initiated from the height hint to the
|
||||
// current height.
|
||||
@@ -2369,9 +2197,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
err = n.ConnectTip(
|
||||
emptyBlock.Hash(), height, emptyBlock.Transactions(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2426,9 +2252,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
op1Hint, err := hintCache.QuerySpendHint(
|
||||
ntfn1.HistoricalDispatch.SpendRequest,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != spendHeight {
|
||||
t.Fatalf("expected hint %d, got %d", spendHeight, op1Hint)
|
||||
}
|
||||
@@ -2445,16 +2269,12 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
// tip while the rescan was in progress, the height hint should not be
|
||||
// updated to the latest height, but stay at the spend height.
|
||||
err = n.UpdateSpendDetails(ntfn1.HistoricalDispatch.SpendRequest, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to update spend details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to update spend details")
|
||||
|
||||
op1Hint, err = hintCache.QuerySpendHint(
|
||||
ntfn1.HistoricalDispatch.SpendRequest,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != spendHeight {
|
||||
t.Fatalf("expected hint %d, got %d", spendHeight, op1Hint)
|
||||
}
|
||||
@@ -2471,9 +2291,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
Transactions: []*wire.MsgTx{spendTx2},
|
||||
})
|
||||
err = n.ConnectTip(block2.Hash(), height, block2.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(height); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2481,9 +2299,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
// The outpoint's spend hint should remain the same as it's already
|
||||
// been spent before.
|
||||
op1Hint, err = hintCache.QuerySpendHint(ntfn1.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != spendHeight {
|
||||
t.Fatalf("expected hint %d, got %d", spendHeight, op1Hint)
|
||||
}
|
||||
@@ -2516,9 +2332,7 @@ func TestTxNotifierSpendDuringHistoricalRescan(t *testing.T) {
|
||||
|
||||
// Finally, check that the height hint is still there, unchanged.
|
||||
op1Hint, err = hintCache.QuerySpendHint(ntfn1.HistoricalDispatch.SpendRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for spend hint of op1: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for spend hint of op1")
|
||||
if op1Hint != spendHeight {
|
||||
t.Fatalf("expected hint %d, got %d", spendHeight, op1Hint)
|
||||
}
|
||||
@@ -2537,13 +2351,9 @@ func TestTxNotifierNtfnDone(t *testing.T) {
|
||||
// We'll start by creating two notification requests: one confirmation
|
||||
// and one spend.
|
||||
confNtfn, err := n.RegisterConf(&chainntnfs.ZeroHash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register conf ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register conf ntfn")
|
||||
spendNtfn, err := n.RegisterSpend(&chainntnfs.ZeroOutPoint, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend")
|
||||
|
||||
// We'll create two transactions that will satisfy the notification
|
||||
// requests above and include them in the next block of the chain.
|
||||
@@ -2559,9 +2369,7 @@ func TestTxNotifierNtfnDone(t *testing.T) {
|
||||
})
|
||||
|
||||
err = n.ConnectTip(block.Hash(), 11, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(11); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2611,9 +2419,7 @@ func TestTxNotifierNtfnDone(t *testing.T) {
|
||||
// We'll reconnect the block that satisfies both of these requests.
|
||||
// We should see notifications dispatched for both once again.
|
||||
err = n.ConnectTip(block.Hash(), 11, block.Transactions())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect block")
|
||||
if err := n.NotifyHeight(11); err != nil {
|
||||
t.Fatalf("unable to dispatch notifications: %v", err)
|
||||
}
|
||||
@@ -2667,13 +2473,9 @@ func TestTxNotifierTearDown(t *testing.T) {
|
||||
// To begin the test, we'll register for a confirmation and spend
|
||||
// notification.
|
||||
confNtfn, err := n.RegisterConf(&chainntnfs.ZeroHash, testRawScript, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register conf ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register conf ntfn")
|
||||
spendNtfn, err := n.RegisterSpend(&chainntnfs.ZeroOutPoint, testRawScript, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register spend ntfn: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register spend ntfn")
|
||||
|
||||
// With the notifications registered, we'll now tear down the notifier.
|
||||
// The notification channels should be closed for notifications, whether
|
||||
|
||||
Reference in new issue
Block a user