From 08d22f8bb477b03ec9e34d9cd77dbc268ad820b6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 22 Aug 2017 00:34:11 -0700 Subject: [PATCH] lnd: modify htlc error integration tests to account for max payment size This commit modifies the HTLC integration tests to be mindful of the max payment size. Rather than sending the payment in one large batch, we instead now send it in chunks of the max payment size. --- lnd_test.go | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index bff2c48f..52eb322c 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -2138,23 +2138,39 @@ out: // To do so, we'll push most of the funds in the channel over to // Alice's side, leaving on 10k satoshis of available balance for bob. - invoiceReq = &lnrpc.Invoice{ - Value: int64(chanAmt) - 10000, - } - carolInvoice2, err := carol.AddInvoice(ctxb, invoiceReq) - if err != nil { - t.Fatalf("unable to generate carol invoice: %v", err) - } - if err := bobPayStream.Send(&lnrpc.SendRequest{ - PaymentRequest: carolInvoice2.PaymentRequest, - }); err != nil { - t.Fatalf("unable to send payment: %v", err) - } + // There's a max payment amount, so we'll have to do this + // incrementally. + amtToSend := int64(chanAmt) - 10000 + amtSent := int64(0) + for amtSent != amtToSend { + // We'll send in chunks of the max payment amount. If we're + // about to send too much, then we'll only send the amount + // remaining. + toSend := int64(maxPaymentMSat.ToSatoshis()) + if toSend+amtSent > amtToSend { + toSend = amtToSend - amtSent + } - if resp, err := bobPayStream.Recv(); err != nil { - t.Fatalf("payment stream has been closed: %v", err) - } else if resp.PaymentError != "" { - t.Fatalf("bob's payment failed: %v", err) + invoiceReq = &lnrpc.Invoice{ + Value: toSend, + } + carolInvoice2, err := carol.AddInvoice(ctxb, invoiceReq) + if err != nil { + t.Fatalf("unable to generate carol invoice: %v", err) + } + if err := bobPayStream.Send(&lnrpc.SendRequest{ + PaymentRequest: carolInvoice2.PaymentRequest, + }); err != nil { + t.Fatalf("unable to send payment: %v", err) + } + + if resp, err := bobPayStream.Recv(); err != nil { + t.Fatalf("payment stream has been closed: %v", err) + } else if resp.PaymentError != "" { + t.Fatalf("bob's payment failed: %v", resp.PaymentError) + } + + amtSent += toSend } // At this point, Alice has 50mil satoshis on her side of the channel,