From 42a263b29facc879cac31cb85ed11415b197cc84 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 28 Aug 2017 21:16:03 -0500 Subject: [PATCH] wire: Correct fuzz test for MsgCommitSig. This corrects the fuzz test in TestLightningWireProtocol for MsgCommitSig to avoid creating an empty slice since the decoded message only creates a slice when there are greater than zero signatures and an empty slice is not considered equal to a nil slice under reflection. This can be tested by running the TestLightningWireProtocol 1000 times in a loop with and without this change. --- lnwire/lnwire_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 1eb74509..b937a9b6 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -316,8 +316,13 @@ func TestLightningWireProtocol(t *testing.T) { } req.CommitSig = testSig + // Only create the slice if there will be any signatures + // in it to prevent false positive test failures due to + // an empty slice versus a nil slice. numSigs := uint16(r.Int31n(1020)) - req.HtlcSigs = make([]*btcec.Signature, numSigs) + if numSigs > 0 { + req.HtlcSigs = make([]*btcec.Signature, numSigs) + } for i := 0; i < int(numSigs); i++ { req.HtlcSigs[i] = testSig }