Skip to content

Commit 3cef9fb

Browse files
itest: add test for ConfirmationsUntilActive field
Signed-off-by: Nishant Bansal <[email protected]>
1 parent 52103dc commit 3cef9fb

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: "confirmations until active on pending",
62+
TestFunc: testConfirmationsUntilActiveOnPending,
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+
// testConfirmationsUntilActiveOnPending verifies that as a channel status
881+
// transitions from pending to active, the ConfirmationsUntilActive field of the
882+
// PendingChannel decreases to 0 as expected.
883+
func testConfirmationsUntilActiveOnPending(ht *lntest.HarnessTest) {
884+
const (
885+
numConfs = int32(5)
886+
chanAmt = 100000
887+
)
888+
889+
// As we need to create a channel that requires more than 1 confirmation
890+
// before it's open, with the current set of defaults, we'll need to
891+
// create a new node instance.
892+
alice := ht.NewNodeWithCoins("Alice", nil)
893+
bob := ht.NewNode("Bob", []string{
894+
fmt.Sprintf("--bitcoin.defaultchanconfs=%v", numConfs),
895+
})
896+
897+
// Ensure Alice and Bob are connected.
898+
ht.EnsureConnected(alice, bob)
899+
900+
// Alice initiates a channel opening to Bob.
901+
param := lntest.OpenChannelParams{Amt: chanAmt}
902+
ht.OpenChannelAssertPending(alice, bob, param)
903+
904+
// Both Alice and Bob have one pending open channel.
905+
ht.AssertNumPendingOpenChannels(alice, 1)
906+
ht.AssertNumPendingOpenChannels(bob, 1)
907+
908+
// Since the funding transaction is not confirmed yet,
909+
// ConfirmationsUntilActive will always be numConfs.
910+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice,
911+
1)[0].ConfirmationsUntilActive)
912+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(bob, 1)[0].
913+
ConfirmationsUntilActive)
914+
915+
// Ensure that even if a block is mined and the funding transaction
916+
// remains unconfirmed, ConfirmationsUntilActive still equals numConfs
917+
ht.MineEmptyBlocks(1)
918+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice,
919+
1)[0].ConfirmationsUntilActive)
920+
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(bob, 1)[0].
921+
ConfirmationsUntilActive)
922+
923+
// Mine the first block containing the funding transaction, This
924+
// confirms the funding transaction but does not change the channel
925+
// status.
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+
// ConfirmationsUntilActive 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+
// ConfirmationsUntilActive 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+
ConfirmationsUntilActive)
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+
ConfirmationsUntilActive)
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 active.
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)