Skip to content

Commit 91d56c7

Browse files
committed
lntest: add InvoiceAcceptor support to node RPC harness
This commit enhances the itest LND node harness to include support for the new `InvoiceAcceptor` RPC endpoint.
1 parent 471816e commit 91d56c7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
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+
// ReceiveInvoiceAcceptor waits until a message is received on the invoice
2188+
// acceptor interceptor stream or the timeout is reached.
2189+
func (h *HarnessTest) ReceiveInvoiceAcceptor(
2190+
stream rpc.InvoiceAcceptorClient) *invoicesrpc.InvoiceAcceptorRequest {
2191+
2192+
chanMsg := make(chan *invoicesrpc.InvoiceAcceptorRequest)
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 acceptor")
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/router.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/lightningnetwork/lnd/lnrpc"
7+
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
78
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
89
"github.com/stretchr/testify/require"
910
)
@@ -193,6 +194,23 @@ func (h *HarnessRPC) HtlcInterceptor() (InterceptorClient, context.CancelFunc) {
193194
return resp, cancel
194195
}
195196

197+
type InvoiceAcceptorClient invoicesrpc.Invoices_InvoiceAcceptorClient
198+
199+
// InvoiceAcceptor makes an RPC call to the node's RouterClient and asserts.
200+
func (h *HarnessRPC) InvoiceAcceptor() (InvoiceAcceptorClient,
201+
context.CancelFunc) {
202+
203+
// InvoiceAcceptor needs to have the context alive for the entire test
204+
// case as the returned client will be used for send and receive events
205+
// stream. Therefore, we use cancel context here instead of a timeout
206+
// context.
207+
ctxt, cancel := context.WithCancel(h.runCtx)
208+
resp, err := h.Invoice.InvoiceAcceptor(ctxt)
209+
h.NoError(err, "InvoiceAcceptor")
210+
211+
return resp, cancel
212+
}
213+
196214
type TrackPaymentsClient routerrpc.Router_TrackPaymentsClient
197215

198216
// TrackPayments makes a RPC call to the node's RouterClient and asserts.

0 commit comments

Comments
 (0)