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

chore: remaining resource packing related tests #126

Merged
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
2 changes: 1 addition & 1 deletion src/algokit_utils/accounts/account_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def rekey_account( # noqa: PLR0913
self.rekeyed(account, rekey_to)

if not suppress_log:
logger.info(f"Rekeyed {account} to {rekey_to} via transaction {result.tx_ids[-1]}")
logger.info(f"Rekeyed {sender_address} to {rekey_address} via transaction {result.tx_ids[-1]}")

return result

Expand Down
6 changes: 3 additions & 3 deletions src/algokit_utils/applications/app_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ def close_out(self, params: AppClientMethodCallWithSendParams) -> SendAppTransac
)

def call(self, params: AppClientMethodCallWithSendParams) -> SendAppTransactionResult:
is_read_only_call = params.on_complete == algosdk.transaction.OnComplete.NoOpOC or (
not params.on_complete and get_arc56_method(params.method, self._app_spec).method.readonly
)
is_read_only_call = (
params.on_complete == algosdk.transaction.OnComplete.NoOpOC or params.on_complete is None
) and get_arc56_method(params.method, self._app_spec).method.readonly

if is_read_only_call:
method_call_to_simulate = self._algorand.new_group().add_app_call_method_call(
Expand Down
50 changes: 50 additions & 0 deletions src/algokit_utils/clients/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import algosdk
from algosdk.atomic_transaction_composer import TransactionSigner
from algosdk.kmd import KMDClient
from algosdk.source_map import SourceMap
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient

# from algokit_utils.applications.app_factory import AppFactory, AppFactoryParams
from algokit_utils._legacy_v2.application_specification import ApplicationSpecification
from algokit_utils.applications.app_client import AppClient, AppClientParams
from algokit_utils.applications.app_factory import AppFactory, AppFactoryParams
from algokit_utils.applications.app_manager import TealTemplateParams
from algokit_utils.clients.dispenser_api_client import TestNetDispenserApiClient
Expand Down Expand Up @@ -152,6 +154,54 @@ def get_app_factory(
)
)

def get_app_client_by_id(
self,
app_spec: (Arc56Contract | ApplicationSpecification | str),
app_id: int,
app_name: str | None = None,
default_sender: str | bytes | None = None,
default_signer: TransactionSigner | None = None,
approval_source_map: SourceMap | None = None,
clear_source_map: SourceMap | None = None,
) -> AppClient:
if not self._algorand:
raise ValueError("Attempt to get app client from a ClientManager without an Algorand client")

return AppClient(
AppClientParams(
app_spec=app_spec,
algorand=self._algorand,
app_id=app_id,
app_name=app_name,
default_sender=default_sender,
default_signer=default_signer,
approval_source_map=approval_source_map,
clear_source_map=clear_source_map,
)
)

def get_app_client_by_network(
self,
app_spec: (Arc56Contract | ApplicationSpecification | str),
app_name: str | None = None,
default_sender: str | bytes | None = None,
default_signer: TransactionSigner | None = None,
approval_source_map: SourceMap | None = None,
clear_source_map: SourceMap | None = None,
) -> AppClient:
if not self._algorand:
raise ValueError("Attempt to get app client from a ClientManager without an Algorand client")

return AppClient.from_network(
app_spec=app_spec,
app_name=app_name,
default_sender=default_sender,
default_signer=default_signer,
approval_source_map=approval_source_map,
clear_source_map=clear_source_map,
algorand=self._algorand,
)

@staticmethod
def get_algod_client(config: AlgoClientConfig | None = None) -> AlgodClient:
"""Returns an {py:class}`algosdk.v2client.algod.AlgodClient` from `config` or environment
Expand Down
5 changes: 2 additions & 3 deletions src/algokit_utils/transactions/transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
TransactionSigner,
TransactionWithSigner,
)
from algosdk.error import AlgodHTTPError
from algosdk.transaction import OnComplete
from algosdk.v2client.algod import AlgodClient
from typing_extensions import deprecated
Expand Down Expand Up @@ -611,7 +610,7 @@ def send_atomic_transaction_composer( # noqa: C901, PLR0912
returns=result.abi_results,
)

except AlgodHTTPError as e:
except Exception as e:
# Handle error with debug info if enabled
if config.debug:
logger.error(
Expand Down Expand Up @@ -649,7 +648,7 @@ def send_atomic_transaction_composer( # noqa: C901, PLR0912
raise error from e

logger.error("Received error executing Atomic Transaction Composer, for more information enable the debug flag")
raise Exception(f"Transaction failed: {e}") from e
raise e


class TransactionComposer:
Expand Down
18 changes: 10 additions & 8 deletions src/algokit_utils/transactions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from algosdk.atomic_transaction_composer import AtomicTransactionComposer, EmptySigner, TransactionWithSigner
from algosdk.error import AtomicTransactionComposerError
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.models import SimulateRequest
from algosdk.v2client.models import SimulateRequest, SimulateRequestTransactionGroup

from algokit_utils.applications.app_manager import BoxReference

Expand Down Expand Up @@ -319,20 +319,22 @@ def is_appl_below_limit(t: TransactionWithSigner) -> bool:
def get_unnamed_app_call_resources_accessed(atc: AtomicTransactionComposer, algod: AlgodClient) -> dict[str, Any]:
"""Get unnamed resources accessed by application calls in an atomic transaction group."""
# Create simulation request with required flags
simulate_request = SimulateRequest(
txn_groups=[], allow_unnamed_resources=True, allow_empty_signatures=True, extra_opcode_budget=0
)
simulate_request = SimulateRequest(txn_groups=[], allow_unnamed_resources=True, allow_empty_signatures=True)

# Create empty signer
null_signer = EmptySigner()

# Clone the ATC and replace signers
empty_signer_atc = atc.clone()
for txn in empty_signer_atc.txn_list:
txn.signer = null_signer
unsigned_txn_groups = atc.build_group()
txn_group = [
SimulateRequestTransactionGroup(
txns=null_signer.sign_transactions([txn_group.txn for txn_group in unsigned_txn_groups], [])
)
]
simulate_request = SimulateRequest(txn_groups=txn_group, allow_unnamed_resources=True, allow_empty_signatures=True)

# Run simulation
result = empty_signer_atc.simulate(algod, simulate_request)
result = atc.simulate(algod, simulate_request)

# Get first group response
group_response = result.simulate_response["txn-groups"][0]
Expand Down
Loading
Loading