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

refactor: refining dataclasses #127

Draft
wants to merge 8 commits into
base: prerelease/ts-feature-parity
Choose a base branch
from
Draft
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@ Txn {txn} had error 'assert failed pc=743' at PC 743:

Could not determine TEAL source line for the error as no approval source map was provided, to receive a trace of the
error please provide an approval SourceMap. Either by:
1. Providing template_values when creating the ApplicationClient, so a SourceMap can be obtained automatically OR
2. Set approval_source_map from a previously compiled approval program OR
3. Import a previously exported source map using import_source_map
1.Providing template_values when creating the ApplicationClient, so a SourceMap can be obtained automatically OR
2.Set approval_source_map from a previously compiled approval program OR
3.Import a previously exported source map using import_source_map
8 changes: 4 additions & 4 deletions legacy_v2_tests/test_debug_utils.py
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ def client_fixture(algod_client: "AlgodClient", app_spec: ApplicationSpecificati
return client


def test_build_teal_sourcemaps(algod_client: "AlgodClient", tmp_path_factory: pytest.TempPathFactory) -> None:
def test_legacy_build_teal_sourcemaps(algod_client: "AlgodClient", tmp_path_factory: pytest.TempPathFactory) -> None:
cwd = tmp_path_factory.mktemp("cwd")

approval = """
@@ -78,7 +78,7 @@ def test_build_teal_sourcemaps(algod_client: "AlgodClient", tmp_path_factory: py
assert item.location != "dummy"


def test_build_teal_sourcemaps_without_sources(
def test_legacy_build_teal_sourcemaps_without_sources(
algod_client: "AlgodClient", tmp_path_factory: pytest.TempPathFactory
) -> None:
cwd = tmp_path_factory.mktemp("cwd")
@@ -118,7 +118,7 @@ def test_build_teal_sourcemaps_without_sources(
check_output_stability(json.dumps(result.to_dict()))


def test_simulate_and_persist_response_via_app_call(
def test_legacy_simulate_and_persist_response_via_app_call(
tmp_path_factory: pytest.TempPathFactory,
client_fixture: ApplicationClient,
mocker: Mock,
@@ -142,7 +142,7 @@ def test_simulate_and_persist_response_via_app_call(
assert simulated_txn["apid"] == client_fixture.app_id


def test_simulate_and_persist_response(
def test_legacy_simulate_and_persist_response(
tmp_path_factory: pytest.TempPathFactory, client_fixture: ApplicationClient, mocker: Mock, funded_account: Account
) -> None:
mock_config = mocker.patch("algokit_utils._legacy_v2.application_client.config")
142 changes: 20 additions & 122 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ readme = "README.md"
python = "^3.10"
py-algorand-sdk = "^2.4.0"
httpx = "^0.23.1"
deprecated = "^1.2.14"
typing-extensions = ">=4.6.0" # Add this line

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
ruff = ">=0.1.6,<=0.8.2"
ruff = ">=0.1.6,<=0.8.3"
pip-audit = "^2.5.6"
pytest-mock = "^3.11.1"
mypy = "^1.5.1"
@@ -29,7 +29,6 @@ sphinx-rtd-theme = "^1.2.0"
sphinx-autodoc2 = ">=0.4.2,<0.6.0"
poethepoet = ">=0.19,<0.26"
beaker-pyteal = "^1.1.1"
types-deprecated = "^1.2.9.2"
pytest-httpx = "^0.21.3"
pytest-xdist = "^3.4.0"
sphinx-markdown-builder = "^0.6.6"
@@ -42,7 +41,7 @@ build-backend = "poetry.core.masonry.api"

[tool.ruff]
line-length = 120
lint.select = [
select = [
# all possible codes as of this ruff version are listed here,
# ones we don't want/need are commented out to make it clear
# which have been omitted on purpose vs which ones get added
@@ -81,7 +80,6 @@ lint.select = [
"SLF", # flake8-self
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"ERA", # eradicate
@@ -136,7 +134,6 @@ suppress-none-returning = true
docs = ["docs-html-only", "docs-md-only"]
docs-md-only = "sphinx-build docs/source docs/markdown -b markdown"
docs-html-only = "sphinx-build docs/source docs/html"
"tests/**/*" = ["PLR2004"]

[tool.pytest.ini_options]
pythonpath = ["src", "tests"]
2 changes: 1 addition & 1 deletion src/algokit_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@
get_creator_apps,
replace_template_variables,
)
from algokit_utils._legacy_v2.logic_error import LogicError
from algokit_utils._legacy_v2.models import (
ABIArgsDict,
ABIMethod,
@@ -97,6 +96,7 @@
DispenserLimitResponse,
TestNetDispenserApiClient,
)
from algokit_utils.errors.logic_error import LogicError
from algokit_utils.models.account import Account
from algokit_utils.models.application import DELETABLE_TEMPLATE_NAME, UPDATABLE_TEMPLATE_NAME
from algokit_utils.transactions.transaction_composer import TransactionComposer
41 changes: 29 additions & 12 deletions src/algokit_utils/_debugging.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
from algosdk.v2client.models import SimulateRequest, SimulateRequestTransactionGroup, SimulateTraceConfig

from algokit_utils._legacy_v2.common import Program
from algokit_utils.models.application import CompiledTeal

if typing.TYPE_CHECKING:
from algosdk.v2client.algod import AlgodClient
@@ -64,7 +65,11 @@ def to_dict(self) -> dict:
@dataclass
class PersistSourceMapInput:
def __init__(
self, app_name: str, file_name: str, raw_teal: str | None = None, compiled_teal: Program | None = None
self,
app_name: str,
file_name: str,
raw_teal: str | None = None,
compiled_teal: CompiledTeal | Program | None = None,
):
self.compiled_teal = compiled_teal
self.app_name = app_name
@@ -76,7 +81,9 @@ def from_raw_teal(cls, raw_teal: str, app_name: str, file_name: str) -> "Persist
return cls(app_name, file_name, raw_teal=raw_teal)

@classmethod
def from_compiled_teal(cls, compiled_teal: Program, app_name: str, file_name: str) -> "PersistSourceMapInput":
def from_compiled_teal(
cls, compiled_teal: CompiledTeal | Program, app_name: str, file_name: str
) -> "PersistSourceMapInput":
return cls(app_name, file_name, compiled_teal=compiled_teal)

@property
@@ -150,15 +157,28 @@ def _build_avm_sourcemap(
output_path: Path,
client: "AlgodClient",
raw_teal: str | None = None,
compiled_teal: Program | None = None,
compiled_teal: CompiledTeal | Program | None = None,
with_sources: bool = True,
) -> AVMDebuggerSourceMapEntry:
if not raw_teal and not compiled_teal:
raise ValueError("Either raw teal or compiled teal must be provided")

result = compiled_teal if compiled_teal else Program(str(raw_teal), client=client)
program_hash = base64.b64encode(checksum(result.raw_binary)).decode()
source_map = result.source_map.__dict__
# Handle both legacy Program and new CompiledTeal
if isinstance(compiled_teal, Program):
program_hash = base64.b64encode(checksum(compiled_teal.raw_binary)).decode()
source_map = compiled_teal.source_map.__dict__
teal_content = compiled_teal.teal
elif isinstance(compiled_teal, CompiledTeal):
program_hash = base64.b64encode(checksum(compiled_teal.compiled)).decode()
source_map = compiled_teal.source_map.__dict__ if compiled_teal.source_map else {}
teal_content = compiled_teal.teal
else:
# Handle raw TEAL case
result = Program(str(raw_teal), client=client)
program_hash = base64.b64encode(checksum(result.raw_binary)).decode()
source_map = result.source_map.__dict__
teal_content = result.teal

source_map["sources"] = [f"{file_name}{TEAL_FILE_EXT}"] if with_sources else []

output_dir_path = output_path / ALGOKIT_DIR / SOURCES_DIR / app_name
@@ -167,7 +187,7 @@ def _build_avm_sourcemap(
_write_to_file(source_map_output_path, json.dumps(source_map))

if with_sources:
_write_to_file(teal_output_path, result.teal)
_write_to_file(teal_output_path, teal_content)

return AVMDebuggerSourceMapEntry(str(source_map_output_path), program_hash)

@@ -211,7 +231,6 @@ def simulate_response(
exec_trace_config: SimulateTraceConfig | None = None,
round: int | None = None, # noqa: A002 TODO: revisit
skip_signatures: int | None = None, # noqa: ARG001 TODO: revisit
fix_signers: bool | None = None, # noqa: ARG001 TODO: revisit
) -> SimulateAtomicTransactionResponse:
"""
Simulate and fetch response for the given AtomicTransactionComposer and AlgodClient.
@@ -244,7 +263,7 @@ def simulate_response(
return atc.simulate(algod_client, simulate_request)


def simulate_and_persist_response( # noqa: PLR0913 TODO: revisit
def simulate_and_persist_response( # noqa: PLR0913
atc: AtomicTransactionComposer,
project_root: Path,
algod_client: "AlgodClient",
@@ -254,9 +273,8 @@ def simulate_and_persist_response( # noqa: PLR0913 TODO: revisit
allow_unnamed_resources: bool | None = None,
extra_opcode_budget: int | None = None,
exec_trace_config: SimulateTraceConfig | None = None,
round: int | None = None, # noqa: A002 TODO: revisit
round: int | None = None, # noqa: A002
skip_signatures: int | None = None,
fix_signers: bool | None = None,
) -> SimulateAtomicTransactionResponse:
"""
Simulates the atomic transactions using the provided `AtomicTransactionComposer` object and `AlgodClient` object,
@@ -291,7 +309,6 @@ def simulate_and_persist_response( # noqa: PLR0913 TODO: revisit
exec_trace_config,
round,
skip_signatures,
fix_signers,
)
txn_results = response.simulate_response["txn-groups"]

Loading
Loading