chainntnfs: fix testHistoricalConfDetailsTxIndex

Fix the following uint test flake,
```
--- FAIL: TestHistoricalConfDetailsTxIndex (0.00s)
    --- FAIL: TestHistoricalConfDetailsTxIndex/rpc_polling_enabled (1.16s)
        bitcoind_test.go:174: should have found the transaction within the mempool, but did not: TxNotFoundIndex
FAIL
```
This commit is contained in:
yyforyongyu 2023-08-24 23:01:27 +08:00
parent d8924d26ce
commit 1968034075
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -5,6 +5,7 @@ package bitcoindnotify
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
"time" "time"
@ -14,6 +15,7 @@ import (
"github.com/lightningnetwork/lnd/blockcache" "github.com/lightningnetwork/lnd/blockcache"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -162,18 +164,21 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
confReq, err := chainntnfs.NewConfRequest(txid, pkScript) confReq, err := chainntnfs.NewConfRequest(txid, pkScript)
require.NoError(t, err, "unable to create conf request") require.NoError(t, err, "unable to create conf request")
// The transaction should be found in the mempool at this point. // The transaction should be found in the mempool at this point. We use
_, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0) // wait here to give miner some time to propagate the tx to our node.
require.NoError(t, err, "unable to retrieve historical conf details") err = wait.NoError(func() error {
// The call should return no error.
_, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0)
require.NoError(t, err)
// Since it has yet to be included in a block, it should have been found if txStatus != chainntnfs.TxFoundMempool {
// within the mempool. return fmt.Errorf("cannot the tx in mempool, status "+
switch txStatus { "is: %v", txStatus)
case chainntnfs.TxFoundMempool: }
default:
t.Fatalf("should have found the transaction within the "+ return nil
"mempool, but did not: %v", txStatus) }, wait.DefaultTimeout)
} require.NoError(t, err, "timeout waitinfg for historicalConfDetails")
if _, err := miner.Client.Generate(1); err != nil { if _, err := miner.Client.Generate(1); err != nil {
t.Fatalf("unable to generate block: %v", err) t.Fatalf("unable to generate block: %v", err)