Skip to content

Commit

Permalink
move simulate_with_request to simulate
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Apr 27, 2023
1 parent 1a2c601 commit acdad32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
36 changes: 0 additions & 36 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,7 @@ def simulate(
Dict[str, Any],
client.simulate_transactions(current_simulation_request),
)
return self.__report_simulation_response(simulation_result)

def __report_simulation_response(self, simulation_result: Dict[str, Any]):
# Only take the first group in the simulate response
txn_group: Dict[str, Any] = simulation_result["txn-groups"][0]

Expand Down Expand Up @@ -810,40 +808,6 @@ def __report_simulation_response(self, simulation_result: Dict[str, Any]):
),
)

def simulate_with_request(
self,
client: algod.AlgodClient,
request: models.SimulateRequest,
):
current_simulation_request = request

if (
self.status < AtomicTransactionComposerStatus.BUILT
or self.status > AtomicTransactionComposerStatus.SUBMITTED
):
raise error.AtomicTransactionComposerError(
"AtomicTransactionComposerStatus must be in range [BUILT, SUBMITTED] "
"to simulate a group"
)
elif self.status == AtomicTransactionComposerStatus.BUILT:
unsigned_txn: List[transaction.GenericSignedTransaction] = [
transaction.SignedTransaction(txn_with_signer.txn, "")
for txn_with_signer in self.txn_list
]
current_simulation_request.txn_groups = [
models.SimulateRequestTransactionGroup(txns=unsigned_txn)
]
else:
current_simulation_request.txn_groups = [
models.SimulateRequestTransactionGroup(txns=self.signed_txns)
]

simulation_result = cast(
Dict[str, Any],
client.simulate_transactions(current_simulation_request),
)
return self.__report_simulation_response(simulation_result)

def execute(
self, client: algod.AlgodClient, wait_rounds: int
) -> AtomicTransactionResponse:
Expand Down
8 changes: 5 additions & 3 deletions tests/steps/other_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,12 +1489,14 @@ def allow_more_logs_in_request(context):

@then("I attach the simulate request to simulate the transaction group.")
def attach_sim_request_to_txn_group_simulation(context):
context.simulate_response = context.atomic_transaction_composer.simulate(
context.app_acl, context.simulate_request
context.atomic_transaction_composer_return = (
context.atomic_transaction_composer.simulate(
context.app_acl, context.simulate_request
)
)


@then('I check the simulation result has power packs allow-more-logging.')
@then("I check the simulation result has power packs allow-more-logging.")
def power_pack_simulation_should_pass(context):
assert context.simulate_response.eval_overrides.max_log_calls
assert context.simulate_response.eval_overrides.max_log_size
Expand Down

0 comments on commit acdad32

Please sign in to comment.