Skip to content

Commit

Permalink
add properties for submissions store
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Nov 29, 2022
1 parent 944222e commit b9b67b9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/wallet/cardano-wallet.cabal
Expand Up @@ -836,6 +836,7 @@ test-suite unit
Cardano.Wallet.DB.Store.Meta.ModelSpec
Cardano.Wallet.DB.Store.Meta.StoreSpec
Cardano.Wallet.DB.Store.Submissions.ModelSpec
Cardano.Wallet.DB.Store.Submissions.New.StoreSpec
Cardano.Wallet.DB.Store.Submissions.StoreSpec
Cardano.Wallet.DB.Store.Transactions.StoreSpec
Cardano.Wallet.DB.Store.Wallets.StoreSpec
Expand Down
5 changes: 5 additions & 0 deletions lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -225,6 +225,8 @@ import Cardano.Wallet.Api.Types.Transaction
, ApiWitnessCount (..)
, mkApiWitnessCount
)
import Cardano.Wallet.DB.Sqlite.Types
( TxId (..) )
import Cardano.Wallet.Gen
( genMnemonic
, genMockXPub
Expand Down Expand Up @@ -2440,6 +2442,9 @@ instance Arbitrary (Hash "BlockHeader") where
instance Arbitrary ApiBlockHeader where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary TxId where
arbitrary = TxId <$> arbitrary
{-------------------------------------------------------------------------------
Specification / Servant-Swagger Machinery
Expand Down
@@ -0,0 +1,56 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Wallet.DB.Store.Submissions.New.StoreSpec ( spec ) where

import Prelude

import Cardano.DB.Sqlite
( ForeignKeysSetting (ForeignKeysDisabled) )
import Cardano.Wallet.Api.TypesSpec
()
import Cardano.Wallet.DB.Fixtures
( WalletProperty, logScale, withDBInMemory, withInitializedWalletProp )
import Cardano.Wallet.DB.Store.Submissions.New.Primitives
( Primitive', mkStorePrimitivesSubmissions )
import Cardano.Wallet.Primitive.Types
( SlotNo (..) )
import Cardano.Wallet.Submissions.PrimitivesSpec
( primitiveDeltaG )
import Cardano.Wallet.Submissions.Submissions
( Submissions (..) )
import Control.Monad
( void )
import Fmt
( Buildable (..) )
import System.Random
( Random )
import Test.DBVar
( prop_StoreUpdates )
import Test.Hspec
( Spec, around, describe, it )
import Test.QuickCheck
( property )

spec :: Spec
spec = do
around (withDBInMemory ForeignKeysDisabled) $ do
describe "submissions for a single wallet store" $ do
it "respects store laws" $ property . prop_SingleWalletStoreLaws

instance Buildable Primitive' where
build = build . show

prop_SingleWalletStoreLaws :: WalletProperty
prop_SingleWalletStoreLaws = withInitializedWalletProp $ \wid runQ -> do
void $ prop_StoreUpdates
runQ
(mkStorePrimitivesSubmissions wid)
(pure $ Submissions mempty 0 0)
(logScale . primitiveDeltaG)

deriving instance Random SlotNo

0 comments on commit b9b67b9

Please sign in to comment.