plutus-ledger-0.1.0.0: Wallet API

Ledger.Generators

Description

Generators for constructing blockchains and transactions for use in property-based testing.

Synopsis

# Mockchain

data Mockchain Source #

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

#### Instances

Instances details
 Source # Instance detailsDefined in Ledger.Generators MethodsshowList :: [Mockchain] -> ShowS Source #

Generate a mockchain using the default GeneratorModel.

Generate a mockchain.

TODO: Generate more than 1 txn

The empty mockchain.

The parameters for the generators in this module.

Constructors

 GeneratorModel FieldsgmInitialBalance :: Map PaymentPubKey ValueValue created at the beginning of the blockchain.gmPubKeys :: Set PaymentPubKeyPublic keys that are to be used for generating transactions.

#### Instances

Instances details
 Source # Instance detailsDefined in Ledger.Generators Methods

A generator model with some sensible defaults.

# Transactions

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.

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.

A transaction with no inputs that mints some value (to be used at the beginning of a blockchain).

# Assertions

assertValid :: (MonadTest m, HasCallStack) => Tx -> 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.

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.

genSlot :: MonadGen m => m Slot Source #

Generate a Slot where the lowest slot number is 0.

Generate a POSIXTime where the lowest value is scSlotZeroTime given a SlotConfig.

Generate a SlotConfig where the slot length goes from 1 to 100000 ms and the time of Slot 0 is the default scSlotZeroTime.

# Etc.

genValue :: MonadGen m => m Value Source #

Generate a Value with a value range of minBound .. maxBound.

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.

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

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.

Validate a transaction in a mockchain.

Attach signatures of all known private keys to a transaction.