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

lightningnetwork / lnd / 12370450655

17 Dec 2024 09:48AM UTC coverage: 57.475%. First build
12370450655

Pull #9306

github

yyforyongyu
itest: fix flake in `testSendDirectPayment`

This bug was hidden because we used standby nodes before, which always
have more-than-necessary wallet utxos.
Pull Request #9306: Beat itest [1/3]: remove the usage of standby nodes

0 of 104 new or added lines in 5 files covered. (0.0%)

102363 of 178100 relevant lines covered (57.48%)

24827.19 hits per line

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

0.0
/itest/lnd_experimental_endorsement.go
1
package itest
2

3
import (
4
        "math"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
        "github.com/lightningnetwork/lnd/lnrpc"
8
        "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
9
        "github.com/lightningnetwork/lnd/lntest"
10
        "github.com/lightningnetwork/lnd/lntest/rpc"
11
        "github.com/lightningnetwork/lnd/lntest/wait"
12
        "github.com/lightningnetwork/lnd/lntypes"
13
        "github.com/lightningnetwork/lnd/lnwire"
14
        "github.com/stretchr/testify/require"
15
)
16

17
// testExperimentalEndorsement tests setting of positive and negative
18
// experimental endorsement signals.
19
func testExperimentalEndorsement(ht *lntest.HarnessTest) {
×
20
        testEndorsement(ht, true)
×
21
        testEndorsement(ht, false)
×
22
}
×
23

24
// testEndorsement sets up a 5 hop network and tests propagation of
25
// experimental endorsement signals.
26
func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
×
NEW
27
        alice := ht.NewNodeWithCoins("Alice", nil)
×
NEW
28
        bob := ht.NewNodeWithCoins("Bob", nil)
×
29
        carol := ht.NewNode(
×
30
                "carol", []string{"--protocol.no-experimental-endorsement"},
×
31
        )
×
32
        dave := ht.NewNode("dave", nil)
×
33
        eve := ht.NewNode("eve", nil)
×
34

×
35
        ht.EnsureConnected(alice, bob)
×
36
        ht.EnsureConnected(bob, carol)
×
37
        ht.EnsureConnected(carol, dave)
×
38
        ht.EnsureConnected(dave, eve)
×
39

×
40
        ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
×
41
        ht.FundCoins(btcutil.SatoshiPerBitcoin, dave)
×
42
        // Open and wait for channels.
×
43
        const chanAmt = btcutil.Amount(300000)
×
44
        p := lntest.OpenChannelParams{Amt: chanAmt}
×
45
        reqs := []*lntest.OpenChannelRequest{
×
46
                {Local: alice, Remote: bob, Param: p},
×
47
                {Local: bob, Remote: carol, Param: p},
×
48
                {Local: carol, Remote: dave, Param: p},
×
49
                {Local: dave, Remote: eve, Param: p},
×
50
        }
×
51
        resp := ht.OpenMultiChannelsAsync(reqs)
×
NEW
52
        _, cpBC, cpCD, cpDE := resp[0], resp[1], resp[2], resp[3]
×
53

×
54
        // Make sure Alice is aware of Bob=>Carol=>Dave=>Eve channels.
×
55
        ht.AssertChannelInGraph(alice, cpBC)
×
56
        ht.AssertChannelInGraph(alice, cpCD)
×
57
        ht.AssertChannelInGraph(alice, cpDE)
×
58

×
59
        bobIntercept, cancelBob := bob.RPC.HtlcInterceptor()
×
60
        defer cancelBob()
×
61

×
62
        carolIntercept, cancelCarol := carol.RPC.HtlcInterceptor()
×
63
        defer cancelCarol()
×
64

×
65
        daveIntercept, cancelDave := dave.RPC.HtlcInterceptor()
×
66
        defer cancelDave()
×
67

×
68
        req := &lnrpc.Invoice{ValueMsat: 1000}
×
69
        addResponse := eve.RPC.AddInvoice(req)
×
70
        invoice := eve.RPC.LookupInvoice(addResponse.RHash)
×
71

×
72
        sendReq := &routerrpc.SendPaymentRequest{
×
73
                PaymentRequest: invoice.PaymentRequest,
×
74
                TimeoutSeconds: int32(wait.PaymentTimeout.Seconds()),
×
75
                FeeLimitMsat:   math.MaxInt64,
×
76
        }
×
77

×
78
        expectedValue := []byte{lnwire.ExperimentalUnendorsed}
×
79
        if aliceEndorse {
×
80
                expectedValue = []byte{lnwire.ExperimentalEndorsed}
×
81
                t := uint64(lnwire.ExperimentalEndorsementType)
×
82
                sendReq.FirstHopCustomRecords = map[uint64][]byte{
×
83
                        t: expectedValue,
×
84
                }
×
85
        }
×
86

87
        _ = alice.RPC.SendPayment(sendReq)
×
88

×
89
        // Validate that our signal (positive or zero) propagates until carol
×
90
        // and then is dropped because she has disabled the feature.
×
91
        validateEndorsedAndResume(ht, bobIntercept, true, expectedValue)
×
92
        validateEndorsedAndResume(ht, carolIntercept, true, expectedValue)
×
93
        validateEndorsedAndResume(ht, daveIntercept, false, nil)
×
94

×
95
        var preimage lntypes.Preimage
×
96
        copy(preimage[:], invoice.RPreimage)
×
97
        ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
×
98
}
99

100
func validateEndorsedAndResume(ht *lntest.HarnessTest,
101
        interceptor rpc.InterceptorClient, hasEndorsement bool,
102
        expectedValue []byte) {
×
103

×
104
        packet := ht.ReceiveHtlcInterceptor(interceptor)
×
105

×
106
        var expectedRecords map[uint64][]byte
×
107
        if hasEndorsement {
×
108
                u64Type := uint64(lnwire.ExperimentalEndorsementType)
×
109
                expectedRecords = map[uint64][]byte{
×
110
                        u64Type: expectedValue,
×
111
                }
×
112
        }
×
113
        require.Equal(ht, expectedRecords, packet.InWireCustomRecords)
×
114

×
115
        err := interceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
×
116
                IncomingCircuitKey: packet.IncomingCircuitKey,
×
117
                Action:             routerrpc.ResolveHoldForwardAction_RESUME,
×
118
        })
×
119
        require.NoError(ht, err)
×
120
}
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