Skip to content

Commit

Permalink
Updating of evm-wallet version to 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
blnkoff committed Apr 22, 2024
1 parent 79aa3dd commit befa9fa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def test_transaction(wallet, eth_amount):

After test, you get similar report:

![Test Report](https://i.ibb.co/n8vKXwB/Screenshot-2024-01-24-at-22-08-29.png)
![Test Report](https://i.ibb.co/h98dNPL/Screenshot-2024-04-22-at-22-41-19.png)

## Usage Example
Here is example of testing with `pytest-evm`:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = 'pytest_evm'
version = '0.1.2'
version = '0.2.0'
description = 'The testing package containing tools to test Web3-based projects'
authors = ['Alexey <abelenkov2006@gmail.com>']
authors = ['Alexey <axbelenkov@gmail.com>']
license = 'MIT'
readme = 'README.md'
repository = 'https://github.com/blnkoff/pytest-evm'
Expand All @@ -24,10 +24,10 @@ packages = [{ include = 'pytest_evm' }]
[tool.poetry.dependencies]
python = '^3.11'
web3 = "^6.12.0"
evm-wallet = "^1.2.0"
python-dotenv = {version = "^1.0.1", optional = true}
pytest = "^8.1.1"
pytest-asyncio = "^0.23.6"
evm-wallet = "^2.0.2"

[tool.poetry.extras]
dotenv = ["python-dotenv"]
Expand Down
15 changes: 10 additions & 5 deletions pytest_evm/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import os
import pytest
from typing import Optional
from evm_wallet import ZERO_ADDRESS
from evm_wallet.types import NetworkOrInfo
from evm_wallet import ZERO_ADDRESS, NetworkInfo
from evm_wallet import AsyncWallet, Wallet
from evm_wallet.types import Network
from web3 import AsyncWeb3
from web3.types import Wei


@pytest.fixture(scope="session")
def make_wallet():
def _make_wallet(network: NetworkOrInfo, private_key: Optional[str] = None, is_async: bool = True):
def _make_wallet(
network: Network | NetworkInfo,
private_key: Optional[str] = None,
is_async: bool = True
) -> AsyncWallet | Wallet:
if not private_key:
private_key = os.getenv('TEST_PRIVATE_KEY')
return AsyncWallet(private_key, network) if is_async else Wallet(private_key, network)
Expand All @@ -18,11 +23,11 @@ def _make_wallet(network: NetworkOrInfo, private_key: Optional[str] = None, is_a


@pytest.fixture(scope="session")
def eth_amount():
def eth_amount() -> Wei:
amount = AsyncWeb3.to_wei(0.001, 'ether')
return amount


@pytest.fixture(scope="session")
def zero_address():
def zero_address() -> str:
return ZERO_ADDRESS
4 changes: 2 additions & 2 deletions pytest_evm/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import wraps
from typing import Iterable
from evm_wallet import Wallet
from pytest_evm.utils import validate_status, get_last_transaction, get_balance
from pytest_evm.utils import validate_status, get_last_transaction


def pytest_configure(config):
Expand Down Expand Up @@ -34,7 +34,7 @@ def pytest_runtest_makereport(item: pytest.Item, call):
wallet = Wallet(wallet.private_key, wallet.network)
tx = get_last_transaction(wallet)
last_tx_hash = tx['hash']
balance = get_balance(wallet)
balance = wallet.get_balance(True)
costs = tx['value'] + tx['gas']*tx['gasPrice']
costs = Web3.from_wei(costs, 'ether')
print()
Expand Down
7 changes: 0 additions & 7 deletions pytest_evm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,3 @@ def get_last_transaction(wallet: Wallet, timeout: float = 10):
break

return last_transaction


def get_balance(wallet: Wallet) -> int:
w3 = Web3(Web3.HTTPProvider(wallet.network['rpc']))
balance = w3.eth.get_balance(account=wallet.public_key)
balance = w3.from_wei(balance, 'ether')
return balance
2 changes: 1 addition & 1 deletion tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
@pytest.mark.asyncio
async def test_transaction(wallet, eth_amount):
recipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'
params = await wallet.build_transaction_params(eth_amount, recipient=recipient)
params = await wallet.build_tx_params(eth_amount, recipient=recipient)
return await wallet.transact(params)

0 comments on commit befa9fa

Please sign in to comment.