tweag / cooked-validators

MIT License
39 stars 11 forks source link

Cooked Validators

Copyright Tweag I/O 2024

cooked-validators is a Haskell library to conveniently and efficiently write off-chain code for Cardano smart contracts. This offchain code will be specifically geared to testing and auditing the smart contract in question with further builtin capabilities of the library.

In particular, cooked-validators allows the user to:

You are free to copy, modify, and distribute cooked-validators under the terms of the MIT license. We provide cooked-validators as a research prototype under active development, and it comes as is with no guarantees whatsoever. Check the license for details.

How to integrate cooked-validators in a project

To use cooked-validators, you need

  1. cooked-validators depends on cardano-haskell-packages to get cardano-related packages and on cardano-node-emulator directly. If you have no constraint on the version of this package, copy the file cabal.project to your project and adapt the packages stanza.

  2. Add the following stanza to the file cabal.project

    source-repository-package
     type: git
     location: https://github.com/tweag/cooked-validators
     tag: myTag
     subdir:
       .

    where myTag is either a commit hash in the repo, or a tag, such as v4.0.0 (see available releases).

Example

  1. Make your project depend on cooked-validators and plutus-script-utils

  2. Enter a Cabal read-eval-print-loop (with cabal repl) and create and validate a transaction which transfers 10 Ada from wallet 1 to wallet 2:

    > import Cooked
    > import qualified Plutus.Script.Utils.Ada as Script
    > printCooked . runMockChain . validateTxSkel $
         txSkelTemplate
           { txSkelOuts = [paysPK (wallet 2) (Script.adaValueOf 10)],
             txSkelSigners = [wallet 1]
           }
    [...]
    - UTxO state:
     • pubkey wallet 1
       - Lovelace: 89_828_471
       - (×4) Lovelace: 100_000_000
     • pubkey wallet 2
       - Lovelace: 10_000_000
       - (×5) Lovelace: 100_000_000
     • pubkey wallet 3
       - (×5) Lovelace: 100_000_000
     • pubkey wallet 4
       - (×5) Lovelace: 100_000_000
    [...]

Documentation