This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from input-output-hk/ksaric/CAD-777
[CAD-777] Add simple tests.
- Loading branch information
Showing
9 changed files
with
219 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.stack-work/ | ||
dist-newstyle/ | ||
*~ | ||
tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ import Cardano.Prelude | |
import Lib | ||
|
||
main :: IO () | ||
main = runApp | ||
main = runApp defaultConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,6 @@ extra-deps: | |
- . | ||
- test | ||
|
||
|
||
|
||
# Override default flag values for local packages and extra-deps | ||
# flags: {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module SmashSpec | ||
( smashSpec | ||
) where | ||
|
||
import Cardano.Prelude | ||
|
||
import Crypto.Sign.Ed25519 (createKeypair) | ||
import Data.IORef (IORef, newIORef) | ||
|
||
import Test.Hspec (Spec, describe, it) | ||
import Test.Hspec.QuickCheck (modifyMaxSuccess, prop) | ||
import Test.QuickCheck (Arbitrary (..), Gen, Property, | ||
elements, generate, listOf) | ||
import Test.QuickCheck.Monadic (assert, monadicIO, run) | ||
|
||
import DB | ||
import Types | ||
|
||
-- | Test spec for smash | ||
smashSpec :: Spec | ||
smashSpec = do | ||
describe "DataLayer" $ do | ||
describe "Blacklisted pool" $ | ||
prop "adding a pool hash adds it to the data layer" $ monadicIO $ do | ||
|
||
(pk, _) <- run $ createKeypair | ||
|
||
let newPoolHash :: PoolHash | ||
newPoolHash = createPoolHash . show $ pk | ||
|
||
ioDataMap <- run $ newIORef stubbedInitialDataMap | ||
ioBlacklistedPools <- run $ newIORef stubbedBlacklistedPools | ||
|
||
let dataLayer :: DataLayer | ||
dataLayer = stubbedDataLayer ioDataMap ioBlacklistedPools | ||
|
||
newBlacklistPoolState <- run $ (dlAddBlacklistedPool dataLayer) newPoolHash | ||
|
||
newBlacklistedPools <- run $ dlGetBlacklistedPools dataLayer | ||
|
||
assert $ isRight newBlacklistPoolState | ||
assert $ isRight newBlacklistedPools | ||
|
||
assert $ newBlacklistedPools == Right (newPoolHash : stubbedBlacklistedPools) | ||
|
||
describe "Pool metadata" $ do | ||
prop "adding a pool metadata and returning the same" $ \(poolOfflineMetadata) -> monadicIO $ do | ||
|
||
(pk, _) <- run $ createKeypair | ||
|
||
let newPoolHash :: PoolHash | ||
newPoolHash = createPoolHash . show $ pk | ||
|
||
ioDataMap <- run $ newIORef stubbedInitialDataMap | ||
ioBlacklistedPools <- run $ newIORef stubbedBlacklistedPools | ||
|
||
let dataLayer :: DataLayer | ||
dataLayer = stubbedDataLayer ioDataMap ioBlacklistedPools | ||
|
||
newPoolOfflineMetadata <- run $ (dlAddPoolMetadata dataLayer) newPoolHash poolOfflineMetadata | ||
|
||
newPoolOfflineMetadata' <- run $ (dlGetPoolMetadata dataLayer) newPoolHash | ||
|
||
assert $ isRight newPoolOfflineMetadata | ||
assert $ isRight newPoolOfflineMetadata' | ||
|
||
assert $ newPoolOfflineMetadata == newPoolOfflineMetadata' | ||
|
||
prop "query non-existing pool metadata" $ monadicIO $ do | ||
|
||
(pk, _) <- run $ createKeypair | ||
|
||
let newPoolHash :: PoolHash | ||
newPoolHash = createPoolHash . show $ pk | ||
|
||
ioDataMap <- run $ newIORef stubbedInitialDataMap | ||
ioBlacklistedPools <- run $ newIORef stubbedBlacklistedPools | ||
|
||
let dataLayer :: DataLayer | ||
dataLayer = stubbedDataLayer ioDataMap ioBlacklistedPools | ||
|
||
newPoolOfflineMetadata <- run $ (dlGetPoolMetadata dataLayer) newPoolHash | ||
|
||
-- This pool hash does not exist! | ||
assert $ isLeft newPoolOfflineMetadata | ||
|
||
|
||
genSafeChar :: Gen Char | ||
genSafeChar = elements ['a'..'z'] | ||
|
||
genSafeText :: Gen Text | ||
genSafeText = toS <$> listOf genSafeChar | ||
|
||
instance Arbitrary PoolOfflineMetadata where | ||
arbitrary = do | ||
poolName <- PoolName <$> genSafeText | ||
poolDescription <- PoolDescription <$> genSafeText | ||
poolTicker <- PoolTicker <$> genSafeText | ||
poolHomepage <- PoolHomepage <$> genSafeText | ||
|
||
return $ createPoolOfflineMetadata | ||
poolName | ||
poolDescription | ||
poolTicker | ||
poolHomepage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
module Main where | ||
|
||
import Cardano.Prelude | ||
|
||
import Test.Hspec (describe, hspec) | ||
|
||
import SmashSpec (smashSpec) | ||
|
||
-- | Entry point for tests. | ||
main :: IO () | ||
main = putStrLn "Test suite not yet implemented" | ||
main = hspec $ do | ||
describe "SMASH tests" smashSpec | ||
|
||
|
||
|