@@ -53,16 +53,38 @@ to [UPLC](https://plutonomicon.github.io/plutonomicon/uplc), such as
5353
5454## How to integrate ` cooked-validators ` in a project
5555
56- 1 . ` cooked-validators ` depends on
57- [ cardano-haskell-packages] ( https://github.com/input-output-hk/cardano-haskell-packages )
58- to get cardano-related packages and on
59- [ cardano-node-emulator] ( https://github.com/tweag/cardano-node-emulator-forked )
60- directly. If you have no constraint on the version of this package, copy the
61- file [ ` cabal.project ` ] ( ./cabal.project ) to your project and
62- [ adapt] ( https://cabal.readthedocs.io/en/stable/cabal-project-description-file.html#specifying-the-local-packages )
63- the ` packages ` stanza.
56+ There are two ways for this integration:
57+
58+ 1 . ` cooked-validators ` , and all its dependencies, are available on
59+ [ cardano-haskel-packages
60+ (CHaP)] ( https://github.com/IntersectMBO/cardano-haskell-packages ) . To rely
61+ on a release available there, add the following stanza to your
62+ ` cabal.project ` :
63+
64+ ``` cabal.project
65+ repository cardano-haskell-packages
66+ url: https://chap.intersectmbo.org/
67+ secure: True
68+ root-keys:
69+ 3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
70+ 443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1
71+ a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82
72+ bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413
73+ c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56
74+ d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee
75+
76+ index-state:
77+ , cardano-haskell-packages 2026-02-13T00:00:02Z
78+ ```
6479
65- 2 . Add the following stanza to the file ` cabal.project `
80+ To find the appropriate index state to fill above, look for
81+ ` cooked-validators ` on [ CHaP's packages
82+ list] ( https://chap.intersectmbo.org/all-packages/ ) .
83+
84+ 2 . Alternatively, if you want to rely on a specific commit or branch not
85+ available on CHaP, you can import ` cooked-validators ` directly from GitHub
86+ with the following stanza:
87+
6688 ``` cabal.project
6789 source-repository-package
6890 type: git
@@ -71,84 +93,128 @@ the `packages` stanza.
7193 subdir:
7294 .
7395 ```
96+
7497 where ` myTag ` is either a commit hash in the repo, or a tag, such as v8.0.0
7598 (see [ available
7699 releases] ( https://github.com/tweag/cooked-validators/releases ) ).
100+
101+ Note that, should you do that, you would likely still need CHaP for all the
102+ other dependencies.
77103
78- 3 . Each release of ` cooked-validators ` is pinned to a specific version of
79- [ ` cardano-api ` ] ( https://github.com/IntersectMBO/cardano-api ) which in turn
80- pins the versions of all other Cardano-related dependencies (including
81- Plutus). Make sure your project relies on the same version.
104+ Each release of ` cooked-validators ` is pinned to a specific version of
105+ [ ` cardano-api ` ] ( https://github.com/IntersectMBO/cardano-api ) which in turn pins
106+ the versions of all other Cardano-related dependencies (including Plutus). Make
107+ sure your project relies on the same version.
82108
83109## Example
84110
85111This example shows how to create and validate a simple transaction that
86- transfers 10 Ada from wallet 1 to wallet 2, without manually handling fees or
87- balancing.
112+ transfers 10 Ada from Alice ( wallet 1) to Bob ( wallet 2) , without manually
113+ handling fees or balancing.
88114
89- 1 . Enter a Cabal read-eval-print-loop (with ` cabal repl ` )
115+ 1 . Create a new Haskell module, for example ` Demo.hs `
90116
911172 . Import your required dependencies
92118 ``` haskell
93119 > import Cooked
94- > import qualified Plutus.Script.Utils. Value as Script
120+ > import Plutus.Script.Utils. Value qualified as Script
95121 ```
96122
97- 3 . Define a transaction which transfers 10 Ada from wallet 1 to wallet 2
123+ 3 . Start the definition of a ` MockChain ` run:
98124 ``` haskell
99- let myTransaction = txSkelTemplate {txSkelOuts = [wallet 2 `receives` Value (Script. ada 10 )], txSkelSignatories = txSkelSignatoriesFromList [wallet 1 ]}
125+ > myDemoRun :: StagedMockChain ()
126+ > myDemoRun = do
127+ ```
128+
129+ 4 . Define aliases for Alice and Bob:
130+ ``` haskell
131+ > alice <- define " Alice" $ wallet 1
132+ > bob <- define " Bob" $ wallet 2
133+ ```
134+
135+ 5 . Give some initial funds to Alice:
136+ ``` haskell
137+ > forceOutputs_ $ replicate 3 $ alice `receives` Value (Script. ada 10 )
138+ ```
139+
140+ 5 . Take some notes:
141+ ``` haskell
142+ > noteS " Alice is sending 10 ADA to Bob"
143+ > noteS " I let cooked-validators do the heavy lifting for me"
144+ ```
145+
146+ 6 . Submit the transaction:
147+ ``` haskell
148+ > validateTxSkel_
149+ > txSkelTemplate
150+ > { txSkelOuts = [bob `receives` Value (Script. ada 10 )],
151+ > txSkelSignatories = txSkelSignatoriesFromList [wallet 1 ]
152+ > }
153+ ```
154+
155+ 7 . Lookup for the UTxOs now owned by Bob, and assert that he indeed possesses 1:
156+ ``` haskell
157+ > bobUtxos <- utxosAt bob
158+ > assert " Bob now has 1 utxo" $ length bobUtxos == 1
100159 ```
101160
102- 4 . Send the transaction for validation, and request the printing of the run
161+ 8 . Enter a ` cabal repl ` , run and print the trace:
103162 ``` haskell
104- printCooked . runMockChain . validateTxSkel_ $ myTransaction
163+ printCooked $ runMockChainDef myDemoRun
105164 ```
106165
107- 5 . Observe the log of the run, including:
108- - The original skeleton, and its balanced counterpart
109- - The associated fee and collaterals
110- - The final mockchain state, with every wallet's assets (notice the 10 ADA
111- payment owned by wallet 2)
112- - The value returned by the run (here `()` as we used `validateTxSkel_`)
113- ``` haskell
166+ 5 . Observe the output of printing the run, including:
167+ - The notes you've taken
168+ - The log produced by cooked, with, the original submitted skeleton as well
169+ as the adjusted and balanced skeletong with computed fee and collaterals.
170+ - The assertions you've made and their evaluation.
171+ - The final mockchain state, with every peer's assets (notice the 10 ADA
172+ payment owned by Bob).
173+ - The value returned by the run (here ` () ` ).
174+
175+
176+ ```
177+ 📔 Notes:
178+ - Alice is going to send 10 ADA to Bob
179+ - I let cooked-validators do the heavy lifting for me
114180 📖 MockChain run log:
115181 ⁍ New raw skeleton submitted to the adjustment pipeline:
116182 - Validity interval: (-∞ , +∞)
117183 - Signatories:
118- - wallet 1 [balancing]
184+ - Alice [balancing]
119185 - Outputs:
120- - Pays to pubkey wallet 2
186+ - Pays to pubkey Bob
121187 - Lovelace: 10_000_000
122188 ⁍ New adjusted skeleton submitted for validation:
123189 - Validity interval: (-∞ , +∞)
124190 - Signatories:
125- - wallet 1 [balancing]
191+ - Alice [balancing]
126192 - Inputs:
127- - Spends # 4480 b35 ! 3 from pubkey wallet 1
193+ - Spends #d769532!1 from pubkey Alice
128194 - Redeemer ()
129- - Lovelace : 100_000_000
195+ - Lovelace: 10_000_000
196+ - Spends #d769532!2 from pubkey Alice
197+ - Redeemer ()
198+ - Lovelace: 10_000_000
130199 - Outputs:
131- - Pays to pubkey wallet 2
200+ - Pays to pubkey Bob
132201 - Lovelace: 10_000_000
133- - Pays to pubkey wallet 1
134- - Lovelace : 89_828_383
135- - Fee : Lovelace : 171_617
202+ - Pays to pubkey Alice
203+ - Lovelace: 9_826_799
204+ - Fee: Lovelace: 173_201
136205 - No collateral required
137206 ⁍ New transaction successfully validated:
138- - Transaction id : # c095342
207+ - Transaction id: #bff7a56
139208 - Number of new outputs: 2
140- ✅ UTxO state:
141- • pubkey wallet 1
142- - Lovelace : 89_828_383
143- - (× 3 ) Lovelace : 100_000_000
144- • pubkey wallet 2
209+ ✅ Assertions:
210+ - ✔ Bob now has 1 utxo
211+ 💰 UTxO state:
212+ • pubkey Alice
213+ - Lovelace: 9_826_799
214+ - Lovelace: 10_000_000
215+ • pubkey Bob
145216 - Lovelace: 10_000_000
146- - (× 4 ) Lovelace : 100_000_000
147- • pubkey wallet 3
148- - (× 4 ) Lovelace : 100_000_000
149- • pubkey wallet 4
150- - (× 4 ) Lovelace : 100_000_000
151- 🟢 Returned value: ()
217+ 🟢 Success with returned value: ()
152218 ```
153219
154220## Documentation
0 commit comments