|
20 | 20 | _var: ContextVar[AlgopyTestContext] = ContextVar("_var") |
21 | 21 |
|
22 | 22 |
|
23 | | -# functions for use by algopy_testing implementations that shouldn't be exposed to the user |
24 | | -def get_test_context() -> AlgopyTestContext: |
25 | | - try: |
26 | | - result = _var.get() |
27 | | - except LookupError: |
28 | | - raise ValueError( |
29 | | - "Test context is not initialized! Use `with algopy_testing_context()` to " |
30 | | - "access the context manager." |
31 | | - ) from None |
32 | | - return result |
33 | | - |
34 | | - |
35 | 23 | class _InternalContext: |
36 | 24 | """For accessing implementation specific functions, with a convenient |
37 | 25 | single entry point for other modules to import Also allows for a single |
38 | 26 | place to check and provide.""" |
39 | 27 |
|
40 | 28 | @property |
41 | 29 | def value(self) -> AlgopyTestContext: |
42 | | - return get_test_context() |
| 30 | + try: |
| 31 | + return _var.get() |
| 32 | + except LookupError: |
| 33 | + raise ValueError( |
| 34 | + "Test context is not initialized! Use `with algopy_testing_context()` to " |
| 35 | + "access the context manager." |
| 36 | + ) from None |
43 | 37 |
|
44 | 38 | @property |
45 | 39 | def ledger(self) -> LedgerContext: |
@@ -67,32 +61,20 @@ def active_group(self) -> TransactionGroup: |
67 | 61 | return group |
68 | 62 |
|
69 | 63 | @property |
70 | | - def active_application(self) -> algopy.Application: |
71 | | - return self.ledger.get_application(self.active_group.active_app_id) |
| 64 | + def active_app(self) -> algopy.Application: |
| 65 | + return self.ledger.get_app(self.active_group.active_app_id) |
| 66 | + |
| 67 | + @property |
| 68 | + def active_app_id(self) -> int: |
| 69 | + return self.active_group.active_app_id |
72 | 70 |
|
73 | 71 | def get_app_data( |
74 | 72 | self, |
75 | 73 | app: algopy.Contract | algopy.Application | algopy.UInt64 | int, |
76 | 74 | ) -> ApplicationContextData: |
77 | | - from algopy_testing.models import Application, Contract |
78 | | - from algopy_testing.primitives import UInt64 |
79 | | - |
80 | | - if isinstance(app, Contract): |
81 | | - app_id = app.__app_id__ |
82 | | - elif isinstance(app, Application): |
83 | | - app_id = app.id.value |
84 | | - elif isinstance(app, UInt64): |
85 | | - app_id = app.value |
86 | | - elif isinstance(app, int): |
87 | | - app_id = app |
88 | | - else: |
89 | | - raise TypeError("invalid type") |
90 | | - if app_id == 0: |
91 | | - app_id = self.active_group.active_app_id |
92 | | - try: |
93 | | - return self.ledger.application_data[app_id] |
94 | | - except KeyError: |
95 | | - raise ValueError("Unknown app id, is there an active transaction?") from None |
| 75 | + if app == 0: |
| 76 | + app = self.active_group.active_app_id |
| 77 | + return self.ledger._get_app_data(app) |
96 | 78 |
|
97 | 79 | def get_asset_data(self, asset_id: int | algopy.UInt64) -> AssetFields: |
98 | 80 | try: |
|
0 commit comments