-
Notifications
You must be signed in to change notification settings - Fork 643
feat: Add comprehensive Python testing infrastructure with Poetry #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
llbbl
wants to merge
1
commit into
eveem-org:master
Choose a base branch
from
UnitSeeker:add-testing-infrastructure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,65 @@ | ||
| __pycache__ | ||
| */__pycache__ | ||
| cache_code | ||
| cache_pabi | ||
| cache_pan | ||
| cache | ||
| cache_pan | ||
| .DS_Store | ||
| # Python | ||
| __pycache__/ | ||
| */__pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| coverage.xml | ||
| *.cover | ||
| .hypothesis/ | ||
| .tox/ | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| ENV/ | ||
| env/ | ||
| .venv | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # Project specific | ||
| cache_code/ | ||
| cache_pabi/ | ||
| cache_pan/ | ||
| cache/ | ||
| cache_*/ | ||
| supplement.db | ||
| supp2.db | ||
| cache_* | ||
|
|
||
| # Claude | ||
| .claude/* | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Poetry | ||
| # Note: Do NOT ignore poetry.lock - it should be committed | ||
| dist/ | ||
| *.egg-info/ | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| [tool.poetry] | ||
| name = "panoramix" | ||
| version = "0.1.0" | ||
| description = "Ethereum smart contract decompiler" | ||
| authors = ["Panoramix Contributors"] | ||
| readme = "README.md" | ||
| packages = [ | ||
| { include = "core" }, | ||
| { include = "pano" }, | ||
| { include = "utils" }, | ||
| { include = "tilde" } | ||
| ] | ||
|
|
||
| [tool.poetry.dependencies] | ||
| python = "^3.8" | ||
| coloredlogs = "*" | ||
| requests = "*" | ||
| web3 = "*" | ||
| timeout-decorator = "*" | ||
|
|
||
| [tool.poetry.group.dev.dependencies] | ||
| pytest = "^7.4.0" | ||
| pytest-cov = "^4.1.0" | ||
| pytest-mock = "^3.11.0" | ||
|
|
||
| [tool.poetry.scripts] | ||
| test = "pytest:main" | ||
| tests = "pytest:main" | ||
|
|
||
| [tool.pytest.ini_options] | ||
| minversion = "7.0" | ||
| testpaths = ["tests"] | ||
| python_files = ["test_*.py", "*_test.py", "tests.py"] | ||
| python_classes = ["Test*", "*Tests"] | ||
| python_functions = ["test_*"] | ||
| addopts = [ | ||
| "-v", | ||
| "--strict-markers", | ||
| "--cov=core", | ||
| "--cov=pano", | ||
| "--cov=utils", | ||
| "--cov=tilde", | ||
| "--cov-report=html", | ||
| "--cov-report=xml", | ||
| "--cov-report=term-missing", | ||
| # Coverage threshold disabled for initial setup | ||
| # "--cov-fail-under=80", | ||
| ] | ||
| markers = [ | ||
| "unit: marks tests as unit tests", | ||
| "integration: marks tests as integration tests", | ||
| "slow: marks tests as slow running", | ||
| ] | ||
| filterwarnings = [ | ||
| "error", | ||
| "ignore::UserWarning", | ||
| "ignore::DeprecationWarning", | ||
| ] | ||
|
|
||
| [tool.coverage.run] | ||
| source = ["core", "pano", "utils", "tilde"] | ||
| omit = [ | ||
| "*/tests/*", | ||
| "*/test_*.py", | ||
| "*/__pycache__/*", | ||
| "*/site-packages/*", | ||
| ] | ||
|
|
||
| [tool.coverage.report] | ||
| precision = 2 | ||
| show_missing = true | ||
| skip_covered = false | ||
| exclude_lines = [ | ||
| "pragma: no cover", | ||
| "def __repr__", | ||
| "if self\\.debug:", | ||
| "if settings\\.DEBUG", | ||
| "raise AssertionError", | ||
| "raise NotImplementedError", | ||
| "if 0:", | ||
| "if __name__ == .__main__.:", | ||
| "if TYPE_CHECKING:", | ||
| "class .*\\bProtocol\\):", | ||
| "@(abc\\.)?abstractmethod", | ||
| ] | ||
|
|
||
| [tool.coverage.html] | ||
| directory = "htmlcov" | ||
|
|
||
| [tool.coverage.xml] | ||
| output = "coverage.xml" | ||
|
|
||
| [build-system] | ||
| requires = ["poetry-core>=1.0.0"] | ||
| build-backend = "poetry.core.masonry.api" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| """Shared pytest fixtures and configuration for Panoramix tests.""" | ||
|
|
||
| import os | ||
| import tempfile | ||
| from pathlib import Path | ||
| from typing import Generator, Dict, Any | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def temp_dir() -> Generator[Path, None, None]: | ||
| """Create a temporary directory for test files.""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| yield Path(tmpdir) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_contract_bytecode() -> str: | ||
| """Sample Ethereum contract bytecode for testing.""" | ||
| # Simple storage contract bytecode | ||
| return "0x608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100d9565b60405180910390f35b610073600480360381019061006e919061009d565b61007e565b005b60008054905090565b8060008190555050565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea2646970667358221220" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_contract_address() -> str: | ||
| """Sample Ethereum contract address for testing.""" | ||
| return "0x1234567890123456789012345678901234567890" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_cache_dir(temp_dir: Path) -> Path: | ||
| """Create mock cache directories for testing.""" | ||
| cache_pan = temp_dir / "cache_pan" | ||
| cache_code = temp_dir / "cache_code" | ||
| cache_pabi = temp_dir / "cache_pabi" | ||
|
|
||
| cache_pan.mkdir() | ||
| cache_code.mkdir() | ||
| cache_pabi.mkdir() | ||
|
|
||
| return temp_dir | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_config() -> Dict[str, Any]: | ||
| """Mock configuration dictionary for testing.""" | ||
| return { | ||
| "etherscan_api_key": "test_api_key", | ||
| "infura_url": "https://mainnet.infura.io/v3/test_project_id", | ||
| "timeout": 30, | ||
| "cache_enabled": True, | ||
| "debug": False, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_function_signature() -> Dict[str, str]: | ||
| """Mock function signature data for testing.""" | ||
| return { | ||
| "0x2e64cec1": "retrieve()", | ||
| "0x6057361d": "store(uint256)", | ||
| "0xa9059cbb": "transfer(address,uint256)", | ||
| "0x70a08231": "balanceOf(address)", | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_opcode_sequence() -> list: | ||
| """Mock EVM opcode sequence for testing.""" | ||
| return [ | ||
| ("PUSH1", "0x80"), | ||
| ("PUSH1", "0x40"), | ||
| ("MSTORE", None), | ||
| ("CALLVALUE", None), | ||
| ("DUP1", None), | ||
| ("ISZERO", None), | ||
| ("PUSH2", "0x0010"), | ||
| ("JUMPI", None), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_storage_slot() -> Dict[str, Any]: | ||
| """Mock storage slot information for testing.""" | ||
| return { | ||
| "slot": 0, | ||
| "offset": 0, | ||
| "type": "uint256", | ||
| "value": "0x0000000000000000000000000000000000000000000000000000000000000005", | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_abi() -> list: | ||
| """Mock contract ABI for testing.""" | ||
| return [ | ||
| { | ||
| "inputs": [], | ||
| "name": "retrieve", | ||
| "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], | ||
| "stateMutability": "view", | ||
| "type": "function", | ||
| }, | ||
| { | ||
| "inputs": [{"internalType": "uint256", "name": "num", "type": "uint256"}], | ||
| "name": "store", | ||
| "outputs": [], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function", | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def reset_environment(monkeypatch): | ||
| """Reset environment variables for each test.""" | ||
| # Clear any existing API keys or sensitive data | ||
| monkeypatch.delenv("ETHERSCAN_API_KEY", raising=False) | ||
| monkeypatch.delenv("INFURA_PROJECT_ID", raising=False) | ||
| monkeypatch.delenv("WEB3_PROVIDER_URL", raising=False) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def isolated_filesystem(tmp_path): | ||
| """Create an isolated filesystem for testing file operations.""" | ||
| original_cwd = os.getcwd() | ||
| os.chdir(tmp_path) | ||
| yield tmp_path | ||
| os.chdir(original_cwd) | ||
|
|
||
|
|
||
| # Markers for test categorization | ||
| def pytest_configure(config): | ||
| """Register custom markers.""" | ||
| config.addinivalue_line("markers", "unit: Unit tests") | ||
| config.addinivalue_line("markers", "integration: Integration tests") | ||
| config.addinivalue_line("markers", "slow: Slow running tests") |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note