Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add store laws for UTxOHistory store.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 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
56 changes: 56 additions & 0 deletions
56
lib/wallet/test/unit/Cardano/Wallet/DB/Store/DeltaUTxO/StoreSpec.hs
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,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 |