Skip to content

Commit

Permalink
chore: extra tests; wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Dec 3, 2024
1 parent af48a12 commit 95613b9
Show file tree
Hide file tree
Showing 22 changed files with 2,274 additions and 496 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": false
}
]
}
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ extend-exclude = [
# Assume Python 3.10.
target-version = "py310"

[tool.ruff.lint.pylint]
max-args = 10

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true
suppress-none-returning = true
Expand Down
47 changes: 35 additions & 12 deletions src/algokit_utils/_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from algosdk.v2client.models import SimulateRequest, SimulateRequestTransactionGroup, SimulateTraceConfig

from algokit_utils._legacy_v2.common import Program
from algokit_utils.transactions.models import SimulateOptions

if typing.TYPE_CHECKING:
from algosdk.v2client.algod import AlgodClient
Expand Down Expand Up @@ -144,7 +143,7 @@ def _write_to_file(path: Path, content: str) -> None:
path.write_text(content)


def _build_avm_sourcemap( # noqa: PLR0913
def _build_avm_sourcemap(
*,
app_name: str,
file_name: str,
Expand Down Expand Up @@ -205,7 +204,14 @@ def persist_sourcemaps(
def simulate_response(
atc: AtomicTransactionComposer,
algod_client: "AlgodClient",
simulate_options: SimulateOptions | dict[str, typing.Any] | None = None,
allow_more_logs: bool | None = None,
allow_empty_signatures: bool | None = None,
allow_unnamed_resources: bool | None = None,
extra_opcode_budget: int | None = None,
exec_trace_config: SimulateTraceConfig | None = None,
round: int | None = None,
skip_signatures: int | None = None,
fix_signers: bool | None = None,
) -> SimulateAtomicTransactionResponse:
"""
Simulate and fetch response for the given AtomicTransactionComposer and AlgodClient.
Expand All @@ -224,16 +230,15 @@ def simulate_response(
fake_signed_transactions = empty_signer.sign_transactions(txn_list, [])
txn_group = [SimulateRequestTransactionGroup(txns=fake_signed_transactions)]
trace_config = SimulateTraceConfig(enable=True, stack_change=True, scratch_change=True, state_change=True)
simulate_params: SimulateOptions = simulate_options or {} # type: ignore[assignment]

simulate_request = SimulateRequest(
txn_groups=txn_group,
allow_more_logs=True,
round=simulate_params.get("round") or None,
extra_opcode_budget=simulate_params.get("extra_opcode_budget") or 0,
allow_unnamed_resources=simulate_params.get("allow_unnamed_resources") or True,
allow_empty_signatures=simulate_params.get("allow_empty_signatures") or True,
exec_trace_config=simulate_params.get("exec_trace_config") or trace_config,
allow_more_logs=allow_more_logs or True,
round=round,
extra_opcode_budget=extra_opcode_budget or 0,
allow_unnamed_resources=allow_unnamed_resources or True,
allow_empty_signatures=allow_empty_signatures or True,
exec_trace_config=exec_trace_config or trace_config,
)

return atc.simulate(algod_client, simulate_request)
Expand All @@ -244,7 +249,14 @@ def simulate_and_persist_response(
project_root: Path,
algod_client: "AlgodClient",
buffer_size_mb: float = 256,
simulate_options: SimulateOptions | dict[str, typing.Any] | None = None,
allow_more_logs: bool | None = None,
allow_empty_signatures: bool | None = None,
allow_unnamed_resources: bool | None = None,
extra_opcode_budget: int | None = None,
exec_trace_config: SimulateTraceConfig | None = None,
round: int | None = None,
skip_signatures: int | None = None,
fix_signers: bool | None = None,
) -> SimulateAtomicTransactionResponse:
"""
Simulates the atomic transactions using the provided `AtomicTransactionComposer` object and `AlgodClient` object,
Expand All @@ -269,7 +281,18 @@ def simulate_and_persist_response(
txn_with_sign.txn.last_valid_round = sp.last
txn_with_sign.txn.genesis_hash = sp.gh

response = simulate_response(atc_to_simulate, algod_client, simulate_options)
response = simulate_response(
atc_to_simulate,
algod_client,
allow_more_logs,
allow_empty_signatures,
allow_unnamed_resources,
extra_opcode_budget,
exec_trace_config,
round,
skip_signatures,
fix_signers,
)
txn_results = response.simulate_response["txn-groups"]

txn_types = [txn_result["txn-results"][0]["txn-result"]["txn"]["txn"]["type"] for txn_result in txn_results]
Expand Down
Loading

0 comments on commit 95613b9

Please sign in to comment.