@@ -96,7 +96,8 @@ func TestPaymentWatcher_WatchPayment_Reconnect(t *testing.T) {
9696 t .Fatalf ("Could not create tx watcher: %v" , err )
9797 }
9898
99- payreq , err := payee .AddInvoice (100000 , "testpaymentwatcher_payinvoice" , "" )
99+ invoiceAmtSat := uint64 (100000 )
100+ payreq , err := payee .AddInvoice (invoiceAmtSat , "testpaymentwatcher_payinvoice" , "" )
100101 if err != nil {
101102 t .Fatalf ("Could not add invoice: %v" , err )
102103 }
@@ -127,6 +128,29 @@ func TestPaymentWatcher_WatchPayment_Reconnect(t *testing.T) {
127128 // We have to reconnect in order to pay the invoice.
128129 payer .Connect (payee , true )
129130
131+ // Ensure the channel is fully re-established before paying.
132+ scid , err := payer .GetScid (payee )
133+ if err != nil {
134+ t .Fatalf ("GetScid() %v" , err )
135+ }
136+ err = testframework .WaitForWithErr (func () (bool , error ) {
137+ active , err := payer .IsChannelActive (scid )
138+ return active , err
139+ }, testframework .TIMEOUT )
140+ if err != nil {
141+ t .Fatalf ("channel did not become active: %v" , err )
142+ }
143+ err = testframework .WaitForWithErr (func () (bool , error ) {
144+ bal , err := payer .GetChannelBalanceSat (scid )
145+ if err != nil {
146+ return false , err
147+ }
148+ return bal >= invoiceAmtSat , nil
149+ }, testframework .TIMEOUT )
150+ if err != nil {
151+ t .Fatalf ("payer has insufficient channel balance: %v" , err )
152+ }
153+
130154 // Now we pay the invoice and check if the watcher is still active. If the
131155 // watcher is still active, the callback should be called.
132156 err = payer .PayInvoice (payreq )
@@ -165,7 +189,8 @@ func TestPaymentWatcher_WatchPayment_Reconnect_OnGracefulStop(t *testing.T) {
165189 t .Fatalf ("Could not create tx watcher: %v" , err )
166190 }
167191
168- payreq , err := payee .AddInvoice (100000 , "testpaymentwatcher_payinvoice" , "" )
192+ invoiceAmtSat := uint64 (100000 )
193+ payreq , err := payee .AddInvoice (invoiceAmtSat , "testpaymentwatcher_payinvoice" , "" )
169194 if err != nil {
170195 t .Fatalf ("Could not add invoice: %v" , err )
171196 }
@@ -199,6 +224,29 @@ func TestPaymentWatcher_WatchPayment_Reconnect_OnGracefulStop(t *testing.T) {
199224 // We have to reconnect in order to pay the invoice.
200225 payer .Connect (payee , true )
201226
227+ // Ensure the channel is fully re-established before paying.
228+ scid , err := payer .GetScid (payee )
229+ if err != nil {
230+ t .Fatalf ("GetScid() %v" , err )
231+ }
232+ err = testframework .WaitForWithErr (func () (bool , error ) {
233+ active , err := payer .IsChannelActive (scid )
234+ return active , err
235+ }, testframework .TIMEOUT )
236+ if err != nil {
237+ t .Fatalf ("channel did not become active: %v" , err )
238+ }
239+ err = testframework .WaitForWithErr (func () (bool , error ) {
240+ bal , err := payer .GetChannelBalanceSat (scid )
241+ if err != nil {
242+ return false , err
243+ }
244+ return bal >= invoiceAmtSat , nil
245+ }, testframework .TIMEOUT )
246+ if err != nil {
247+ t .Fatalf ("payer has insufficient channel balance: %v" , err )
248+ }
249+
202250 // Now we pay the invoice and check if the watcher is still active. If the
203251 // watcher is still active, the callback should be called.
204252 err = payer .PayInvoice (payreq )
0 commit comments