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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

0.0
/chainntnfs/test_utils.go
1
//go:build dev
2
// +build dev
3

4
package chainntnfs
5

6
import (
7
        "errors"
8
        "fmt"
9
        "testing"
10
        "time"
11

12
        "github.com/btcsuite/btcd/btcec/v2"
13
        "github.com/btcsuite/btcd/btcjson"
14
        "github.com/btcsuite/btcd/btcutil"
15
        "github.com/btcsuite/btcd/chaincfg/chainhash"
16
        "github.com/btcsuite/btcd/integration/rpctest"
17
        "github.com/btcsuite/btcd/txscript"
18
        "github.com/btcsuite/btcd/wire"
19
        "github.com/lightningnetwork/lnd/input"
20
        "github.com/lightningnetwork/lnd/lntest/unittest"
21
        "github.com/stretchr/testify/require"
22
)
23

24
var (
25
        // TrickleInterval is the interval at which the miner should trickle
26
        // transactions to its peers. We'll set it small to ensure the miner
27
        // propagates transactions quickly in the tests.
28
        TrickleInterval = 10 * time.Millisecond
29
)
30

31
// randPubKeyHashScript generates a P2PKH script that pays to the public key of
32
// a randomly-generated private key.
33
func randPubKeyHashScript() ([]byte, *btcec.PrivateKey, error) {
×
34
        privKey, err := btcec.NewPrivateKey()
×
35
        if err != nil {
×
36
                return nil, nil, err
×
37
        }
×
38

39
        pubKeyHash := btcutil.Hash160(privKey.PubKey().SerializeCompressed())
×
40
        addrScript, err := btcutil.NewAddressWitnessPubKeyHash(
×
41
                pubKeyHash, unittest.NetParams,
×
42
        )
×
43
        if err != nil {
×
44
                return nil, nil, err
×
45
        }
×
46

47
        pkScript, err := txscript.PayToAddrScript(addrScript)
×
48
        if err != nil {
×
49
                return nil, nil, err
×
50
        }
×
51

52
        return pkScript, privKey, nil
×
53
}
54

55
// GetTestTxidAndScript generate a new test transaction and returns its txid and
56
// the script of the output being generated.
57
func GetTestTxidAndScript(h *rpctest.Harness) (*chainhash.Hash, []byte, error) {
×
58
        pkScript, _, err := randPubKeyHashScript()
×
59
        if err != nil {
×
60
                return nil, nil, fmt.Errorf("unable to generate pkScript: %w",
×
61
                        err)
×
62
        }
×
63
        output := &wire.TxOut{Value: 2e8, PkScript: pkScript}
×
64
        txid, err := h.SendOutputs([]*wire.TxOut{output}, 10)
×
65
        if err != nil {
×
66
                return nil, nil, err
×
67
        }
×
68

69
        return txid, pkScript, nil
×
70
}
71

72
// WaitForMempoolTx waits for the txid to be seen in the miner's mempool.
73
func WaitForMempoolTx(miner *rpctest.Harness, txid *chainhash.Hash) error {
×
74
        timeout := time.After(10 * time.Second)
×
75
        trickle := time.After(2 * TrickleInterval)
×
76
        for {
×
77
                // Check for the harness' knowledge of the txid.
×
78
                tx, err := miner.Client.GetRawTransaction(txid)
×
79
                if err != nil {
×
80
                        jsonErr, ok := err.(*btcjson.RPCError)
×
81
                        if ok && jsonErr.Code == btcjson.ErrRPCNoTxInfo {
×
82
                                continue
×
83
                        }
84
                        return err
×
85
                }
86

87
                if tx != nil && tx.Hash().IsEqual(txid) {
×
88
                        break
×
89
                }
90

91
                select {
×
92
                case <-time.After(100 * time.Millisecond):
×
93
                case <-timeout:
×
94
                        return errors.New("timed out waiting for tx")
×
95
                }
96
        }
97

98
        // To ensure any transactions propagate from the miner to the peers
99
        // before returning, ensure we have waited for at least
100
        // 2*trickleInterval before returning.
101
        select {
×
102
        case <-trickle:
×
103
        case <-timeout:
×
104
                return errors.New("timeout waiting for trickle interval. " +
×
105
                        "Trickle interval to large?")
×
106
        }
107

108
        return nil
×
109
}
110

111
// CreateSpendableOutput creates and returns an output that can be spent later
112
// on.
113
func CreateSpendableOutput(t *testing.T,
114
        miner *rpctest.Harness) (*wire.OutPoint, *wire.TxOut, *btcec.PrivateKey) {
×
115

×
116
        t.Helper()
×
117

×
118
        // Create a transaction that only has one output, the one destined for
×
119
        // the recipient.
×
120
        pkScript, privKey, err := randPubKeyHashScript()
×
121
        require.NoError(t, err, "unable to generate pkScript")
×
122
        output := &wire.TxOut{Value: 2e8, PkScript: pkScript}
×
123
        txid, err := miner.SendOutputsWithoutChange([]*wire.TxOut{output}, 10)
×
124
        require.NoError(t, err, "unable to create tx")
×
125

×
126
        // Mine the transaction to mark the output as spendable.
×
127
        if err := WaitForMempoolTx(miner, txid); err != nil {
×
128
                t.Fatalf("tx not relayed to miner: %v", err)
×
129
        }
×
130
        if _, err := miner.Client.Generate(1); err != nil {
×
131
                t.Fatalf("unable to generate single block: %v", err)
×
132
        }
×
133

134
        return wire.NewOutPoint(txid, 0), output, privKey
×
135
}
136

137
// CreateSpendTx creates a transaction spending the specified output.
138
func CreateSpendTx(t *testing.T, prevOutPoint *wire.OutPoint,
139
        prevOutput *wire.TxOut, privKey *btcec.PrivateKey) *wire.MsgTx {
×
140

×
141
        t.Helper()
×
142

×
143
        // Create a new output.
×
144
        outputAmt := int64(1e8)
×
145
        witnessProgram, _, err := randPubKeyHashScript()
×
146
        require.NoError(t, err, "unable to generate pkScript")
×
147
        output := wire.NewTxOut(outputAmt, witnessProgram)
×
148

×
149
        // Create a new tx.
×
150
        tx := wire.NewMsgTx(2)
×
151
        tx.AddTxIn(wire.NewTxIn(prevOutPoint, nil, nil))
×
152
        tx.AddTxOut(output)
×
153

×
154
        // Generate the witness.
×
155
        sigHashes := input.NewTxSigHashesV0Only(tx)
×
156
        witnessScript, err := txscript.WitnessSignature(
×
157
                tx, sigHashes, 0, prevOutput.Value, prevOutput.PkScript,
×
158
                txscript.SigHashAll, privKey, true,
×
159
        )
×
160
        require.NoError(t, err, "unable to sign tx")
×
161

×
162
        tx.TxIn[0].Witness = witnessScript
×
163

×
164
        return tx
×
165
}
×
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