diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 6e9cfea..06cb01d 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -25,3 +25,5 @@ jobs: black --check ./ - name: Type Check (mypy) run: mypy src + - name: Tests + run: pytest tests/e2e/test_blockchain_data.py diff --git a/src/helpers/blockchain_data.py b/src/helpers/blockchain_data.py index 361b050..df6028d 100644 --- a/src/helpers/blockchain_data.py +++ b/src/helpers/blockchain_data.py @@ -50,6 +50,7 @@ def get_tx_hashes_blocks( if any( log.topics[0].to_0x_hex() == INVALIDATED_ORDER_TOPIC for log in receipt.logs # type: ignore[attr-defined] + if log.topics # type: ignore[attr-defined] ): continue # status = 0 indicates a reverted tx, status = 1 is successful tx diff --git a/tests/e2e/test_blockchain_data.py b/tests/e2e/test_blockchain_data.py new file mode 100644 index 0000000..30b4260 --- /dev/null +++ b/tests/e2e/test_blockchain_data.py @@ -0,0 +1,32 @@ +from os import getenv, environ +from unittest.mock import patch + +import pytest +from web3 import Web3 + + +@pytest.fixture() +def set_env_variables(monkeypatch): + with patch.dict(environ, clear=True): + envvars = { + "CHAIN_SLEEP_TIME": "1", + "NODE_URL": "https://rpc.mevblocker.io", + } + for k, v in envvars.items(): + monkeypatch.setenv(k, v) + yield # This is the magical bit which restore the environment after + + +def tests_get_tx_hashes_blocks(set_env_variables): + # import has to happen after patching environment variable + from src.helpers.blockchain_data import BlockchainData + + web3 = Web3(Web3.HTTPProvider(getenv("NODE_URL"))) + blockchain = BlockchainData(web3) + start_block = 20892118 + end_block = start_block + res = blockchain.get_tx_hashes_blocks(start_block, end_block) + assert res[0] == ( + "0xb75e03b63d4f06c56549effd503e1e37f3ccfc3c00e6985a5aacc9b0534d7c5c", + 20892118, + )