-
Notifications
You must be signed in to change notification settings - Fork 211
/
StoreSpec.hs
56 lines (49 loc) · 1.7 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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Wallet.DB.Store.DeltaUTxO.StoreSpec (spec) where
import Prelude
import Cardano.DB.Sqlite
( ForeignKeysSetting (..) )
import Cardano.Wallet.DB.Arbitrary
()
import Cardano.Wallet.DB.Fixtures
( WalletProperty, logScale, withDBInMemory, withInitializedWalletProp )
import Cardano.Wallet.DB.Store.DeltaUTxO.Model
( DeltaUTxOHistory (AppendBlock, Rollback), UTxOHistory, empty )
import Cardano.Wallet.DB.Store.DeltaUTxO.ModelSpec
( genDelta, genSlot, genSlotNo, genUTxO )
import Cardano.Wallet.DB.Store.DeltaUTxO.Store
( mkStoreUTxOHistory )
import Fmt
( Buildable (..) )
import Test.DBVar
( prop_StoreUpdates )
import Test.Hspec
( Spec, around, describe, it )
import Test.QuickCheck
( Gen, frequency, property )
spec :: Spec
spec = around (withDBInMemory ForeignKeysEnabled) $ do
describe "DeltaUTxO store" $ do
it "respects store laws" $
property . prop_StoreMetaLaws
genDeltas :: UTxOHistory -> Gen DeltaUTxOHistory
genDeltas history =
frequency
[ (10, AppendBlock <$> genSlotNo history (1, 1, 4) <*> genDelta history)
, (3, Rollback <$> genSlot history (1, 4, 1))
, (7, Rollback <$> genSlot history (1, 4, 1))
]
prop_StoreMetaLaws :: WalletProperty
prop_StoreMetaLaws = withInitializedWalletProp $ \wid runQ ->
prop_StoreUpdates
runQ
(mkStoreUTxOHistory wid)
(empty <$> genUTxO (empty mempty))
(logScale . genDeltas)
instance Buildable DeltaUTxOHistory where
build = build . show