bolt7

Routing gossip protocol, per BOLT #7 (docs.ppad.tech/bolt7).
git clone git://git.ppad.tech/bolt7.git
Log | Files | Refs | README | LICENSE

commit bfb5c7c0bd6434bfd57613440f98c8ea68109590
parent 9dc08f2708ef257b265f3bdd7233bc7c8493cfd5
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 10 Oct 2026 13:27:24 +0400

test: hash input length tests

The hash and checksum functions return Nothing for input shorter
than a channel_update, or shorter than an announcement's declared
feature and address lengths.

Diffstat:
Mtest/Main.hs | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/test/Main.hs b/test/Main.hs @@ -687,6 +687,37 @@ hash_tests = testGroup "Hash Functions" [ } channelUpdateChecksum msg1 @?= channelUpdateChecksum msg2 ] + , testGroup "Input length" [ + testCase "channel_update needs 136 bytes" $ do + let wire = encodeChannelUpdate testChannelUpdate + channelUpdateHash (BS.take 135 wire) @?= Nothing + channelUpdateChecksum (BS.take 135 wire) @?= Nothing + channelUpdateChecksum "short" @?= Nothing + fmap BS.length (channelUpdateHash wire) @?= Just 32 + assertBool "checksum" (channelUpdateChecksum wire /= Nothing) + , testCase "channel_announcement needs its declared features" $ + case encodeChannelAnnouncement + (testChannelAnn (featureBits (BS.pack [1, 2]))) of + Left e -> assertFailure $ "encode failed: " ++ show e + Right wire -> do + fmap BS.length (channelAnnouncementHash wire) @?= Just 32 + channelAnnouncementHash (BS.take (BS.length wire - 1) wire) + @?= Nothing + -- claim one more feature byte than present + channelAnnouncementHash (setByte 257 3 wire) @?= Nothing + channelAnnouncementHash (BS.take 257 wire) @?= Nothing + , testCase "node_announcement needs its declared addresses" $ do + v4 <- addrV4 + case encodeNodeAnnouncement (testNodeAnn [v4]) of + Left e -> assertFailure $ "encode failed: " ++ show e + Right wire -> do + fmap BS.length (nodeAnnouncementHash wire) @?= Just 32 + nodeAnnouncementHash (BS.take (BS.length wire - 1) wire) + @?= Nothing + -- claim one more address byte than present (addrlen 8) + nodeAnnouncementHash (setByte 139 8 wire) @?= Nothing + nodeAnnouncementHash (BS.take 139 wire) @?= Nothing + ] ] -- Validation Tests -----------------------------------------------------------