Skip to content

Commit

Permalink
Fix the Bech32 character mutation test.
Browse files Browse the repository at this point in the history
The test occasionally fails because it attempts to be extremely specific when
pattern matching the error produced by decoding a mutated string.

Unfortunately, changing just a single character in a valid Bech32 string can
cause the decoder to produce many different types of error, depending on
the location of the mutation, and the nature of the mutation.

We can prevent spurious failures by changing the test to be less specific:
we can expect merely that the string is rejected with some error.

(This already gets us most of what we want, namely that mutating a
character cause the resultant string to be rejected.)
  • Loading branch information
jonathanknowles committed May 28, 2019
1 parent 4a07faa commit 9db619a
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions lib/bech32/test/Codec/Binary/Bech32Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import Test.QuickCheck
, elements
, property
, (.&&.)
, (.||.)
, (===)
, (==>)
)
Expand Down Expand Up @@ -203,15 +202,7 @@ spec = do
corruptedString /= originalString ==>
(T.length corruptedString === T.length originalString)
.&&.
(result `shouldBe` Left
StringToDecodeMissingSeparatorChar)
.||.
(result `shouldBe` Left
(StringToDecodeContainsInvalidChars []))
.||.
(result `shouldBe` Left
(StringToDecodeContainsInvalidChars
[CharPosition index]))
(result `shouldSatisfy` isLeft)

it "Decoding fails for an upper-case string with a lower-case \
\character." $
Expand Down

0 comments on commit 9db619a

Please sign in to comment.