From a252cb4528cc53c1aacbaa9e2e13ed884b1d1c86 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 4 Sep 2023 14:16:31 +0800 Subject: [PATCH] contractcourt: fix test flake in `TestTaprootBriefcase` When the numTweaks is zero, we should return a nil instead of initializing an empty map as we'd get the following error, ``` Diff: --- Expected +++ Actual @@ -11007,4 +11007,3 @@ }, - BreachedHtlcTweaks: (contractcourt.htlcTapTweaks) { - }, + BreachedHtlcTweaks: (contractcourt.htlcTapTweaks) , ``` --- contractcourt/taproot_briefcase_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contractcourt/taproot_briefcase_test.go b/contractcourt/taproot_briefcase_test.go index 40c7b620f..38471ed74 100644 --- a/contractcourt/taproot_briefcase_test.go +++ b/contractcourt/taproot_briefcase_test.go @@ -29,8 +29,14 @@ func randResolverCtrlBlocks(t *testing.T) resolverCtrlBlocks { func randHtlcTweaks(t *testing.T) htlcTapTweaks { numTweaks := rand.Int() % 256 - tweaks := make(htlcTapTweaks, numTweaks) + // If the numTweaks happens to be zero, we return a nil to avoid + // initializing the map. + if numTweaks == 0 { + return nil + } + + tweaks := make(htlcTapTweaks, numTweaks) for i := 0; i < numTweaks; i++ { var id resolverID _, err := rand.Read(id[:])