Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: debugger related helpers and utils #61

Merged
merged 27 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
75e8c0d
chore: wip
aorumbayev Nov 20, 2023
7445c89
Auto stash before merge of "feat/debugger-support" and "origin/main"
aorumbayev Nov 22, 2023
8be9c41
feat: initial draft implementation for debugger support
aorumbayev Nov 22, 2023
32f3b47
refactor: addressing pr comments, adding extra tests
aorumbayev Nov 23, 2023
c57fccf
chore: regen docs; fix spinx docs bug
aorumbayev Nov 23, 2023
6296564
chore: renaming back to .tok.map
aorumbayev Nov 23, 2023
afe1c69
chore: updating name for traces files
aorumbayev Nov 24, 2023
5fa8a35
chore: addressing pr comments
aorumbayev Nov 24, 2023
3d7a164
chore: update src/algokit_utils/_debug_utils.py
aorumbayev Nov 27, 2023
e567258
refactor: addressing pr comments
aorumbayev Nov 27, 2023
f2d7371
chore: typo fix
aorumbayev Nov 27, 2023
3858095
chore: addressing pr comments
aorumbayev Nov 27, 2023
989813e
chore: windows runner
aorumbayev Nov 27, 2023
916fdec
chore: testing ci
aorumbayev Nov 27, 2023
4de25d4
chore: testing ci
aorumbayev Nov 27, 2023
a294cf5
chore: removing windows as its unsupported by official images, adding…
aorumbayev Nov 27, 2023
840e9dc
chore: merge conflict fixes
aorumbayev Nov 27, 2023
5a86bd5
chore: minor tweaks
aorumbayev Nov 27, 2023
b39b688
refactor: minor improvements
aorumbayev Nov 29, 2023
0b4cd21
chore: bumping cryptography for pip-audit
aorumbayev Nov 29, 2023
a8089d9
chore: fixing tests
aorumbayev Nov 29, 2023
24542a0
refactor: propagating comments from utils ts pr review
aorumbayev Dec 4, 2023
981a28b
chore: refining links to debugger
aorumbayev Dec 4, 2023
b3180ea
docs: regen docs
aorumbayev Dec 4, 2023
97c1c95
chore: fixing typo
aorumbayev Dec 8, 2023
ec61c4a
docs: updating information on how to read trace files
aorumbayev Dec 8, 2023
2771431
chore: refining links to the marketplace
aorumbayev Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions .github/workflows/build-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,34 @@ jobs:
build-python:
strategy:
matrix:
os: ["ubuntu-latest" ]
python: ["3.10"]
os: ["ubuntu-latest"]
python: ["3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: "poetry"

- name: Install pipx
run: |
python -m pip install --upgrade pip
python -m pip install pipx
python -m pipx ensurepath

- name: Cache Poetry
uses: actions/cache@v2
with:
path: ~/.local/share/pipx/venvs/poetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Install poetry
run: pipx install poetry

- name: Install dependencies
run: poetry install --no-interaction
Expand Down
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
]
},

// PowerShell
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"powershell.codeFormatting.preset": "Stroustrup"
// PowerShell
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"powershell.codeFormatting.preset": "Stroustrup",
"python.testing.pytestArgs": ["."]
}
205 changes: 200 additions & 5 deletions docs/html/_sources/apidocs/algokit_utils/algokit_utils.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ orphan: true
:parser: myst
:summary:
```
* - {py:obj}`Program <algokit_utils.application_client.Program>`
- ```{autodoc2-docstring} algokit_utils.application_client.Program
* - {py:obj}`Program <algokit_utils.common.Program>`
- ```{autodoc2-docstring} algokit_utils.common.Program
:parser: myst
:summary:
```
Expand All @@ -190,6 +190,11 @@ orphan: true
:parser: myst
:summary:
```
* - {py:obj}`TransactionParametersDict <algokit_utils.models.TransactionParametersDict>`
- ```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict
:parser: myst
:summary:
```
* - {py:obj}`TransactionResponse <algokit_utils.models.TransactionResponse>`
- ```{autodoc2-docstring} algokit_utils.models.TransactionResponse
:parser: myst
Expand Down Expand Up @@ -318,11 +323,31 @@ orphan: true
:parser: myst
:summary:
```
* - {py:obj}`opt_in <algokit_utils.asset.opt_in>`
- ```{autodoc2-docstring} algokit_utils.asset.opt_in
:parser: myst
:summary:
```
* - {py:obj}`opt_out <algokit_utils.asset.opt_out>`
- ```{autodoc2-docstring} algokit_utils.asset.opt_out
:parser: myst
:summary:
```
* - {py:obj}`persist_sourcemaps <algokit_utils._debugging.persist_sourcemaps>`
- ```{autodoc2-docstring} algokit_utils._debugging.persist_sourcemaps
:parser: myst
:summary:
```
* - {py:obj}`replace_template_variables <algokit_utils.deploy.replace_template_variables>`
- ```{autodoc2-docstring} algokit_utils.deploy.replace_template_variables
:parser: myst
:summary:
```
* - {py:obj}`simulate_and_persist_response <algokit_utils._debugging.simulate_and_persist_response>`
- ```{autodoc2-docstring} algokit_utils._debugging.simulate_and_persist_response
:parser: myst
:summary:
```
* - {py:obj}`transfer <algokit_utils._transfer.transfer>`
- ```{autodoc2-docstring} algokit_utils._transfer.transfer
:parser: myst
Expand Down Expand Up @@ -1502,16 +1527,16 @@ Bases: {py:obj}`enum.Enum`
`````

````{py:class} Program(program: str, client: algosdk.v2client.algod.AlgodClient)
:canonical: algokit_utils.application_client.Program
:canonical: algokit_utils.common.Program

```{autodoc2-docstring} algokit_utils.application_client.Program
```{autodoc2-docstring} algokit_utils.common.Program
:parser: myst
```

```{rubric} Initialization
```

```{autodoc2-docstring} algokit_utils.application_client.Program.__init__
```{autodoc2-docstring} algokit_utils.common.Program.__init__
:parser: myst
```

Expand Down Expand Up @@ -1713,6 +1738,144 @@ Bases: {py:obj}`enum.Enum`

`````

`````{py:class} TransactionParametersDict()
:canonical: algokit_utils.models.TransactionParametersDict

Bases: {py:obj}`typing.TypedDict`

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict
:parser: myst
```

```{rubric} Initialization
```

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.__init__
:parser: myst
```

````{py:attribute} accounts
:canonical: algokit_utils.models.TransactionParametersDict.accounts
:type: list[str]
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.accounts
:parser: myst
```

````

````{py:attribute} boxes
:canonical: algokit_utils.models.TransactionParametersDict.boxes
:type: collections.abc.Sequence[tuple[int, bytes | bytearray | str | int]]
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.boxes
:parser: myst
```

````

````{py:attribute} foreign_apps
:canonical: algokit_utils.models.TransactionParametersDict.foreign_apps
:type: list[int]
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.foreign_apps
:parser: myst
```

````

````{py:attribute} foreign_assets
:canonical: algokit_utils.models.TransactionParametersDict.foreign_assets
:type: list[int]
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.foreign_assets
:parser: myst
```

````

````{py:attribute} lease
:canonical: algokit_utils.models.TransactionParametersDict.lease
:type: bytes | str
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.lease
:parser: myst
```

````

````{py:attribute} note
:canonical: algokit_utils.models.TransactionParametersDict.note
:type: bytes | str
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.note
:parser: myst
```

````

````{py:attribute} rekey_to
:canonical: algokit_utils.models.TransactionParametersDict.rekey_to
:type: str
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.rekey_to
:parser: myst
```

````

````{py:attribute} sender
:canonical: algokit_utils.models.TransactionParametersDict.sender
:type: str
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.sender
:parser: myst
```

````

````{py:attribute} signer
:canonical: algokit_utils.models.TransactionParametersDict.signer
:type: algosdk.atomic_transaction_composer.TransactionSigner
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.signer
:parser: myst
```

````

````{py:attribute} suggested_params
:canonical: algokit_utils.models.TransactionParametersDict.suggested_params
:type: algosdk.transaction.SuggestedParams
:value: >
None

```{autodoc2-docstring} algokit_utils.models.TransactionParametersDict.suggested_params
:parser: myst
```

````

`````

`````{py:class} TransactionResponse
:canonical: algokit_utils.models.TransactionResponse

Expand Down Expand Up @@ -1957,6 +2120,30 @@ Bases: {py:obj}`algokit_utils._transfer.TransferParametersBase`
```
````

````{py:function} opt_in(algod_client: algosdk.v2client.algod.AlgodClient, account: algokit_utils.models.Account, asset_ids: list[int]) -> dict[int, str]
:canonical: algokit_utils.asset.opt_in

```{autodoc2-docstring} algokit_utils.asset.opt_in
:parser: myst
```
````

````{py:function} opt_out(algod_client: algosdk.v2client.algod.AlgodClient, account: algokit_utils.models.Account, asset_ids: list[int]) -> dict[int, str]
:canonical: algokit_utils.asset.opt_out

```{autodoc2-docstring} algokit_utils.asset.opt_out
:parser: myst
```
````

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

```{autodoc2-docstring} algokit_utils._debugging.persist_sourcemaps
:parser: myst
```
````

````{py:function} replace_template_variables(program: str, template_values: algokit_utils.deploy.TemplateValueMapping) -> str
:canonical: algokit_utils.deploy.replace_template_variables

Expand All @@ -1965,6 +2152,14 @@ Bases: {py:obj}`algokit_utils._transfer.TransferParametersBase`
```
````

````{py:function} simulate_and_persist_response(atc: algosdk.atomic_transaction_composer.AtomicTransactionComposer, project_root: pathlib.Path, algod_client: algosdk.v2client.algod.AlgodClient, buffer_size_mb: float = 256) -> algosdk.atomic_transaction_composer.SimulateAtomicTransactionResponse
:canonical: algokit_utils._debugging.simulate_and_persist_response

```{autodoc2-docstring} algokit_utils._debugging.simulate_and_persist_response
:parser: myst
```
````

````{py:function} transfer(client: algosdk.v2client.algod.AlgodClient, parameters: algokit_utils._transfer.TransferParameters) -> algosdk.transaction.PaymentTxn
:canonical: algokit_utils._transfer.transfer

Expand Down
30 changes: 30 additions & 0 deletions docs/html/_sources/capabilities/debugger.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Debugger

The AlgoKit Python Utilities package provides a set of debugging tools that can be used to simulate and trace transactions on the Algorand blockchain. These tools and methods are optimized for developers who are building applications on Algorand and need to test and debug their smart contracts via [AVM Debugger extension](link to vscode extension).

## Configuration

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 [`AVM Debugger`](links to extension). 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 [AVM Debugger](link to vscode extension) 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.

To enable debug mode in your project you can configure it as follows:

```py
from algokit_utils.config import config

config.configure(debug=True)
```

## Debugging Utilities

Debugging utilities can be used to simplify gathering artifacts to be used with [AVM Debugger](link to vscode extension) 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.
- `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.
Loading
Loading