Skip to content
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

Testing packaging #13

Merged
merged 12 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
pip install .
pip install types-setuptools

mkdir -p .github/linters
cp mypy.ini .github/linters
cp pyproject.toml .github/linters

- name: Mypy
uses: github/super-linter/[email protected]
Expand All @@ -46,4 +46,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Run only black
VALIDATE_PYTHON_MYPY: true
PYTHON_MYPY_CONFIG_FILE: mypy.ini
PYTHON_MYPY_CONFIG_FILE: pyproject.toml
4 changes: 2 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Pytest

defaults:
run:
shell: bash

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
# run CI every day even if no PRs/merges occur
- cron: '0 12 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-2022"]
python: ${{ (github.event_name == 'pull_request' && fromJSON('["3.10", "3.12"]')) || fromJSON('["3.10", "3.11", "3.12"]') }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: "pip"
cache-dependency-path: setup.py

- name: Install dependencies
run: |
pip install ".[test]"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run tests
run: |
make test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ out/
crytic-export/

# VENV
test-generator/
env/
13 changes: 4 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Test-generator uses the pull request contribution model. Please make an account

Some pull request guidelines:

- Work from the [`dev`](https://github.com/crytic/test-generator/tree/dev) branch. We performed extensive tests prior to merging anything to `main`, working from `dev` will allow us to merge your work faster.

- Minimize irrelevant changes (formatting, whitespace, etc) to code that would otherwise not be touched by this patch. Save formatting or style corrections for a separate pull request that does not make any semantic changes.
- When possible, large changes should be split up into smaller focused pull requests.
- Fill out the pull request description with a summary of what your patch does, key changes that have been made, and any further points of discussion, if applicable.
Expand All @@ -39,20 +39,15 @@ Below is a rough outline of test-generator's design:

## Development Environment

`test-generator` currently runs requires at least Python3.8 so make sure you have a sufficiently up-to-date installation by running `python --version`. We recommend [pyenv](https://github.com/pyenv/pyenv) to manage python versions.
`test-generator` currently runs requires at least Python3.10 so make sure you have a sufficiently up-to-date installation by running `python --version`. We recommend [pyenv](https://github.com/pyenv/pyenv) to manage python versions.

To start working on modifications to test-generator locally, run:
```bash
git clone https://github.com/crytic/test-generator
cd test-generator
git checkout dev

python3 -m venv env
source env/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
make dev
```
This will create a virtual environment, ./env/, in the root of the repo, activate it, and install dependencies.
This will create a virtual environment, ./env/, in the root of the repository and install dependencies.

To run commands using your development version of `test-generator`, run:
```bash
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PY_MODULE := test_generator
TEST_MODULE := tests

# Optionally overriden by the user, if they're using a virtual environment manager.
VENV ?= test-generator
VENV ?= env

# On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
VENV_BIN := $(VENV)/bin
Expand All @@ -18,6 +18,10 @@ BUMP_ARGS :=
# Optionally overridden by the user in the `test` target.
TESTS :=

# Optionally overridden by the user/CI, to limit the installation to a specific
# subset of development dependencies.
TEST_GENERATOR_EXTRA := dev

# If the user selects a specific test pattern to run, set `pytest` to fail fast
# and only run tests that match the pattern.
# Otherwise, run all tests and enable coverage assertions, since we expect
Expand All @@ -32,10 +36,19 @@ endif
all:
@echo "Run my targets individually!"

.PHONY: dev
dev: $(VENV)/pyvenv.cfg

.PHONY: run
run: $(VENV)/pyvenv.cfg
@. $(VENV_BIN)/activate && test-generator $(ARGS)

$(VENV)/pyvenv.cfg: pyproject.toml
# Create our Python 3 virtual environment
python3 -m venv env
$(VENV_BIN)/python -m pip install --upgrade pip
$(VENV_BIN)/python -m pip install -e .[$(TEST_GENERATOR_EXTRA)]

.PHONY: lint
lint: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
Expand All @@ -54,6 +67,7 @@ reformat:
.PHONY: test tests
test tests: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
solc-select use 0.8.19 --always-install && \
pytest $(T) $(TEST_ARGS)

.PHONY: package
Expand Down
11 changes: 0 additions & 11 deletions mypy.ini

This file was deleted.

67 changes: 0 additions & 67 deletions requirements.txt

This file was deleted.

24 changes: 17 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@
author="Trail of Bits",
version="0.0.1",
packages=find_packages(exclude=["tests"]),
python_requires=">=3.8",
python_requires=">=3.10",
install_requires=[
"colorama",
"crytic_compile",
"eth_utils",
"slither_analyzer",
"web3",
"jinja2",
"colorama>=0.4.0",
"slither_analyzer>=0.10.0",
"jinja2>=3.1.0",
],
extras_require={
"lint": [
"black==22.3.0",
"pylint==2.13.4",
],
"test": [
"pytest",
"solc-select>=0.1.4",
],
"dev": [
"slither-analyzer[lint,test]",
],
},
entry_points={"console_scripts": ["test-generator = test_generator.main:main"]},
)
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def medusa_generate_tests(self) -> None:
self.medusa_generator.create_poc()


@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True) # type: ignore[misc]
def change_test_dir(request: Any, monkeypatch: Any) -> None:
"""Helper fixture to change the working directory"""
# Directory of the test file
Expand All @@ -45,7 +45,7 @@ def change_test_dir(request: Any, monkeypatch: Any) -> None:
monkeypatch.chdir(data_dir)


@pytest.fixture
@pytest.fixture # type: ignore[misc]
def basic_types() -> TestGenerator:
"""Fixture for the BasicTypes test contract"""
target = "BasicTypes"
Expand All @@ -55,7 +55,7 @@ def basic_types() -> TestGenerator:
return TestGenerator(target, target_path, corpus_dir)


@pytest.fixture
@pytest.fixture # type: ignore[misc]
def fixed_size_arrays() -> TestGenerator:
"""Fixture for the FixedArrays test contract"""
target = "FixedArrays"
Expand All @@ -65,7 +65,7 @@ def fixed_size_arrays() -> TestGenerator:
return TestGenerator(target, target_path, corpus_dir)


@pytest.fixture
@pytest.fixture # type: ignore[misc]
def dynamic_arrays() -> TestGenerator:
"""Fixture for the DynamicArrays test contract"""
target = "DynamicArrays"
Expand All @@ -75,7 +75,7 @@ def dynamic_arrays() -> TestGenerator:
return TestGenerator(target, target_path, corpus_dir)


@pytest.fixture
@pytest.fixture # type: ignore[misc]
def structs_and_enums() -> TestGenerator:
"""Fixture for the TupleTypes test contract"""
target = "TupleTypes"
Expand All @@ -85,7 +85,7 @@ def structs_and_enums() -> TestGenerator:
return TestGenerator(target, target_path, corpus_dir)


@pytest.fixture
@pytest.fixture # type: ignore[misc]
def value_transfer() -> TestGenerator:
"""Fixture for the ValueTransfer test contract"""
target = "ValueTransfer"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
src = "src"
out = "out"
libs = ["lib"]

solc = "0.8.19"
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 2 additions & 0 deletions tests/test_types_medusa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import subprocess
import pytest
from .conftest import TestGenerator

TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
Expand Down Expand Up @@ -133,6 +134,7 @@ def test_medusa_structs_and_enums(structs_and_enums: TestGenerator) -> None:
assert False, "No tests were ran"


@pytest.mark.xfail(strict=True) # type: ignore[misc]
def test_medusa_value_transfer(value_transfer: TestGenerator) -> None:
"""Tests the BasicTypes contract with a Medusa corpus"""
value_transfer.medusa_generate_tests()
Expand Down
Loading