itest: initialize context inside ConnectNodes

This commit is contained in:
yyforyongyu
2021-08-19 20:30:33 +08:00
parent dca20d80a7
commit 8de495b96b
17 changed files with 94 additions and 155 deletions

View File

@@ -103,9 +103,8 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
net.ConnectNodes(t.t, carol, dave)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// Open a channel with 100k satoshis between Carol and Dave with Carol
@@ -467,9 +466,8 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
net.ConnectNodes(t.t, carol, net.Bob)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
chanPointBob := openChannelAndAssert(
@@ -647,8 +645,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, charlie)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, charlie)
net.ConnectNodes(t.t, carol, charlie)
chanPointCarol := openChannelAndAssert(
t, net, carol, charlie,
@@ -761,9 +758,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
net.ConnectNodes(t.t, dave, net.Alice)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, dave, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
chanPointDave := openChannelAndAssert(
@@ -787,8 +783,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, dave)
net.ConnectNodes(t.t, carol, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
@@ -835,8 +830,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
}
// Now create a _private_ channel directly between Carol and
// Alice of 100k.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
net.ConnectNodes(t.t, carol, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate := openChannelStream(
ctxt, t, net, carol, net.Alice,
@@ -1079,8 +1073,7 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
defer shutdownAndAssert(net, t, carol)
// Connect Carol to Bob.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Bob)
net.ConnectNodes(t.t, carol, net.Bob)
// Open a channel with 100k satoshis between Bob and Carol.
chanPointBobCarol := openChannelAndAssert(
@@ -1110,7 +1103,7 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
Value: paymentAmt,
Private: true,
}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := carol.AddInvoice(ctxt, invoice)
require.NoError(t.t, err, "unable to create invoice for carol")
@@ -1210,8 +1203,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
net.ConnectNodes(t.t, net.Alice, carol)
chanPointCarol := openChannelAndAssert(
t, net, net.Alice, carol,
lntest.OpenChannelParams{
@@ -1225,8 +1217,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// we should only include routing hints for nodes that are publicly
// advertised, otherwise we'd end up leaking information about nodes
// that wish to stay unadvertised.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, net.Bob, carol)
net.ConnectNodes(t.t, net.Bob, carol)
chanPointBobCarol := openChannelAndAssert(
t, net, net.Bob, carol,
lntest.OpenChannelParams{
@@ -1242,8 +1233,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, net.Alice, dave)
net.ConnectNodes(t.t, net.Alice, dave)
chanPointDave := openChannelAndAssert(
t, net, net.Alice, dave,
lntest.OpenChannelParams{
@@ -1257,8 +1247,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// channel has been created to avoid populating routing hints for
// inactive channels.
eve := net.NewNode(t.t, "Eve", nil)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, net.Alice, eve)
net.ConnectNodes(t.t, net.Alice, eve)
chanPointEve := openChannelAndAssert(
t, net, net.Alice, eve,
lntest.OpenChannelParams{
@@ -1301,7 +1290,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
var predErr error
var decoded *lnrpc.PayReq
err := wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := net.Alice.AddInvoice(ctxt, invoice)
if err != nil {
predErr = fmt.Errorf("unable to add invoice: %v", err)
@@ -1341,7 +1330,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// We'll need the short channel ID of the channel between Alice and Bob
// to make sure the routing hint is for this channel.
listReq := &lnrpc.ListChannelsRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
listResp, err := net.Alice.ListChannels(ctxt, listReq)
if err != nil {
t.Fatalf("unable to retrieve alice's channels: %v", err)
@@ -1427,8 +1416,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, net.Bob, carol)
net.ConnectNodes(t.t, net.Bob, carol)
chanPointBob := openChannelAndAssert(
t, net, net.Bob, carol,
lntest.OpenChannelParams{
@@ -1470,8 +1458,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, dave)
net.ConnectNodes(t.t, carol, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
@@ -1606,9 +1593,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
net.ConnectNodes(t.t, carol, net.Bob)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
chanPointBob := openChannelAndAssert(
@@ -1623,8 +1609,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, dave, carol)
net.ConnectNodes(t.t, dave, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
@@ -1895,9 +1880,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
net.ConnectNodes(t.t, carol, net.Alice)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
chanPointAliceCarol := openChannelAndAssert(
@@ -1912,8 +1896,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, dave, net.Bob)
net.ConnectNodes(t.t, dave, net.Bob)
chanPointBobDave := openChannelAndAssert(
t, net, net.Bob, dave,
lntest.OpenChannelParams{
@@ -1922,8 +1905,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
)
// Open a channel between Carol and Dave.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, dave)
net.ConnectNodes(t.t, carol, dave)
chanPointCarolDave := openChannelAndAssert(
t, net, carol, dave,
lntest.OpenChannelParams{