From 3131bc4d6487c5850f7b3fb7efa31c8d568de64b Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 13 Sep 2019 12:29:42 +0200 Subject: [PATCH] cnct/test: test outgoing dust htlc resolution --- contractcourt/channel_arbitrator_test.go | 40 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 65bfde65..c0f78e62 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -496,6 +496,8 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) { return nil } + chanArb.cfg.PreimageDB = newMockWitnessBeacon() + chanArb.cfg.Registry = &mockRegistry{} if err := chanArb.Start(); err != nil { t.Fatalf("unable to start ChannelArbitrator: %v", err) @@ -512,16 +514,26 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) { chanArb.UpdateContractSignals(signals) // Add HTLC to channel arbitrator. - htlcIndex := uint64(99) htlc := channeldb.HTLC{ Incoming: false, Amt: 10000, - HtlcIndex: htlcIndex, + HtlcIndex: 99, + } + + outgoingDustHtlc := channeldb.HTLC{ + Incoming: false, + Amt: 100, + HtlcIndex: 100, + OutputIndex: -1, + } + + htlcSet := []channeldb.HTLC{ + htlc, outgoingDustHtlc, } htlcUpdates <- &ContractUpdate{ HtlcKey: LocalHtlcSet, - Htlcs: []channeldb.HTLC{htlc}, + Htlcs: htlcSet, } errChan := make(chan error, 1) @@ -607,7 +619,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) { CommitSet: CommitSet{ ConfCommitKey: &LocalHtlcSet, HtlcSets: map[HtlcSetKey][]channeldb.HTLC{ - LocalHtlcSet: {htlc}, + LocalHtlcSet: htlcSet, }, }, } @@ -617,6 +629,22 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) { StateWaitingFullResolution, ) + // We expect an immediate resolution message for the outgoing dust htlc. + // It is not resolvable on-chain. + select { + case msgs := <-resolutions: + if len(msgs) != 1 { + t.Fatalf("expected 1 message, instead got %v", len(msgs)) + } + + if msgs[0].HtlcIndex != outgoingDustHtlc.HtlcIndex { + t.Fatalf("wrong htlc index: expected %v, got %v", + outgoingDustHtlc.HtlcIndex, msgs[0].HtlcIndex) + } + case <-time.After(5 * time.Second): + t.Fatalf("resolution msgs not sent") + } + // htlcOutgoingContestResolver is now active and waiting for the HTLC to // expire. It should not yet have passed it on for incubation. select { @@ -649,9 +677,9 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) { t.Fatalf("expected 1 message, instead got %v", len(msgs)) } - if msgs[0].HtlcIndex != htlcIndex { + if msgs[0].HtlcIndex != htlc.HtlcIndex { t.Fatalf("wrong htlc index: expected %v, got %v", - htlcIndex, msgs[0].HtlcIndex) + htlc.HtlcIndex, msgs[0].HtlcIndex) } case <-time.After(5 * time.Second): t.Fatalf("resolution msgs not sent")