|
5 | 5 | [herc badge]: https://img.shields.io/badge/ci--by--hercules-green.svg
|
6 | 6 | [herc link]: https://hercules-ci.com/github/mlabs-haskell/plutip
|
7 | 7 |
|
8 |
| -Plutip is Cardano tool for spawning local clusters. |
9 |
| -Use it to start up disposable private network with arbitrary amount of funded addresses (providing keys for that addresses as well). |
| 8 | +Plutip is a Cardano tool for spawning local clusters. |
| 9 | +You can use it to start up disposable private network with an arbitrary amount of funded addresses (Plutip will provide corresponding key pairs as well). |
10 | 10 |
|
11 |
| -TLDR: `plutip :: IO CardanoNodeSocket` where the node belongs to a small cluster, optionally you can ask for prefunded keys. |
| 11 | +For smart contract testing see [CTL integration with Plutip](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/doc/plutip-testing.md). |
12 | 12 |
|
13 |
| -## Requirements |
| 13 | +**TL;DR**: plutip gets you a cardano node socket where the node belongs to a small cluster on a private network, and you can prefund addresses with ADA. |
14 | 14 |
|
15 |
| -Best way of building and launching Plutip libraries is using `Nix` and `cabal`. E.g. to start local network with two funded addresses run |
| 15 | +<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> |
| 16 | +**Table of Contents** |
16 | 17 |
|
17 |
| -```bash |
18 |
| -nix build .#plutip-core:exe:local-cluster |
19 |
| -./result/bin/local-cluster -n 2 |
20 |
| -``` |
| 18 | +- [Plutip](#plutip) |
| 19 | + - [Prerequisites](#prerequisites) |
| 20 | + - [When using Plutip as a Haskell library](#when-using-plutip-as-a-haskell-library) |
| 21 | + - [Quick start](#quick-start) |
| 22 | + - [Run as an executable](#run-as-an-executable) |
| 23 | + - [Use in a Haskell program](#use-in-a-haskell-program) |
| 24 | + - [Overview](#overview) |
| 25 | + - [As a library](#as-a-library) |
| 26 | + - [As an executable](#as-an-executable) |
| 27 | + - [Via CTL for contract testing](#via-ctl-for-contract-testing) |
| 28 | + - [Tutorials](#tutorials) |
| 29 | + - [Advanced network setup](#advanced-network-setup) |
| 30 | + - [Useful links](#useful-links) |
| 31 | + - [Plutip for integration testing of smart contracts](#plutip-for-integration-testing-of-smart-contracts) |
| 32 | + - [Maintenance](#maintenance) |
21 | 33 |
|
22 |
| -or |
| 34 | +<!-- markdown-toc end --> |
23 | 35 |
|
24 |
| -```bash |
25 |
| -nix develop |
26 |
| -cabal run local-cluster -- -n 2 |
27 |
| -``` |
| 36 | +## Prerequisites |
| 37 | + |
| 38 | +1. [Nix](https://nix.dev/tutorials/install-nix) |
| 39 | +2. [Set up haskell.nix binary cache](https://input-output-hk.github.io/haskell.nix/tutorials/getting-started#setting-up-the-binary-cache) |
| 40 | + |
| 41 | +### When using Plutip as a Haskell library |
28 | 42 |
|
29 | 43 | If your project is importing and making use of `Plutip`s library you will need to make sure that the following executables are present in your `PATH`:
|
30 | 44 |
|
31 | 45 | * `cardano-cli` executable available in the environment
|
32 | 46 | * `cardano-node` executable available in the environment
|
33 | 47 |
|
34 |
| -And the following ghc flag must to be set for the test execution: `-Wall -threaded -rtsopts` |
| 48 | +The following GHC flags must be used in order for Plutip to run: `-threaded -rtsopts`. |
35 | 49 |
|
36 |
| -## NOTES |
37 |
| - |
38 |
| -⚠️ This branch launches local network in `Vasil`. It was tested with node `1.35.4` (this node version used in nix environment as well). Please use appropriate node version when setting up own binaries in `PATH`. |
| 50 | +**NOTE:** This branch launches local network in `Vasil`. |
| 51 | +It was tested with node `1.35.4` (this node version is used in the Nix environment as well). |
| 52 | +Please use an appropriate node version when setting up own binaries in `PATH`. |
39 | 53 |
|
40 | 54 | ## Quick start
|
41 | 55 |
|
42 |
| -Launch local cluster with: |
| 56 | +### Run as an executable |
| 57 | + |
| 58 | +```bash |
| 59 | +nix run github:mlabs-haskell/plutip#plutip-core:exe:local-cluster -- --help |
| 60 | + |
| 61 | +# start local network with 2 funded addresses 10,000 ADA each |
| 62 | +nix run github:mlabs-haskell/plutip#plutip-core:exe:local-cluster -- -n 2 |
| 63 | + |
| 64 | +# or if you want to use the local version, clone the repo and then |
| 65 | +nix run .#plutip-core:exe:local-cluster -- --help |
43 | 66 | ```
|
| 67 | + |
| 68 | +### Use in a Haskell program |
| 69 | + |
| 70 | +Launch local cluster with: |
| 71 | +```haskell |
44 | 72 | withCluster :: PlutipConfig -> (ClusterEnv -> IO a) -> IO a
|
| 73 | +withCluster conf action |
45 | 74 | ```
|
46 | 75 | Use `withFundedCluster` to additionaly receive pre-funded keys.
|
47 | 76 |
|
48 |
| -Cluster shutdowns when the user action completes. Use `startCluster`/`startFundedCluster` and `stopCluster` variants to keep cluster running. |
| 77 | +Cluster shuts down when the user action (second argument to `withCluster`) completes. |
| 78 | +Use `startCluster`/`startFundedCluster` and `stopCluster` variants to keep the cluster running. |
49 | 79 |
|
50 | 80 | ## Overview
|
51 | 81 |
|
52 |
| -Plutip is in essence a simpler wrapper on some cardano-wallet code for spawning private disposable cardano clusters. |
53 |
| -It can be used in few ways: |
54 |
| - 1. as a library |
55 |
| - 2. as an executable |
56 |
| - 3. indirectly via cardano-transaction-lib e2e plutip tests. This is a facility for testing contracts e2e in isolated environment: with wallet mocks and a private plutip cluster. See [ctl](https://github.com/Plutonomicon/cardano-transaction-lib/tree/develop) and their documentation on e2e tests. That's very much the recommended way if you're a ctl user. |
57 |
| - 4. Historical mention: you could test pab `Contract`s with plutip itself, but this functionality is unmantained and was removed. If you're interested check out the archive branch `plutip-bpi`. |
| 82 | +Plutip is in essence a simpler wrapper over some `cardano-wallet` code for spawning private disposable Cardano clusters. |
| 83 | + |
| 84 | +It can be used in a few ways: |
| 85 | + 1. as a library, |
| 86 | + 2. as an executable, |
| 87 | + 3. indirectly via cardano-transaction-lib (CTL) smart contract tests. This is a facility for testing contracts in an isolated environment: with wallet mocks and a private plutip cluster. See [CTL](https://github.com/Plutonomicon/cardano-transaction-lib/) and their [documentation](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/doc/testing.md#testing-with-plutip) on Plutip tests. That's very much the recommended way if you're a CTL user. |
| 88 | + 4. Historical mention: you could test PAB `Contract`s with Plutip itself, but this functionality is unmantained and was removed as most users switched to [CTL](https://github.com/Plutonomicon/cardano-transaction-lib/). If you're interested check out the archive branch [`plutip-bpi`](https://github.com/mlabs-haskell/plutip/tree/plutip-bpi) and the old [tutorial](https://github.com/mlabs-haskell/plutip/blob/plutip-bpi/docs/interactive-plutip.md). |
58 | 89 |
|
59 | 90 | ### As a library
|
60 | 91 |
|
61 | 92 | Launch local cluster with
|
62 |
| -``` |
| 93 | +```haskell |
63 | 94 | withCluster :: PlutipConfig -> (ClusterEnv -> IO a) -> IO a
|
| 95 | +withCluster conf action |
64 | 96 | ```
|
65 |
| -where |
66 |
| - - `PlutipConfig` specifies the working directory of a spawned cluster (can be temporary) and in some capacity the parameters of the cluster. Use `Data.Default (def)` to spawn default cluster in temporary directory. |
| 97 | +where: |
| 98 | + - `conf :: PlutipConfig` specifies the working directory of a spawned cluster (can be temporary) and in some capacity the parameters of the cluster. Use `Data.Default (def)` to spawn default cluster in a temporary directory. |
67 | 99 | - `ClusterEnv` is essentially a wrapper around the node socket. The socket belongs to one of the nodes.
|
| 100 | + - `action :: ClusterEnv -> IO a` is a user action which has access to a `cardano-node` in a cluster via `Cardano.Api`. |
68 | 101 |
|
69 | 102 | Use
|
70 |
| -``` |
| 103 | +```haskell |
71 | 104 | withFundedCluster :: PlutipConfig -> [[Lovelace]] -> (ClusterEnv -> [KeyPair] -> IO a) -> IO a
|
72 | 105 | ```
|
73 |
| -to additionaly receive keys prefunded with specified fund distributions (i.e. Key 1 with [1 Lovelace] and Key 2 with [2 Lovelace, 4 Lovelace]). |
| 106 | +to additionaly receive keys prefunded with specified fund distributions (e.g. Key 1 with `[1 Lovelace]` and Key 2 with `[2 Lovelace, 4 Lovelace]`). |
74 | 107 |
|
75 |
| -Additionaly there's helpers `startCluster`, `startFundedCluster`, `stopCluster` useful when you want your cluster to keep running, instead of close after the IO action is completed. |
| 108 | +Additionaly there are helpers `startCluster`, `startFundedCluster`, `stopCluster` which are useful when you want your cluster to keep running, instead of shutting down after the IO action is completed. |
76 | 109 |
|
77 |
| -Full example: |
78 |
| -``` |
| 110 | +Example: |
| 111 | +```haskell |
79 | 112 | import Data.Default (Default (def))
|
80 | 113 | import Plutip.CardanoApi (currentBlock)
|
81 | 114 | import Plutip.Cluster (withFundedCluster)
|
82 | 115 | import Plutip.Keys (cardanoMainnetAddress)
|
83 | 116 |
|
84 | 117 | main = withFundedCluster def [[ada 1], [ada 2, ada 4]] $ \cenv [key1, key2] -> do
|
85 | 118 | -- You have a default cluster using a temporary directory for storage and 7 Ada to use wisely.
|
86 |
| - -- You can i.e. query the node for block number with |
| 119 | + -- You can query the node for block number with |
87 | 120 | res <- currentBlock cenv
|
88 | 121 | ...
|
89 | 122 | -- See Plutip.CardanoApi for example queries and construct your own queries with Cardano.Api.
|
90 | 123 | -- To make use of your keys, also use Cardano.Api.
|
91 | 124 |
|
92 | 125 | ada = (*) 1_000_000
|
93 |
| -
|
94 | 126 | ```
|
95 | 127 |
|
96 | 128 | ### As an executable
|
97 | 129 |
|
98 |
| -Plutip provides a `local-cluster` executable. You can build it and run with nix package manager: |
99 |
| -``` |
| 130 | +Plutip provides a `local-cluster` executable. |
| 131 | +You can build it and run with Nix: |
| 132 | +```bash |
100 | 133 | nix run github:mlabs-haskell/plutip#plutip-core:exe:local-cluster -- --help
|
101 | 134 | ```
|
102 |
| -Available options mostly match the `withFundedCluster` interface, see `--help` and [README](local-cluster/README.md). |
103 | 135 |
|
104 |
| -### Via CTL |
| 136 | +Available options mostly match the `withFundedCluster` interface, see `--help` and [local-cluster README](local-cluster/README.md) for detailed description of the arguments. |
| 137 | + |
| 138 | +### Via CTL for contract testing |
105 | 139 |
|
106 |
| -CTL is a purescript sdk for creating dapps. One of its features is ability to test contracts with private networks, see [plutip-testing](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/doc/plutip-testing.md). |
| 140 | +[CTL](https://github.com/Plutonomicon/cardano-transaction-lib) is a PureScript SDK for creating DApps. |
| 141 | +One of its features is the ability to test contracts on disposable private networks which Plutip sets up, see [plutip-testing](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/doc/plutip-testing.md). |
| 142 | +CTL provides (via Nix) a runtime environment containing several services, including [plutip-server](https://github.com/Plutonomicon/cardano-transaction-lib/tree/develop/plutip-server) which allows to control Plutip via HTTP. |
| 143 | +As long as you are using CTL's Nix environment (or your setup is based on it) there's no need to install Plutip separately. |
| 144 | +<!-- See a full working example of a CTL-based project with smart contract tests is [here](...). You can base your project's structure on it. --> |
107 | 145 |
|
108 | 146 | ## Tutorials
|
109 | 147 |
|
110 |
| -* [Running disposable local network and building own runners](./local-cluster/README.md) |
111 |
| -* [Running Contracts is REPL](./docs/interactive-plutip.md) |
| 148 | +* [Running disposable local network and building custom runners](./local-cluster/README.md) |
| 149 | +<!-- * [CTL-based project with smart contract tests example](...) --> |
112 | 150 |
|
113 | 151 | ## Advanced network setup
|
114 | 152 |
|
115 | 153 | * [Tweaking local network](./docs/tweaking-network.md)
|
116 |
| -* [Regenerating network configs](./docs/regenerate-network-configs.md) |
| 154 | +* [How to (re)generate network configs from node config and genesis files](./docs/regenerate-network-configs.md) |
117 | 155 |
|
118 |
| -## Examples |
| 156 | +## Useful links |
119 | 157 |
|
120 |
| -* [Starting private network from Haskell and executing contract](./contract-execution/Main.hs) |
121 |
| -* [Template for setting a Nix flake that includes Plutip](https://github.com/MitchyCola/plutip-flake). Kudos to @MitchyCola |
| 158 | +* [Template for setting up a Nix flake that includes Plutip](https://github.com/MitchyCola/plutip-flake). Kudos to @MitchyCola |
122 | 159 |
|
123 |
| -## Plutip for integration testing smart contracts |
| 160 | +## Plutip for integration testing of smart contracts |
124 | 161 |
|
125 | 162 | If your goal is to:
|
126 |
| -* build tests with `tasty` Haskell framework where user can run Plutus contracts (`Contract w s e a`) using mentioned above private network |
127 |
| -* run contracts in REPL on local network |
| 163 | +* run tests with the `tasty` Haskell framework where user can run Plutus contracts (`Contract w s e a`) using the disposable private network set up by Plutip, |
| 164 | +* run contracts in REPL on a local network, |
128 | 165 |
|
129 |
| -then check out [CTL](https://github.com/Plutonomicon/cardano-transaction-lib) or legacy plutip revision at branch `plutip-bpi`. |
| 166 | +then check out [CTL](https://github.com/Plutonomicon/cardano-transaction-lib) or a legacy Plutip revision ([`plutip-bpi`](https://github.com/mlabs-haskell/plutip/tree/plutip-bpi)) or Plutip v1.3.1 and older releases. |
130 | 167 |
|
131 | 168 | ## Maintenance
|
132 | 169 |
|
133 |
| -* [Important notes on updating `cardano-wallet` dependency](./docs/cardano-wallet-update.md) |
| 170 | +* [Important notes on updating the `cardano-wallet` dependency](./docs/cardano-wallet-update.md) |
0 commit comments