bech32

Pure Haskell bech32, bech32m encodings (docs.ppad.tech/bech32).
git clone git://git.ppad.tech/bech32.git
Log | Files | Refs | README | LICENSE

commit f7805a77a4d070c72379bbb60d8bffb432627f02
parent 379efc378700c28ba3c625a8c502dd886330033c
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri,  3 Jan 2025 14:05:12 -0330

test: failing base32 test

Diffstat:
Mtest/Main.hs | 24++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/test/Main.hs b/test/Main.hs @@ -2,10 +2,14 @@ module Main where import qualified Data.ByteString as BS import qualified Data.ByteString.Bech32 as Bech32 +import qualified Data.ByteString.Base32 as B32 import Test.Tasty import qualified Test.Tasty.QuickCheck as Q import qualified Reference.Bech32 as R +newtype BS = BS BS.ByteString + deriving (Eq, Show) + data Input = Input BS.ByteString BS.ByteString deriving (Eq, Show) @@ -15,6 +19,11 @@ instance Q.Arbitrary Input where b <- bytes (83 - BS.length h) pure (Input h b) +instance Q.Arbitrary BS where + arbitrary = do + b <- bytes 1024 + pure (BS b) + hrp :: Q.Gen BS.ByteString hrp = do l <- Q.chooseInt (1, 83) @@ -33,6 +42,17 @@ matches (Input h b) = our = Bech32.encode h b in ref == our +decode_inverts_encode :: BS -> Bool +decode_inverts_encode (BS bs) = case B32.decode (B32.encode bs) of + Nothing -> False + Just b -> b == bs + main :: IO () -main = defaultMain $ - Q.testProperty "encoding matches reference" matches +main = defaultMain $ testGroup "ppad-bech32" [ + testGroup "base32" [ + Q.testProperty "decode inverts encode" decode_inverts_encode + ] + , testGroup "bech32" [ + Q.testProperty "encoding matches reference" matches + ] + ]