Skip to content

Commit 0cc84d0

Browse files
authored
Merge pull request #10353 from starius/fix-rbf_coop_test
chancloser: stabilize remote RBF coop tests
2 parents 9fcd7c2 + d47d86c commit 0cc84d0

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lnwallet/chancloser/rbf_coop_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,16 @@ func (r *rbfCloserTestHarness) assertSingleRbfIteration(
681681
r.assertLocalClosePending()
682682
}
683683

684+
// assertSingleRemoteRbfIteration asserts that a single RBF iteration initiated
685+
// by the remote party completes successfully. The sendEvent callback controls
686+
// when the event that kicks off the process is sent, which is useful for tests
687+
// that need to set up mocks before the event is processed. The callback is
688+
// provided with the context and the initial offer event so most callers can
689+
// pass chanCloser.SendEvent directly.
684690
func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
685691
initEvent *OfferReceivedEvent, balanceAfterClose,
686692
absoluteFee btcutil.Amount, sequence uint32, iteration bool,
687-
sendInit bool) {
693+
sendEvent func(context.Context, ProtocolEvent)) {
688694

689695
ctx := r.T.Context()
690696

@@ -696,9 +702,7 @@ func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
696702
absoluteFee, balanceAfterClose, false,
697703
)
698704

699-
if sendInit {
700-
r.chanCloser.SendEvent(ctx, initEvent)
701-
}
705+
sendEvent(ctx, initEvent)
702706

703707
// Our outer state should transition to ClosingNegotiation state.
704708
transitions := []RbfState{
@@ -1386,10 +1390,13 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
13861390
// Now we'll send in the channel flushed event, and assert that
13871391
// this triggers a remote RBF iteration (we process their early
13881392
// offer and send our sig).
1389-
closeHarness.chanCloser.SendEvent(ctx, &flushEvent)
13901393
closeHarness.assertSingleRemoteRbfIteration(
13911394
remoteOffer, absoluteFee, absoluteFee, sequence, true,
1392-
false,
1395+
func(ctx context.Context, _ ProtocolEvent) {
1396+
closeHarness.chanCloser.SendEvent(
1397+
ctx, &flushEvent,
1398+
)
1399+
},
13931400
)
13941401
})
13951402

@@ -1857,7 +1864,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
18571864
// sig.
18581865
closeHarness.assertSingleRemoteRbfIteration(
18591866
feeOffer, balanceAfterClose, absoluteFee, sequence,
1860-
false, true,
1867+
false, closeHarness.chanCloser.SendEvent,
18611868
)
18621869

18631870
// Next, we'll receive an offer from the remote party, and drive
@@ -1867,7 +1874,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
18671874
absoluteFee = feeOffer.SigMsg.FeeSatoshis
18681875
closeHarness.assertSingleRemoteRbfIteration(
18691876
feeOffer, balanceAfterClose, absoluteFee, sequence,
1870-
true, true,
1877+
true, closeHarness.chanCloser.SendEvent,
18711878
)
18721879

18731880
closeHarness.assertNoStateTransitions()
@@ -1950,7 +1957,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
19501957
// sig.
19511958
closeHarness.assertSingleRemoteRbfIteration(
19521959
feeOffer, balanceAfterClose, absoluteFee, sequence,
1953-
false, true,
1960+
false, closeHarness.chanCloser.SendEvent,
19541961
)
19551962
})
19561963

@@ -2048,7 +2055,7 @@ func TestRbfCloseErr(t *testing.T) {
20482055
// sig.
20492056
closeHarness.assertSingleRemoteRbfIteration(
20502057
feeOffer, balanceAfterClose, absoluteFee, sequence,
2051-
true, true,
2058+
true, closeHarness.chanCloser.SendEvent,
20522059
)
20532060
})
20542061

0 commit comments

Comments
 (0)