Skip to content

Commit

Permalink
feat: puya debugging support (#106)
Browse files Browse the repository at this point in the history
* refactor: disable persisting sources.avm.json by default; deprecate `persist_sourcemaps`

* docs: refresh docs

* chore: tweak docs

* chore: pip audit

* chore: bump deprecation version

* chore: updating teal.tok.map to teal.map extension

* fix: set state_change to true in simulate_response method

* chore: removing the # delimeter from trace file names

* chore: remove sources.avm.json generation as part of persist sourcemaps

* fix: filename generation for trace files and add a unit test
  • Loading branch information
aorumbayev authored Nov 25, 2024
1 parent 5df807f commit 4606bc7
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ Bases: {py:obj}`algokit_utils._transfer.TransferParametersBase`
````


````{py:function} persist_sourcemaps(*, sources: list[algokit_utils._debugging.PersistSourceMapInput], project_root: pathlib.Path, client: algosdk.v2client.algod.AlgodClient, with_sources: bool = True) -> None
````{py:function} persist_sourcemaps(*, sources: list[algokit_utils._debugging.PersistSourceMapInput], project_root: pathlib.Path, client: algosdk.v2client.algod.AlgodClient, with_sources: bool = True, persist_mappings: bool = False) -> None
:canonical: algokit_utils._debugging.persist_sourcemaps

```{autodoc2-docstring} algokit_utils._debugging.persist_sourcemaps
Expand Down
21 changes: 10 additions & 11 deletions docs/html/_sources/capabilities/debugger.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ The AlgoKit Python Utilities package provides a set of debugging tools that can

The `config.py` file contains the `UpdatableConfig` class which manages and updates configuration settings for the AlgoKit project. The class has the following attributes:

- `debug`: Indicates whether debug mode is enabled.
- `project_root`: The path to the project root directory. Can be ignored if you are using `algokit_utils` inside an `algokit` compliant project (containing `.algokit.toml` file). For non algokit compliant projects, simply provide the path to the folder where you want to store sourcemaps and traces to be used with [`AlgoKit AVM Debugger`](https://github.com/algorandfoundation/algokit-avm-vscode-debugger). Alternatively you can also set the value via the `ALGOKIT_PROJECT_ROOT` environment variable.
- `trace_all`: Indicates whether to trace all operations. Defaults to false, this means that when debug mode is enabled, any (or all) application client calls performed via `algokit_utils` will store responses from `simulate` endpoint. These files are called traces, and can be used with `AlgoKit AVM Debugger` to debug TEAL source codes, transactions in the atomic group and etc.
- `trace_buffer_size_mb`: The size of the trace buffer in megabytes. By default uses 256 megabytes. When output folder containing debug trace files exceedes the size, oldest files are removed to optimize for storage consumption.
- `max_search_depth`: The maximum depth to search for a an `algokit` config file. By default it will traverse at most 10 folders searching for `.algokit.toml` file which will be used to assume algokit compliant project root path.
- `debug`: Indicates whether debug mode is enabled.
- `project_root`: The path to the project root directory. Can be ignored if you are using `algokit_utils` inside an `algokit` compliant project (containing `.algokit.toml` file). For non algokit compliant projects, simply provide the path to the folder where you want to store sourcemaps and traces to be used with [`AlgoKit AVM Debugger`](https://github.com/algorandfoundation/algokit-avm-vscode-debugger). Alternatively you can also set the value via the `ALGOKIT_PROJECT_ROOT` environment variable.
- `trace_all`: Indicates whether to trace all operations. Defaults to false, this means that when debug mode is enabled, any (or all) application client calls performed via `algokit_utils` will store responses from `simulate` endpoint. These files are called traces, and can be used with `AlgoKit AVM Debugger` to debug TEAL source codes, transactions in the atomic group and etc.
- `trace_buffer_size_mb`: The size of the trace buffer in megabytes. By default uses 256 megabytes. When output folder containing debug trace files exceedes the size, oldest files are removed to optimize for storage consumption.
- `max_search_depth`: The maximum depth to search for a an `algokit` config file. By default it will traverse at most 10 folders searching for `.algokit.toml` file which will be used to assume algokit compliant project root path.

The `configure` method can be used to set these attributes.

Expand All @@ -26,8 +26,7 @@ config.configure(debug=True)

Debugging utilities can be used to simplify gathering artifacts to be used with [AlgoKit AVM Debugger](https://github.com/algorandfoundation/algokit-avm-vscode-debugger) in non algokit compliant projects. The following methods are provided:

- `persist_sourcemaps`: This method persists the sourcemaps for the given sources as AVM Debugger compliant artifacts. It takes a list of `PersistSourceMapInput` objects, a `Path` object representing the root directory of the project, an `AlgodClient` object for interacting with the Algorand blockchain, and a boolean indicating whether to dump teal source files along with sourcemaps.
- `simulate_and_persist_response`: This method simulates the atomic transactions using the provided `AtomicTransactionComposer` object and `AlgodClient` object, and persists the simulation response to an AVM Debugger compliant JSON file. It takes an `AtomicTransactionComposer` object representing the atomic transactions to be simulated and persisted, a `Path` object representing the root directory of the project, an `AlgodClient` object representing the Algorand client, and a float representing the size of the trace buffer in megabytes.
- `simulate_and_persist_response`: This method simulates the atomic transactions using the provided `AtomicTransactionComposer` object and `AlgodClient` object, and persists the simulation response to an AVM Debugger compliant JSON file. It takes an `AtomicTransactionComposer` object representing the atomic transactions to be simulated and persisted, a `Path` object representing the root directory of the project, an `AlgodClient` object representing the Algorand client, and a float representing the size of the trace buffer in megabytes.

### Trace filename format

Expand All @@ -39,8 +38,8 @@ The trace files are named in a specific format to provide useful information abo

Where:

- `timestamp`: The time when the trace file was created, in ISO 8601 format, with colons and periods removed.
- `last_round`: The last round when the simulation was performed.
- `transaction_types`: A string representing the types and counts of transactions in the atomic group. Each transaction type is represented as `${count}#${type}`, and different transaction types are separated by underscores.
- `timestamp`: The time when the trace file was created, in ISO 8601 format, with colons and periods removed.
- `last_round`: The last round when the simulation was performed.
- `transaction_types`: A string representing the types and counts of transactions in the atomic group. Each transaction type is represented as `${count}${type}`, and different transaction types are separated by underscores.

For example, a trace file might be named `20220301T123456Z_lr1000_2#pay_1#axfer.trace.avm.json`, indicating that the trace file was created at `2022-03-01T12:34:56Z`, the last round was `1000`, and the atomic group contained 2 payment transactions and 1 asset transfer transaction.
For example, a trace file might be named `20220301T123456Z_lr1000_2pay_1axfer.trace.avm.json`, indicating that the trace file was created at `2022-03-01T12:34:56Z`, the last round was `1000`, and the atomic group contained 2 payment transactions and 1 asset transfer transaction.
6 changes: 4 additions & 2 deletions docs/html/apidocs/algokit_utils/algokit_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -1534,14 +1534,16 @@ <h3>Example<a class="headerlink" href="#example" title="Permalink to this headin

<dl class="py function">
<dt class="sig sig-object py" id="algokit_utils.persist_sourcemaps">
<span class="sig-prename descclassname"><span class="pre">algokit_utils.</span></span><span class="sig-name descname"><span class="pre">persist_sourcemaps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sources</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">algokit_utils._debugging.PersistSourceMapInput</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">project_root</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(in Python v3.13)"><span class="pre">pathlib.Path</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">client</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient" title="(in algosdk)"><span class="pre">algosdk.v2client.algod.AlgodClient</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">with_sources</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#algokit_utils.persist_sourcemaps" title="Permalink to this definition"></a></dt>
<span class="sig-prename descclassname"><span class="pre">algokit_utils.</span></span><span class="sig-name descname"><span class="pre">persist_sourcemaps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sources</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">algokit_utils._debugging.PersistSourceMapInput</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">project_root</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(in Python v3.13)"><span class="pre">pathlib.Path</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">client</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient" title="(in algosdk)"><span class="pre">algosdk.v2client.algod.AlgodClient</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">with_sources</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">persist_mappings</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></span></span><a class="headerlink" href="#algokit_utils.persist_sourcemaps" title="Permalink to this definition"></a></dt>
<dd><p>Persist the sourcemaps for the given sources as an AlgoKit AVM Debugger compliant artifacts.
Args:
sources (list[PersistSourceMapInput]): A list of PersistSourceMapInput objects.
project_root (Path): The root directory of the project.
client (AlgodClient): An AlgodClient object for interacting with the Algorand blockchain.
with_sources (bool): If True, it will dump teal source files along with sourcemaps.
Default is True, as needed by an AlgoKit AVM debugger.</p>
Default is True, as needed by an AlgoKit AVM debugger.
persist_mappings (bool): Enables legacy behavior of persisting the <code class="docutils literal notranslate"><span class="pre">sources.avm.json</span></code> mappings to
the project root. Default is False, given that the AlgoKit AVM VSCode extension will manage the mappings.</p>
</dd></dl>

<dl class="py function">
Expand Down
5 changes: 2 additions & 3 deletions docs/html/capabilities/debugger.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ <h2>Configuration<a class="headerlink" href="#configuration" title="Permalink to
<h2>Debugging Utilities<a class="headerlink" href="#debugging-utilities" title="Permalink to this heading"></a></h2>
<p>Debugging utilities can be used to simplify gathering artifacts to be used with <a class="reference external" href="https://github.com/algorandfoundation/algokit-avm-vscode-debugger">AlgoKit AVM Debugger</a> in non algokit compliant projects. The following methods are provided:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">persist_sourcemaps</span></code>: This method persists the sourcemaps for the given sources as AVM Debugger compliant artifacts. It takes a list of <code class="docutils literal notranslate"><span class="pre">PersistSourceMapInput</span></code> objects, a <code class="docutils literal notranslate"><span class="pre">Path</span></code> object representing the root directory of the project, an <code class="docutils literal notranslate"><span class="pre">AlgodClient</span></code> object for interacting with the Algorand blockchain, and a boolean indicating whether to dump teal source files along with sourcemaps.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">simulate_and_persist_response</span></code>: This method simulates the atomic transactions using the provided <code class="docutils literal notranslate"><span class="pre">AtomicTransactionComposer</span></code> object and <code class="docutils literal notranslate"><span class="pre">AlgodClient</span></code> object, and persists the simulation response to an AVM Debugger compliant JSON file. It takes an <code class="docutils literal notranslate"><span class="pre">AtomicTransactionComposer</span></code> object representing the atomic transactions to be simulated and persisted, a <code class="docutils literal notranslate"><span class="pre">Path</span></code> object representing the root directory of the project, an <code class="docutils literal notranslate"><span class="pre">AlgodClient</span></code> object representing the Algorand client, and a float representing the size of the trace buffer in megabytes.</p></li>
</ul>
<section id="trace-filename-format">
Expand All @@ -123,9 +122,9 @@ <h3>Trace filename format<a class="headerlink" href="#trace-filename-format" tit
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">timestamp</span></code>: The time when the trace file was created, in ISO 8601 format, with colons and periods removed.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">last_round</span></code>: The last round when the simulation was performed.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">transaction_types</span></code>: A string representing the types and counts of transactions in the atomic group. Each transaction type is represented as <code class="docutils literal notranslate"><span class="pre">${count}#${type}</span></code>, and different transaction types are separated by underscores.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">transaction_types</span></code>: A string representing the types and counts of transactions in the atomic group. Each transaction type is represented as <code class="docutils literal notranslate"><span class="pre">${count}${type}</span></code>, and different transaction types are separated by underscores.</p></li>
</ul>
<p>For example, a trace file might be named <code class="docutils literal notranslate"><span class="pre">20220301T123456Z_lr1000_2#pay_1#axfer.trace.avm.json</span></code>, indicating that the trace file was created at <code class="docutils literal notranslate"><span class="pre">2022-03-01T12:34:56Z</span></code>, the last round was <code class="docutils literal notranslate"><span class="pre">1000</span></code>, and the atomic group contained 2 payment transactions and 1 asset transfer transaction.</p>
<p>For example, a trace file might be named <code class="docutils literal notranslate"><span class="pre">20220301T123456Z_lr1000_2pay_1axfer.trace.avm.json</span></code>, indicating that the trace file was created at <code class="docutils literal notranslate"><span class="pre">2022-03-01T12:34:56Z</span></code>, the last round was <code class="docutils literal notranslate"><span class="pre">1000</span></code>, and the atomic group contained 2 payment transactions and 1 asset transfer transaction.</p>
</section>
</section>
</section>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/searchindex.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docs/markdown/apidocs/algokit_utils/algokit_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ Returns:
dict[int, str]: A dictionary where the keys are the asset IDs and the values are the transaction IDs of
the executed transactions.

### algokit_utils.persist_sourcemaps(\*, sources: [list](https://docs.python.org/3/library/stdtypes.html#list)[algokit_utils._debugging.PersistSourceMapInput], project_root: [pathlib.Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path), client: [algosdk.v2client.algod.AlgodClient](https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient), with_sources: [bool](https://docs.python.org/3/library/functions.html#bool) = True) → [None](https://docs.python.org/3/library/constants.html#None)
### algokit_utils.persist_sourcemaps(\*, sources: [list](https://docs.python.org/3/library/stdtypes.html#list)[algokit_utils._debugging.PersistSourceMapInput], project_root: [pathlib.Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path), client: [algosdk.v2client.algod.AlgodClient](https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient), with_sources: [bool](https://docs.python.org/3/library/functions.html#bool) = True, persist_mappings: [bool](https://docs.python.org/3/library/functions.html#bool) = False) → [None](https://docs.python.org/3/library/constants.html#None)

Persist the sourcemaps for the given sources as an AlgoKit AVM Debugger compliant artifacts.
Args:
Expand All @@ -1058,6 +1058,8 @@ project_root (Path): The root directory of the project.
client (AlgodClient): An AlgodClient object for interacting with the Algorand blockchain.
with_sources (bool): If True, it will dump teal source files along with sourcemaps.
Default is True, as needed by an AlgoKit AVM debugger.
persist_mappings (bool): Enables legacy behavior of persisting the `sources.avm.json` mappings to
the project root. Default is False, given that the AlgoKit AVM VSCode extension will manage the mappings.

### algokit_utils.replace_template_variables(program: [str](https://docs.python.org/3/library/stdtypes.html#str), template_values: [algokit_utils.deploy.TemplateValueMapping](#algokit_utils.TemplateValueMapping)) → [str](https://docs.python.org/3/library/stdtypes.html#str)

Expand Down
Loading

1 comment on commit 4606bc7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit_utils
   _debugging.py1311589%20, 39–41, 44, 53, 61, 76, 80, 89, 103–107, 126
   _ensure_funded.py69199%99
   _transfer.py67396%13, 76–77
   account.py851385%14–17, 61–65, 96, 109, 136, 139, 183
   application_client.py5287785%59–60, 167, 172, 201, 313, 318–319, 321, 323, 788, 803, 821–824, 914, 954, 966, 979, 1021, 1081–1087, 1091–1096, 1098, 1134, 1141, 1254, 1284, 1298, 1336–1338, 1340, 1350–1407, 1418–1423, 1443–1446
   application_specification.py971189%92, 94, 193–202, 206
   asset.py79594%9, 27–30
   common.py13192%13
   config.py511865%38–39, 50, 55, 60, 64–69, 100–109
   deploy.py4632595%30–33, 168, 172–173, 190, 246, 362–363, 418, 429–437, 454–457, 467, 475, 668–669, 693
   dispenser_api.py821285%112–113, 117–120, 155–157, 176–178
   logic_error.py39295%8, 31
   models.py131695%45, 50–52, 61–62
   network_clients.py63395%93–94, 125
src/algokit_utils/beta
   account_manager.py551475%39–40, 64, 123–130, 183–187, 198–200
   algorand_client.py1011585%111–112, 121–122, 143–145, 154–155, 224, 259, 274, 290, 303, 319
   client_manager.py371073%40, 61–63, 68–70, 75–78
   composer.py3217278%335–336, 339–340, 343–344, 347–348, 355–356, 359–360, 389, 391, 393, 396, 399, 404, 407, 411, 414, 456–489, 494–505, 510–516, 521–529, 549–562, 566, 590, 593–610, 618, 643, 659–660, 662–663, 665–666, 668–669, 671–672, 678–682
TOTAL242630388% 

Tests Skipped Failures Errors Time
214 0 💤 0 ❌ 0 🔥 2m 8s ⏱️

Please sign in to comment.