Skip to content

Commit

Permalink
removed arbitrary constraint from ShelleyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
polinavino committed Oct 20, 2020
1 parent 01a9626 commit 56306ab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 228 deletions.
Expand Up @@ -26,6 +26,7 @@ module BenchValidation
)
where

import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CryptoClass
import Cardano.Ledger.Era (Era (..))
import Cardano.Prelude (NFData (rnf))
Expand All @@ -34,6 +35,7 @@ import Control.Monad.Except ()
import Control.State.Transition.Extended
import qualified Data.Map as Map
import Data.Proxy
import Test.QuickCheck (Arbitrary)
import Data.Sequence (Seq)
import Shelley.Spec.Ledger.API.Protocol
( ChainDepState (..),
Expand Down Expand Up @@ -82,6 +84,7 @@ instance NFData (ValidateInput era) where

validateInput ::
( ShelleyTest era,
Arbitrary (Core.VALUE era),
Mock (Crypto era),
STS (LEDGERS era),
BaseM (LEDGERS era) ~ ShelleyBase,
Expand All @@ -101,6 +104,7 @@ validateInput utxoSize = genValidateInput utxoSize

genValidateInput ::
( ShelleyTest era,
Arbitrary (Core.VALUE era),
Mock (Crypto era),
STS (LEDGERS era),
BaseM (LEDGERS era) ~ ShelleyBase,
Expand Down Expand Up @@ -201,6 +205,7 @@ instance CryptoClass.Crypto c => NFData (UpdateInputs c) where
genUpdateInputs ::
forall era.
( ShelleyTest era,
Arbitrary (Core.VALUE era),
Environment (CHAIN era) ~ (),
STS (LEDGERS era),
BaseM (LEDGERS era) ~ ShelleyBase,
Expand Down
Expand Up @@ -10,6 +10,7 @@ module Shelley.Spec.Ledger.Bench.Gen
)
where

import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Era (Crypto)
import Control.State.Transition.Extended
import Data.Either (fromRight)
Expand All @@ -31,7 +32,7 @@ import Shelley.Spec.Ledger.LedgerState
import Shelley.Spec.Ledger.STS.Chain (CHAIN)
import Shelley.Spec.Ledger.STS.Ledger (LEDGER, LedgerEnv)
import Shelley.Spec.Ledger.STS.Ledgers (LEDGERS, LedgersEnv)
import Test.QuickCheck (generate)
import Test.QuickCheck (generate, Arbitrary)
import Test.Shelley.Spec.Ledger.BenchmarkFunctions (ledgerEnv)
import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes (Mock)
import qualified Test.Shelley.Spec.Ledger.Generator.Block as GenBlock
Expand All @@ -54,6 +55,7 @@ import Test.Shelley.Spec.Ledger.Utils (ShelleyTest)
-- | Generate a genesis chain state given a UTxO size
genChainState ::
( ShelleyTest era,
Arbitrary (Core.VALUE era),
Environment (CHAIN era) ~ ()
) =>
Int ->
Expand Down Expand Up @@ -105,6 +107,7 @@ genBlock ge cs = generate $ GenBlock.genBlock ge cs
genTriple ::
( Mock (Crypto era),
ShelleyTest era,
(Arbitrary (Core.VALUE era)),
Environment (CHAIN era) ~ ()
) =>
Proxy era ->
Expand Down
Expand Up @@ -10,6 +10,7 @@ module Shelley.Spec.Ledger.Bench.Rewards
)
where

import qualified Cardano.Ledger.Core as Core
import Cardano.Crypto.VRF (hashVerKeyVRF)
import Cardano.Slotting.EpochInfo
import Cardano.Slotting.Slot (EpochNo)
Expand Down Expand Up @@ -39,7 +40,7 @@ import qualified Shelley.Spec.Ledger.LedgerState as LS
import Shelley.Spec.Ledger.STS.Chain (CHAIN, ChainState, chainNes, totalAda)
import Shelley.Spec.Ledger.TxBody (PoolParams (..), TxOut (..))
import Shelley.Spec.Ledger.UTxO (UTxO (..))
import Test.QuickCheck (Gen)
import Test.QuickCheck (Gen, Arbitrary)
import Test.Shelley.Spec.Ledger.BenchmarkFunctions (B)
import Test.Shelley.Spec.Ledger.Generator.Block (genBlockWithTxGen)
import Test.Shelley.Spec.Ledger.Generator.Constants
Expand All @@ -63,7 +64,7 @@ import Cardano.Ledger.Era (Era(Crypto))
-- | Generate a chain state at a given epoch. Since we are only concerned about
-- rewards, this will populate the chain with empty blocks (only issued by the
-- original genesis delegates).
genChainInEpoch :: EpochNo -> Gen (ChainState B)
genChainInEpoch :: Arbitrary (Core.VALUE B) => EpochNo -> Gen (ChainState B)
genChainInEpoch epoch = do
genesisChainState <-
fromRight (error "genChainState failed")
Expand Down
Expand Up @@ -104,7 +104,7 @@ longTraceLen = 150
---------------------------------------------------------------------

-- | Tx inputs are eliminated, outputs added to utxo and TxIds are unique
collisionFreeComplete :: Property
collisionFreeComplete :: (Arbitrary Coin) => Property
collisionFreeComplete =
forAllChainTrace traceLen $ \tr -> do
let ssts = sourceSignalTargets tr
Expand All @@ -119,7 +119,7 @@ collisionFreeComplete =
]

-- | Various preservation properties
adaPreservationChain :: Property
adaPreservationChain :: (Arbitrary Coin) => Property
adaPreservationChain =
forAllChainTrace longTraceLen $ \tr -> do
let ssts = sourceSignalTargets tr
Expand Down Expand Up @@ -226,7 +226,7 @@ potsSumIncreaseWdrlsPerTx SourceSignalTarget {source = chainSt, signal = block}
signal = tx,
target = (UTxOState {_utxo = u', _deposited = d', _fees = f'}, _)
} =
(balance u' <+> (Val.inject $ d' <+> f')) <-> (balance u <+> (Val.inject $ d <+> f))
(balance u' <+> (Val.inject $ d' <+> f')) <-> (balance u <+> (Val.inject $ d <+> f))
=== (Val.inject $ fold (unWdrl . _wdrls $ _body tx))

-- | (Utxo + Deposits + Fees) increases by the reward delta
Expand All @@ -248,7 +248,7 @@ potsSumIncreaseByRewardsPerTx SourceSignalTarget {source = chainSt, signal = blo
DPState {_dstate = DState {_rewards = rewards'}}
)
} =
(balance u' <+> (Val.inject $ d' <+> f')) <-> (balance u <+> (Val.inject $ d <+> f))
(balance u' <+> (Val.inject $ d' <+> f')) <-> (balance u <+> (Val.inject $ d <+> f))
=== (Val.inject $ fold rewards <-> fold rewards')

-- | The Rewards pot decreases by the sum of withdrawals in a transaction
Expand Down Expand Up @@ -473,7 +473,7 @@ feesNonDecreasing SourceSignalTarget {source, target} =

-- | Various properties of the POOL STS Rule, tested on longer traces
-- (double the default length)
poolProperties :: Property
poolProperties :: (Arbitrary Coin) => Property
poolProperties =
forAllChainTrace traceLen $ \tr -> do
let ssts = sourceSignalTargets tr
Expand Down Expand Up @@ -519,7 +519,7 @@ poolStateIsInternallyConsistent (SourceSignalTarget {source = chainSt, signal =

-- | Various properties of the POOL STS Rule, tested on longer traces
-- (double the default length)
delegProperties :: Property
delegProperties :: (Arbitrary Coin) => Property
delegProperties =
forAllChainTrace traceLen $ \tr -> do
conjoin $
Expand Down Expand Up @@ -650,7 +650,7 @@ chainSstWithTick ledgerTr =
-- Properties for PoolReap (using the CHAIN Trace) --
----------------------------------------------------------------------

removedAfterPoolreap :: Property
removedAfterPoolreap :: (Arbitrary Coin) => Property
removedAfterPoolreap =
forAllChainTrace traceLen $ \tr ->
conjoin $
Expand All @@ -669,7 +669,7 @@ removedAfterPoolreap =
---------------------------

forAllChainTrace ::
(Testable prop) =>
(Testable prop, Arbitrary Coin) =>
Word64 -> -- trace length
(Trace (CHAIN C) -> prop) ->
Property
Expand Down

This file was deleted.

0 comments on commit 56306ab

Please sign in to comment.