/
StoreSpec.hs
57 lines (49 loc) · 1.55 KB
/
StoreSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Cardano.Wallet.DB.Store.Transactions.StoreSpec
( spec
) where
import Prelude
import Cardano.Wallet.DB.Arbitrary
()
import Cardano.Wallet.DB.Fixtures
( StoreProperty, logScale, withDBInMemory, withStoreProp )
import Cardano.Wallet.DB.Sqlite.Types
( TxId (TxId) )
import Cardano.Wallet.DB.Store.Transactions.Model
( DeltaTxHistory (..), TxHistoryF (..), mkTxHistory )
import Cardano.Wallet.DB.Store.Transactions.Store
( mkStoreTransactions )
import Test.DBVar
( GenDelta, prop_StoreUpdates )
import Test.Hspec
( Spec, around, describe, it )
import Test.QuickCheck
( arbitrary, elements, frequency, property )
import qualified Data.Map.Strict as Map
spec :: Spec
spec = around withDBInMemory $ do
describe "Transactions store" $ do
it "respects store laws"
$ property . prop_StoreMetaLaws
prop_StoreMetaLaws :: StoreProperty
prop_StoreMetaLaws = withStoreProp $ \runQ ->
prop_StoreUpdates
runQ
mkStoreTransactions
(pure mempty)
(logScale . genDeltas)
-- | Generate interesting changes to 'TxHistory'.
genDeltas :: GenDelta DeltaTxHistory
genDeltas (TxHistoryF history) =
frequency
[ (8, Expand . mkTxHistory <$> arbitrary)
, (1, Delete . TxId <$> arbitrary)
, (2, Delete
<$> if null history
then TxId <$> arbitrary
else elements (Map.keys history)
)
]