| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Node.Emulator.Generators
Description
Generators for constructing blockchains and transactions for use in property-based testing.
Synopsis
- data Mockchain = Mockchain {}
- genMockchain :: MonadGen m => m Mockchain
- genMockchain' :: MonadGen m => GeneratorModel -> m Mockchain
- emptyChain :: Mockchain
- data GeneratorModel = GeneratorModel {}
- data TxInputWitnessed = TxInputWitnessed !TxOutRef !TxInType
- generatorModel :: GeneratorModel
- genValidTransaction :: Alternative m => MonadGen m => Mockchain -> m CardanoTx
- genValidTransaction' :: Alternative m => MonadGen m => GeneratorModel -> Mockchain -> m CardanoTx
- genValidTransactionSpending :: Alternative m => MonadGen m => [TxInputWitnessed] -> Value -> m CardanoTx
- genValidTransactionSpending' :: Alternative m => MonadGen m => GeneratorModel -> [TxInputWitnessed] -> Value -> m CardanoTx
- genInitialTransaction :: GeneratorModel -> (CardanoTx, [TxOut])
- assertValid :: (MonadTest m, HasCallStack) => CardanoTx -> Mockchain -> m ()
- genInterval :: (MonadFail m, Ord a) => m a -> m (Interval a)
- genSlotRange :: (MonadFail m, MonadGen m) => m SlotRange
- genTimeRange :: (MonadFail m, MonadGen m) => SlotConfig -> m POSIXTimeRange
- genSlot :: MonadGen m => m Slot
- genPOSIXTime :: MonadGen m => SlotConfig -> m POSIXTime
- genSlotConfig :: MonadGen m => m SlotConfig
- genSomeCardanoApiTx :: (GenBase m ~ Identity, MonadGen m) => m SomeCardanoApiTx
- genAda :: MonadGen m => m Ada
- genMintingPolicyHash :: MonadGen m => m MintingPolicyHash
- genCurrencySymbol :: MonadGen m => m CurrencySymbol
- genAssetClass :: MonadGen m => m AssetClass
- genValue :: MonadGen m => m Value
- genValueNonNegative :: MonadGen m => m Value
- genSizedByteString :: forall m. MonadGen m => Int -> m ByteString
- genSizedByteStringExact :: forall m. MonadGen m => Int -> m ByteString
- genTokenName :: MonadGen m => m TokenName
- genSeed :: MonadGen m => m ByteString
- genPassphrase :: MonadGen m => m Passphrase
- splitVal :: (MonadGen m, Integral n) => Int -> n -> m [n]
- validateMockchain :: Mockchain -> CardanoTx -> Maybe ValidationErrorInPhase
- signAll :: CardanoTx -> CardanoTx
- signTx :: Params -> Map TxOutRef TxOut -> CardanoTx -> CardanoTx
- knownAddresses :: [CardanoAddress]
- knownPaymentPublicKeys :: [PaymentPubKey]
- knownPaymentPrivateKeys :: [PaymentPrivateKey]
- knownPaymentKeys :: Map PaymentPubKey PaymentPrivateKey
- knownXPrvs :: [XPrv]
- someTokenValue :: TokenName -> Integer -> Value
Mockchain
Blockchain for testing the emulator implementation and traces.
To avoid having to rely on functions from the implementation of
plutus-ledger (in particular, unspentOutputs) we note the
unspent outputs of the chain when it is first created.
Constructors
| Mockchain | |
Fields | |
genMockchain :: MonadGen m => m Mockchain Source #
Generate a mockchain using the default GeneratorModel.
genMockchain' :: MonadGen m => GeneratorModel -> m Mockchain Source #
Generate a mockchain.
TODO: Generate more than 1 txn
emptyChain :: Mockchain Source #
The empty mockchain.
data GeneratorModel Source #
The parameters for the generators in this module.
Constructors
| GeneratorModel | |
Fields
| |
Instances
| Show GeneratorModel Source # | |
Defined in Cardano.Node.Emulator.Generators | |
data TxInputWitnessed Source #
A transaction input, consisting of a transaction output reference and an input type with data witnesses.
Constructors
| TxInputWitnessed !TxOutRef !TxInType |
generatorModel :: GeneratorModel Source #
A generator model with some sensible defaults.
Transactions
genValidTransaction :: Alternative m => MonadGen m => Mockchain -> m CardanoTx Source #
Generate a valid transaction, using the unspent outputs provided. Fails if the there are no unspent outputs, or if the total value of the unspent outputs is smaller than the minimum fee.
genValidTransaction' :: Alternative m => MonadGen m => GeneratorModel -> Mockchain -> m CardanoTx Source #
Generate a valid transaction, using the unspent outputs provided. Fails if the there are no unspent outputs, or if the total value of the unspent outputs is smaller than the estimated fee.
genValidTransactionSpending :: Alternative m => MonadGen m => [TxInputWitnessed] -> Value -> m CardanoTx Source #
genValidTransactionSpending' :: Alternative m => MonadGen m => GeneratorModel -> [TxInputWitnessed] -> Value -> m CardanoTx Source #
genInitialTransaction :: GeneratorModel -> (CardanoTx, [TxOut]) Source #
A transaction with no inputs that mints some value (to be used at the beginning of a blockchain).
Assertions
assertValid :: (MonadTest m, HasCallStack) => CardanoTx -> Mockchain -> m () Source #
Assert that a transaction is valid in a chain.
Time
genInterval :: (MonadFail m, Ord a) => m a -> m (Interval a) Source #
Generate an 'Interval where the lower bound if less or equal than the upper bound.
genSlotRange :: (MonadFail m, MonadGen m) => m SlotRange Source #
Generate a SlotRange where the lower bound if less or equal than the
upper bound.
genTimeRange :: (MonadFail m, MonadGen m) => SlotConfig -> m POSIXTimeRange Source #
Generate a POSIXTimeRange where the lower bound if less or equal than the
upper bound.
genPOSIXTime :: MonadGen m => SlotConfig -> m POSIXTime Source #
Generate a POSIXTime where the lowest value is scSlotZeroTime given a
SlotConfig.
genSlotConfig :: MonadGen m => m SlotConfig Source #
Generate a SlotConfig where the slot length goes from 1 to 100000
ms and the time of Slot 0 is the default scSlotZeroTime.
Etc.
genSomeCardanoApiTx :: (GenBase m ~ Identity, MonadGen m) => m SomeCardanoApiTx Source #
genMintingPolicyHash :: MonadGen m => m MintingPolicyHash Source #
A minting policy hash is an arbitrary bytestring of length 28
genCurrencySymbol :: MonadGen m => m CurrencySymbol Source #
A currency symbol is either a minting policy hash (bytestring of length 28) or the ada symbol (empty bytestring).
genAssetClass :: MonadGen m => m AssetClass Source #
An asset class is either the ada symbol with the ada token name or a minting policy hash symbol with an arbitrary token name
genValue :: MonadGen m => m Value Source #
Generate a Value with a value range of minBound .. maxBound.
genValueNonNegative :: MonadGen m => m Value Source #
Generate a Value with a value range of 0 .. maxBound.
genSizedByteString :: forall m. MonadGen m => Int -> m ByteString Source #
Generate a 'ByteString s' of up to s bytes.
genSizedByteStringExact :: forall m. MonadGen m => Int -> m ByteString Source #
Generate a 'ByteString s' of exactly s bytes.
genTokenName :: MonadGen m => m TokenName Source #
A TokenName is either an arbitrary bytestring or the ada token name
genSeed :: MonadGen m => m ByteString Source #
Seed suitable for testing a seed but not for actual wallets as ScrubbedBytes isn't used to ensure memory isn't inspectable
genPassphrase :: MonadGen m => m Passphrase Source #
splitVal :: (MonadGen m, Integral n) => Int -> n -> m [n] Source #
Split a value into max. n positive-valued parts such that the sum of the parts equals the original value. Each part should contain the required minimum amount of Ada.
I noticed how for values of mx > 1000 the resulting lists are much smaller than
one would expect. I think this may be caused by the way we select the next value
for the split. It looks like the available funds get exhausted quite fast, which
makes the function return before generating anything close to mx values.
validateMockchain :: Mockchain -> CardanoTx -> Maybe ValidationErrorInPhase Source #
Validate a transaction in a mockchain.
signAll :: CardanoTx -> CardanoTx Source #
Attach signatures of all known private keys to a transaction.
knownXPrvs :: [XPrv] Source #