|
2 | 2 | import os |
3 | 3 | import signal |
4 | 4 | import subprocess |
5 | | -from contextlib import suppress |
6 | 5 | from pathlib import Path |
7 | | -from typing import AsyncGenerator, Callable, Literal, Optional, Sequence, Tuple, Union |
| 6 | +from typing import AsyncGenerator, Callable, Literal, Optional, Union |
8 | 7 |
|
9 | 8 | from pytest import fixture |
10 | 9 | from pytest_asyncio import fixture as async_fixture |
11 | 10 | from pytest_xprocess import getrootdir |
12 | | -from solders.account import Account |
13 | | -from solders.pubkey import Pubkey |
14 | 11 | from xprocess import ProcessStarter, XProcess, XProcessInfo |
15 | 12 |
|
16 | 13 | from anchorpy.program.core import Program |
17 | 14 | from anchorpy.workspace import close_workspace, create_workspace |
18 | 15 |
|
19 | | -with suppress(ImportError): |
20 | | - from solders import bankrun |
21 | | - |
22 | 16 | _Scope = Literal["session", "package", "module", "class", "function"] |
23 | 17 |
|
24 | 18 |
|
@@ -240,57 +234,3 @@ class Starter(ProcessStarter): |
240 | 234 | _fixed_xprocess.getinfo("localnet").terminate() |
241 | 235 |
|
242 | 236 | return _workspace_fixture |
243 | | - |
244 | | - |
245 | | -async def _bankrun_helper( |
246 | | - path: Union[Path, str], |
247 | | - build_cmd: Optional[str] = None, |
248 | | - accounts: Optional[Sequence[Tuple[Pubkey, Account]]] = None, |
249 | | - compute_max_units: Optional[int] = None, |
250 | | - transaction_account_lock_limit: Optional[int] = None, |
251 | | -) -> "bankrun.ProgramTestContext": |
252 | | - actual_build_cmd = "anchor build" if build_cmd is None else build_cmd |
253 | | - subprocess.run(actual_build_cmd, cwd=path, check=True, shell=True) |
254 | | - path_to_use = Path(path) |
255 | | - return await bankrun.start_anchor( |
256 | | - path_to_use, |
257 | | - accounts=accounts, |
258 | | - compute_max_units=compute_max_units, |
259 | | - transaction_account_lock_limit=transaction_account_lock_limit, |
260 | | - ) |
261 | | - |
262 | | - |
263 | | -def bankrun_fixture( |
264 | | - path: Union[Path, str], |
265 | | - scope: _Scope = "module", |
266 | | - build_cmd: Optional[str] = None, |
267 | | - accounts: Optional[Sequence[Tuple[Pubkey, Account]]] = None, |
268 | | - compute_max_units: Optional[int] = None, |
269 | | - transaction_account_lock_limit: Optional[int] = None, |
270 | | -) -> "bankrun.ProgramTestContext": |
271 | | - """Create a fixture that builds the project and starts a bankrun with all the programs in the workspace deployed. |
272 | | -
|
273 | | - Args: |
274 | | - path: Path to root of the Anchor project. |
275 | | - scope: Pytest fixture scope. |
276 | | - build_cmd: Command to build the project. Defaults to `anchor build`. |
277 | | - accounts: A sequence of (address, account_object) tuples, indicating |
278 | | - what data to write to the given addresses. |
279 | | - compute_max_units: Override the default compute unit limit for a transaction. |
280 | | - transaction_account_lock_limit: Override the default transaction account lock limit. |
281 | | -
|
282 | | - Returns: |
283 | | - A bankrun fixture for use with pytest. |
284 | | - """ # noqa: E501,D202 |
285 | | - |
286 | | - @async_fixture(scope=scope) |
287 | | - async def _bankrun_fixture() -> bankrun.ProgramTestContext: |
288 | | - return await _bankrun_helper( |
289 | | - path, |
290 | | - build_cmd, |
291 | | - accounts, |
292 | | - compute_max_units, |
293 | | - transaction_account_lock_limit, |
294 | | - ) |
295 | | - |
296 | | - return _bankrun_fixture |
0 commit comments