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

Simulate: Support newer simulate options #537

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ def __init__(
max_log_calls: Optional[int] = None,
max_log_size: Optional[int] = None,
allow_empty_signatures: Optional[bool] = None,
allow_unnamed_resources: Optional[bool] = None,
extra_opcode_budget: Optional[int] = None,
) -> None:
self.max_log_calls = max_log_calls
self.max_log_size = max_log_size
self.allow_empty_signatures = allow_empty_signatures
self.allow_unnamed_resources = allow_unnamed_resources
self.extra_opcode_budget = extra_opcode_budget

@staticmethod
Expand All @@ -297,6 +299,10 @@ def from_simulation_result(
eval_override.allow_empty_signatures = eval_override_dict[
"allow-empty-signatures"
]
if "allow-unnamed-resources" in eval_override_dict:
eval_override.allow_unnamed_resources = eval_override_dict[
"allow-unnamed-resources"
]
if "extra-opcode-budget" in eval_override_dict:
eval_override.extra_opcode_budget = eval_override_dict[
"extra-opcode-budget"
Expand Down
13 changes: 13 additions & 0 deletions algosdk/v2client/models/simulate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,27 @@ class SimulateTraceConfig:
enable: bool
stack_change: bool
scratch_change: bool
state_change: bool

def __init__(
self,
*,
enable: bool = False,
stack_change: bool = False,
scratch_change: bool = False,
state_change: bool = False,
) -> None:
self.enable = enable
self.stack_change = stack_change
self.scratch_change = scratch_change
self.state_change = state_change

def dictify(self) -> Dict[str, Any]:
return {
"enable": self.enable,
"stack-change": self.stack_change,
"scratch-change": self.scratch_change,
"state-change": self.state_change,
}

@staticmethod
Expand All @@ -45,28 +49,35 @@ def undictify(d: Dict[str, Any]) -> "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"],
state_change="state-change" in d and d["state-change"],
)


class SimulateRequest:
txn_groups: List[SimulateRequestTransactionGroup]
allow_more_logs: bool
allow_empty_signatures: bool
allow_unnamed_resources: bool
extra_opcode_budget: int
exec_trace_config: SimulateTraceConfig
round: Optional[int]

def __init__(
self,
*,
txn_groups: List[SimulateRequestTransactionGroup],
round: Optional[int] = None,
allow_more_logs: bool = False,
allow_empty_signatures: bool = False,
allow_unnamed_resources: bool = False,
extra_opcode_budget: int = 0,
exec_trace_config: Optional[SimulateTraceConfig] = None,
) -> None:
self.txn_groups = txn_groups
self.round = round
self.allow_more_logs = allow_more_logs
self.allow_empty_signatures = allow_empty_signatures
self.allow_unnamed_resources = allow_unnamed_resources
self.extra_opcode_budget = extra_opcode_budget
self.exec_trace_config = (
exec_trace_config if exec_trace_config else SimulateTraceConfig()
Expand All @@ -77,7 +88,9 @@ def dictify(self) -> Dict[str, Any]:
"txn-groups": [
txn_group.dictify() for txn_group in self.txn_groups
],
"round": self.round,
"allow-more-logging": self.allow_more_logs,
"allow-unnamed-resources": self.allow_unnamed_resources,
"allow-empty-signatures": self.allow_empty_signatures,
"extra-opcode-budget": self.extra_opcode_budget,
"exec-trace-config": self.exec_trace_config.dictify(),
Expand Down
3 changes: 2 additions & 1 deletion tests/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
@simulate
@simulate.lift_log_limits
@simulate.extra_opcode_budget
@simulate.exec_trace_with_stack_scratch
@simulate.exec_trace_with_stack_scratch
@simulate.exec_trace_with_state_change_and_hash
65 changes: 43 additions & 22 deletions tests/steps/application_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def operation_string_to_enum(operation):
return transaction.OnComplete.NoOpOC
elif operation == "create":
return transaction.OnComplete.NoOpOC
elif operation == "create-and-optin":
jannotti marked this conversation as resolved.
Show resolved Hide resolved
return transaction.OnComplete.OptInOC
elif operation == "noop":
return transaction.OnComplete.NoOpOC
elif operation == "update":
Expand Down Expand Up @@ -359,7 +361,7 @@ def build_app_txn_with_transient(
if (
hasattr(context, "current_application_id")
and context.current_application_id
and operation != "create"
and operation not in ("create", "create-and-optin")
):
application_id = context.current_application_id
operation = operation_string_to_enum(operation)
Expand Down Expand Up @@ -640,6 +642,7 @@ def add_nonce(context, nonce):

def abi_method_adder(
context,
*,
account_type,
operation,
create_when_calling=False,
Expand All @@ -652,6 +655,7 @@ def abi_method_adder(
extra_pages=None,
force_unique_transactions=False,
exception_key="none",
comma_separated_boxes_string=None,
):
if account_type == "transient":
sender = context.transient_pk
Expand Down Expand Up @@ -698,6 +702,10 @@ def int_if_given(given):
+ context.nonce.encode()
)

boxes = None
if comma_separated_boxes_string is not None:
boxes = split_and_process_boxes(comma_separated_boxes_string)

try:
context.atomic_transaction_composer.add_method_call(
app_id=app_id,
Expand All @@ -713,6 +721,7 @@ def int_if_given(given):
clear_program=clear_program,
extra_pages=extra_pages,
note=note,
boxes=boxes,
)
except AtomicTransactionComposerError as atce:
assert (
Expand All @@ -739,6 +748,18 @@ def int_if_given(given):
), f"should have encountered an AtomicTransactionComposerError keyed by '{exception_key}', but no such exception has been detected"


@when(
'I add a method call with the transient account, the current application, suggested params, on complete "{operation}", current transaction signer, current method arguments, boxes "{boxes}".'
)
def add_abi_method_call_with_boxes(context, operation, boxes):
abi_method_adder(
context,
account_type="transient",
operation=operation,
comma_separated_boxes_string=boxes,
)


@step(
'I add a method call with the {account_type} account, the current application, suggested params, on complete "{operation}", current transaction signer, current method arguments; any resulting exception has key "{exception_key}".'
)
Expand All @@ -747,8 +768,8 @@ def add_abi_method_call_with_exception(
):
abi_method_adder(
context,
account_type,
operation,
account_type=account_type,
operation=operation,
exception_key=exception_key,
)

Expand All @@ -759,8 +780,8 @@ def add_abi_method_call_with_exception(
def add_abi_method_call(context, account_type, operation):
abi_method_adder(
context,
account_type,
operation,
account_type=account_type,
operation=operation,
)


Expand All @@ -781,16 +802,16 @@ def add_abi_method_call_creation_with_allocs(
):
abi_method_adder(
context,
account_type,
operation,
True,
approval_program_path,
clear_program_path,
global_bytes,
global_ints,
local_bytes,
local_ints,
extra_pages,
account_type=account_type,
operation=operation,
create_when_calling=True,
approval_program_path=approval_program_path,
clear_program_path=clear_program_path,
global_bytes=global_bytes,
global_ints=global_ints,
local_bytes=local_bytes,
local_ints=local_ints,
extra_pages=extra_pages,
)


Expand All @@ -806,11 +827,11 @@ def add_abi_method_call_creation(
):
abi_method_adder(
context,
account_type,
operation,
True,
approval_program_path,
clear_program_path,
account_type=account_type,
operation=operation,
create_when_calling=True,
approval_program_path=approval_program_path,
clear_program_path=clear_program_path,
)


Expand All @@ -820,8 +841,8 @@ def add_abi_method_call_creation(
def add_abi_method_call_nonced(context, account_type, operation):
abi_method_adder(
context,
account_type,
operation,
account_type=account_type,
operation=operation,
force_unique_transactions=True,
)

Expand Down
Loading
Loading