test: modify all testing involving HTLC routing to directly use payreqs
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.
This commit is contained in:
parent
e02af3f877
commit
3e64ba0394
84
lnd_test.go
84
lnd_test.go
@ -1030,9 +1030,7 @@ func testSingleHopInvoice(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to create alice payment stream: %v", err)
|
t.Fatalf("unable to create alice payment stream: %v", err)
|
||||||
}
|
}
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: invoiceResp.RHash,
|
PaymentRequest: invoiceResp.PaymentRequest,
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := sendStream.Send(sendReq); err != nil {
|
if err := sendStream.Send(sendReq); err != nil {
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
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 {
|
if resp, err := sendStream.Recv(); err != nil {
|
||||||
t.Fatalf("payment stream has been close: %v", err)
|
t.Fatalf("payment stream has been close: %v", err)
|
||||||
} else if resp.PaymentError != "" {
|
} 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) {
|
} else if !bytes.Equal(preimage, resp.PaymentPreimage) {
|
||||||
t.Fatalf("preimage mismatch: expected %v, got %v", preimage,
|
t.Fatalf("preimage mismatch: expected %v, got %v", preimage,
|
||||||
resp.GetPaymentPreimage())
|
resp.GetPaymentPreimage())
|
||||||
@ -1165,9 +1163,7 @@ func testListPayments(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to create alice payment stream: %v", err)
|
t.Fatalf("unable to create alice payment stream: %v", err)
|
||||||
}
|
}
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: invoiceResp.RHash,
|
PaymentRequest: invoiceResp.PaymentRequest,
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := sendStream.Send(sendReq); err != nil {
|
if err := sendStream.Send(sendReq); err != nil {
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
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.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
rHashes := make([][]byte, numPayments)
|
payReqs := make([]string, numPayments)
|
||||||
for i := 0; i < numPayments; i++ {
|
for i := 0; i < numPayments; i++ {
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
Memo: "testing",
|
Memo: "testing",
|
||||||
@ -1312,7 +1308,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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,
|
// 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
|
// will unblock on the recv once the HTLC it sent has been fully
|
||||||
// settled.
|
// settled.
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, rHash := range rHashes {
|
for _, payReq := range payReqs {
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: rHash,
|
PaymentRequest: payReq,
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := carolPayStream.Send(sendReq); err != nil {
|
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)
|
t.Fatalf("unable to create alice payment stream: %v", err)
|
||||||
}
|
}
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: invoiceResp.RHash,
|
PaymentRequest: invoiceResp.PaymentRequest,
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := sendStream.Send(sendReq); err != nil {
|
if err := sendStream.Send(sendReq); err != nil {
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
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
|
// 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.
|
// 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++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := bytes.Repeat([]byte{byte(255 - i)}, 32)
|
preimage := bytes.Repeat([]byte{byte(255 - i)}, 32)
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
@ -1792,7 +1784,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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
|
// 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 {
|
sendPayments := func(start, stop int) error {
|
||||||
for i := start; i < stop; i++ {
|
for i := start; i < stop; i++ {
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: bobPaymentHashes[i],
|
PaymentRequest: bobPayReqs[i],
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := alicePayStream.Send(sendReq); err != nil {
|
if err := alicePayStream.Send(sendReq); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -2051,7 +2041,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(
|
|||||||
|
|
||||||
// With the channel open, we'll create a few invoices for Carol that
|
// 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.
|
// 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++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := bytes.Repeat([]byte{byte(192 - i)}, 32)
|
preimage := bytes.Repeat([]byte{byte(192 - i)}, 32)
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
@ -2064,7 +2054,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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
|
// 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 {
|
sendPayments := func(start, stop int) error {
|
||||||
for i := start; i < stop; i++ {
|
for i := start; i < stop; i++ {
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: carolPaymentHashes[i],
|
PaymentRequest: carolPayReqs[i],
|
||||||
Dest: carol.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := alicePayStream.Send(sendReq); err != nil {
|
if err := alicePayStream.Send(sendReq); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -2304,7 +2292,7 @@ func testRevokedCloseRetributionRemoteHodl(
|
|||||||
|
|
||||||
// With the channel open, we'll create a few invoices for Carol that
|
// 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.
|
// 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++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := bytes.Repeat([]byte{byte(192 - i)}, 32)
|
preimage := bytes.Repeat([]byte{byte(192 - i)}, 32)
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
@ -2317,7 +2305,7 @@ func testRevokedCloseRetributionRemoteHodl(
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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
|
// 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 {
|
sendPayments := func(start, stop int, isHodl bool) error {
|
||||||
for i := start; i < stop; i++ {
|
for i := start; i < stop; i++ {
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: carolPaymentHashes[i],
|
PaymentRequest: carolPayReqs[i],
|
||||||
Dest: carol.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
if err := alicePayStream.Send(sendReq); err != nil {
|
if err := alicePayStream.Send(sendReq); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -3335,9 +3321,9 @@ func testAsyncPayments(net *networkHarness, t *harnessTest) {
|
|||||||
// Initialize seed random in order to generate invoices.
|
// Initialize seed random in order to generate invoices.
|
||||||
prand.Seed(time.Now().UnixNano())
|
prand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
// With the channel open, we'll create a invoices for Bob that
|
// With the channel open, we'll create a invoices for Bob that Alice
|
||||||
// Alice will pay to in order to advance the state of the channel.
|
// 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++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := make([]byte, 32)
|
preimage := make([]byte, 32)
|
||||||
_, err := rand.Read(preimage)
|
_, err := rand.Read(preimage)
|
||||||
@ -3355,7 +3341,7 @@ func testAsyncPayments(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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.
|
// 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()
|
now := time.Now()
|
||||||
for i := 0; i < numInvoices; i++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
sendReq := &lnrpc.SendRequest{
|
sendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: bobPaymentHashes[i],
|
PaymentRequest: bobPayReqs[i],
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := alicePayStream.Send(sendReq); err != nil {
|
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.
|
// Initialize seed random in order to generate invoices.
|
||||||
prand.Seed(time.Now().UnixNano())
|
prand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
// With the channel open, we'll create a invoices for Bob that
|
// With the channel open, we'll create a invoices for Bob that Alice
|
||||||
// Alice will pay to in order to advance the state of the channel.
|
// 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++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := make([]byte, 32)
|
preimage := make([]byte, 32)
|
||||||
_, err := rand.Read(preimage)
|
_, err := rand.Read(preimage)
|
||||||
@ -3534,12 +3518,12 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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
|
// With the channel open, we'll create a invoices for Alice that Bob
|
||||||
// Bob will pay to in order to advance the state of the channel.
|
// will pay to in order to advance the state of the channel.
|
||||||
alicePaymentHashes := make([][]byte, numInvoices)
|
alicePayReqs := make([]string, numInvoices)
|
||||||
for i := 0; i < numInvoices; i++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
preimage := make([]byte, 32)
|
preimage := make([]byte, 32)
|
||||||
_, err := rand.Read(preimage)
|
_, err := rand.Read(preimage)
|
||||||
@ -3557,7 +3541,7 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to add invoice: %v", err)
|
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.
|
// Wait for Alice to receive the channel edge from the funding manager.
|
||||||
@ -3587,15 +3571,11 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) {
|
|||||||
// manner.
|
// manner.
|
||||||
for i := 0; i < numInvoices; i++ {
|
for i := 0; i < numInvoices; i++ {
|
||||||
aliceSendReq := &lnrpc.SendRequest{
|
aliceSendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: bobPaymentHashes[i],
|
PaymentRequest: bobPayReqs[i],
|
||||||
Dest: net.Bob.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bobSendReq := &lnrpc.SendRequest{
|
bobSendReq := &lnrpc.SendRequest{
|
||||||
PaymentHash: alicePaymentHashes[i],
|
PaymentRequest: alicePayReqs[i],
|
||||||
Dest: net.Alice.PubKey[:],
|
|
||||||
Amt: paymentAmt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := alicePayStream.Send(aliceSendReq); err != nil {
|
if err := alicePayStream.Send(aliceSendReq); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user