Skip to content

Commit

Permalink
chore: adding initial logic error exposer
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Dec 3, 2024
1 parent 95613b9 commit 52a6d7d
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 89 deletions.
23 changes: 12 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@
"**/__pycache__": true,
".idea": true
},

// Python
"platformSettings.autoLoad": true,
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
"python.analysis.extraPaths": ["${workspaceFolder}/src"],
"python.analysis.extraPaths": [
"${workspaceFolder}/src"
],
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.analysis.exclude": [
"tests/artifacts/**"
],
"python.analysis.typeCheckingMode": "basic",
"ruff.enable": true,
"ruff.lint.run": "onSave",
"ruff.lint.args": ["--config=pyproject.toml"],
"ruff.lint.args": [
"--config=pyproject.toml"
],
"ruff.importStrategy": "fromEnvironment",
"ruff.fixAll": true, //lint and fix all files in workspace
"ruff.organizeImports": true, //organize imports on save
Expand All @@ -37,7 +43,6 @@
"ruff.codeAction.fixViolation": {
"enable": true
},

"mypy.configFile": "pyproject.toml",
// set to empty array to use config from project
"mypy.targets": [],
Expand All @@ -52,11 +57,7 @@
}
]
},

// PowerShell
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"powershell.codeFormatting.preset": "Stroustrup",
"python.testing.pytestArgs": ["."]
"python.testing.pytestArgs": [
"."
],
}
37 changes: 19 additions & 18 deletions legacy_v2_tests/test_app_client_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
from typing import TYPE_CHECKING
from unittest.mock import Mock, patch

import algokit_utils
import pytest
from algokit_utils import (
Account,
ApplicationClient,
ApplicationSpecification,
CreateCallParameters,
get_account,
)
from algosdk.atomic_transaction_composer import (
AccountTransactionSigner,
AtomicTransactionComposer,
TransactionWithSigner,
)
from algosdk.transaction import ApplicationCallTxn, PaymentTxn

import algokit_utils
import algokit_utils._legacy_v2
import algokit_utils._legacy_v2.logic_error
from algokit_utils import (
Account,
ApplicationClient,
ApplicationSpecification,
CreateCallParameters,
get_account,
)
from legacy_v2_tests.conftest import check_output_stability, get_unique_name

if TYPE_CHECKING:
Expand Down Expand Up @@ -186,7 +188,7 @@ def test_readonly_call(client_fixture: ApplicationClient) -> None:


def test_readonly_call_with_error(client_fixture: ApplicationClient) -> None:
with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
client_fixture.call(
"readonly",
error=1,
Expand All @@ -211,7 +213,7 @@ def test_readonly_call_with_error_with_new_client_provided_template_values(
)
new_client.approval_source_map = client.approval_source_map

with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
new_client.call(
"readonly",
error=1,
Expand All @@ -234,7 +236,7 @@ def test_readonly_call_with_error_with_new_client_provided_source_map(
new_client = ApplicationClient(algod_client, app_spec, app_id=client.app_id, signer=funded_account)
new_client.approval_source_map = client.approval_source_map

with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
new_client.call(
"readonly",
error=1,
Expand All @@ -259,7 +261,7 @@ def test_readonly_call_with_error_with_imported_source_map(
new_client = ApplicationClient(algod_client, app_spec, app_id=client.app_id, signer=funded_account)
new_client.import_source_map(source_map_export)

with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
new_client.call(
"readonly",
error=1,
Expand All @@ -281,7 +283,7 @@ def test_readonly_call_with_error_with_new_client_missing_source_map(

new_client = ApplicationClient(algod_client, app_spec, app_id=client.app_id, signer=funded_account)

with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
new_client.call(
"readonly",
error=1,
Expand All @@ -292,7 +294,7 @@ def test_readonly_call_with_error_with_new_client_missing_source_map(

def test_readonly_call_with_error_debug_mode_disabled(mock_config: Mock, client_fixture: ApplicationClient) -> None:
mock_config.debug = False
with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
client_fixture.call(
"readonly",
error=1,
Expand All @@ -302,7 +304,7 @@ def test_readonly_call_with_error_debug_mode_disabled(mock_config: Mock, client_


def test_readonly_call_with_error_debug_mode_enabled(client_fixture: ApplicationClient) -> None:
with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
client_fixture.call(
"readonly",
error=1,
Expand All @@ -322,7 +324,7 @@ def test_app_call_with_error_debug_mode_disabled(mock_config: Mock, client_fixtu
min_funding_increment_micro_algos=200_000,
),
)
with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
client_fixture.call(
"set_box",
name=b"ssss",
Expand All @@ -342,12 +344,11 @@ def test_app_call_with_error_debug_mode_enabled(client_fixture: ApplicationClien
min_funding_increment_micro_algos=200_000,
),
)
with pytest.raises(algokit_utils.LogicError) as ex:
with pytest.raises(algokit_utils._legacy_v2.logic_error.LogicError) as ex: # noqa: SLF001
client_fixture.call(
"set_box",
name=b"ssss",
value="test",
)

assert ex.value.traces is not None
assert ex.value.traces[0].exec_trace["approval-program-trace"] is not None
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ lint.ignore = [
"Q002", # bad quotes docstring
"Q003", # avoidable escaped quotes
"W191", # indentation contains tabs
"ERA001", # commented out code
]
# Exclude a variety of commonly ignored directories.
extend-exclude = [
"docs",
".git",
".mypy_cache",
".ruff_cache",

"tests/artifacts",
]
# Assume Python 3.10.
target-version = "py310"
Expand All @@ -127,7 +128,7 @@ suppress-none-returning = true

[tool.ruff.lint.per-file-ignores]
"src/algokit_utils/beta/*" = ["ERA001", "E501", "PLR0911"]
"path/to/file.py" = ["E402"]
"src/algokit_utils/applications/app_client.py" = ["SLF001"]
"tests/clients/test_algorand_client.py" = ["ERA001"]

[tool.poe.tasks]
Expand All @@ -140,7 +141,7 @@ pythonpath = ["src", "tests"]

[tool.mypy]
files = ["src", "tests"]
exclude = ["dist"]
exclude = ["dist", "tests/artifacts"]
python_version = "3.10"
warn_unused_ignores = true
warn_redundant_casts = true
Expand Down
2 changes: 1 addition & 1 deletion src/algokit_utils/_legacy_v2/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class AppChanges:
schema_change_description: str | None


def check_for_app_changes( # noqa: PLR0913
def check_for_app_changes(
algod_client: "AlgodClient",
*,
new_approval: bytes,
Expand Down
5 changes: 4 additions & 1 deletion src/algokit_utils/_legacy_v2/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 deprecated import deprecated

from algokit_utils._legacy_v2.models import SimulationTrace

if TYPE_CHECKING:
Expand Down Expand Up @@ -37,8 +39,9 @@ def parse_logic_error(
}


@deprecated(reason="Use algokit_utils.models.error.LogicError instead", version="3.0.0")
class LogicError(Exception):
def __init__( # noqa: PLR0913
def __init__(
self,
*,
logic_error_str: str,
Expand Down
Loading

0 comments on commit 52a6d7d

Please sign in to comment.