lntest/itest: update SendToRoute tests to include payment addr
This commit is contained in:
parent
43fc84919e
commit
7fdf46ea4e
@ -751,6 +751,10 @@ func createPayReqs(node *lntest.HarnessNode, paymentAmt btcutil.Amount,
|
|||||||
"invoice: %v", err)
|
"invoice: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the payment address in the invoice so the caller can
|
||||||
|
// properly use it.
|
||||||
|
invoice.PaymentAddr = resp.PaymentAddr
|
||||||
|
|
||||||
payReqs[i] = resp.PaymentRequest
|
payReqs[i] = resp.PaymentRequest
|
||||||
rHashes[i] = resp.RHash
|
rHashes[i] = resp.RHash
|
||||||
invoices[i] = invoice
|
invoices[i] = invoice
|
||||||
@ -5351,10 +5355,6 @@ type singleHopSendToRouteCase struct {
|
|||||||
// routerrpc submits the request to the routerrpc subserver if true,
|
// routerrpc submits the request to the routerrpc subserver if true,
|
||||||
// otherwise submits to the main rpc server.
|
// otherwise submits to the main rpc server.
|
||||||
routerrpc bool
|
routerrpc bool
|
||||||
|
|
||||||
// mpp sets the MPP fields on the request if true, otherwise submits a
|
|
||||||
// regular payment.
|
|
||||||
mpp bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var singleHopSendToRouteCases = []singleHopSendToRouteCase{
|
var singleHopSendToRouteCases = []singleHopSendToRouteCase{
|
||||||
@ -5371,17 +5371,14 @@ var singleHopSendToRouteCases = []singleHopSendToRouteCase{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mpp main sync",
|
name: "mpp main sync",
|
||||||
mpp: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mpp main stream",
|
name: "mpp main stream",
|
||||||
streaming: true,
|
streaming: true,
|
||||||
mpp: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mpp routerrpc sync",
|
name: "mpp routerrpc sync",
|
||||||
routerrpc: true,
|
routerrpc: true,
|
||||||
mpp: true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5558,11 +5555,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// - routerrpc server sync
|
// - routerrpc server sync
|
||||||
sendToRouteSync := func() {
|
sendToRouteSync := func() {
|
||||||
for i, rHash := range rHashes {
|
for i, rHash := range rHashes {
|
||||||
// Populate the MPP fields for the final hop if we are
|
setMPPFields(i)
|
||||||
// testing MPP payments.
|
|
||||||
if test.mpp {
|
|
||||||
setMPPFields(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
sendReq := &lnrpc.SendToRouteRequest{
|
sendReq := &lnrpc.SendToRouteRequest{
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
@ -5591,11 +5584,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, rHash := range rHashes {
|
for i, rHash := range rHashes {
|
||||||
// Populate the MPP fields for the final hop if we are
|
setMPPFields(i)
|
||||||
// testing MPP payments.
|
|
||||||
if test.mpp {
|
|
||||||
setMPPFields(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
sendReq := &lnrpc.SendToRouteRequest{
|
sendReq := &lnrpc.SendToRouteRequest{
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
@ -5619,11 +5608,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
}
|
}
|
||||||
sendToRouteRouterRPC := func() {
|
sendToRouteRouterRPC := func() {
|
||||||
for i, rHash := range rHashes {
|
for i, rHash := range rHashes {
|
||||||
// Populate the MPP fields for the final hop if we are
|
setMPPFields(i)
|
||||||
// testing MPP payments.
|
|
||||||
if test.mpp {
|
|
||||||
setMPPFields(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
sendReq := &routerrpc.SendToRouteRequest{
|
sendReq := &routerrpc.SendToRouteRequest{
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
@ -5719,26 +5704,22 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
// properly populated. Otherwise the hop should not have an MPP
|
// properly populated. Otherwise the hop should not have an MPP
|
||||||
// record.
|
// record.
|
||||||
hop := htlc.Route.Hops[0]
|
hop := htlc.Route.Hops[0]
|
||||||
if test.mpp {
|
if hop.MppRecord == nil {
|
||||||
if hop.MppRecord == nil {
|
t.Fatalf("expected mpp record for mpp payment")
|
||||||
t.Fatalf("expected mpp record for mpp payment")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if hop.MppRecord.TotalAmtMsat != paymentAmtSat*1000 {
|
if hop.MppRecord.TotalAmtMsat != paymentAmtSat*1000 {
|
||||||
t.Fatalf("incorrect mpp total msat for payment %d "+
|
t.Fatalf("incorrect mpp total msat for payment %d "+
|
||||||
"want: %d, got: %d",
|
"want: %d, got: %d",
|
||||||
i, paymentAmtSat*1000,
|
i, paymentAmtSat*1000,
|
||||||
hop.MppRecord.TotalAmtMsat)
|
hop.MppRecord.TotalAmtMsat)
|
||||||
}
|
}
|
||||||
|
|
||||||
expAddr := payAddrs[i]
|
expAddr := payAddrs[i]
|
||||||
if !bytes.Equal(hop.MppRecord.PaymentAddr, expAddr) {
|
if !bytes.Equal(hop.MppRecord.PaymentAddr, expAddr) {
|
||||||
t.Fatalf("incorrect mpp payment addr for payment %d "+
|
t.Fatalf("incorrect mpp payment addr for payment %d "+
|
||||||
"want: %x, got: %x",
|
"want: %x, got: %x",
|
||||||
i, expAddr, hop.MppRecord.PaymentAddr)
|
i, expAddr, hop.MppRecord.PaymentAddr)
|
||||||
}
|
|
||||||
} else if hop.MppRecord != nil {
|
|
||||||
t.Fatalf("unexpected mpp record for non-mpp payment")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5877,11 +5858,23 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query for routes to pay from Alice to Carol.
|
// Create 5 invoices for Carol, which expect a payment from Alice for 1k
|
||||||
// We set FinalCltvDelta to 40 since by default QueryRoutes returns
|
// satoshis with a different preimage each time.
|
||||||
// the last hop with a final cltv delta of 9 where as the default in
|
const (
|
||||||
// htlcswitch is 40.
|
numPayments = 5
|
||||||
const paymentAmt = 1000
|
paymentAmt = 1000
|
||||||
|
)
|
||||||
|
_, rHashes, invoices, err := createPayReqs(
|
||||||
|
carol, paymentAmt, numPayments,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a route from Alice to Carol for each of the invoices
|
||||||
|
// created above. We set FinalCltvDelta to 40 since by default
|
||||||
|
// QueryRoutes returns the last hop with a final cltv delta of 9 where
|
||||||
|
// as the default in htlcswitch is 40.
|
||||||
routesReq := &lnrpc.QueryRoutesRequest{
|
routesReq := &lnrpc.QueryRoutesRequest{
|
||||||
PubKey: carol.PubKeyStr,
|
PubKey: carol.PubKeyStr,
|
||||||
Amt: paymentAmt,
|
Amt: paymentAmt,
|
||||||
@ -5893,16 +5886,6 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to get route: %v", err)
|
t.Fatalf("unable to get route: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create 5 invoices for Carol, which expect a payment from Alice for 1k
|
|
||||||
// satoshis with a different preimage each time.
|
|
||||||
const numPayments = 5
|
|
||||||
_, rHashes, _, err := createPayReqs(
|
|
||||||
carol, paymentAmt, numPayments,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We'll wait for all parties to recognize the new channels within the
|
// We'll wait for all parties to recognize the new channels within the
|
||||||
// network.
|
// network.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
@ -5916,30 +5899,31 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Using Alice as the source, pay to the 5 invoices from Carol created
|
// Using Alice as the source, pay to the 5 invoices from Carol created
|
||||||
// above.
|
// above.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
alicePayStream, err := net.Alice.SendToRoute(ctxt)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to create payment stream for alice: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, rHash := range rHashes {
|
for i, rHash := range rHashes {
|
||||||
sendReq := &lnrpc.SendToRouteRequest{
|
// Manually set the MPP payload a new for each payment since
|
||||||
|
// the payment addr will change with each invoice, although we
|
||||||
|
// can re-use the route itself.
|
||||||
|
route := *routes.Routes[0]
|
||||||
|
route.Hops[len(route.Hops)-1].TlvPayload = true
|
||||||
|
route.Hops[len(route.Hops)-1].MppRecord = &lnrpc.MPPRecord{
|
||||||
|
PaymentAddr: invoices[i].PaymentAddr,
|
||||||
|
TotalAmtMsat: int64(
|
||||||
|
lnwire.NewMSatFromSatoshis(paymentAmt),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
sendReq := &routerrpc.SendToRouteRequest{
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
Route: routes.Routes[0],
|
Route: &route,
|
||||||
}
|
}
|
||||||
err := alicePayStream.Send(sendReq)
|
resp, err := net.Alice.RouterClient.SendToRouteV2(ctxt, sendReq)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
t.Fatalf("unable to send payment: %v", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for range rHashes {
|
if resp.Failure != nil {
|
||||||
resp, err := alicePayStream.Recv()
|
t.Fatalf("received payment error: %v", resp.Failure)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
|
||||||
}
|
|
||||||
if resp.PaymentError != "" {
|
|
||||||
t.Fatalf("received payment error: %v", resp.PaymentError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user