Skip to content
Permalink
Browse files

Merge pull request #404 from input-output-hk/KtorZ/test-tweaks

Small test tweaks for enhanced speed & coverage
  • Loading branch information...
KtorZ committed Jun 12, 2019
2 parents 869803f + 8efaf5c commit 43818b1d2ad4408f63946ff2841c3f53f5dff00c
@@ -89,17 +89,23 @@ jobs:

- stage: checks 🔬
if: type = pull_request OR (branch IN (bors/staging, bors/trying))
name: "Tests: http-bridge"
name: "Tests: unit"
script:
- stack --no-terminal test --fast cardano-wallet-core cardano-wallet-launcher cardano-wallet-cli text-class bech32 cardano-wallet-http-bridge:unit cardano-wallet-jormungandr:unit

- stage: checks 🔬
if: type = pull_request OR (branch IN (bors/staging, bors/trying))
name: "Tests: integration (http-bridge)"
script:
- travis_retry curl -L -o hermes-testnet.tar.gz https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/lib/http-bridge/test/data/cardano-http-bridge/hermes-testnet.tar.gz
- tar xzf hermes-testnet.tar.gz -C $HOME
- stack --no-terminal test cardano-wallet-core cardano-wallet-launcher cardano-wallet-cli text-class bech32 cardano-wallet-http-bridge --fast
- stack --no-terminal test --fast cardano-wallet-http-bridge:integration

- stage: checks 🔬
if: type = pull_request OR (branch IN (bors/staging, bors/trying))
name: "Tests: jormungandr"
name: "Tests: integration (jormungandr)"
script:
- stack --no-terminal test cardano-wallet-jormungandr --fast
- stack --no-terminal test --fast cardano-wallet-jormungandr:integration

################################################################################
#
@@ -58,10 +58,11 @@ test-suite bech32-test
build-depends:
base
, bech32
, bytestring
, containers
, deepseq
, extra
, hspec
, bytestring
, QuickCheck
, text
, vector
@@ -1,5 +1,6 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
@@ -27,6 +28,8 @@ import Codec.Binary.Bech32.Internal
, humanReadablePartToText
, separatorChar
)
import Control.DeepSeq
( deepseq )
import Control.Monad
( forM_, replicateM )
import Data.Bits
@@ -36,7 +39,7 @@ import Data.ByteString
import Data.Char
( chr, isUpper, ord, toLower, toUpper )
import Data.Either
( fromRight, isLeft, isRight )
( fromRight, isRight )
import Data.Either.Extra
( eitherToMaybe )
import Data.Functor.Identity
@@ -96,7 +99,7 @@ spec = do
let checksumCorrupted =
(hrp `T.snoc` (chr (ord first `xor` 1)))
`T.append` rest'
(Bech32.decode checksumCorrupted) `shouldSatisfy` isLeft
(Bech32.decode checksumCorrupted) `shouldSatisfy` isLeft'
-- test that re-encoding the decoded checksum results in
-- the same checksum.
let checksumEncoded = Bech32.encode resultHRP resultData
@@ -171,7 +174,7 @@ spec = do
char1 /= char2 ==>
(T.length corruptedString === T.length originalString)
.&&.
(Bech32.decode corruptedString `shouldSatisfy` isLeft)
(Bech32.decode corruptedString `shouldSatisfy` isLeft')

it "Decoding fails when a character is omitted." $
property $ withMaxSuccess 10000 $ \s -> do
@@ -189,7 +192,7 @@ spec = do
return $ counterexample description $
(T.length corruptedString === T.length originalString - 1)
.&&.
(Bech32.decode corruptedString `shouldSatisfy` isLeft)
(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
@@ -224,7 +227,7 @@ spec = do
"inserted into the middle" $
(T.length corruptedString === T.length originalString + 1)
.&&.
(Bech32.decode corruptedString `shouldSatisfy` isLeft)
(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
@@ -256,7 +259,7 @@ spec = do
corruptedString /= originalString ==>
(T.length corruptedString === T.length originalString)
.&&.
(result `shouldSatisfy` isLeft)
(result `shouldSatisfy` isLeft')

it "Decoding fails for an upper-case string with a lower-case \
\character." $
@@ -625,3 +628,10 @@ isMixedCase :: Text -> Bool
isMixedCase t =
T.toUpper t /= t &&
T.toLower t /= t

-- | Strict `isLeft`, evaluate the left-side and return 'True' if 'Left'.
-- 'False' otherwise.
isLeft' :: Show e => Either e a -> Bool
isLeft' = \case
Left e -> show e `deepseq` True
Right _ -> False
@@ -62,7 +62,7 @@ import Test.QuickCheck
, elements
, expectFailure
, property
, suchThat
, vectorOf
, (.&&.)
, (===)
, (==>)
@@ -343,13 +343,8 @@ instance {-# OVERLAPS #-} Arbitrary (Passphrase "encryption") where

instance {-# OVERLAPS #-} Arbitrary (Passphrase "seed") where
arbitrary = do
n <- choose (5, 255)
bytes <-
T.encodeUtf8 . T.pack <$> replicateM n arbitraryPrintableChar
`suchThat`
(\bs ->
let bsLength = (BS.length . T.encodeUtf8 . T.pack) bs
in bsLength >= 16 && bsLength <= 255)
n <- choose (16, 64)
bytes <- BS.pack <$> vectorOf n arbitrary
return $ Passphrase $ BA.convert bytes

instance Arbitrary ChangeChain where

0 comments on commit 43818b1

Please sign in to comment.
You can’t perform that action at this time.