From 3e64ba0394d6dc709e31cf81eca554617eb110d1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 22 Oct 2017 18:35:38 -0700 Subject: [PATCH] test: modify all testing involving HTLC routing to directly use payreqs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit we modify all the test that involve sending payments to use the payreq returned rather than manually populating the payhash+dest fields in the SendRequest proto argument to SendPayment. This is required as if we don’t use the payreq returned, then the receiving node will reject the payment as it’ll use the global final CLTV delta value, rather than the value (within the pay req) that the receiver is expecting. --- lnd_test.go | 84 ++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 3e56e30e..2cfe5c48 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -1030,9 +1030,7 @@ func testSingleHopInvoice(net *networkHarness, t *harnessTest) { t.Fatalf("unable to create alice payment stream: %v", err) } sendReq := &lnrpc.SendRequest{ - PaymentHash: invoiceResp.RHash, - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: invoiceResp.PaymentRequest, } if err := sendStream.Send(sendReq); err != nil { t.Fatalf("unable to send payment: %v", err) @@ -1042,7 +1040,7 @@ func testSingleHopInvoice(net *networkHarness, t *harnessTest) { if resp, err := sendStream.Recv(); err != nil { t.Fatalf("payment stream has been close: %v", err) } else if resp.PaymentError != "" { - t.Fatalf("error when attempting recv: %v", err) + t.Fatalf("error when attempting recv: %v", resp.PaymentError) } else if !bytes.Equal(preimage, resp.PaymentPreimage) { t.Fatalf("preimage mismatch: expected %v, got %v", preimage, resp.GetPaymentPreimage()) @@ -1165,9 +1163,7 @@ func testListPayments(net *networkHarness, t *harnessTest) { t.Fatalf("unable to create alice payment stream: %v", err) } sendReq := &lnrpc.SendRequest{ - PaymentHash: invoiceResp.RHash, - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: invoiceResp.PaymentRequest, } if err := sendStream.Send(sendReq); err != nil { t.Fatalf("unable to send payment: %v", err) @@ -1301,7 +1297,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) { // satoshis with a different preimage each time. const numPayments = 5 const paymentAmt = 1000 - rHashes := make([][]byte, numPayments) + payReqs := make([]string, numPayments) for i := 0; i < numPayments; i++ { invoice := &lnrpc.Invoice{ Memo: "testing", @@ -1312,7 +1308,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) { t.Fatalf("unable to add invoice: %v", err) } - rHashes[i] = resp.RHash + payReqs[i] = resp.PaymentRequest } // Wait for carol to recognize both the Channel from herself to Carol, @@ -1338,11 +1334,9 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) { // will unblock on the recv once the HTLC it sent has been fully // settled. var wg sync.WaitGroup - for _, rHash := range rHashes { + for _, payReq := range payReqs { sendReq := &lnrpc.SendRequest{ - PaymentHash: rHash, - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: payReq, } if err := carolPayStream.Send(sendReq); err != nil { @@ -1539,9 +1533,7 @@ func testInvoiceSubscriptions(net *networkHarness, t *harnessTest) { t.Fatalf("unable to create alice payment stream: %v", err) } sendReq := &lnrpc.SendRequest{ - PaymentHash: invoiceResp.RHash, - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: invoiceResp.PaymentRequest, } if err := sendStream.Send(sendReq); err != nil { t.Fatalf("unable to send payment: %v", err) @@ -1779,7 +1771,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) { // With the channel open, we'll create a few invoices for Bob that // Alice will pay to in order to advance the state of the channel. - bobPaymentHashes := make([][]byte, numInvoices) + bobPayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := bytes.Repeat([]byte{byte(255 - i)}, 32) invoice := &lnrpc.Invoice{ @@ -1792,7 +1784,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) { t.Fatalf("unable to add invoice: %v", err) } - bobPaymentHashes[i] = resp.RHash + bobPayReqs[i] = resp.PaymentRequest } // As we'll be querying the state of bob's channels frequently we'll @@ -1829,9 +1821,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) { sendPayments := func(start, stop int) error { for i := start; i < stop; i++ { sendReq := &lnrpc.SendRequest{ - PaymentHash: bobPaymentHashes[i], - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: bobPayReqs[i], } if err := alicePayStream.Send(sendReq); err != nil { return err @@ -2051,7 +2041,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput( // With the channel open, we'll create a few invoices for Carol that // Alice will pay to in order to advance the state of the channel. - carolPaymentHashes := make([][]byte, numInvoices) + carolPayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := bytes.Repeat([]byte{byte(192 - i)}, 32) invoice := &lnrpc.Invoice{ @@ -2064,7 +2054,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput( t.Fatalf("unable to add invoice: %v", err) } - carolPaymentHashes[i] = resp.RHash + carolPayReqs[i] = resp.PaymentRequest } // As we'll be querying the state of Carols's channels frequently we'll @@ -2101,9 +2091,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput( sendPayments := func(start, stop int) error { for i := start; i < stop; i++ { sendReq := &lnrpc.SendRequest{ - PaymentHash: carolPaymentHashes[i], - Dest: carol.PubKey[:], - Amt: paymentAmt, + PaymentRequest: carolPayReqs[i], } if err := alicePayStream.Send(sendReq); err != nil { return err @@ -2304,7 +2292,7 @@ func testRevokedCloseRetributionRemoteHodl( // With the channel open, we'll create a few invoices for Carol that // Alice will pay to in order to advance the state of the channel. - carolPaymentHashes := make([][]byte, numInvoices) + carolPayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := bytes.Repeat([]byte{byte(192 - i)}, 32) invoice := &lnrpc.Invoice{ @@ -2317,7 +2305,7 @@ func testRevokedCloseRetributionRemoteHodl( t.Fatalf("unable to add invoice: %v", err) } - carolPaymentHashes[i] = resp.RHash + carolPayReqs[i] = resp.PaymentRequest } // As we'll be querying the state of Carol's channels frequently we'll @@ -2381,9 +2369,7 @@ func testRevokedCloseRetributionRemoteHodl( sendPayments := func(start, stop int, isHodl bool) error { for i := start; i < stop; i++ { sendReq := &lnrpc.SendRequest{ - PaymentHash: carolPaymentHashes[i], - Dest: carol.PubKey[:], - Amt: paymentAmt, + PaymentRequest: carolPayReqs[i], } if err := alicePayStream.Send(sendReq); err != nil { return err @@ -3335,9 +3321,9 @@ func testAsyncPayments(net *networkHarness, t *harnessTest) { // Initialize seed random in order to generate invoices. prand.Seed(time.Now().UnixNano()) - // With the channel open, we'll create a invoices for Bob that - // Alice will pay to in order to advance the state of the channel. - bobPaymentHashes := make([][]byte, numInvoices) + // With the channel open, we'll create a invoices for Bob that Alice + // will pay to in order to advance the state of the channel. + bobPayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := make([]byte, 32) _, err := rand.Read(preimage) @@ -3355,7 +3341,7 @@ func testAsyncPayments(net *networkHarness, t *harnessTest) { t.Fatalf("unable to add invoice: %v", err) } - bobPaymentHashes[i] = resp.RHash + bobPayReqs[i] = resp.PaymentRequest } // Wait for Alice to receive the channel edge from the funding manager. @@ -3379,9 +3365,7 @@ func testAsyncPayments(net *networkHarness, t *harnessTest) { now := time.Now() for i := 0; i < numInvoices; i++ { sendReq := &lnrpc.SendRequest{ - PaymentHash: bobPaymentHashes[i], - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: bobPayReqs[i], } if err := alicePayStream.Send(sendReq); err != nil { @@ -3514,9 +3498,9 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) { // Initialize seed random in order to generate invoices. prand.Seed(time.Now().UnixNano()) - // With the channel open, we'll create a invoices for Bob that - // Alice will pay to in order to advance the state of the channel. - bobPaymentHashes := make([][]byte, numInvoices) + // With the channel open, we'll create a invoices for Bob that Alice + // will pay to in order to advance the state of the channel. + bobPayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := make([]byte, 32) _, err := rand.Read(preimage) @@ -3534,12 +3518,12 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) { t.Fatalf("unable to add invoice: %v", err) } - bobPaymentHashes[i] = resp.RHash + bobPayReqs[i] = resp.PaymentRequest } - // With the channel open, we'll create a invoices for Alice that - // Bob will pay to in order to advance the state of the channel. - alicePaymentHashes := make([][]byte, numInvoices) + // With the channel open, we'll create a invoices for Alice that Bob + // will pay to in order to advance the state of the channel. + alicePayReqs := make([]string, numInvoices) for i := 0; i < numInvoices; i++ { preimage := make([]byte, 32) _, err := rand.Read(preimage) @@ -3557,7 +3541,7 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) { t.Fatalf("unable to add invoice: %v", err) } - alicePaymentHashes[i] = resp.RHash + alicePayReqs[i] = resp.PaymentRequest } // Wait for Alice to receive the channel edge from the funding manager. @@ -3587,15 +3571,11 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) { // manner. for i := 0; i < numInvoices; i++ { aliceSendReq := &lnrpc.SendRequest{ - PaymentHash: bobPaymentHashes[i], - Dest: net.Bob.PubKey[:], - Amt: paymentAmt, + PaymentRequest: bobPayReqs[i], } bobSendReq := &lnrpc.SendRequest{ - PaymentHash: alicePaymentHashes[i], - Dest: net.Alice.PubKey[:], - Amt: paymentAmt, + PaymentRequest: alicePayReqs[i], } if err := alicePayStream.Send(aliceSendReq); err != nil {