Skip to content

Commit

Permalink
lntest+itest: add new method AssertChannelInGraph
Browse files Browse the repository at this point in the history
 This commit replaces `AssertTopologyChannelOpen` with
`AssertChannelInGraph`, which asserts a given channel edge is found.
`AssertTopologyChannelOpen` only asserts a given edge has been received
via the topology subscription, while we need to make sure the channel is
in the graph before continuing our tests.
  • Loading branch information
yyforyongyu committed Nov 12, 2024
1 parent 969c209 commit e9ca4ea
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 87 deletions.
4 changes: 2 additions & 2 deletions itest/lnd_channel_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,8 @@ func createLegacyRevocationChannel(ht *lntest.HarnessTest,
}

ht.MineBlocksAndAssertNumTxes(6, 1)
ht.AssertTopologyChannelOpen(from, chanPoint)
ht.AssertTopologyChannelOpen(to, chanPoint)
ht.AssertChannelInGraph(from, chanPoint)
ht.AssertChannelInGraph(to, chanPoint)
}

// chanRestoreViaRPC is a helper test method that returns a nodeRestorer
Expand Down
14 changes: 7 additions & 7 deletions itest/lnd_channel_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
}

// Make sure Alice and Carol have seen each other's channels.
ht.AssertTopologyChannelOpen(alice, chanPoint2)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertChannelInGraph(alice, chanPoint2)
ht.AssertChannelInGraph(carol, chanPoint)

// First we'll try to send a payment from Alice to Carol with an amount
// less than the min_htlc value required by Carol. This payment should
Expand Down Expand Up @@ -292,7 +292,7 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
)

// Make sure Bob knows this channel.
ht.AssertTopologyChannelOpen(bob, chanPoint3)
ht.AssertChannelInGraph(bob, chanPoint3)

// Make a global update, and check that both channels' new policies get
// propagated.
Expand Down Expand Up @@ -515,9 +515,9 @@ func testSendUpdateDisableChannel(ht *lntest.HarnessTest) {
ht.RestartNodeWithExtraArgs(eve, nodeCfg)

// Dave should know all the channels.
ht.AssertTopologyChannelOpen(dave, chanPointAliceBob)
ht.AssertTopologyChannelOpen(dave, chanPointAliceCarol)
ht.AssertTopologyChannelOpen(dave, chanPointEveCarol)
ht.AssertChannelInGraph(dave, chanPointAliceBob)
ht.AssertChannelInGraph(dave, chanPointAliceCarol)
ht.AssertChannelInGraph(dave, chanPointEveCarol)

// We should expect to see a channel update with the default routing
// policy, except that it should indicate the channel is disabled.
Expand Down Expand Up @@ -701,7 +701,7 @@ func testUpdateChannelPolicyForPrivateChannel(ht *lntest.HarnessTest) {
)

// Carol should be aware of the channel between Alice and Bob.
ht.AssertTopologyChannelOpen(carol, chanPointAliceBob)
ht.AssertChannelInGraph(carol, chanPointAliceBob)

// We should have the following topology now,
// Alice <--public:100k--> Bob <--private:100k--> Carol
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_coop_close_with_htlcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func coopCloseWithHTLCs(ht *lntest.HarnessTest) {
})

// Wait for Bob to understand that the channel is ready to use.
ht.AssertTopologyChannelOpen(bob, chanPoint)
ht.AssertChannelInGraph(bob, chanPoint)

// Here we set things up so that Alice generates a HODL invoice so we
// can test whether the shutdown is deferred until the settlement of
Expand Down Expand Up @@ -141,7 +141,7 @@ func coopCloseWithHTLCsWithRestart(ht *lntest.HarnessTest) {
})

// Wait for Bob to understand that the channel is ready to use.
ht.AssertTopologyChannelOpen(bob, chanPoint)
ht.AssertChannelInGraph(bob, chanPoint)

// Set up a HODL invoice so that we can be sure that an HTLC is pending
// on the channel at the time that shutdown is requested.
Expand Down
12 changes: 6 additions & 6 deletions itest/lnd_forward_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func testForwardInterceptorDedupHtlc(ht *lntest.HarnessTest) {
cpAB, cpBC := resp[0], resp[1]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Connect the interceptor.
interceptor, cancelInterceptor := bob.RPC.HtlcInterceptor()
Expand Down Expand Up @@ -209,7 +209,7 @@ func testForwardInterceptorBasic(ht *lntest.HarnessTest) {
cpAB, cpBC := resp[0], resp[1]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Connect the interceptor.
interceptor, cancelInterceptor := bob.RPC.HtlcInterceptor()
Expand Down Expand Up @@ -370,7 +370,7 @@ func testForwardInterceptorModifiedHtlc(ht *lntest.HarnessTest) {
cpAB, cpBC := resp[0], resp[1]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Connect an interceptor to Bob's node.
bobInterceptor, cancelBobInterceptor := bob.RPC.HtlcInterceptor()
Expand Down Expand Up @@ -478,7 +478,7 @@ func testForwardInterceptorWireRecords(ht *lntest.HarnessTest) {
cpAB, cpBC, cpCD := resp[0], resp[1], resp[2]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Connect an interceptor to Bob's node.
bobInterceptor, cancelBobInterceptor := bob.RPC.HtlcInterceptor()
Expand Down Expand Up @@ -609,8 +609,8 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
cpAB, cpBC, cpCD := resp[0], resp[1], resp[2]

// Make sure Alice is aware of channels Bob=>Carol and Carol=>Dave.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertTopologyChannelOpen(alice, cpCD)
ht.AssertChannelInGraph(alice, cpBC)
ht.AssertChannelInGraph(alice, cpCD)

// Connect an interceptor to Bob's node.
bobInterceptor, cancelBobInterceptor := bob.RPC.HtlcInterceptor()
Expand Down
12 changes: 6 additions & 6 deletions itest/lnd_funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ func testChannelFundingPersistence(ht *lntest.HarnessTest) {

// Make sure Alice and Carol have seen the channel in their network
// topology.
ht.AssertTopologyChannelOpen(alice, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertChannelInGraph(alice, chanPoint)
ht.AssertChannelInGraph(carol, chanPoint)

// Create an additional check for our channel assertion that will
// check that our label is as expected.
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {

// Ensure that Alice can send funds to Eve via the zero-conf channel
// before the batch transaction was mined.
ht.AssertTopologyChannelOpen(alice, chanPoint4)
ht.AssertChannelInGraph(alice, chanPoint4)
eveInvoiceParams := &lnrpc.Invoice{
Value: int64(10_000),
Private: true,
Expand All @@ -1068,9 +1068,9 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
// Mine the batch transaction and check the network topology.
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, *txHash)
ht.AssertTopologyChannelOpen(alice, chanPoint1)
ht.AssertTopologyChannelOpen(alice, chanPoint2)
ht.AssertTopologyChannelOpen(alice, chanPoint3)
ht.AssertChannelInGraph(alice, chanPoint1)
ht.AssertChannelInGraph(alice, chanPoint2)
ht.AssertChannelInGraph(alice, chanPoint3)

// Check if the change type from the batch_open_channel funding is P2TR.
rawTx := ht.GetRawTransaction(*txHash)
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_hold_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) {
)

// Wait for Carol to see the open channel Alice-Bob.
ht.AssertTopologyChannelOpen(carol, chanPointBob)
ht.AssertChannelInGraph(carol, chanPointBob)

// Create preimages for all payments we are going to initiate.
var preimages []lntypes.Preimage
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_invoice_acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testInvoiceHtlcModifierBasic(ht *lntest.HarnessTest) {
cpAB, cpBC := resp[0], resp[1]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Initiate Carol's invoice HTLC modifier.
invoiceModifier, cancelModifier := carol.RPC.InvoiceHtlcModifier()
Expand Down
10 changes: 5 additions & 5 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ func testSphinxReplayPersistence(ht *lntest.HarnessTest) {
invoiceResp := dave.RPC.AddInvoice(invoice)

// Wait for all channels to be recognized and advertized.
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertTopologyChannelOpen(dave, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPointFC)
ht.AssertTopologyChannelOpen(fred, chanPointFC)
ht.AssertChannelInGraph(carol, chanPoint)
ht.AssertChannelInGraph(dave, chanPoint)
ht.AssertChannelInGraph(carol, chanPointFC)
ht.AssertChannelInGraph(fred, chanPointFC)

// With the invoice for Dave added, send a payment from Fred paying
// to the above generated invoice.
Expand Down Expand Up @@ -417,7 +417,7 @@ func testMaxPendingChannels(ht *lntest.HarnessTest) {
// Ensure that the funding transaction enters a block, and is
// properly advertised by Alice.
ht.AssertTxInBlock(block, fundingTxID)
ht.AssertTopologyChannelOpen(alice, fundingChanPoint)
ht.AssertChannelInGraph(alice, fundingChanPoint)

// The channel should be listed in the peer information
// returned by both peers.
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (m *mppTestScenario) openChannels(r *mppOpenChannelRequest) {
// Make sure every node has heard every channel.
for _, hn := range m.nodes {
for _, cp := range m.channelPoints {
m.ht.AssertTopologyChannelOpen(hn, cp)
m.ht.AssertChannelInGraph(hn, cp)
}

// Each node should have exactly 6 edges.
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_multi-hop-error-propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func testHtlcErrorPropagation(ht *lntest.HarnessTest) {
)

// Ensure that Alice has Carol in her routing table before proceeding.
ht.AssertTopologyChannelOpen(alice, chanPointBob)
ht.AssertChannelInGraph(alice, chanPointBob)

cType := ht.GetChannelCommitType(alice, chanPointAlice)
commitFee := lntest.CalcStaticFee(cType, 0)
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_multi-hop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2295,8 +2295,8 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
// We'll only do this though if it wasn't a private channel we opened
// earlier.
if !privateChan {
ht.AssertTopologyChannelOpen(alice, bobChanPoint)
ht.AssertTopologyChannelOpen(carol, aliceChanPoint)
ht.AssertChannelInGraph(alice, bobChanPoint)
ht.AssertChannelInGraph(carol, aliceChanPoint)
} else {
// Otherwise, we want to wait for all the channels to be shown
// as active before we proceed.
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {

// Wait for Alice and Bob to recognize and advertise the new channel
// generated above.
ht.AssertTopologyChannelOpen(alice, chanPoint)
ht.AssertTopologyChannelOpen(bob, chanPoint)
ht.AssertChannelInGraph(alice, chanPoint)
ht.AssertChannelInGraph(bob, chanPoint)

// Alice should now have 1 edge in her graph.
ht.AssertNumActiveEdges(alice, 1, true)
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ func testPaymentFailureReasonCanceled(ht *lntest.HarnessTest) {
cpAB, cpBC := resp[0], resp[1]

// Make sure Alice is aware of channel Bob=>Carol.
ht.AssertTopologyChannelOpen(alice, cpBC)
ht.AssertChannelInGraph(alice, cpBC)

// Connect the interceptor.
interceptor, cancelInterceptor := bob.RPC.HtlcInterceptor()
Expand Down
10 changes: 5 additions & 5 deletions itest/lnd_psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
txHash := finalTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPoint2)
ht.AssertChannelInGraph(carol, chanPoint)
ht.AssertChannelInGraph(carol, chanPoint2)

// With the channel open, ensure that it is counted towards Carol's
// total channel balance.
Expand Down Expand Up @@ -482,8 +482,8 @@ func runPsbtChanFundingExternal(ht *lntest.HarnessTest, carol,
// for the new channel to be propagated through the network.
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertTopologyChannelOpen(carol, chanPoint2)
ht.AssertChannelInGraph(carol, chanPoint)
ht.AssertChannelInGraph(carol, chanPoint2)

// With the channel open, ensure that it is counted towards Carol's
// total channel balance.
Expand Down Expand Up @@ -639,7 +639,7 @@ func runPsbtChanFundingSingleStep(ht *lntest.HarnessTest, carol,
txHash := finalTx.TxHash()
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
ht.AssertTxInBlock(block, txHash)
ht.AssertTopologyChannelOpen(carol, chanPoint)
ht.AssertChannelInGraph(carol, chanPoint)

// Next, to make sure the channel functions as normal, we'll make some
// payments within the channel.
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_res_handoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func testResHandoff(ht *lntest.HarnessTest) {
chanPointCarol := ht.OpenChannel(bob, carol, params)

// Wait for Alice to see the channel edge in the graph.
ht.AssertTopologyChannelOpen(alice, chanPointCarol)
ht.AssertChannelInGraph(alice, chanPointCarol)

// We'll create an invoice for Carol that Alice will attempt to pay.
// Since Carol is in hodl.commit mode, she won't send back any commit
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_revocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func revokedCloseRetributionZeroValueRemoteOutputCase(ht *lntest.HarnessTest,
ht.EnsureConnected(dave, carol)

// Once connected, give Dave some time to enable the channel again.
ht.AssertTopologyChannelOpen(dave, chanPoint)
ht.AssertChannelInGraph(dave, chanPoint)

// Finally, send payments from Dave to Carol, consuming Carol's
// remaining payment hashes.
Expand Down Expand Up @@ -502,7 +502,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
ht.EnsureConnected(dave, carol)

// Once connected, give Dave some time to enable the channel again.
ht.AssertTopologyChannelOpen(dave, chanPoint)
ht.AssertChannelInGraph(dave, chanPoint)

// Finally, send payments from Dave to Carol, consuming Carol's
// remaining payment hashes.
Expand Down
10 changes: 5 additions & 5 deletions itest/lnd_route_blinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func testQueryBlindedRoutes(ht *lntest.HarnessTest) {

// Wait for Alice to see Bob/Carol's channel because she'll need it for
// pathfinding.
ht.AssertTopologyChannelOpen(alice, chanPointBobCarol)
ht.AssertChannelInGraph(alice, chanPointBobCarol)

// Lookup full channel info so that we have channel ids for our route.
aliceBobChan := ht.GetChannelByChanPoint(alice, chanPointAliceBob)
Expand Down Expand Up @@ -593,7 +593,7 @@ func setupFourHopNetwork(ht *lntest.HarnessTest,
nodes := []*node.HarnessNode{ht.Alice, ht.Bob, carol, dave}
for _, chanPoint := range networkChans {
for _, node := range nodes {
ht.AssertTopologyChannelOpen(node, chanPoint)
ht.AssertChannelInGraph(node, chanPoint)
}
}

Expand Down Expand Up @@ -981,7 +981,7 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) {
}

numPublic++
ht.AssertTopologyChannelOpen(hn, cp)
ht.AssertChannelInGraph(hn, cp)
}

// Each node should have exactly numPublic edges.
Expand Down Expand Up @@ -1152,7 +1152,7 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
// Make sure every node has heard about every channel.
for _, hn := range nodes {
for _, cp := range channelPoints {
ht.AssertTopologyChannelOpen(hn, cp)
ht.AssertChannelInGraph(hn, cp)
}

// Each node should have exactly 5 edges.
Expand Down Expand Up @@ -1321,7 +1321,7 @@ func testMPPToMultipleBlindedPaths(ht *lntest.HarnessTest) {
// Make sure every node has heard every channel.
for _, hn := range nodes {
for _, cp := range channelPoints {
ht.AssertTopologyChannelOpen(hn, cp)
ht.AssertChannelInGraph(hn, cp)
}

// Each node should have exactly 5 edges.
Expand Down
12 changes: 6 additions & 6 deletions itest/lnd_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func runMultiHopSendToRoute(ht *lntest.HarnessTest, useGraphCache bool) {
defer ht.CloseChannel(carol, chanPointBob)

// Make sure Alice knows the channel between Bob and Carol.
ht.AssertTopologyChannelOpen(alice, chanPointBob)
ht.AssertChannelInGraph(alice, chanPointBob)

// Create 5 invoices for Carol, which expect a payment from Alice for
// 1k satoshis with a different preimage each time.
Expand Down Expand Up @@ -965,7 +965,7 @@ func testMultiHopOverPrivateChannels(ht *lntest.HarnessTest) {
)

// Alice should know the new channel from Bob.
ht.AssertTopologyChannelOpen(alice, chanPointBob)
ht.AssertChannelInGraph(alice, chanPointBob)

// Next, we'll create Dave's node and open a private channel between
// him and Carol with Carol being the funder.
Expand All @@ -981,7 +981,7 @@ func testMultiHopOverPrivateChannels(ht *lntest.HarnessTest) {
)

// Dave should know the channel[Bob<->Carol] from Carol.
ht.AssertTopologyChannelOpen(dave, chanPointBob)
ht.AssertChannelInGraph(dave, chanPointBob)

// Now that all the channels are set up according to the topology from
// above, we can proceed to test payments. We'll create an invoice for
Expand Down Expand Up @@ -1077,8 +1077,8 @@ func testQueryRoutes(ht *lntest.HarnessTest) {

// Before we continue, give Alice some time to catch up with the newly
// opened channels.
ht.AssertTopologyChannelOpen(alice, chanPointBob)
ht.AssertTopologyChannelOpen(alice, chanPointCarol)
ht.AssertChannelInGraph(alice, chanPointBob)
ht.AssertChannelInGraph(alice, chanPointCarol)

// Query for routes to pay from Alice to Dave.
const paymentAmt = 1000
Expand Down Expand Up @@ -1389,7 +1389,7 @@ func testRouteFeeCutoff(ht *lntest.HarnessTest) {
}
for _, chanPoint := range networkChans {
for _, node := range nodes {
ht.AssertTopologyChannelOpen(node, chanPoint)
ht.AssertChannelInGraph(node, chanPoint)
}
}

Expand Down
Loading

0 comments on commit e9ca4ea

Please sign in to comment.