Skip to content

Commit 08429c6

Browse files
ffranrguggero
authored andcommitted
lntest: add HtlcModifier support to node RPC harness
This commit enhances the itest LND node harness to include support for the new `HtlcModifier` RPC endpoint. At the same time we move another method to the correct file.
1 parent 2580661 commit 08429c6

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

lntest/harness.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/lightningnetwork/lnd/fn"
1717
"github.com/lightningnetwork/lnd/kvdb/etcd"
1818
"github.com/lightningnetwork/lnd/lnrpc"
19+
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
1920
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
2021
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2122
"github.com/lightningnetwork/lnd/lntest/node"
@@ -2183,6 +2184,39 @@ func (h *HarnessTest) ReceiveHtlcInterceptor(
21832184
return nil
21842185
}
21852186

2187+
// ReceiveInvoiceHtlcModification waits until a message is received on the
2188+
// invoice HTLC modifier stream or the timeout is reached.
2189+
func (h *HarnessTest) ReceiveInvoiceHtlcModification(
2190+
stream rpc.InvoiceHtlcModifierClient) *invoicesrpc.HtlcModifyRequest {
2191+
2192+
chanMsg := make(chan *invoicesrpc.HtlcModifyRequest)
2193+
errChan := make(chan error)
2194+
go func() {
2195+
// Consume one message. This will block until the message is
2196+
// received.
2197+
resp, err := stream.Recv()
2198+
if err != nil {
2199+
errChan <- err
2200+
return
2201+
}
2202+
chanMsg <- resp
2203+
}()
2204+
2205+
select {
2206+
case <-time.After(DefaultTimeout):
2207+
require.Fail(h, "timeout", "timeout invoice HTLC modifier")
2208+
2209+
case err := <-errChan:
2210+
require.Failf(h, "err from stream",
2211+
"received err from stream: %v", err)
2212+
2213+
case updateMsg := <-chanMsg:
2214+
return updateMsg
2215+
}
2216+
2217+
return nil
2218+
}
2219+
21862220
// ReceiveChannelEvent waits until a message is received from the
21872221
// ChannelEventsClient stream or the timeout is reached.
21882222
func (h *HarnessTest) ReceiveChannelEvent(

lntest/rpc/invoices.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/lightningnetwork/lnd/lnrpc"
77
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
8-
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
98
)
109

1110
// =====================
@@ -84,18 +83,19 @@ func (h *HarnessRPC) SubscribeSingleInvoice(rHash []byte) SingleInvoiceClient {
8483
return client
8584
}
8685

87-
type TrackPaymentClient routerrpc.Router_TrackPaymentV2Client
86+
type InvoiceHtlcModifierClient invoicesrpc.Invoices_HtlcModifierClient
8887

89-
// TrackPaymentV2 creates a subscription client for given invoice and
90-
// asserts its creation.
91-
func (h *HarnessRPC) TrackPaymentV2(payHash []byte) TrackPaymentClient {
92-
req := &routerrpc.TrackPaymentRequest{PaymentHash: payHash}
88+
// InvoiceHtlcModifier makes an RPC call to the node's RouterClient and asserts.
89+
func (h *HarnessRPC) InvoiceHtlcModifier() (InvoiceHtlcModifierClient,
90+
context.CancelFunc) {
9391

94-
// TrackPaymentV2 needs to have the context alive for the entire test
95-
// case as the returned client will be used for send and receive events
96-
// stream. Thus we use runCtx here instead of a timeout context.
97-
client, err := h.Router.TrackPaymentV2(h.runCtx, req)
98-
h.NoError(err, "TrackPaymentV2")
92+
// InvoiceHtlcModifier needs to have the context alive for the entire
93+
// test case as the returned client will be used for send and receive
94+
// events stream. Therefore, we use cancel context here instead of a
95+
// timeout context.
96+
ctxt, cancel := context.WithCancel(h.runCtx)
97+
resp, err := h.Invoice.HtlcModifier(ctxt)
98+
h.NoError(err, "InvoiceHtlcModifier")
9999

100-
return client
100+
return resp, cancel
101101
}

lntest/rpc/router.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,19 @@ func (h *HarnessRPC) TrackPayments(
224224

225225
return resp
226226
}
227+
228+
type TrackPaymentClient routerrpc.Router_TrackPaymentV2Client
229+
230+
// TrackPaymentV2 creates a subscription client for given invoice and
231+
// asserts its creation.
232+
func (h *HarnessRPC) TrackPaymentV2(payHash []byte) TrackPaymentClient {
233+
req := &routerrpc.TrackPaymentRequest{PaymentHash: payHash}
234+
235+
// TrackPaymentV2 needs to have the context alive for the entire test
236+
// case as the returned client will be used for send and receive events
237+
// stream. Thus we use runCtx here instead of a timeout context.
238+
client, err := h.Router.TrackPaymentV2(h.runCtx, req)
239+
h.NoError(err, "TrackPaymentV2")
240+
241+
return client
242+
}

0 commit comments

Comments
 (0)