Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test class laws for AnyRecentEra. #3958

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/wallet/bench/restore-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ import Cardano.BM.Trace
import Cardano.Mnemonic
( SomeMnemonic (..), entropyToMnemonic )
import Cardano.Wallet
( WalletException (..)
, WalletLayer (..)
, WalletWorkerLog (..)
, dummyChangeAddressGen
)
( WalletLayer (..), WalletWorkerLog (..), dummyChangeAddressGen )
import Cardano.Wallet.Address.Book
( AddressBookIso )
import Cardano.Wallet.Address.Derivation
Expand Down
4 changes: 0 additions & 4 deletions lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ import Test.QuickCheck
, forAll
, frequency
, liftArbitrary
, listOf
, oneof
, property
, scale
Expand Down Expand Up @@ -2170,9 +2169,6 @@ selectFromPreparedBinaries = elements $ toByteString <$>
let (Right bs) = fromHex $ T.encodeUtf8 txt
in bs

genWits :: Gen ByteString
genWits = BS.pack <$> Test.QuickCheck.scale (min 32) (listOf arbitrary)

deriving instance Arbitrary a => Arbitrary (ApiAsArray s a)

instance Arbitrary (ApiBytesT base ByteString) where
Expand Down
27 changes: 26 additions & 1 deletion lib/wallet/test/unit/Cardano/Wallet/Write/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import Cardano.Ledger.Babbage.TxBody
import Cardano.Wallet.Unsafe
( unsafeFromHex )
import Cardano.Wallet.Write.Tx
( BinaryData
( AnyRecentEra
, BinaryData
, RecentEra (..)
, Script
, StandardBabbage
Expand Down Expand Up @@ -59,11 +60,18 @@ import Test.QuickCheck
( Arbitrary (..)
, Arbitrary1 (liftArbitrary)
, Property
, arbitraryBoundedEnum
, conjoin
, counterexample
, property
, (===)
)
import Test.QuickCheck.Classes
( boundedEnumLaws, eqLaws, showLaws )
import Test.QuickCheck.Extra
( shrinkBoundedEnum )
import Test.Utils.Laws
( testLawsMany )

import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Gen as Cardano
Expand All @@ -75,6 +83,15 @@ import qualified Data.Map as Map

spec :: Spec
spec = do

describe "AnyRecentEra" $ do
describe "Class instances obey laws" $ do
testLawsMany @AnyRecentEra
[ boundedEnumLaws
, eqLaws
, showLaws
]

describe "BinaryData" $ do
it "BinaryData is isomorphic to Cardano.ScriptData" $
testIsomorphism
Expand Down Expand Up @@ -265,6 +282,14 @@ testIsomorphism (NamedFun f fName) (NamedFun g gName) normalize =
(property $ \x -> g (f x) === x)
]

--------------------------------------------------------------------------------
-- Arbitrary instances
--------------------------------------------------------------------------------

instance Arbitrary AnyRecentEra where
arbitrary = arbitraryBoundedEnum
shrink = shrinkBoundedEnum

--------------------------------------------------------------------------------
-- Test Data
--------------------------------------------------------------------------------
Expand Down