• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 12209990843

07 Dec 2024 02:45AM UTC coverage: 58.977% (+1.1%) from 57.911%
12209990843

Pull #9260

github

yyforyongyu
lnrpc: sort `Invoice.HTLCs` based on `HtlcIndex`

So the returned HTLCs are ordered.
Pull Request #9260: Beat itest [3/3]: fix all itest flakes

4 of 132 new or added lines in 9 files covered. (3.03%)

17 existing lines in 8 files now uncovered.

134149 of 227459 relevant lines covered (58.98%)

19442.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lntest/harness_setup.go
1
package lntest
2

3
import (
4
        "context"
5
        "os"
6
        "testing"
7

8
        "github.com/btcsuite/btcd/integration/rpctest"
9
        "github.com/lightningnetwork/lnd/lntest/miner"
10
        "github.com/lightningnetwork/lnd/lntest/node"
11
        "github.com/lightningnetwork/lnd/lntest/wait"
12
        "github.com/stretchr/testify/require"
13
)
14

15
// SetupHarness creates a new HarnessTest with a series of setups such that the
16
// instance is ready for usage. The setups are,
17
// 1. create the directories to hold lnd files.
18
// 2. start a btcd miner.
19
// 3. start a chain backend(btcd, bitcoind, or neutrino).
20
// 4. connect the miner and the chain backend.
21
// 5. start the HarnessTest.
22
func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
23
        nativeSQL bool, feeService WebFeeService) *HarnessTest {
×
24

×
25
        t.Log("Setting up HarnessTest...")
×
26

×
27
        // Parse testing flags that influence our test execution.
×
28
        logDir := node.GetLogDir()
×
29
        require.NoError(t, os.MkdirAll(logDir, 0700), "create log dir failed")
×
30

×
31
        // Parse database backend
×
32
        dbBackend := prepareDBBackend(t, dbBackendName)
×
33

×
34
        // Create a new HarnessTest.
×
35
        ht := NewHarnessTest(t, binaryPath, feeService, dbBackend, nativeSQL)
×
36

×
37
        // Init the miner.
×
38
        t.Log("Prepare the miner and mine blocks to activate segwit...")
×
39
        miner := prepareMiner(ht.runCtx, ht.T)
×
40

×
41
        // Start a chain backend.
×
42
        chainBackend, cleanUp := prepareChainBackend(t, miner.P2PAddress())
×
43
        ht.stopChainBackend = cleanUp
×
44

×
45
        // Connect our chainBackend to our miner.
×
46
        t.Logf("Connecting the miner at %v with the chain backend...",
×
47
                miner.P2PAddress())
×
48

×
NEW
49
        //  Get the current best height.
×
NEW
50
        _, height, err := miner.Client.GetBestBlock()
×
NEW
51
        require.NoError(t, err, "miner GetBestBlock")
×
NEW
52

×
53
        // Give the chain backend some time to fully start up, re-trying if any
×
54
        // errors in connecting to the miner are encountered.
×
NEW
55
        err = wait.NoError(func() error {
×
NEW
56
                return chainBackend.ConnectMiner(height)
×
57
        }, DefaultTimeout)
×
58
        require.NoError(t, err, "connect miner")
×
59

×
60
        // Start the HarnessTest with the chainBackend and miner.
×
61
        ht.Start(chainBackend, miner)
×
62

×
63
        return ht
×
64
}
65

66
// prepareMiner creates an instance of the btcd's rpctest.Harness that will act
67
// as the miner for all tests. This will be used to fund the wallets of the
68
// nodes within the test network and to drive blockchain related events within
69
// the network. Revert the default setting of accepting non-standard
70
// transactions on simnet to reject them. Transactions on the lightning network
71
// should always be standard to get better guarantees of getting included in to
72
// blocks.
73
func prepareMiner(ctxt context.Context, t *testing.T) *miner.HarnessMiner {
×
74
        m := miner.NewMiner(ctxt, t)
×
75

×
76
        // Before we start anything, we want to overwrite some of the
×
77
        // connection settings to make the tests more robust. We might need to
×
78
        // restart the miner while there are already blocks present, which will
×
79
        // take a bit longer than the 1 second the default settings amount to.
×
80
        // Doubling both values will give us retries up to 4 seconds.
×
81
        m.MaxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
×
82
        m.ConnectionRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
×
83

×
84
        // Set up miner and connect chain backend to it.
×
85
        require.NoError(t, m.SetUp(true, 50))
×
86
        require.NoError(t, m.Client.NotifyNewTransactions(false))
×
87

×
88
        // Next mine enough blocks in order for segwit and the CSV package
×
89
        // soft-fork to activate on SimNet.
×
90
        numBlocks := miner.HarnessNetParams.MinerConfirmationWindow * 2
×
91
        m.GenerateBlocks(numBlocks)
×
92

×
93
        return m
×
94
}
×
95

96
// prepareChainBackend creates a new chain backend.
97
func prepareChainBackend(t *testing.T,
98
        minerAddr string) (node.BackendConfig, func()) {
×
99

×
100
        chainBackend, cleanUp, err := NewBackend(
×
101
                minerAddr, miner.HarnessNetParams,
×
102
        )
×
103
        require.NoError(t, err, "new backend")
×
104

×
105
        return chainBackend, func() {
×
106
                require.NoError(t, cleanUp(), "cleanup")
×
107
        }
×
108
}
109

110
// prepareDBBackend parses a DatabaseBackend based on the name given.
111
func prepareDBBackend(t *testing.T,
112
        dbBackendName string) node.DatabaseBackend {
×
113

×
114
        var dbBackend node.DatabaseBackend
×
115
        switch dbBackendName {
×
116
        case "bbolt":
×
117
                dbBackend = node.BackendBbolt
×
118

119
        case "etcd":
×
120
                dbBackend = node.BackendEtcd
×
121

122
        case "postgres":
×
123
                dbBackend = node.BackendPostgres
×
124

125
        case "sqlite":
×
126
                dbBackend = node.BackendSqlite
×
127

128
        default:
×
129
                require.Fail(t, "unknown db backend")
×
130
        }
131

132
        return dbBackend
×
133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc