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

lightningnetwork / lnd / 13589551993

28 Feb 2025 01:52PM UTC coverage: 58.841% (+0.007%) from 58.834%
13589551993

push

github

web-flow
Merge pull request #9566 from yyforyongyu/improve-itest

lntest+itest: change the method signature of `AssertPaymentStatus`

0 of 6 new or added lines in 2 files covered. (0.0%)

55 existing lines in 16 files now uncovered.

136440 of 231880 relevant lines covered (58.84%)

19280.95 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/node"
11
        "github.com/lightningnetwork/lnd/lntest/rpc"
12
        "github.com/lightningnetwork/lnd/lntest/wait"
13
        "github.com/lightningnetwork/lnd/lntypes"
14
        "github.com/lightningnetwork/lnd/lnwire"
15
        "github.com/stretchr/testify/require"
16
)
17

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

25
// testEndorsement sets up a 5 hop network and tests propagation of
26
// experimental endorsement signals.
27
func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
×
28
        cfg := node.CfgAnchor
×
29
        carolCfg := append(
×
30
                []string{"--protocol.no-experimental-endorsement"}, cfg...,
×
31
        )
×
32
        cfgs := [][]string{cfg, cfg, carolCfg, cfg, cfg}
×
33

×
34
        const chanAmt = btcutil.Amount(300000)
×
35
        p := lntest.OpenChannelParams{Amt: chanAmt}
×
36

×
37
        _, nodes := ht.CreateSimpleNetwork(cfgs, p)
×
38
        alice, bob, carol, dave, eve := nodes[0], nodes[1], nodes[2], nodes[3],
×
39
                nodes[4]
×
40

×
41
        bobIntercept, cancelBob := bob.RPC.HtlcInterceptor()
×
42
        defer cancelBob()
×
43

×
44
        carolIntercept, cancelCarol := carol.RPC.HtlcInterceptor()
×
45
        defer cancelCarol()
×
46

×
47
        daveIntercept, cancelDave := dave.RPC.HtlcInterceptor()
×
48
        defer cancelDave()
×
49

×
50
        req := &lnrpc.Invoice{ValueMsat: 1000}
×
51
        addResponse := eve.RPC.AddInvoice(req)
×
52
        invoice := eve.RPC.LookupInvoice(addResponse.RHash)
×
53

×
54
        sendReq := &routerrpc.SendPaymentRequest{
×
55
                PaymentRequest: invoice.PaymentRequest,
×
56
                TimeoutSeconds: int32(wait.PaymentTimeout.Seconds()),
×
57
                FeeLimitMsat:   math.MaxInt64,
×
58
        }
×
59

×
60
        expectedValue := []byte{lnwire.ExperimentalUnendorsed}
×
61
        if aliceEndorse {
×
62
                expectedValue = []byte{lnwire.ExperimentalEndorsed}
×
63
                t := uint64(lnwire.ExperimentalEndorsementType)
×
64
                sendReq.FirstHopCustomRecords = map[uint64][]byte{
×
65
                        t: expectedValue,
×
66
                }
×
67
        }
×
68

69
        _ = alice.RPC.SendPayment(sendReq)
×
70

×
71
        // Validate that our signal (positive or zero) propagates until carol
×
72
        // and then is dropped because she has disabled the feature.
×
73
        validateEndorsedAndResume(ht, bobIntercept, true, expectedValue)
×
74
        validateEndorsedAndResume(ht, carolIntercept, true, expectedValue)
×
75
        validateEndorsedAndResume(ht, daveIntercept, false, nil)
×
76

×
77
        var preimage lntypes.Preimage
×
78
        copy(preimage[:], invoice.RPreimage)
×
NEW
79
        ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
×
80
}
81

82
func validateEndorsedAndResume(ht *lntest.HarnessTest,
83
        interceptor rpc.InterceptorClient, hasEndorsement bool,
84
        expectedValue []byte) {
×
85

×
86
        packet := ht.ReceiveHtlcInterceptor(interceptor)
×
87

×
88
        var expectedRecords map[uint64][]byte
×
89
        if hasEndorsement {
×
90
                u64Type := uint64(lnwire.ExperimentalEndorsementType)
×
91
                expectedRecords = map[uint64][]byte{
×
92
                        u64Type: expectedValue,
×
93
                }
×
94
        }
×
95
        require.Equal(ht, expectedRecords, packet.InWireCustomRecords)
×
96

×
97
        err := interceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
×
98
                IncomingCircuitKey: packet.IncomingCircuitKey,
×
99
                Action:             routerrpc.ResolveHoldForwardAction_RESUME,
×
100
        })
×
101
        require.NoError(ht, err)
×
102
}
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