diff --git a/client/test/Test/Pos/Client/Txp/UtilSpec.hs b/client/test/Test/Pos/Client/Txp/UtilSpec.hs index 47a20ec019e..b52ed6e7731 100644 --- a/client/test/Test/Pos/Client/Txp/UtilSpec.hs +++ b/client/test/Test/Pos/Client/Txp/UtilSpec.hs @@ -15,7 +15,7 @@ import qualified Data.Map as M import qualified Data.Set as S import Formatting (build, hex, left, sformat, shown, (%), (%.)) import Test.Hspec (Spec, describe, runIO) -import Test.Hspec.QuickCheck (prop) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) import Test.QuickCheck (Discard (..), Gen, Testable, arbitrary, choose, generate) import Test.QuickCheck.Monadic (forAllM, stop) @@ -38,6 +38,7 @@ import Pos.Util.Util (leftToPanic) import Test.Pos.Client.Txp.Mode (HasTxpConfigurations, TxpTestMode, TxpTestProperty, withBVData) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Arbitrary (nonrepeating) import Test.Pos.Util.QuickCheck.Property (stopProperty) @@ -45,16 +46,24 @@ import Test.Pos.Util.QuickCheck.Property (stopProperty) -- Tests ---------------------------------------------------------------------------- + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ diff --git a/core/test/Test/Pos/Core/AddressSpec.hs b/core/test/Test/Pos/Core/AddressSpec.hs index 85c7be25800..6c56aade05a 100644 --- a/core/test/Test/Pos/Core/AddressSpec.hs +++ b/core/test/Test/Pos/Core/AddressSpec.hs @@ -27,6 +27,14 @@ import Pos.Crypto (EncryptedSecretKey, PassPhrase, ProtocolMagic (..), import Pos.Crypto.HD (HDAddressPayload (..)) import Test.Pos.Core.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) + + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 spec :: Spec spec = do @@ -34,10 +42,11 @@ spec = do runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm -- An attempt to avoid rightward creep specBody :: ProtocolMagic -> Spec diff --git a/core/test/Test/Pos/Core/CborSpec.hs b/core/test/Test/Pos/Core/CborSpec.hs index dc7197f7e27..ffdf1bd450b 100644 --- a/core/test/Test/Pos/Core/CborSpec.hs +++ b/core/test/Test/Pos/Core/CborSpec.hs @@ -13,6 +13,7 @@ module Test.Pos.Core.CborSpec import Universum import Test.Hspec (Spec, describe, runIO) +import Test.Hspec.QuickCheck (modifyMaxSuccess) import Test.QuickCheck (Arbitrary (..), generate) import Test.QuickCheck.Arbitrary.Generic (genericArbitrary, genericShrink) @@ -29,7 +30,7 @@ import Pos.Merkle (MerkleTree) import Test.Pos.Binary.Helpers (binaryTest) import Test.Pos.Core.Arbitrary () import Test.Pos.Core.Chrono () -import Test.Pos.Crypto.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) data MyScript = MyScript @@ -77,6 +78,11 @@ instance Bi (Attributes X2) where ---------------------------------------- +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 spec :: Spec spec = do @@ -84,43 +90,44 @@ spec = do runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - withGenesisSpec 0 (defaultCoreConfiguration pm) $ \_ -> - describe "Cbor Bi instances" $ do - describe "Core.Address" $ do - binaryTest @Address - binaryTest @Address' - binaryTest @AddrType - binaryTest @AddrStakeDistribution - binaryTest @AddrSpendingData - describe "Core.Types" $ do - binaryTest @Timestamp - binaryTest @TimeDiff - binaryTest @EpochIndex - binaryTest @Coin - binaryTest @CoinPortion - binaryTest @LocalSlotIndex - binaryTest @SlotId - binaryTest @EpochOrSlot - binaryTest @SharedSeed - binaryTest @ChainDifficulty - binaryTest @SoftforkRule - binaryTest @BlockVersionData - binaryTest @(Attributes ()) - binaryTest @(Attributes AddrAttributes) - describe "Core.Fee" $ do - binaryTest @Coeff - binaryTest @TxSizeLinear - binaryTest @TxFeePolicy - describe "Core.Script" $ do - binaryTest @Script - describe "Core.Vss" $ do - binaryTest @VssCertificate - describe "Core.Version" $ do - binaryTest @ApplicationName - binaryTest @SoftwareVersion - binaryTest @BlockVersion - describe "Merkle" $ do - binaryTest @(MerkleTree Int32) +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + withGenesisSpec 0 (defaultCoreConfiguration pm) $ \_ -> + describe "Cbor Bi instances" $ do + describe "Core.Address" $ do + binaryTest @Address + binaryTest @Address' + binaryTest @AddrType + binaryTest @AddrStakeDistribution + binaryTest @AddrSpendingData + describe "Core.Types" $ do + binaryTest @Timestamp + binaryTest @TimeDiff + binaryTest @EpochIndex + binaryTest @Coin + binaryTest @CoinPortion + binaryTest @LocalSlotIndex + binaryTest @SlotId + binaryTest @EpochOrSlot + binaryTest @SharedSeed + binaryTest @ChainDifficulty + binaryTest @SoftforkRule + binaryTest @BlockVersionData + binaryTest @(Attributes ()) + binaryTest @(Attributes AddrAttributes) + describe "Core.Fee" $ do + binaryTest @Coeff + binaryTest @TxSizeLinear + binaryTest @TxFeePolicy + describe "Core.Script" $ do + binaryTest @Script + describe "Core.Vss" $ do + binaryTest @VssCertificate + describe "Core.Version" $ do + binaryTest @ApplicationName + binaryTest @SoftwareVersion + binaryTest @BlockVersion + describe "Merkle" $ do + binaryTest @(MerkleTree Int32) diff --git a/core/test/Test/Pos/Core/SlottingSpec.hs b/core/test/Test/Pos/Core/SlottingSpec.hs index 9e5cd82f8ef..137bdf180d7 100644 --- a/core/test/Test/Pos/Core/SlottingSpec.hs +++ b/core/test/Test/Pos/Core/SlottingSpec.hs @@ -7,27 +7,35 @@ module Test.Pos.Core.SlottingSpec import Universum import Test.Hspec (Expectation, Spec, anyErrorCall, describe, runIO) -import Test.Hspec.QuickCheck (prop) -import Test.QuickCheck (NonNegative (..), Positive (..), Property, arbitrary, generate, - (===), (==>)) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) +import Test.QuickCheck (NonNegative (..), Positive (..), Property, generate, (===), (==>)) import Pos.Core (EpochOrSlot, HasConfiguration, SlotId (..), defaultCoreConfiguration, flattenSlotId, unflattenSlotId, withGenesisSpec) import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) import Test.Pos.Core.Arbitrary (EoSToIntOverflow (..), UnreasonableEoS (..)) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (shouldThrowException, (.=.)) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withGenesisSpec 0 (defaultCoreConfiguration pm) $ \_ -> describe "Slotting" $ do diff --git a/crypto/test/Test/Pos/Crypto/Arbitrary.hs b/crypto/test/Test/Pos/Crypto/Arbitrary.hs index 79a9852964b..6bf61ed69fc 100644 --- a/crypto/test/Test/Pos/Crypto/Arbitrary.hs +++ b/crypto/test/Test/Pos/Crypto/Arbitrary.hs @@ -9,6 +9,7 @@ module Test.Pos.Crypto.Arbitrary , genSignature , genSignatureEncoded , genRedeemSignature + , genProtocolMagicUniformWithRNM ) where import Universum hiding (keys) @@ -16,7 +17,7 @@ import Universum hiding (keys) import Control.Monad (zipWithM) import qualified Data.ByteArray as ByteArray import Data.List.NonEmpty (fromList) -import Test.QuickCheck (Arbitrary (..), Gen, elements, oneof, vector) +import Test.QuickCheck (Arbitrary (..), Gen, choose, elements, oneof, vector) import Test.QuickCheck.Arbitrary.Generic (genericArbitrary, genericShrink) import Pos.Binary.Class (AsBinary (..), AsBinaryClass (..), Bi, Raw) @@ -54,6 +55,12 @@ instance Arbitrary ProtocolMagicId where instance Arbitrary RequiresNetworkMagic where arbitrary = elements [NMMustBeNothing, NMMustBeJust] +genProtocolMagicUniformWithRNM :: RequiresNetworkMagic -> Gen ProtocolMagic +genProtocolMagicUniformWithRNM rnm = + (\ident -> ProtocolMagic (ProtocolMagicId ident) rnm) + <$> + choose (minBound, maxBound) + {- A note on 'Arbitrary' instances ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/explorer/cardano-sl-explorer.cabal b/explorer/cardano-sl-explorer.cabal index e2eca8a5c20..f5740ae6c9d 100644 --- a/explorer/cardano-sl-explorer.cabal +++ b/explorer/cardano-sl-explorer.cabal @@ -356,6 +356,7 @@ test-suite cardano-explorer-test , cardano-sl-block-test , cardano-sl-core , cardano-sl-crypto + , cardano-sl-crypto-test , cardano-sl-explorer , cardano-sl-txp , cardano-sl-util diff --git a/explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs b/explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs index 68cd85a263a..b2c97524517 100644 --- a/explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs +++ b/explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs @@ -16,12 +16,12 @@ import qualified Data.Set as S import Network.EngineIO (SocketId) import Test.Hspec (Spec, anyException, describe, it, runIO, shouldBe, shouldThrow) -import Test.Hspec.QuickCheck (modifyMaxSize, prop) +import Test.Hspec.QuickCheck (modifyMaxSize, modifyMaxSuccess, prop) import Test.QuickCheck (Property, arbitrary, forAll, generate) import Test.QuickCheck.Monadic (assert, monadicIO, run) import Pos.Core.NetworkMagic (NetworkMagic, makeNetworkMagic) -import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..), SecretKey) +import Pos.Crypto (RequiresNetworkMagic (..), SecretKey) import Pos.Explorer.ExplorerMode (runSubTestMode) import Pos.Explorer.Socket.Holder (ConnectionsState, ExplorerSocket (..), csAddressSubscribers, csBlocksPageSubscribers, @@ -36,6 +36,7 @@ import Pos.Explorer.Socket.Methods (addrSubParam, addressSetByTxs, blo import Pos.Explorer.TestUtil (secretKeyToAddress) import Pos.Explorer.Web.ClientTypes (CAddress (..), toCAddress) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Explorer.MockFactory (mkTxOut) @@ -45,16 +46,23 @@ import Test.Pos.Explorer.MockFactory (mkTxOut) -- stack test cardano-sl-explorer --fast --test-arguments "-m Test.Pos.Explorer.Socket" +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody (makeNetworkMagic pm) +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody (makeNetworkMagic pm) specBody :: NetworkMagic -> Spec specBody nm = diff --git a/explorer/test/Test/Pos/Explorer/Web/ServerSpec.hs b/explorer/test/Test/Pos/Explorer/Web/ServerSpec.hs index 576e3673cae..02e0bd399ff 100644 --- a/explorer/test/Test/Pos/Explorer/Web/ServerSpec.hs +++ b/explorer/test/Test/Pos/Explorer/Web/ServerSpec.hs @@ -31,6 +31,7 @@ import Pos.Util.Mockable () import Test.Pos.Block.Arbitrary () import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) ---------------------------------------------------------------- @@ -40,16 +41,24 @@ import Test.Pos.Configuration (withProvidedMagicConfig) {-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-} -- stack test cardano-sl-explorer --fast --test-arguments "-m Pos.Explorer.Web.Server" + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ do diff --git a/generator/test/Test/Pos/Binary/CommunicationSpec.hs b/generator/test/Test/Pos/Binary/CommunicationSpec.hs index 6dae0864943..96fa7b2ee62 100644 --- a/generator/test/Test/Pos/Binary/CommunicationSpec.hs +++ b/generator/test/Test/Pos/Binary/CommunicationSpec.hs @@ -7,8 +7,8 @@ import Universum import qualified Data.ByteString.Lazy as BSL import Data.Default (def) import Test.Hspec (Spec, describe, runIO) -import Test.Hspec.QuickCheck (prop) -import Test.QuickCheck (arbitrary, generate) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) +import Test.QuickCheck (generate) import Test.QuickCheck.Monadic (assert) import Pos.Binary.Class (decodeFull, serialize') @@ -21,6 +21,7 @@ import Pos.Util.CompileInfo (withCompileInfo) import Test.Pos.Block.Logic.Mode (blockPropertyTestable) import Test.Pos.Block.Logic.Util (EnableTxPayload (..), InplaceDB (..), bpGenBlock) import Test.Pos.Configuration (HasStaticConfigurations, withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) -- | -- The binary encoding of `MsgSerializedBlock` using `serializeMsgSerializedBlock` @@ -63,16 +64,24 @@ deserializeSerilizedMsgSerializedBlockSpec pm = do desc = "deserialization of a serialized MsgSerializedBlock message should give back corresponding MsgBlock" descNoBlock = "deserialization of a serialized MsgNoSerializedBlock message should give back corresponding MsgNoBlock" + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ withCompileInfo def $ diff --git a/generator/test/Test/Pos/Block/Logic/CreationSpec.hs b/generator/test/Test/Pos/Block/Logic/CreationSpec.hs index 7e2611e83f5..f6ae823c6c8 100644 --- a/generator/test/Test/Pos/Block/Logic/CreationSpec.hs +++ b/generator/test/Test/Pos/Block/Logic/CreationSpec.hs @@ -31,20 +31,28 @@ import Pos.Update.Configuration (HasUpdateConfiguration) import Test.Pos.Block.Arbitrary () import Test.Pos.Configuration (withDefUpdateConfiguration, withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Delegation.Arbitrary (genDlgPayload) import Test.Pos.Txp.Arbitrary (GoodTx, goodTxToTxAux) import Test.Pos.Util.QuickCheck (SmallGenerator (..), makeSmall) +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ withDefUpdateConfiguration $ diff --git a/generator/test/Test/Pos/Block/Logic/VarSpec.hs b/generator/test/Test/Pos/Block/Logic/VarSpec.hs index e22930f1e12..f864ace4ef8 100644 --- a/generator/test/Test/Pos/Block/Logic/VarSpec.hs +++ b/generator/test/Test/Pos/Block/Logic/VarSpec.hs @@ -17,7 +17,7 @@ import qualified Data.Ratio as Ratio import Data.Semigroup ((<>)) import Test.Hspec (Spec, describe, runIO) import Test.Hspec.QuickCheck (modifyMaxSuccess) -import Test.QuickCheck (arbitrary, generate) +import Test.QuickCheck (generate) import Test.QuickCheck.Gen (Gen (MkGen)) import Test.QuickCheck.Monadic (assert, pick, pre) import Test.QuickCheck.Random (QCGen) @@ -47,21 +47,30 @@ import Test.Pos.Block.Logic.Util (EnableTxPayload (..), InplaceDB (..) satisfySlotCheck) import Test.Pos.Block.Property (blockPropertySpec) import Test.Pos.Configuration (HasStaticConfigurations, withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (splitIntoChunks, stopProperty) -- stack test cardano-sl --fast --test-arguments "-m Test.Pos.Block.Logic.Var" -spec :: Spec -- Unfortunatelly, blocks generation is quite slow nowdays. -- See CSL-1382. + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + +spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ diff --git a/generator/test/Test/Pos/Generator/Block/LrcSpec.hs b/generator/test/Test/Pos/Generator/Block/LrcSpec.hs index e28592f528b..5d293a93afc 100644 --- a/generator/test/Test/Pos/Generator/Block/LrcSpec.hs +++ b/generator/test/Test/Pos/Generator/Block/LrcSpec.hs @@ -41,19 +41,27 @@ import Test.Pos.Block.Logic.Util (EnableTxPayload (..), InplaceDB (..) bpGenBlocks) import Test.Pos.Block.Property (blockPropertySpec) import Test.Pos.Configuration (defaultTestBlockVersionData, withStaticConfigurations) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck (maybeStopProperty, stopProperty) +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withStaticConfigurations $ \_ -> diff --git a/lib/test/Test/Pos/Block/Identity/SafeCopySpec.hs b/lib/test/Test/Pos/Block/Identity/SafeCopySpec.hs index 5de94683f4d..1e65f120277 100644 --- a/lib/test/Test/Pos/Block/Identity/SafeCopySpec.hs +++ b/lib/test/Test/Pos/Block/Identity/SafeCopySpec.hs @@ -5,7 +5,8 @@ module Test.Pos.Block.Identity.SafeCopySpec ) where import Test.Hspec (Spec, describe, runIO) -import Test.QuickCheck (arbitrary, generate) +import Test.Hspec.QuickCheck (modifyMaxSuccess) +import Test.QuickCheck (generate) import Universum import qualified Pos.Core.Block as BT @@ -15,6 +16,14 @@ import Pos.SafeCopy () import Test.Pos.Binary.Helpers (safeCopyTest) import Test.Pos.Block.Arbitrary () import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) + + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 spec :: Spec spec = do @@ -22,10 +31,11 @@ spec = do runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Block types" $ diff --git a/lib/test/Test/Pos/Cbor/CborSpec.hs b/lib/test/Test/Pos/Cbor/CborSpec.hs index 808145ec459..7e39729550d 100644 --- a/lib/test/Test/Pos/Cbor/CborSpec.hs +++ b/lib/test/Test/Pos/Cbor/CborSpec.hs @@ -58,7 +58,7 @@ import Test.Pos.Block.Arbitrary () import Test.Pos.Block.Arbitrary.Message () import Test.Pos.Configuration (withProvidedMagicConfig) import Test.Pos.Core.Arbitrary () -import Test.Pos.Crypto.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Delegation.Arbitrary () import Test.Pos.Txp.Arbitrary.Network () import Test.Pos.Util.QuickCheck (SmallGenerator) @@ -69,16 +69,24 @@ type UpId' = Tagged (U.UpdateProposal, [U.UpdateVote])U.UpId ---------------------------------------- + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ do diff --git a/lib/test/Test/Pos/Diffusion/BlockSpec.hs b/lib/test/Test/Pos/Diffusion/BlockSpec.hs index a73e7739518..c14b4ad76f8 100644 --- a/lib/test/Test/Pos/Diffusion/BlockSpec.hs +++ b/lib/test/Test/Pos/Diffusion/BlockSpec.hs @@ -15,7 +15,8 @@ import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString.Lazy as LBS import Data.Semigroup ((<>)) import Test.Hspec (Spec, describe, it, runIO, shouldBe) -import Test.QuickCheck (arbitrary, generate) +import Test.Hspec.QuickCheck (modifyMaxSuccess) +import Test.QuickCheck (generate) import Data.Bits import Data.List.NonEmpty (NonEmpty ((:|))) @@ -48,6 +49,7 @@ import Pos.Logic.Types as Logic (Logic (..)) import Pos.Core.Chrono (NewestFirst (..), OldestFirst (..)) import Pos.Util.Trace (wlogTrace) import Test.Pos.Block.Arbitrary.Generate (generateMainBlock) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) -- HLint warning disabled since I ran into https://ghc.haskell.org/trac/ghc/ticket/13106 -- when trying to resolve it. @@ -272,31 +274,42 @@ batchSimple pm blocks = do liftIO . blockDownloadBatch serverAddress (someHash, checkPoints) return True +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - describe "Blockdownload" $ do - it "Stream 4 blocks" $ do - r <- streamSimple pm 2048 4 - r `shouldBe` True - it "Stream 128 blocks" $ do - r <- streamSimple pm 2048 128 - r `shouldBe` True - it "Stream 4096 blocks" $ do - r <- streamSimple pm 128 4096 - r `shouldBe` True - it "Streaming dislabed by client" $ do - r <- streamSimple pm 0 4 - r `shouldBe` False - it "Batch, single block" $ do - r <- batchSimple pm 1 - r `shouldBe` True - it "Batch of blocks" $ do - r <- batchSimple pm 2200 - r `shouldBe` True +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm + +specBody :: ProtocolMagic -> Spec +specBody pm = + describe "Blockdownload" $ do + it "Stream 4 blocks" $ do + r <- streamSimple pm 2048 4 + r `shouldBe` True + it "Stream 128 blocks" $ do + r <- streamSimple pm 2048 128 + r `shouldBe` True + it "Stream 4096 blocks" $ do + r <- streamSimple pm 128 4096 + r `shouldBe` True + it "Streaming dislabed by client" $ do + r <- streamSimple pm 0 4 + r `shouldBe` False + it "Batch, single block" $ do + r <- batchSimple pm 1 + r `shouldBe` True + it "Batch of blocks" $ do + r <- batchSimple pm 2200 + r `shouldBe` True diff --git a/lib/test/Test/Pos/Genesis/CanonicalSpec.hs b/lib/test/Test/Pos/Genesis/CanonicalSpec.hs index ff5e1c51f1d..4aa9cc423b1 100644 --- a/lib/test/Test/Pos/Genesis/CanonicalSpec.hs +++ b/lib/test/Test/Pos/Genesis/CanonicalSpec.hs @@ -8,7 +8,7 @@ import Universum import Test.Hspec (Spec, describe, runIO) import Test.Hspec.QuickCheck (modifyMaxSuccess) -import Test.QuickCheck (arbitrary, generate) +import Test.QuickCheck (generate) import Pos.Core.Genesis (GenesisAvvmBalances, GenesisData, GenesisDelegation, GenesisProtocolConstants, GenesisWStakeholders) @@ -16,18 +16,27 @@ import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) import Test.Pos.Configuration (withProvidedMagicConfig) import Test.Pos.Core.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Helpers (canonicalJsonTest) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Genesis" $ modifyMaxSuccess (const 10) $ do diff --git a/lib/test/Test/Pos/Ssc/ComputeSharesSpec.hs b/lib/test/Test/Pos/Ssc/ComputeSharesSpec.hs index 3ab3afa6995..25935b85bea 100644 --- a/lib/test/Test/Pos/Ssc/ComputeSharesSpec.hs +++ b/lib/test/Test/Pos/Ssc/ComputeSharesSpec.hs @@ -12,7 +12,7 @@ import qualified Data.HashMap.Strict as HM import Data.Reflection (Reifies (..)) import Test.Hspec (Expectation, Spec, describe, runIO, shouldBe) import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) -import Test.QuickCheck (Property, arbitrary, generate, (.&&.), (===)) +import Test.QuickCheck (Property, generate, (.&&.), (===)) import Pos.Core (Coin, CoinPortion, StakeholderId, mkCoin, unsafeAddressHash, unsafeCoinPortionFromDouble, unsafeGetCoin, unsafeSubCoin) @@ -24,20 +24,29 @@ import Pos.Ssc (SscVerifyError, computeSharesDistrPure, isDistrInaccur sharesDistrMaxSumDistr) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Lrc.Arbitrary (GenesisMpcThd, InvalidRichmenStakes (..), ValidRichmenStakes (..)) import Test.Pos.Util.QuickCheck.Property (qcIsLeft) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "computeSharesDistr" $ do diff --git a/lib/test/Test/Pos/Ssc/Toss/BaseSpec.hs b/lib/test/Test/Pos/Ssc/Toss/BaseSpec.hs index b7b4f85fc56..a4ec3d27b08 100644 --- a/lib/test/Test/Pos/Ssc/Toss/BaseSpec.hs +++ b/lib/test/Test/Pos/Ssc/Toss/BaseSpec.hs @@ -13,7 +13,7 @@ import qualified Data.HashSet as HS import Data.List.Extra (nubOrdOn) import System.Random (mkStdGen, randomR) import Test.Hspec (Spec, describe, runIO) -import Test.Hspec.QuickCheck (prop) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) import Test.QuickCheck (Arbitrary (..), Gen, NonEmptyList (..), Property, arbitrary, elements, generate, listOf, property, sublistOf, suchThat, vector, (.&&.), (===), (==>)) @@ -41,18 +41,27 @@ import Test.Pos.Lrc.Arbitrary (GenesisMpcThd, ValidRichmenStakes (..)) import Test.Pos.Util.QuickCheck.Property (qcElem, qcFail, qcIsRight) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Crypto.Dummy (dummyProtocolMagic) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Ssc.Base" $ do diff --git a/lib/test/Test/Pos/Ssc/Toss/PureSpec.hs b/lib/test/Test/Pos/Ssc/Toss/PureSpec.hs index aede0c866d1..57f38ac9b5c 100644 --- a/lib/test/Test/Pos/Ssc/Toss/PureSpec.hs +++ b/lib/test/Test/Pos/Ssc/Toss/PureSpec.hs @@ -23,7 +23,14 @@ import qualified Pos.Ssc.Toss.Pure as Toss import qualified Pos.Ssc.Types as Toss import Test.Pos.Configuration (withProvidedMagicConfig) -import Test.Pos.Core.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) + + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 spec :: Spec spec = do @@ -31,10 +38,11 @@ spec = do runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ do diff --git a/lib/test/Test/Pos/Ssc/VssCertDataSpec.hs b/lib/test/Test/Pos/Ssc/VssCertDataSpec.hs index f33753882b1..7d9f4b46de1 100644 --- a/lib/test/Test/Pos/Ssc/VssCertDataSpec.hs +++ b/lib/test/Test/Pos/Ssc/VssCertDataSpec.hs @@ -12,7 +12,7 @@ import Data.List.Extra (nubOrdOn) import qualified Data.Set as S import Data.Tuple (swap) import Test.Hspec (Spec, describe, runIO) -import Test.Hspec.QuickCheck (prop) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) import Test.QuickCheck (Arbitrary (..), Gen, Property, arbitrary, choose, conjoin, counterexample, generate, suchThat, vectorOf, (.&&.), (==>)) @@ -29,19 +29,28 @@ import Pos.Ssc (SscGlobalState (..), VssCertData (..), delete, empty, import Test.Pos.Configuration (withProvidedMagicConfig) import Test.Pos.Core.Arbitrary () +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Crypto.Dummy (dummyProtocolMagic) import Test.Pos.Util.QuickCheck.Property (qcIsJust) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Ssc.VssCertData" $ do diff --git a/lib/test/Test/Pos/Types/BlockSpec.hs b/lib/test/Test/Pos/Types/BlockSpec.hs index 683951bbbab..69c116d1c56 100644 --- a/lib/test/Test/Pos/Types/BlockSpec.hs +++ b/lib/test/Test/Pos/Types/BlockSpec.hs @@ -11,7 +11,7 @@ import Universum import Serokell.Util (isVerSuccess) import Test.Hspec (Spec, describe, it, runIO) import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) -import Test.QuickCheck (Property, arbitrary, generate, (===), (==>)) +import Test.QuickCheck (Property, generate, (===), (==>)) import Pos.Binary (Bi) import qualified Pos.Block.Logic.Integrity as T @@ -25,19 +25,27 @@ import Pos.Data.Attributes (mkAttributes) import Test.Pos.Block.Arbitrary as T import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Crypto.Dummy (dummyProtocolMagic, dummyProtocolMagicId) --- This tests are quite slow, hence max success is at most 20. + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ diff --git a/lib/test/Test/Pos/Types/Identity/SafeCopySpec.hs b/lib/test/Test/Pos/Types/Identity/SafeCopySpec.hs index f64fabd124e..f067807718a 100644 --- a/lib/test/Test/Pos/Types/Identity/SafeCopySpec.hs +++ b/lib/test/Test/Pos/Types/Identity/SafeCopySpec.hs @@ -7,7 +7,8 @@ module Test.Pos.Types.Identity.SafeCopySpec import Universum import Test.Hspec (Spec, describe, runIO) -import Test.QuickCheck (arbitrary, generate) +import Test.Hspec.QuickCheck (modifyMaxSuccess) +import Test.QuickCheck (generate) import qualified Pos.Core as Core import qualified Pos.Core.Txp as Txp @@ -16,19 +17,28 @@ import Pos.SafeCopy () import Test.Pos.Binary.Helpers (safeCopyTest) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Txp.Arbitrary () import Test.Pos.Txp.Arbitrary.Network () + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Types" $ do diff --git a/lib/test/Test/Pos/Update/PollSpec.hs b/lib/test/Test/Pos/Update/PollSpec.hs index 1e10594b8de..b0be8016953 100644 --- a/lib/test/Test/Pos/Update/PollSpec.hs +++ b/lib/test/Test/Pos/Update/PollSpec.hs @@ -26,18 +26,27 @@ import qualified Pos.Util.Modifier as MM import Test.Pos.Binary.Helpers () import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (formsMonoid) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ describe "Poll" $ do diff --git a/pkgs/default.nix b/pkgs/default.nix index 6202b727ba7..6b0541c61be 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -16411,6 +16411,7 @@ cardano-sl-block cardano-sl-block-test cardano-sl-core cardano-sl-crypto +cardano-sl-crypto-test cardano-sl-txp cardano-sl-util containers @@ -18305,6 +18306,7 @@ license = stdenv.lib.licenses.mit; , cardano-sl-core , cardano-sl-core-test , cardano-sl-crypto +, cardano-sl-crypto-test , cardano-sl-db , cardano-sl-delegation , cardano-sl-infra @@ -18529,6 +18531,7 @@ cardano-sl-block cardano-sl-client cardano-sl-core cardano-sl-crypto +cardano-sl-crypto-test cardano-sl-db cardano-sl-delegation cardano-sl-lrc diff --git a/txp/test/Test/Pos/Txp/Toil/UtxoSpec.hs b/txp/test/Test/Pos/Txp/Toil/UtxoSpec.hs index 27d539398f6..0de93cb1031 100644 --- a/txp/test/Test/Pos/Txp/Toil/UtxoSpec.hs +++ b/txp/test/Test/Pos/Txp/Toil/UtxoSpec.hs @@ -15,7 +15,7 @@ import qualified Data.Vector as V (fromList) import Fmt (blockListF', genericF, nameF, (+|), (|+)) import Serokell.Util (allDistinct) import Test.Hspec (Expectation, Spec, describe, expectationFailure, it, runIO) -import Test.Hspec.QuickCheck (prop) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) import Test.QuickCheck (Property, arbitrary, counterexample, forAll, generate, (==>)) import Pos.Core (HasConfiguration, addressHash, checkPubKeyAddress, @@ -38,6 +38,7 @@ import Pos.Txp (ToilVerFailure (..), Utxo, VTxContext (..), VerifyTxUt utxoToLookup, verifyTxUtxo) import qualified Pos.Util.Modifier as MM +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Txp.Arbitrary (BadSigsTx (..), DoubleInputTx (..), GoodTx (..), genGoodTxWithMagic) import Test.Pos.Util.QuickCheck.Arbitrary (SmallGenerator (..), nonrepeating, runGen) @@ -47,16 +48,24 @@ import Test.Pos.Util.QuickCheck.Property (qcIsLeft, qcIsRight) -- Spec ---------------------------------------------------------------------------- + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pmTop = diff --git a/wallet-new/cardano-sl-wallet-new.cabal b/wallet-new/cardano-sl-wallet-new.cabal index 27a77d99fca..bf3f96a50be 100755 --- a/wallet-new/cardano-sl-wallet-new.cabal +++ b/wallet-new/cardano-sl-wallet-new.cabal @@ -419,6 +419,7 @@ test-suite wallet-unit-tests , cardano-sl-client , cardano-sl-core , cardano-sl-crypto + , cardano-sl-crypto-test , cardano-sl-db , cardano-sl-delegation , cardano-sl-lrc @@ -495,6 +496,7 @@ test-suite wallet-new-specs , cardano-sl-client , cardano-sl-core , cardano-sl-crypto + , cardano-sl-crypto-test , cardano-sl-txp , cardano-sl-util , cardano-sl-util-test diff --git a/wallet-new/test/DevelopmentSpec.hs b/wallet-new/test/DevelopmentSpec.hs index 1b83c32552f..ed4fd620ceb 100644 --- a/wallet-new/test/DevelopmentSpec.hs +++ b/wallet-new/test/DevelopmentSpec.hs @@ -26,8 +26,9 @@ import Test.Pos.Util.QuickCheck.Property (assertProperty) import Test.Hspec (Spec, describe, runIO) import Test.Hspec.QuickCheck (modifyMaxSuccess) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Wallet.Web.Mode (walletPropertySpec) -import Test.QuickCheck (arbitrary, generate) +import Test.QuickCheck (generate) import Cardano.Wallet.API.Development.LegacyHandlers (deleteSecretKeys) import Cardano.Wallet.Server.CLI (RunMode (..)) @@ -35,16 +36,24 @@ import Servant {-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-} + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = diff --git a/wallet-new/test/unit/Test/Spec/Kernel.hs b/wallet-new/test/unit/Test/Spec/Kernel.hs index cc1d9bbcdaf..2b212108826 100644 --- a/wallet-new/test/unit/Test/Spec/Kernel.hs +++ b/wallet-new/test/unit/Test/Spec/Kernel.hs @@ -5,6 +5,7 @@ module Test.Spec.Kernel ( import Universum import qualified Data.Set as Set +import Test.Hspec.QuickCheck (modifyMaxSuccess) import qualified Cardano.Wallet.Kernel as Kernel import qualified Cardano.Wallet.Kernel.Diffusion as Kernel @@ -12,6 +13,7 @@ import Pos.Core (Coeff (..), TxSizeLinear (..)) import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) import Test.Infrastructure.Generator +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Util.Buildable.Hspec import Util.Buildable.QuickCheck import UTxO.Bootstrap @@ -29,16 +31,24 @@ import qualified Wallet.Basic as Base Compare the wallet kernel with the pure model -------------------------------------------------------------------------------} + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = diff --git a/wallet-new/test/unit/Test/Spec/Models.hs b/wallet-new/test/unit/Test/Spec/Models.hs index 6a694c7b8d0..c5a7bdeed16 100644 --- a/wallet-new/test/unit/Test/Spec/Models.hs +++ b/wallet-new/test/unit/Test/Spec/Models.hs @@ -5,8 +5,10 @@ module Test.Spec.Models ( import Universum import qualified Data.Set as Set +import Test.Hspec.QuickCheck (modifyMaxSuccess) import Test.Infrastructure.Generator +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Util.Buildable.Hspec import Util.Buildable.QuickCheck import UTxO.Bootstrap @@ -31,16 +33,24 @@ import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) -------------------------------------------------------------------------------} -- | Test the pure wallet models + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = diff --git a/wallet-new/test/unit/Test/Spec/Translation.hs b/wallet-new/test/unit/Test/Spec/Translation.hs index ae9850ac726..6ac636b62d4 100644 --- a/wallet-new/test/unit/Test/Spec/Translation.hs +++ b/wallet-new/test/unit/Test/Spec/Translation.hs @@ -18,6 +18,7 @@ import qualified Pos.Txp.Toil as Cardano import Test.Infrastructure.Generator import Test.Infrastructure.Genesis +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Util.Buildable.Hspec import Util.Buildable.QuickCheck import Util.Validated @@ -31,16 +32,24 @@ import UTxO.Translate UTxO->Cardano translation tests -------------------------------------------------------------------------------} + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = do diff --git a/wallet/test/Test/Pos/Util/MnemonicsSpec.hs b/wallet/test/Test/Pos/Util/MnemonicsSpec.hs index 02ac672ca06..4d7b8e621a1 100644 --- a/wallet/test/Test/Pos/Util/MnemonicsSpec.hs +++ b/wallet/test/Test/Pos/Util/MnemonicsSpec.hs @@ -4,20 +4,26 @@ import Universum import Data.ByteString.Char8 (pack) import Data.Set (Set) +import qualified Data.Set as Set import Test.Hspec (Spec, describe, it, runIO, shouldSatisfy, xit) import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) import Test.QuickCheck (Arbitrary (..), arbitrary, forAll, generate, property) import Test.QuickCheck.Gen (oneof, vectorOf) import Pos.Core.NetworkMagic (NetworkMagic, makeNetworkMagic) -import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) +import Pos.Crypto (RequiresNetworkMagic (..)) import Pos.Util.BackupPhrase (BackupPhrase (..), safeKeysFromPhrase) import Pos.Util.Mnemonics (defMnemonic, fromMnemonic, toMnemonic) import Pos.Wallet.Web.ClientTypes.Functions (encToCId) import Pos.Wallet.Web.ClientTypes.Types (CId) -import qualified Data.Set as Set +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 spec :: Spec spec = do @@ -25,10 +31,11 @@ spec = do runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody (makeNetworkMagic pm) +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody (makeNetworkMagic pm) specBody :: NetworkMagic -> Spec specBody _nm = do diff --git a/wallet/test/Test/Pos/Wallet/Web/AddressSpec.hs b/wallet/test/Test/Pos/Wallet/Web/AddressSpec.hs index cbaaf69061f..68acb569c36 100644 --- a/wallet/test/Test/Pos/Wallet/Web/AddressSpec.hs +++ b/wallet/test/Test/Pos/Wallet/Web/AddressSpec.hs @@ -30,21 +30,30 @@ import Pos.Wallet.Web.Methods.Logic (newAccount) import Pos.Wallet.Web.State (askWalletSnapshot, getWalletAddresses, wamAddress) import Pos.Wallet.Web.Util (decodeCTypeOrFail) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (assertProperty, expectedOne) import Test.Pos.Wallet.Web.Mode (WalletProperty) import Test.Pos.Wallet.Web.Util (importSingleWallet, mostlyEmptyPassphrases) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - withProvidedMagicConfig pm $ - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + withProvidedMagicConfig pm $ + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: HasConfigurations => ProtocolMagic -> Spec specBody pm = describe "Fake address has maximal possible size" $ diff --git a/wallet/test/Test/Pos/Wallet/Web/Methods/BackupDefaultAddressesSpec.hs b/wallet/test/Test/Pos/Wallet/Web/Methods/BackupDefaultAddressesSpec.hs index 668b359b201..686bf5cd5ac 100644 --- a/wallet/test/Test/Pos/Wallet/Web/Methods/BackupDefaultAddressesSpec.hs +++ b/wallet/test/Test/Pos/Wallet/Web/Methods/BackupDefaultAddressesSpec.hs @@ -17,21 +17,30 @@ import Pos.Wallet.Web.Methods.Restore (restoreWalletFromBackup) import Test.Hspec (Spec, describe, runIO) import Test.Hspec.QuickCheck (modifyMaxSuccess) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (assertProperty) import Test.Pos.Wallet.Web.Mode (walletPropertySpec) import Test.QuickCheck (arbitrary, generate) import Test.QuickCheck.Monadic (pick) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ diff --git a/wallet/test/Test/Pos/Wallet/Web/Methods/LogicSpec.hs b/wallet/test/Test/Pos/Wallet/Web/Methods/LogicSpec.hs index 3dfff46a5a6..c50a58c63ee 100644 --- a/wallet/test/Test/Pos/Wallet/Web/Methods/LogicSpec.hs +++ b/wallet/test/Test/Pos/Wallet/Web/Methods/LogicSpec.hs @@ -8,8 +8,8 @@ module Test.Pos.Wallet.Web.Methods.LogicSpec import Universum import Test.Hspec (Spec, describe, runIO) -import Test.Hspec.QuickCheck (prop) -import Test.QuickCheck (arbitrary, generate) +import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) +import Test.QuickCheck (generate) import Pos.Core.NetworkMagic (NetworkMagic, makeNetworkMagic) import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..)) @@ -17,20 +17,29 @@ import Pos.Launcher (HasConfigurations) import Pos.Wallet.Web.Methods.Logic (getAccounts, getWallets) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (stopProperty) import Test.Pos.Wallet.Web.Mode (WalletProperty) -- TODO remove HasCompileInfo when MonadWalletWebMode will be splitted. + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ diff --git a/wallet/test/Test/Pos/Wallet/Web/Methods/PaymentSpec.hs b/wallet/test/Test/Pos/Wallet/Web/Methods/PaymentSpec.hs index 0801610e807..8eef78275b1 100644 --- a/wallet/test/Test/Pos/Wallet/Web/Methods/PaymentSpec.hs +++ b/wallet/test/Test/Pos/Wallet/Web/Methods/PaymentSpec.hs @@ -45,6 +45,7 @@ import Pos.Wallet.Web.Util (decodeCTypeOrFail, getAccountAddrsOrThrow) import Pos.Util.Servant (encodeCType) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (assertProperty, expectedOne, maybeStopProperty, splitWord, stopProperty) import Test.Pos.Wallet.Web.Mode (WalletProperty, getSentTxs, submitTxTestMode, @@ -57,19 +58,27 @@ import Test.Pos.Wallet.Web.Util (deriveRandomAddress, expectedAddrBala deriving instance Eq CTx -- TODO remove HasCompileInfo when MonadWalletWebMode will be splitted. + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - withProvidedMagicConfig pm $ - describe "Wallet.Web.Methods.Payment" $ modifyMaxSuccess (const 10) $ do - describe "Submitting a payment when restoring" (rejectPaymentIfRestoringSpec pm) - describe "One payment" (oneNewPaymentBatchSpec pm) +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + withProvidedMagicConfig pm $ + describe "Wallet.Web.Methods.Payment" $ modifyMaxSuccess (const 10) $ do + describe "Submitting a payment when restoring" (rejectPaymentIfRestoringSpec pm) + describe "One payment" (oneNewPaymentBatchSpec pm) data PaymentFixture = PaymentFixture { pswd :: PassPhrase diff --git a/wallet/test/Test/Pos/Wallet/Web/Tracking/SyncSpec.hs b/wallet/test/Test/Pos/Wallet/Web/Tracking/SyncSpec.hs index 1ea043abfa0..be1c48ada76 100644 --- a/wallet/test/Test/Pos/Wallet/Web/Tracking/SyncSpec.hs +++ b/wallet/test/Test/Pos/Wallet/Web/Tracking/SyncSpec.hs @@ -39,20 +39,29 @@ import Pos.Wallet.Web.Tracking.Types (newSyncRequest) import Test.Pos.Block.Logic.Util (EnableTxPayload (..), InplaceDB (..)) import Test.Pos.Configuration (withProvidedMagicConfig) +import Test.Pos.Crypto.Arbitrary (genProtocolMagicUniformWithRNM) import Test.Pos.Util.QuickCheck.Property (assertProperty) import Test.Pos.Wallet.Web.Mode (walletPropertySpec) import Test.Pos.Wallet.Web.Util (importSomeWallets, wpGenBlocks) + +-- We run the tests this number of times, with different `ProtocolMagics`, to get increased +-- coverage. We should really do this inside of the `prop`, but it is difficult to do that +-- without significant rewriting of the testsuite. +testMultiple :: Int +testMultiple = 3 + spec :: Spec spec = do runWithMagic NMMustBeNothing runWithMagic NMMustBeJust runWithMagic :: RequiresNetworkMagic -> Spec -runWithMagic rnm = do - pm <- (\ident -> ProtocolMagic ident rnm) <$> runIO (generate arbitrary) - describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ - specBody pm +runWithMagic rnm = replicateM_ testMultiple $ + modifyMaxSuccess (`div` testMultiple) $ do + pm <- runIO (generate (genProtocolMagicUniformWithRNM rnm)) + describe ("(requiresNetworkMagic=" ++ show rnm ++ ")") $ + specBody pm specBody :: ProtocolMagic -> Spec specBody pm = withProvidedMagicConfig pm $ do