You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,11 @@ If your project is importing and making use of `Plutip`s library you will need t
36
36
37
37
And the following ghc flag must to be set for the test execution: `-Wall -threaded -rtsopts`
38
38
39
-
NOTE: This branch launches local network in `Vasil`. It was tested with node `1.35.3` (this node version used in nix environment as well). Please use appropriate node version when setting up own binaries in `PATH`.
39
+
## NOTES
40
+
41
+
⚠️ This branch launches local network in `Vasil`. It was tested with node `1.35.3` (this node version used in nix environment as well). Please use appropriate node version when setting up own binaries in `PATH`.
Before running *any* contract `Plutip` under the hood creates dedicated UTxO at "own" wallet address to be used *only* as collateral. This UTxO is created by submitting transaction and spending "own" wallet's funds . For collateral `Plutip` always uses **10 Ada** at this point and if wallet address already has UTxO with 10 Ada on it, then Plutip will use it as collateral.
4
+
5
+
UTxO that was created or picked for collateral is stored in memory, so during Contract execution `Plutip` will always use this exact same UTxO. Collateral UTxO has special properties - to guard it from being consumed by accident it is not accessible from Contract. I.e. calls like `utxosAt`***will not return*** UTxO used for collateral. This means, that users don't have to care really about collateral UTxO during contract execution.
6
+
7
+
The only place where collateral "sticks out" is the moment of wallet creation. Ii is also visible for `cardano-cli` queries.
8
+
9
+
## Cluster runner
10
+
11
+
With [cluster runners](../local-cluster/README.md), when creating wallet with `addSomeWallet [100_000_000]`, if you want to have UTxO with exactly 100 Ada while running the Contract, you should add 10 Ada more to wallet's initial distribution, or UTxO with 100 Ada will be used to create collateral.
12
+
13
+
E.g.:
14
+
15
+
```haskell
16
+
main::IO()
17
+
main =do
18
+
let executeContract wallet contract =
19
+
ask >>=\cEnv -> runContract cEnv wallet contract
20
+
21
+
(st, _) <- startCluster def $do
22
+
w <- addSomeWallet [100_000_000, 10_000_000] -- 10 Ada will be used as collateral
23
+
awaitWalletFunded w 1
24
+
result <- executeContract w someContract
25
+
doSomething result
26
+
stopCluster st
27
+
```
28
+
29
+
Or just make helper function:
30
+
31
+
```haskell
32
+
addSomeWalletWithCollateral funds =
33
+
addSomeWallet (toAda 10: funds)
34
+
```
35
+
36
+
## Tasty integration
37
+
38
+
For collateral handling in tasty integration see [Collateral handling section](./tasty-integration.md#collateral-handling).
Copy file name to clipboardexpand all lines: docs/tasty-integration.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -126,7 +126,9 @@ To assert the final `Value` which `wallet` will have after contract execution sp
126
126
*`initAdaAssertValue [100] 133` - initialize `wallet` with single UTxO with 100 Ada and check that after contract execution final `Value` of all `wallet`'s UTxOs is equal to 133 Ada.
127
127
*`initAndAssertLovelaceWith [1_000_000] VGt 2_000_000` - initialize `wallet` with single UTxO with 1000000 Lovelace and check that after contract execution final `Value` of all `wallet`'s UTxOs is *greater than* 2000000 Lovelace.
128
128
129
-
***One important note*** is that Plutip creates dedicated UTxO to be used *only* as collateral under the hood. This UTxO would normally be created by spending wallets funds, and the transaction fee and Ada amount used for collateral UTxO would mess up balance assertions. So when using assertions for `Value` it is advised to wrap `wallets` initialization with `withCollateral` function. This simply adds a small UTxO to the `wallets`'s balance during network setup that is then picked up for collateral instead avoiding the problem. Use it like so:
129
+
#### Collateral handling
130
+
131
+
***One important note*** is that Plutip creates dedicated UTxO to be used *only* as collateral under the hood. This UTxO would normally be created by spending wallets funds, and the transaction fee and Ada amount used for collateral UTxO would mess up balance assertions. So when using any kind of assertions for `Value` it is advised to wrap `wallets` initialization with `withCollateral` function. This simply adds a small UTxO to the `wallets`'s balance during network setup that is then picked up for collateral instead avoiding the problem. Use it like so:
0 commit comments