Skip to content

Commit

Permalink
deserialize trace config
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Aug 1, 2023
1 parent b97914f commit e4e3f0a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 62 deletions.
13 changes: 11 additions & 2 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def __init__(
tx_ids: List[str],
results: List[SimulateABIResult],
eval_overrides: Optional[SimulateEvalOverrides] = None,
exec_trace_config: Optional[models.SimulateTraceConfig] = None,
) -> None:
self.version = version
self.failure_message = failure_message
Expand All @@ -323,6 +324,7 @@ def __init__(
self.tx_ids = tx_ids
self.abi_results = results
self.eval_overrides = eval_overrides
self.exec_trace_config = exec_trace_config


class AtomicTransactionComposer:
Expand Down Expand Up @@ -796,8 +798,6 @@ def simulate(
# build up data structure with fields we'd want
sim_results = []
for idx, result in enumerate(method_results):
sim_txn: Dict[str, Any] = txn_group["txn-results"][idx]

sim_results.append(
SimulateABIResult(
tx_id=result.tx_id,
Expand All @@ -809,6 +809,14 @@ def simulate(
)
)

exec_trace_config: Optional[models.SimulateTraceConfig] = (
None
if "exec-trace-config" not in simulation_result
else models.SimulateTraceConfig.undictify(
simulation_result["exec-trace-config"]
)
)

return SimulateAtomicTransactionResponse(
version=simulation_result.get("version", 0),
failure_message=txn_group.get("failure-message", ""),
Expand All @@ -819,6 +827,7 @@ def simulate(
eval_overrides=SimulateEvalOverrides.from_simulation_result(
simulation_result
),
exec_trace_config=exec_trace_config,
)

def execute(
Expand Down
4 changes: 0 additions & 4 deletions algosdk/v2client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
SimulateRequestTransactionGroup,
SimulateTraceConfig,
)
from algosdk.v2client.models.avm_value import AVMValue
from algosdk.v2client.models.simulate_exec_trace import SimulateExecTrace

__all__ = [
"Account",
Expand All @@ -56,6 +54,4 @@
"SimulateRequest",
"SimulateRequestTransactionGroup",
"SimulateTraceConfig",
"AVMValue",
"SimulateExecTrace",
]
21 changes: 0 additions & 21 deletions algosdk/v2client/models/avm_value.py

This file was deleted.

31 changes: 0 additions & 31 deletions algosdk/v2client/models/simulate_exec_trace.py

This file was deleted.

8 changes: 8 additions & 0 deletions algosdk/v2client/models/simulate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def dictify(self) -> Dict[str, Any]:
"scratch-change": self.scratch_change,
}

@staticmethod
def undictify(d: Dict[str, Any]) -> "SimulateTraceConfig":
return SimulateTraceConfig(
enable="enable" in d and d["enable"],
stack_change="stack-change" in d and d["stack-change"],
scratch_change="scratch-change" in d and d["scratch-change"],
)


class SimulateRequest:
txn_groups: List[SimulateRequestTransactionGroup]
Expand Down
20 changes: 16 additions & 4 deletions tests/steps/other_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,22 @@ def exec_trace_config_in_simulation(context, options: str):
)


@then(u'{unit_index}th unit in the "{trace_type}" trace at txn-groups path "{group_path}" should add to stack "{stack_addition:MaybeString}", pop from stack by {pop_count}, write to "{scratch_index}" scratch slot by "{scratch_var}".')
def step_impl(context, unit_index, trace_type, group_path, stack_addition: str, pop_count, scratch_index, scratch_var):
raise NotImplementedError(u'STEP: Then 4th unit in the "approval" trace at txn-groups path "0" should add to stack "uint64:2", pop from stack by 2, write to "none" scratch slot by "none".')

@then(
'{unit_index}th unit in the "{trace_type}" trace at txn-groups path "{group_path}" should add to stack "{stack_addition:MaybeString}", pop from stack by {pop_count}, write to "{scratch_index}" scratch slot by "{scratch_var}".'
)
def step_impl(
context,
unit_index,
trace_type,
group_path,
stack_addition: str,
pop_count,
scratch_index,
scratch_var,
):
raise NotImplementedError(
'STEP: Then 4th unit in the "approval" trace at txn-groups path "0" should add to stack "uint64:2", pop from stack by 2, write to "none" scratch slot by "none".'
)


@when("we make a SetSyncRound call against round {round}")
Expand Down

0 comments on commit e4e3f0a

Please sign in to comment.