Skip to content

Commit dcf27a2

Browse files
committed
itest: optimize coop_close_with_external_delivery
Reuse Alice and Bob accross test cases. This brings the number of blocks mined down and also reduces test run time about 3 times.
1 parent cb9a216 commit dcf27a2

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

itest/lnd_coop_close_external_delivery_test.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ import (
77
"github.com/btcsuite/btcd/btcutil"
88
"github.com/lightningnetwork/lnd/lnrpc"
99
"github.com/lightningnetwork/lnd/lntest"
10+
"github.com/lightningnetwork/lnd/lntest/node"
1011
"github.com/lightningnetwork/lnd/lntest/wait"
1112
"github.com/stretchr/testify/require"
1213
)
1314

1415
func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
16+
alice := ht.NewNodeWithCoins("Alice", nil)
17+
bob := ht.NewNodeWithCoins("bob", nil)
18+
ht.ConnectNodes(alice, bob)
19+
1520
ok := ht.Run("set P2WPKH delivery address at open", func(t *testing.T) {
16-
tt := ht.Subtest(t)
1721
testCoopCloseWithExternalDeliveryImpl(
18-
tt, true, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
22+
ht, alice, bob, true,
23+
lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
1924
)
2025
})
2126
// Abort the test if failed.
@@ -24,9 +29,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
2429
}
2530

2631
ok = ht.Run("set P2WPKH delivery address at close", func(t *testing.T) {
27-
tt := ht.Subtest(t)
2832
testCoopCloseWithExternalDeliveryImpl(
29-
tt, false, lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
33+
ht, alice, bob, false,
34+
lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH,
3035
)
3136
})
3237
// Abort the test if failed.
@@ -35,9 +40,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
3540
}
3641

3742
ok = ht.Run("set P2TR delivery address at open", func(t *testing.T) {
38-
tt := ht.Subtest(t)
3943
testCoopCloseWithExternalDeliveryImpl(
40-
tt, true, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
44+
ht, alice, bob, true,
45+
lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
4146
)
4247
})
4348
// Abort the test if failed.
@@ -46,9 +51,9 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
4651
}
4752

4853
ht.Run("set P2TR delivery address at close", func(t *testing.T) {
49-
tt := ht.Subtest(t)
5054
testCoopCloseWithExternalDeliveryImpl(
51-
tt, false, lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
55+
ht, alice, bob, false,
56+
lnrpc.AddressType_UNUSED_TAPROOT_PUBKEY,
5257
)
5358
})
5459
}
@@ -58,11 +63,8 @@ func testCoopCloseWithExternalDelivery(ht *lntest.HarnessTest) {
5863
// not. Some users set this value to be an address in a different wallet and
5964
// this should not affect our ability to accurately report the settled balance.
6065
func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
61-
upfrontShutdown bool, deliveryAddressType lnrpc.AddressType) {
62-
63-
alice := ht.NewNodeWithCoins("Alice", nil)
64-
bob := ht.NewNodeWithCoins("bob", nil)
65-
ht.ConnectNodes(alice, bob)
66+
alice, bob *node.HarnessNode, upfrontShutdown bool,
67+
deliveryAddressType lnrpc.AddressType) {
6668

6769
// Here we generate a final delivery address in bob's wallet but set by
6870
// alice. We do this to ensure that the address is not in alice's LND
@@ -121,11 +123,22 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
121123
Cooperative: true,
122124
})
123125

124-
if len(closed.Channels) == 0 {
126+
// Find our channel. We do not recreate alice and bob between
127+
// testCoopCloseWithExternalDeliveryImpl calls.
128+
var closedChannel *lnrpc.ChannelCloseSummary
129+
chanPointStr := ht.OutPointFromChannelPoint(chanPoint).String()
130+
for _, summary := range closed.Channels {
131+
if summary.ChannelPoint == chanPointStr {
132+
closedChannel = summary
133+
break
134+
}
135+
}
136+
137+
if closedChannel == nil {
125138
return fmt.Errorf("expected closed channel not found")
126139
}
127140

128-
if closed.Channels[0].SettledBalance == 0 {
141+
if closedChannel.SettledBalance == 0 {
129142
return fmt.Errorf("expected settled balance to be zero")
130143
}
131144

0 commit comments

Comments
 (0)