Skip to content

Commit

Permalink
itest: add interceptor wire records access test
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed May 17, 2024
1 parent 9f15cb3 commit ce2a005
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
4 changes: 2 additions & 2 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testForwardInterceptorModifiedHtlc,
},
{
Name: "forward interceptor first hop records",
TestFunc: testForwardInterceptorFirstHopRecords,
Name: "forward interceptor wire records",
TestFunc: testForwardInterceptorWireRecords,
},
{
Name: "zero conf channel open",
Expand Down
57 changes: 23 additions & 34 deletions itest/lnd_forward_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ func testForwardInterceptorModifiedHtlc(ht *lntest.HarnessTest) {
ht.CloseChannel(bob, cpBC)
}

// testForwardInterceptorFirstHopRecords
func testForwardInterceptorFirstHopRecords(ht *lntest.HarnessTest) {
func testForwardInterceptorWireRecords(ht *lntest.HarnessTest) {
// Initialize the test context with 3 connected nodes.
ts := newInterceptorTestScenario(ht)

Expand All @@ -499,6 +498,9 @@ func testForwardInterceptorFirstHopRecords(ht *lntest.HarnessTest) {
// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)

// Connect an interceptor to Bob's node.
bobInterceptor, cancelBobInterceptor := bob.RPC.HtlcInterceptor()

req := &lnrpc.Invoice{ValueMsat: 1000}
addResponse := carol.RPC.AddInvoice(req)
invoice := carol.RPC.LookupInvoice(addResponse.RHash)
Expand All @@ -511,45 +513,32 @@ func testForwardInterceptorFirstHopRecords(ht *lntest.HarnessTest) {
65537: []byte("test"),
},
}
stream := alice.RPC.SendPayment(sendReq)
ht.AssertPaymentStatusFromStream(stream, lnrpc.Payment_SUCCEEDED)

// Formulate custom records target log string.
var (
cr record.CustomSet = make(record.CustomSet)
buf bytes.Buffer
)

cr[65537] = []byte("test")
_ = alice.RPC.SendPayment(sendReq)

err := cr.Encode(&buf)
require.NoError(ht, err, "failed to encode custom records")
customRecordsBytes := buf.Bytes()
// We start the htlc interceptor with a simple implementation that saves
// all intercepted packets. These packets are held to simulate a
// pending payment.
packet := ht.ReceiveHtlcInterceptor(bobInterceptor)

targetCustomRecordsStr := fmt.Sprintf(
"custom_records_blob=%x", customRecordsBytes,
)
require.Len(ht, packet.WireCustomRecords, 1)

logEntryCheck := func(logEntry string) bool {
return strings.Contains(logEntry, "custom_records_blob") &&
strings.Contains(logEntry, targetCustomRecordsStr)
}
val, ok := packet.WireCustomRecords[65537]
require.True(ht, ok, "expected custom record")
require.Equal(ht, []byte("test"), val)

require.Eventually(ht, func() bool {
ctx := context.Background()
dbgInfo, err := bob.RPC.LN.GetDebugInfo(
ctx, &lnrpc.GetDebugInfoRequest{},
)
require.NoError(ht, err, "failed to get Barol node debug info")
action := routerrpc.ResolveHoldForwardAction_RESUME_MODIFIED
newOutgoingAmountMsat := packet.OutgoingAmountMsat + 800

for _, logEntry := range dbgInfo.Log {
if logEntryCheck(logEntry) {
return true
}
}
err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: packet.IncomingCircuitKey,
OutgoingAmountMsat: newOutgoingAmountMsat,
Action: action,
})
require.NoError(ht, err, "failed to send request")

return false
}, defaultTimeout, time.Second)
// Cancel the context, which will disconnect Bob's interceptor.
cancelBobInterceptor()

// Assert that the payment was successful.
var preimage lntypes.Preimage
Expand Down

0 comments on commit ce2a005

Please sign in to comment.