diff --git a/lib/bech32/test/Codec/Binary/Bech32Spec.hs b/lib/bech32/test/Codec/Binary/Bech32Spec.hs index 4aed1104fc2..4beac85110d 100644 --- a/lib/bech32/test/Codec/Binary/Bech32Spec.hs +++ b/lib/bech32/test/Codec/Binary/Bech32Spec.hs @@ -57,6 +57,7 @@ import Test.QuickCheck , counterexample , elements , property + , withMaxSuccess , (.&&.) , (.||.) , (===) @@ -125,7 +126,7 @@ spec = do describe "Decoding a corrupted string should fail" $ do it "Decoding fails when an adjacent pair of characters is swapped." $ - property $ \s -> do + property $ withMaxSuccess 10000 $ \s -> do let originalString = getValidBech32String s index <- choose (0, T.length originalString - 2) let prefix = T.take index originalString @@ -147,7 +148,7 @@ spec = do (Bech32.decode corruptedString `shouldSatisfy` isLeft) it "Decoding fails when a character is omitted." $ - property $ \s -> do + property $ withMaxSuccess 10000 $ \s -> do let originalString = getValidBech32String s index <- choose (0, T.length originalString - 1) let char = T.index originalString index @@ -163,9 +164,19 @@ spec = do (T.length corruptedString === T.length originalString - 1) .&&. (Bech32.decode corruptedString `shouldSatisfy` isLeft) + .||. + -- In the case where the tail of a valid Bech32 string is + -- composed of one or more consecutive 'q' characters + -- followed by a single 'p' character, omitting any or all + -- of the 'q' characters will still result in a valid + -- Bech32 string: + (T.length suffix > 0 + && T.last suffix == 'p' + && char == 'q' + && T.all (== 'q') (T.dropEnd 1 suffix)) it "Decoding fails when a character is inserted." $ - property $ \s c -> do + property $ withMaxSuccess 10000 $ \s c -> do let originalString = getValidBech32String s let char = getDataChar c index <- choose (0, T.length originalString - 1) @@ -181,6 +192,15 @@ spec = do (T.length corruptedString === T.length originalString + 1) .&&. (Bech32.decode corruptedString `shouldSatisfy` isLeft) + .||. + -- In the case where the last character of a valid Bech32 + -- string is the character 'p', inserting any number of + -- consecutive 'q' characters immediately before the 'p' + -- will still result in a valid Bech32 string. + (T.length suffix > 0 + && T.last suffix == 'p' + && char == 'q' + && T.all (== 'q') (T.dropEnd 1 suffix)) it "Decoding fails when a single character is mutated." $ property $ \s c -> do