From fc773745007946dbf7f2f9243e4e6e14e8381dab Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 4 Jul 2020 00:22:33 +0200 Subject: [PATCH] remove flaky so-called 'unit' network spec for byron & shelley These tests are quite flaky and often failing for no reason. Plus, they are testing things at the integration level since they require a running node and they are redundant with other integration scenario that are ran as part of the integration test suite --- lib/byron/cardano-wallet-byron.cabal | 5 -- .../unit/Cardano/Wallet/Byron/NetworkSpec.hs | 82 ----------------- lib/shelley/cardano-wallet-shelley.cabal | 7 -- .../Cardano/Wallet/Shelley/NetworkSpec.hs | 89 ------------------- 4 files changed, 183 deletions(-) delete mode 100644 lib/byron/test/unit/Cardano/Wallet/Byron/NetworkSpec.hs delete mode 100644 lib/shelley/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs diff --git a/lib/byron/cardano-wallet-byron.cabal b/lib/byron/cardano-wallet-byron.cabal index f02644aa62c..f237086ff46 100644 --- a/lib/byron/cardano-wallet-byron.cabal +++ b/lib/byron/cardano-wallet-byron.cabal @@ -133,18 +133,14 @@ test-suite unit , cardano-crypto-wrapper , cardano-wallet-byron , cardano-wallet-core - , cardano-wallet-test-utils , cborg , containers , fmt - , generic-lens , hspec - , iohk-monitoring , memory , ouroboros-consensus-byron , ouroboros-network , QuickCheck - , retry , text , transformers build-tools: @@ -157,7 +153,6 @@ test-suite unit Main.hs other-modules: Cardano.Wallet.Byron.CompatibilitySpec - Cardano.Wallet.Byron.NetworkSpec Cardano.Wallet.Byron.TransactionSpec test-suite integration diff --git a/lib/byron/test/unit/Cardano/Wallet/Byron/NetworkSpec.hs b/lib/byron/test/unit/Cardano/Wallet/Byron/NetworkSpec.hs deleted file mode 100644 index d9930d8152b..00000000000 --- a/lib/byron/test/unit/Cardano/Wallet/Byron/NetworkSpec.hs +++ /dev/null @@ -1,82 +0,0 @@ -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE TemplateHaskell #-} - -module Cardano.Wallet.Byron.NetworkSpec (spec) where - -import Prelude - -import Cardano.BM.Data.Severity - ( Severity (..) ) -import Cardano.BM.Trace - ( nullTracer ) -import Cardano.Wallet.Byron.Compatibility - ( NodeVersionData ) -import Cardano.Wallet.Byron.Launch - ( withCardanoNode ) -import Cardano.Wallet.Byron.Network - ( NetworkLayerLog (..), withNetworkLayer ) -import Cardano.Wallet.Network - ( NetworkLayer (..) ) -import Cardano.Wallet.Primitive.Types - ( FeePolicy (..) - , NetworkParameters (..) - , ProtocolParameters (..) - , TxParameters (..) - ) -import Control.Retry - ( constantDelay, limitRetries, recoverAll ) -import Data.Function - ( (&) ) -import Data.Generics.Internal.VL.Lens - ( set ) -import Data.Generics.Labels - () -import Data.Maybe - ( mapMaybe ) -import Data.Quantity - ( Quantity (..) ) -import Test.Hspec - ( Spec, describe, it, shouldBe, shouldReturn ) -import Test.Utils.Paths - ( getTestData ) -import Test.Utils.Trace - ( withLogging ) - -{------------------------------------------------------------------------------- - Spec --------------------------------------------------------------------------------} - -spec :: Spec -spec = describe "getTxParameters" $ do - it "Correct values are queried" $ - withTestNode $ \np sock vData -> withLogging $ \(tr, getLogs) -> do - -- Initial TxParameters for NetworkLayer are all zero - let np' = np & - (#protocolParameters . #txParameters) `set` zeroTxParameters - withNetworkLayer tr np' sock vData $ \nl -> do - -- After a short while, the network layer should have gotten - -- protocol parameters from the node, and they should reflect - -- the genesis block configuration. - let retryPolicy = constantDelay 1_000_000 <> limitRetries 100 - recoverAll retryPolicy $ const $ - getProtocolParameters nl `shouldReturn` - protocolParameters np - -- Parameters update should be logged exactly once. - msg <- mapMaybe isMsgProtocolParams <$> getLogs - msg `shouldBe` [protocolParameters np] - -withTestNode - :: (NetworkParameters -> FilePath -> NodeVersionData -> IO a) - -> IO a -withTestNode action = withCardanoNode nullTracer $(getTestData) Error $ - \sock _block0 (np, vData) -> action np sock vData - -isMsgProtocolParams :: NetworkLayerLog -> Maybe ProtocolParameters -isMsgProtocolParams (MsgProtocolParameters pp) = Just pp -isMsgProtocolParams _ = Nothing - -zeroTxParameters :: TxParameters -zeroTxParameters = TxParameters - (LinearFee (Quantity 0) (Quantity 0) (Quantity 0)) - (Quantity 0) diff --git a/lib/shelley/cardano-wallet-shelley.cabal b/lib/shelley/cardano-wallet-shelley.cabal index 69e4725e140..860bf0dbc1a 100644 --- a/lib/shelley/cardano-wallet-shelley.cabal +++ b/lib/shelley/cardano-wallet-shelley.cabal @@ -143,15 +143,11 @@ test-suite unit , cardano-crypto-class , cardano-wallet-core , cardano-wallet-shelley - , cardano-wallet-test-utils , containers - , generic-lens , hspec - , iohk-monitoring , memory , ouroboros-consensus-shelley , ouroboros-network - , retry , shelley-spec-ledger , text , text-class @@ -167,7 +163,6 @@ test-suite unit Main.hs other-modules: Cardano.Wallet.Shelley.CompatibilitySpec - Cardano.Wallet.Shelley.NetworkSpec Cardano.Wallet.Shelley.TransactionSpec test-suite integration @@ -187,8 +182,6 @@ test-suite integration , async , bytestring , cardano-wallet-cli - , cardano-addresses - , cardano-slotting , cardano-wallet-core , cardano-wallet-core-integration , cardano-wallet-launcher diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs deleted file mode 100644 index 8abbed312a5..00000000000 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs +++ /dev/null @@ -1,89 +0,0 @@ -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE OverloadedLabels #-} - -module Cardano.Wallet.Shelley.NetworkSpec (spec) where - -import Prelude - -import Cardano.BM.Data.Severity - ( Severity (..) ) -import Cardano.BM.Trace - ( nullTracer ) -import Cardano.Wallet.Network - ( NetworkLayer (..) ) -import Cardano.Wallet.Primitive.Types - ( DecentralizationLevel (..) - , FeePolicy (..) - , NetworkParameters (..) - , ProtocolParameters (..) - , TxParameters (..) - ) -import Cardano.Wallet.Shelley.Compatibility - ( NodeVersionData ) -import Cardano.Wallet.Shelley.Launch - ( singleNodeParams, withBFTNode, withSystemTempDir ) -import Cardano.Wallet.Shelley.Network - ( NetworkLayerLog (..), withNetworkLayer ) -import Control.Retry - ( constantDelay, limitRetries, recoverAll ) -import Data.Function - ( (&) ) -import Data.Generics.Internal.VL.Lens - ( set ) -import Data.Generics.Labels - () -import Data.Maybe - ( mapMaybe ) -import Data.Quantity - ( Quantity (..), mkPercentage ) -import Test.Hspec - ( Spec, describe, it, shouldBe, shouldReturn ) -import Test.Utils.Trace - ( withLogging ) - -{------------------------------------------------------------------------------- - Spec --------------------------------------------------------------------------------} - -spec :: Spec -spec = describe "getTxParameters" $ do - it "Correct values are queried" $ - withTestNode $ \np sock vData -> withLogging $ \(tr, getLogs) -> do - -- Initial TxParameters for NetworkLayer are all zero - let np' = np & - (#protocolParameters . #txParameters) `set` zeroTxParameters & - (#protocolParameters . #decentralizationLevel) `set` fakeD - withNetworkLayer tr np' sock vData $ \nl -> do - -- After a short while, the network layer should have gotten - -- protocol parameters from the node, and they should reflect - -- the genesis block configuration. - let retryPolicy = constantDelay 1_000_000 <> limitRetries 100 - recoverAll retryPolicy $ const $ - getProtocolParameters nl `shouldReturn` - protocolParameters np - -- Parameters update should be logged exactly once. - msg <- mapMaybe isMsgProtocolParams <$> getLogs - msg `shouldBe` [protocolParameters np] - -withTestNode - :: (NetworkParameters -> FilePath -> NodeVersionData -> IO a) - -> IO a -withTestNode action = do - cfg <- singleNodeParams Error - withSystemTempDir nullTracer "network-spec" $ \dir -> - withBFTNode nullTracer dir cfg $ \sock _block0 (np, vData) -> - action np sock vData - -isMsgProtocolParams :: NetworkLayerLog -> Maybe ProtocolParameters -isMsgProtocolParams (MsgProtocolParameters pp) = Just pp -isMsgProtocolParams _ = Nothing - -zeroTxParameters :: TxParameters -zeroTxParameters = TxParameters - (LinearFee (Quantity 0) (Quantity 0) (Quantity 0)) - (Quantity 0) - --- | A value that is not the same as what's in the test data genesis. -fakeD :: DecentralizationLevel -fakeD = DecentralizationLevel p - where Right p = mkPercentage (5/32)