Skip to content

Commit d57ad4f

Browse files
itest: add test for ConfirmationUntilConfirmed field
Signed-off-by: Nishant Bansal <[email protected]>
1 parent 84aeebe commit d57ad4f

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

itest/list_on_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ var allTestCases = []*lntest.TestCase{
5757
Name: "funding expiry blocks on pending",
5858
TestFunc: testFundingExpiryBlocksOnPending,
5959
},
60+
{
61+
Name: "confirmation until confirmed on pending",
62+
TestFunc: testConfirmationUntilConfirmedOnPending,
63+
},
6064
{
6165
Name: "list channels",
6266
TestFunc: testListChannels,

itest/lnd_open_channel_test.go

+86
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,92 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
877877
ht.MineBlocksAndAssertNumTxes(1, 1)
878878
}
879879

880+
// testConfirmationUntilConfirmedOnPending verifies that for a pending channel,
881+
// after the funding transaction has been confirmed but before the channel is
882+
// fully opened, the ConfirmationUntilConfirmed field of the PendingChannel
883+
// decreases to 0 as expected.
884+
func testConfirmationUntilConfirmedOnPending(ht *lntest.HarnessTest) {
885+
const (
886+
numConfs = int32(5)
887+
chanAmt = 100000
888+
)
889+
890+
// As we need to create a channel that requires more than 1 confirmation
891+
// before it's open, with the current set of defaults, we'll need to
892+
// create a new node instance.
893+
alice := ht.NewNodeWithCoins("Alice", nil)
894+
bob := ht.NewNode("Bob", []string{
895+
fmt.Sprintf("--bitcoin.defaultchanconfs=%v", numConfs),
896+
})
897+
898+
// Ensure Alice and Bob are connected.
899+
ht.EnsureConnected(alice, bob)
900+
901+
// Alice initiates a channel opening to Bob.
902+
param := lntest.OpenChannelParams{Amt: chanAmt}
903+
ht.OpenChannelAssertPending(alice, bob, param)
904+
905+
// Both Alice and Bob have one pending open channel.
906+
ht.AssertNumPendingOpenChannels(alice, 1)
907+
ht.AssertNumPendingOpenChannels(bob, 1)
908+
909+
// Since the funding transaction is not confirmed yet,
910+
// ConfirmationUntilConfirmed will always be numConfs.
911+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice,
912+
1)[0].ConfirmationUntilConfirmed)
913+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(bob, 1)[0].
914+
ConfirmationUntilConfirmed)
915+
916+
// Ensure that even if a block is mined and the funding transaction
917+
// remains unconfirmed, ConfirmationUntilConfirmed still equals numConfs
918+
ht.MineEmptyBlocks(1)
919+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice,
920+
1)[0].ConfirmationUntilConfirmed)
921+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(bob, 1)[0].
922+
ConfirmationUntilConfirmed)
923+
924+
// Mine the first block containing the funding transaction, This
925+
// confirms the funding transaction but does not yet open the channel.
926+
ht.MineBlocksAndAssertNumTxes(1, 1)
927+
928+
// Channel remains pending after the first confirmation.
929+
ht.AssertNumPendingOpenChannels(alice, 1)
930+
ht.AssertNumPendingOpenChannels(bob, 1)
931+
932+
// Restart both nodes to test that the appropriate state has been
933+
// persisted and that both nodes recover gracefully.
934+
ht.RestartNode(alice)
935+
ht.RestartNode(bob)
936+
937+
// ConfirmationUntilConfirmed field should decrease as each block is
938+
// mined until the required number of confirmations is reached. Let's
939+
// mine a few empty blocks and verify the value of
940+
// ConfirmationUntilConfirmed at each step.
941+
for i := int32(1); i < numConfs; i++ {
942+
expectedConfirmationsLeft := numConfs - i
943+
944+
// Retrieve pending channels for Alice and verify the remaining
945+
// confirmations.
946+
pendingAlice := ht.AssertNumPendingOpenChannels(alice, 1)
947+
require.Equal(ht, expectedConfirmationsLeft, pendingAlice[0].
948+
ConfirmationUntilConfirmed)
949+
950+
// Retrieve pending channels for Bob and verify the remaining
951+
// confirmations.
952+
pendingBob := ht.AssertNumPendingOpenChannels(bob, 1)
953+
require.Equal(ht, expectedConfirmationsLeft, pendingBob[0].
954+
ConfirmationUntilConfirmed)
955+
956+
// Mine the next block.
957+
ht.MineEmptyBlocks(1)
958+
}
959+
960+
// After the required number of confirmations, the channel should be
961+
// marked as open.
962+
ht.AssertNumPendingOpenChannels(alice, 0)
963+
ht.AssertNumPendingOpenChannels(bob, 0)
964+
}
965+
880966
// testSimpleTaprootChannelActivation ensures that a simple taproot channel is
881967
// active if the initiator disconnects and reconnects in between channel opening
882968
// and channel confirmation.

0 commit comments

Comments
 (0)