From b58ef85513fa476055d25c6442056e49addc1e6b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 18 Sep 2017 19:42:12 +0200 Subject: [PATCH] lnwire: make test clause within TestChannelIDOutPointConversion stricter This commit modifies the main test loop within TestChannelIDOutPointConversion stricter. With this commit, we now ensure that the conversion function actually does _something_. This is the first in a series of commits to fix a recently discovered bug within the outpoint to channel ID conversion routines. --- lnwire/channel_id_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lnwire/channel_id_test.go b/lnwire/channel_id_test.go index 388a044c..b46a6c7f 100644 --- a/lnwire/channel_id_test.go +++ b/lnwire/channel_id_test.go @@ -11,6 +11,7 @@ func TestChannelIDOutPointConversion(t *testing.T) { // For a given OutPoint, we'll run through all the possible output // index values, mutating our test outpoint to match that output index. + var prevChanID ChannelID for i := uint32(0); i < MaxFundingTxOutputs; i++ { testChanPoint.Index = i @@ -24,6 +25,16 @@ func TestChannelIDOutPointConversion(t *testing.T) { t.Fatalf("channelID not recognized as seed channel "+ "point: cid=%v, op=%v", cid, testChanPoint) } + + // We also ensure that the channel ID itself have changed + // between iterations. This case is meant to catch an issue + // where the transformation function itself is a no-op. + if prevChanID == cid { + t.Fatalf("#%v: channelID not modified: old=%v, new=%v", + i, prevChanID, cid) + } + + prevChanID = cid } } @@ -36,6 +47,7 @@ func TestGenPossibleOutPoints(t *testing.T) { // We'll first convert out test outpoint into a ChannelID. testChanPoint := *outpoint1 + testChanPoint.Index = 24 chanID := NewChanIDFromOutPoint(&testChanPoint) // With the chan ID created, we'll generate all possible root outpoints