lntest: isolate alice+bob in mppTestContext
This commit is contained in:
parent
2ecd1de713
commit
4e93c1303c
@ -66,9 +66,9 @@ func testSendPaymentAMP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
ctxt, _ := context.WithTimeout(context.Background(), 4*defaultTimeout)
|
ctxt, _ := context.WithTimeout(context.Background(), 4*defaultTimeout)
|
||||||
payment := sendAndAssertSuccess(
|
payment := sendAndAssertSuccess(
|
||||||
ctxt, t, net.Alice,
|
ctxt, t, ctx.alice,
|
||||||
&routerrpc.SendPaymentRequest{
|
&routerrpc.SendPaymentRequest{
|
||||||
Dest: net.Bob.PubKey[:],
|
Dest: ctx.bob.PubKey[:],
|
||||||
Amt: int64(paymentAmt),
|
Amt: int64(paymentAmt),
|
||||||
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,
|
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,
|
||||||
TimeoutSeconds: 60,
|
TimeoutSeconds: 60,
|
||||||
@ -98,7 +98,7 @@ func testSendPaymentAMP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch Bob's invoices.
|
// Fetch Bob's invoices.
|
||||||
invoiceResp, err := net.Bob.ListInvoices(
|
invoiceResp, err := ctx.bob.ListInvoices(
|
||||||
ctxb, &lnrpc.ListInvoiceRequest{},
|
ctxb, &lnrpc.ListInvoiceRequest{},
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
@ -205,7 +205,7 @@ func testSendToRouteAMP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Define a closure for sending each of the three shards.
|
// Define a closure for sending each of the three shards.
|
||||||
sendShard := func(i int, hops []*lntest.HarnessNode) {
|
sendShard := func(i int, hops []*lntest.HarnessNode) {
|
||||||
// Build a route for the specified hops.
|
// Build a route for the specified hops.
|
||||||
r, err := ctx.buildRoute(ctxb, shardAmt, net.Alice, hops)
|
r, err := ctx.buildRoute(ctxb, shardAmt, ctx.alice, hops)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to build route: %v", err)
|
t.Fatalf("unable to build route: %v", err)
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ func testSendToRouteAMP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// block as long as the payment is in flight.
|
// block as long as the payment is in flight.
|
||||||
go func() {
|
go func() {
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
resp, err := net.Alice.RouterClient.SendToRouteV2(ctxt, sendReq)
|
resp, err := ctx.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)
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ func testSendToRouteAMP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Also fetch Bob's invoice from ListInvoices and assert it is equal to
|
// Also fetch Bob's invoice from ListInvoices and assert it is equal to
|
||||||
// the one recevied via the subscription.
|
// the one recevied via the subscription.
|
||||||
invoiceResp, err := net.Bob.ListInvoices(
|
invoiceResp, err := ctx.bob.ListInvoices(
|
||||||
ctxb, &lnrpc.ListInvoiceRequest{},
|
ctxb, &lnrpc.ListInvoiceRequest{},
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
|
@ -55,7 +55,7 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Make Bob create an invoice for Alice to pay.
|
// Make Bob create an invoice for Alice to pay.
|
||||||
payReqs, rHashes, invoices, err := createPayReqs(
|
payReqs, rHashes, invoices, err := createPayReqs(
|
||||||
net.Bob, paymentAmt, 1,
|
ctx.bob, paymentAmt, 1,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@ -65,7 +65,7 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
payReq := payReqs[0]
|
payReq := payReqs[0]
|
||||||
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
decodeResp, err := net.Bob.DecodePayReq(
|
decodeResp, err := ctx.bob.DecodePayReq(
|
||||||
ctxt, &lnrpc.PayReqString{PayReq: payReq},
|
ctxt, &lnrpc.PayReqString{PayReq: payReq},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,7 +84,7 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
responses := make(chan *lnrpc.HTLCAttempt, len(sendRoutes))
|
responses := make(chan *lnrpc.HTLCAttempt, len(sendRoutes))
|
||||||
for _, hops := range sendRoutes {
|
for _, hops := range sendRoutes {
|
||||||
// Build a route for the specified hops.
|
// Build a route for the specified hops.
|
||||||
r, err := ctx.buildRoute(ctxb, shardAmt, net.Alice, hops)
|
r, err := ctx.buildRoute(ctxb, shardAmt, ctx.alice, hops)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to build route: %v", err)
|
t.Fatalf("unable to build route: %v", err)
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// block as long as the payment is in flight.
|
// block as long as the payment is in flight.
|
||||||
go func() {
|
go func() {
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
resp, err := net.Alice.RouterClient.SendToRouteV2(ctxt, sendReq)
|
resp, err := ctx.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)
|
||||||
}
|
}
|
||||||
@ -234,10 +234,10 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Finally check that the payment shows up with three settled HTLCs in
|
// Finally check that the payment shows up with three settled HTLCs in
|
||||||
// Alice's list of payments...
|
// Alice's list of payments...
|
||||||
assertNumHtlcs(net.Alice, 3)
|
assertNumHtlcs(ctx.alice, 3)
|
||||||
|
|
||||||
// ...and in Bob's list of paid invoices.
|
// ...and in Bob's list of paid invoices.
|
||||||
assertSettledInvoice(net.Bob, rHash, 3)
|
assertSettledInvoice(ctx.bob, rHash, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mppTestContext struct {
|
type mppTestContext struct {
|
||||||
@ -257,6 +257,16 @@ func newMppTestContext(t *harnessTest,
|
|||||||
|
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
|
alice, err := net.NewNode("alice", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create alice: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bob, err := net.NewNode("bob", []string{"--accept-amp"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create bob: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Create a five-node context consisting of Alice, Bob and three new
|
// Create a five-node context consisting of Alice, Bob and three new
|
||||||
// nodes.
|
// nodes.
|
||||||
carol, err := net.NewNode("carol", nil)
|
carol, err := net.NewNode("carol", nil)
|
||||||
@ -275,7 +285,7 @@ func newMppTestContext(t *harnessTest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect nodes to ensure propagation of channels.
|
// Connect nodes to ensure propagation of channels.
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol, dave, eve}
|
nodes := []*lntest.HarnessNode{alice, bob, carol, dave, eve}
|
||||||
for i := 0; i < len(nodes); i++ {
|
for i := 0; i < len(nodes); i++ {
|
||||||
for j := i + 1; j < len(nodes); j++ {
|
for j := i + 1; j < len(nodes); j++ {
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
@ -288,8 +298,8 @@ func newMppTestContext(t *harnessTest,
|
|||||||
ctx := mppTestContext{
|
ctx := mppTestContext{
|
||||||
t: t,
|
t: t,
|
||||||
net: net,
|
net: net,
|
||||||
alice: net.Alice,
|
alice: alice,
|
||||||
bob: net.Bob,
|
bob: bob,
|
||||||
carol: carol,
|
carol: carol,
|
||||||
dave: dave,
|
dave: dave,
|
||||||
eve: eve,
|
eve: eve,
|
||||||
|
@ -59,7 +59,7 @@ func testSendMultiPathPayment(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Our first test will be Alice paying Bob using a SendPayment call.
|
// Our first test will be Alice paying Bob using a SendPayment call.
|
||||||
// Let Bob create an invoice for Alice to pay.
|
// Let Bob create an invoice for Alice to pay.
|
||||||
payReqs, rHashes, invoices, err := createPayReqs(
|
payReqs, rHashes, invoices, err := createPayReqs(
|
||||||
net.Bob, paymentAmt, 1,
|
ctx.bob, paymentAmt, 1,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@ -70,7 +70,7 @@ func testSendMultiPathPayment(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
payment := sendAndAssertSuccess(
|
payment := sendAndAssertSuccess(
|
||||||
ctxt, t, net.Alice,
|
ctxt, t, ctx.alice,
|
||||||
&routerrpc.SendPaymentRequest{
|
&routerrpc.SendPaymentRequest{
|
||||||
PaymentRequest: payReq,
|
PaymentRequest: payReq,
|
||||||
MaxParts: 10,
|
MaxParts: 10,
|
||||||
|
Loading…
Reference in New Issue
Block a user