cooked-validators-4.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Tweak.TamperDatum

Description

This module provide tweaks to tamper with output datums in a typed manner. There are many use cases where slight changes in datum can have a drastic effect on the bahavior of a contract, and can be unchecked. Here is the way to test those cases.

Synopsis

Documentation

tamperDatumTweak Source #

Arguments

:: forall a m. (MonadTweak m, Show a, PrettyCooked a, ToData a, FromData a, Typeable a) 
=> (a -> Maybe a)

Use this function to return Just the changed datum, if you want to perform a change, and Nothing, if you want to leave it as-is. All datums on outputs that are not of type a are never touched.

-> m [a] 

A tweak that tries to change the datum on outputs carrying datums of a certain type with a prescribed tampering function.

The tweak returns a list of the modified datums, as they were *before* the modification was applied to them.

malformDatumTweak :: forall a m. (MonadTweak m, ToData a, FromData a, Typeable a) => (a -> [BuiltinData]) -> m () Source #

A tweak that tries to change the datum on outputs carrying datums of a certain type with a prescribed tampering function. There are two main differences with tamperDatumTweak. First, the tampering function returns BuiltinData, allowing it to do pretty much anything with the datums. Second, for every output datum there are zero or more options for how to modify it, and all combinations of these modifications are tried.

That is, if there are n output datums, for which there are 'k_1,...,k_n' possible modifications, this tweak will try

  k_1 + ... + k_n
+ k_1 * k_2 + ... + k_{n-1} * k_n
+ k_1 * k_2 * k_3 + ... + k_{n-2} * k_{n-1} * k_n
+ ...
+ k_1 * k_2 * ... * k_{n-1} * k_n
== (k_1 + 1) * ... * (k_n + 1) - 1

modified transactions.