{"id":21611207,"url":"https://github.com/crocofactory/pytest-evm","last_synced_at":"2026-01-05T12:51:31.091Z","repository":{"id":218969628,"uuid":"747821796","full_name":"CrocoFactory/pytest-evm","owner":"CrocoFactory","description":"The testing package containing tools to test Web3-based projects","archived":false,"fork":false,"pushed_at":"2024-09-15T21:32:35.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-15T22:29:21.264Z","etag":null,"topics":["ethereum","ethereum-contract","evm-wallet","pytest","pytest-plugin","python3","testing","testing-tools","web3py"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pytest-evm/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CrocoFactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-24T17:53:57.000Z","updated_at":"2024-09-15T21:33:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"2648e545-67e2-4b8d-935f-a5c3f1600fad","html_url":"https://github.com/CrocoFactory/pytest-evm","commit_stats":null,"previous_names":["blnkoff/pytest-evm","crocofactory/pytest-evm"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fpytest-evm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fpytest-evm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fpytest-evm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fpytest-evm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrocoFactory","download_url":"https://codeload.github.com/CrocoFactory/pytest-evm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226233369,"owners_count":17592877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","ethereum-contract","evm-wallet","pytest","pytest-plugin","python3","testing","testing-tools","web3py"],"created_at":"2024-11-24T21:11:26.469Z","updated_at":"2026-01-05T12:51:31.037Z","avatar_url":"https://github.com/CrocoFactory.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytest-evm\n\n\u003ca href=\"https://github.com/CrocoFactory\"\u003e\u003cimg alt=\"Croco Logo\" src=\"https://raw.githubusercontent.com/CrocoFactory/.github/main/branding/logo/bookmark_rounded.png\" width=\"100\"\u003e\u003c/a\u003e\n            \n[![PyPi Version](https://img.shields.io/pypi/v/pytest-evm)](https://pypi.org/project/pytest-evm/)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/pytest-evm?label=downloads)](https://pypi.org/project/pytest-evm/)\n[![License](https://img.shields.io/github/license/CrocoFactory/pytest-evm.svg)](https://pypi.org/project/pytest-evm/)\n[![Last Commit](https://img.shields.io/github/last-commit/CrocoFactory/pytest-evm.svg)](https://pypi.org/project/pytest-evm/)\n[![Development Status](https://img.shields.io/pypi/status/pytest-evm)](https://pypi.org/project/pytest-evm/)\n\nThe testing package containing tools to test Web3-based projects\n\n- **[Bug reports](https://github.com/CrocoFactory/pytest-evm/issues)**\n\nPackage's source code is made available under the [MIT License](LICENSE)\n\nThe project is made by the **[Croco Factory](https://github.com/CrocoFactory)** team\n\n# Quick Start\nThere are few features simplifying your testing with pytest:\n- **[Fixtures](#fixtures)**\n- **[Test Reporting](#test-reporting)**\n- **[Usage Example](#usage-example)**\n\n## Fixtures\n\n### make_wallet\nThis fixture simplify creating wallet instances as fixtures. Wallet instances are from `evm-wallet` package\n\n```python\nimport os\nimport pytest\nfrom typing import Optional\nfrom evm_wallet.types import NetworkInfo\nfrom evm_wallet import AsyncWallet, Wallet\n\n@pytest.fixture(scope=\"session\")\ndef make_wallet():\n    def _make_wallet(network: NetworkOrInfo, private_key: Optional[str] = None, is_async: bool = True):\n        if not private_key:\n            private_key = os.getenv('TEST_PRIVATE_KEY')\n        return AsyncWallet(private_key, network) if is_async else Wallet(private_key, network)\n\n    return _make_wallet\n```\n\nYou can specify whether your wallet should be of async or sync version. Instead of specifying RPC, you only have to provide\nchain's name. You can also specify a custom Network, using `NetworkOrInfo`. \n\n```python\nimport pytest\n\n@pytest.fixture\ndef wallet(make_wallet):\n    return make_wallet('Optimism')\n```\n\nAs you can see, a private key wasn't passed. This because of by-default `make_wallet` takes it from\nenvironment variable `TEST_PRIVATE_KEY`. You can set environment variables using extra-package `python-dotenv`.\n\n```python\n# conftest.py\n\nimport pytest\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\n\n@pytest.fixture(scope=\"session\")\ndef wallet(make_wallet):\n    return make_wallet('Polygon')\n```\n \nHere is the content of .env file\n\n```shell\n# .env\n\nTEST_PRIVATE_KEY=0x0000000000000000000000000000000000000000\n```\n\nYou can install `python-dotenv` along with `pytest-evm`:\n\n```shell\npip install pytest-evm[dotenv]\n```\n\n### zero_address\nThis fixture returns ZERO_ADDRESS value      \n\n```python\nimport pytest\nfrom evm_wallet import ZERO_ADDRESS\n\n@pytest.fixture(scope=\"session\")\ndef zero_address():\n    return ZERO_ADDRESS\n```\n\n### eth_amount\nThis fixture returns 0.001 ETH in Wei, which is the most using minimal value for tests \n\n```python\nimport pytest\nfrom web3 import AsyncWeb3\n\n@pytest.fixture(scope=\"session\")\ndef eth_amount():\n    amount = AsyncWeb3.to_wei(0.001, 'ether')\n    return amount\n```\n\n## Test Reporting\nIf your want to test one transaction, you can automatically `assert` transaction status and get useful report after test,\nif it completed successfully. To do this, you need to add mark `pytest.mark.tx` to your test and you must **return \ntransaction hash in test**\n\n```python\nimport pytest\n\n@pytest.mark.tx\n@pytest.mark.asyncio\nasync def test_transaction(wallet, eth_amount):\n    recipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'\n    params = await wallet.build_transaction_params(eth_amount, recipient=recipient)\n    return await wallet.transact(params)\n```\n\nAfter test, you get similar report:\n\n![Test Report](https://i.ibb.co/h98dNPL/Screenshot-2024-04-22-at-22-41-19.png)\n         \n## Usage Example\nHere is example of testing with `pytest-evm`:\n\n```python\nimport pytest\nfrom bridge import Bridge\n\nclass TestBridge:\n    @pytest.mark.tx\n    @pytest.mark.asyncio\n    async def test_swap(self, wallet, eth_amount, bridge, destination_network):\n        return await bridge.swap(eth_amount, destination_network)\n\n    @pytest.mark.tx\n    @pytest.mark.asyncio\n    async def test_swap_to_eth(self, wallet, eth_amount, bridge):\n        return await bridge.swap_to_eth(eth_amount)\n\n    @pytest.fixture\n    def wallet(self, make_wallet):\n        return make_wallet('Optimism')\n\n    @pytest.fixture\n    def bridge(self, wallet):\n        return Bridge(wallet)\n\n    @pytest.fixture\n    def destination_network(self):\n        return 'Arbitrum'\n```\n\n# Installing pytest-evm\nTo install the package from GitHub you can use:\n\n```shell\npip install git+https://github.com/CrocoFactory/pytest-evm.git\n```\n\nTo install the package from PyPi you can use:\n```shell\npip install pytest-evm\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fpytest-evm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrocofactory%2Fpytest-evm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fpytest-evm/lists"}