@@ -978,6 +978,83 @@ func TestChannelStateTransition(t *testing.T) {
978
978
require .Empty (t , fwdPkgs , "no forwarding packages should exist" )
979
979
}
980
980
981
+ // TestOpeningChannelTxConfirmation verifies that calling MarkConfirmationHeight
982
+ // correctly updates the confirmed state. It also ensures that calling Refresh
983
+ // on a different OpenChannel updates its in-memory state to reflect the prior
984
+ // MarkConfirmationHeight call.
985
+ func TestOpeningChannelTxConfirmation (t * testing.T ) {
986
+ t .Parallel ()
987
+
988
+ fullDB , err := MakeTestDB (t )
989
+ require .NoError (t , err , "unable to make test database" )
990
+
991
+ cdb := fullDB .ChannelStateDB ()
992
+
993
+ // Create a pending channel that was broadcast at height 99.
994
+ const broadcastHeight = uint32 (99 )
995
+ channelState := createTestChannel (
996
+ t , cdb , pendingHeightOption (broadcastHeight ),
997
+ )
998
+
999
+ // Fetch pending channels from the database.
1000
+ pendingChannels , err := cdb .FetchPendingChannels ()
1001
+ require .NoError (t , err , "unable to list pending channels" )
1002
+ require .Len (t , pendingChannels , 1 , "expected one pending channel" )
1003
+
1004
+ // Verify the broadcast height of the pending channel.
1005
+ require .Equal (
1006
+ t , broadcastHeight , pendingChannels [0 ].FundingBroadcastHeight ,
1007
+ "broadcast height mismatch" ,
1008
+ )
1009
+
1010
+ confirmationHeight := broadcastHeight + 1
1011
+
1012
+ // Mark the channel's confirmation height.
1013
+ err = pendingChannels [0 ].MarkConfirmationHeight (confirmationHeight )
1014
+ require .NoError (t , err , "unable to mark channel's confirmation height" )
1015
+
1016
+ // Verify the ConfirmationHeight is updated correctly.
1017
+ require .Equal (
1018
+ t , confirmationHeight , pendingChannels [0 ].ConfirmationHeight ,
1019
+ "channel confirmation height not updated correctly" ,
1020
+ )
1021
+
1022
+ // Re-fetch the pending channels to confirm persistence.
1023
+ pendingChannels , err = cdb .FetchPendingChannels ()
1024
+ require .NoError (t , err , "unable to list pending channels" )
1025
+ require .Len (t , pendingChannels , 1 , "expected one pending channel" )
1026
+
1027
+ // Validate the confirmation and broadcast height.
1028
+ require .Equal (
1029
+ t , confirmationHeight , pendingChannels [0 ].ConfirmationHeight ,
1030
+ "channel confirmation height mismatch after re-fetching" ,
1031
+ )
1032
+ require .Equal (
1033
+ t , broadcastHeight , pendingChannels [0 ].FundingBroadcastHeight ,
1034
+ "broadcast height mismatch after re-fetching" ,
1035
+ )
1036
+
1037
+ // Ensure the original channel state's confirmation height is not
1038
+ // updated before refresh.
1039
+ require .NotEqual (
1040
+ t , channelState .ConfirmationHeight ,
1041
+ pendingChannels [0 ].ConfirmationHeight , "original channel " +
1042
+ "state's ConfirmationHeight should not match before " +
1043
+ "refresh" ,
1044
+ )
1045
+
1046
+ // Refresh the original channel state.
1047
+ err = channelState .Refresh ()
1048
+ require .NoError (t , err , "unable to refresh channel state" )
1049
+
1050
+ // Verify that both channel states now have the same ConfirmationHeight.
1051
+ require .Equal (
1052
+ t , channelState .ConfirmationHeight ,
1053
+ pendingChannels [0 ].ConfirmationHeight ,
1054
+ "channel ConfirmationHeight mismatch after refresh" ,
1055
+ )
1056
+ }
1057
+
981
1058
func TestFetchPendingChannels (t * testing.T ) {
982
1059
t .Parallel ()
983
1060
@@ -1007,7 +1084,7 @@ func TestFetchPendingChannels(t *testing.T) {
1007
1084
}
1008
1085
1009
1086
chanOpenLoc := lnwire.ShortChannelID {
1010
- BlockHeight : 5 ,
1087
+ BlockHeight : broadcastHeight + 1 ,
1011
1088
TxIndex : 10 ,
1012
1089
TxPosition : 15 ,
1013
1090
}
0 commit comments