Skip to content

Commit

Permalink
fix: bumping mypy; making traces object typed to prevent misc mypy er…
Browse files Browse the repository at this point in the history
…ror on LogicError (#105)
  • Loading branch information
aorumbayev authored Aug 8, 2024
1 parent d21147d commit a9ffb78
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 49 deletions.
17 changes: 8 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// General - see also /.editorconfig
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
// Don't want to use isort because it conflicts with Ruff - see run on save below
"source.organizeImports": true,
"source.fixAll": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.exclude": {
Expand Down Expand Up @@ -54,10 +53,10 @@
]
},

// PowerShell
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"powershell.codeFormatting.preset": "Stroustrup",
"python.testing.pytestArgs": ["."]
// PowerShell
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"powershell.codeFormatting.preset": "Stroustrup",
"python.testing.pytestArgs": ["."]
}
58 changes: 29 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/algokit_utils/application_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
CreateCallParametersDict,
OnCompleteCallParameters,
OnCompleteCallParametersDict,
SimulationTrace,
TransactionParameters,
TransactionParametersDict,
TransactionResponse,
Expand Down Expand Up @@ -1236,7 +1237,7 @@ def _try_convert_to_logic_error(
source_ex: Exception | str,
approval_program: str,
approval_source_map: SourceMap | typing.Callable[[], SourceMap | None] | None = None,
simulate_traces: list | None = None,
simulate_traces: list[SimulationTrace] | None = None,
) -> Exception | None:
source_ex_str = str(source_ex)
logic_error_data = parse_logic_error(source_ex_str)
Expand Down Expand Up @@ -1297,7 +1298,7 @@ def execute_atc_with_logic_error(
raise ex


def _create_simulate_traces(simulate: SimulateAtomicTransactionResponse) -> list[dict[str, Any]]:
def _create_simulate_traces(simulate: SimulateAtomicTransactionResponse) -> list[SimulationTrace]:
traces = []
if hasattr(simulate, "simulate_response") and hasattr(simulate, "failed_at") and simulate.failed_at:
for txn_group in simulate.simulate_response["txn-groups"]:
Expand All @@ -1307,12 +1308,12 @@ def _create_simulate_traces(simulate: SimulateAtomicTransactionResponse) -> list
txn_result = txn_group.get("txn-results", [{}])[0]
exec_trace = txn_result.get("exec-trace", {})
traces.append(
{
"app-budget-added": app_budget_added,
"app-budget-consumed": app_budget_consumed,
"failure-message": failure_message,
"exec-trace": exec_trace,
}
SimulationTrace(
app_budget_added=app_budget_added,
app_budget_consumed=app_budget_consumed,
failure_message=failure_message,
exec_trace=exec_trace,
)
)
return traces

Expand Down
4 changes: 3 additions & 1 deletion src/algokit_utils/logic_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from copy import copy
from typing import TYPE_CHECKING, TypedDict

from algokit_utils.models import SimulationTrace

if TYPE_CHECKING:
from algosdk.source_map import SourceMap as AlgoSourceMap

Expand Down Expand Up @@ -46,7 +48,7 @@ def __init__( # noqa: PLR0913
message: str,
pc: int,
logic_error: Exception | None = None,
traces: list | None = None,
traces: list[SimulationTrace] | None = None,
):
self.logic_error = logic_error
self.logic_error_str = logic_error_str
Expand Down
8 changes: 8 additions & 0 deletions src/algokit_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,11 @@ class CommonCallParameters(TransactionParameters):
@deprecated(reason="Use TransactionParametersDict instead", version="1.3.1")
class CommonCallParametersDict(TransactionParametersDict):
"""Deprecated, use TransactionParametersDict instead"""


@dataclasses.dataclass
class SimulationTrace:
app_budget_added: int | None
app_budget_consumed: int | None
failure_message: str | None
exec_trace: dict[str, object]
4 changes: 2 additions & 2 deletions tests/test_app_client_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def test_readonly_call_with_error_debug_mode_enabled(client_fixture: Application
)

assert ex.value.traces is not None
assert ex.value.traces[0]["exec-trace"]["approval-program-trace"] is not None
assert ex.value.traces[0].exec_trace["approval-program-trace"] is not None


def test_app_call_with_error_debug_mode_disabled(mock_config: Mock, client_fixture: ApplicationClient) -> None:
Expand Down Expand Up @@ -350,4 +350,4 @@ def test_app_call_with_error_debug_mode_enabled(client_fixture: ApplicationClien
)

assert ex.value.traces is not None
assert ex.value.traces[0]["exec-trace"]["approval-program-trace"] is not None
assert ex.value.traces[0].exec_trace["approval-program-trace"] is not None

1 comment on commit a9ffb78

@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.py140795%20, 41, 76, 80, 89, 129, 157
   _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.py4552395%30–33, 168, 172–173, 190, 246, 402, 413–421, 438–441, 451, 459, 652–653, 677
   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.py3207178%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
TOTAL242629288% 

Tests Skipped Failures Errors Time
204 0 💤 0 ❌ 0 🔥 2m 19s ⏱️

Please sign in to comment.