From 2d7270fcf8a8198707ba73a982bcfa233d354f14 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Mon, 29 Jul 2024 14:42:18 +0800 Subject: [PATCH 01/10] update pyo3 to 0.22.2 --- Cargo.lock | 43 ++++++++++++++++++++++++++----------------- aderyn_py/Cargo.toml | 2 +- aderyn_py/src/lib.rs | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6db72ae99..b841fc14c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1791,9 +1791,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "inlinable_string" @@ -2454,6 +2454,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2554,15 +2560,16 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.19.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38" +checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -2571,9 +2578,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.19.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" +checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8" dependencies = [ "once_cell", "target-lexicon", @@ -2581,9 +2588,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.19.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" +checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6" dependencies = [ "libc", "pyo3-build-config", @@ -2591,25 +2598,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.19.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfeb4c99597e136528c6dd7d5e3de5434d1ceaf487436a3f03b2d56b6fc9efd1" +checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 1.0.109", + "syn 2.0.67", ] [[package]] name = "pyo3-macros-backend" -version = "0.19.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947dc12175c254889edc0c02e399476c2f652b4b9ebd123aa655c224de259536" +checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372" dependencies = [ + "heck 0.5.0", "proc-macro2", + "pyo3-build-config", "quote", - "syn 1.0.109", + "syn 2.0.67", ] [[package]] @@ -3836,9 +3845,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "untrusted" diff --git a/aderyn_py/Cargo.toml b/aderyn_py/Cargo.toml index 90a44c0e8..5ce8abf01 100644 --- a/aderyn_py/Cargo.toml +++ b/aderyn_py/Cargo.toml @@ -17,6 +17,6 @@ crate-type = ["cdylib"] aderyn_driver = { path = "../aderyn_driver", version = "0.1.8" } [dependencies.pyo3] -version = "0.19.0" +version = "0.22.2" # "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8 features = ["abi3-py37"] \ No newline at end of file diff --git a/aderyn_py/src/lib.rs b/aderyn_py/src/lib.rs index 70a664733..93c856ccb 100644 --- a/aderyn_py/src/lib.rs +++ b/aderyn_py/src/lib.rs @@ -28,7 +28,7 @@ fn main() { /// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to /// import the module. #[pymodule] - fn aderynpy(_py: Python, m: &PyModule) -> PyResult<()> { + fn aderynpy(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(generate_report, m)?)?; Ok(()) From bedbd961095a36d1bff5d206ac90c9a10f54a7fb Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Thu, 1 Aug 2024 00:15:38 +0800 Subject: [PATCH 02/10] initial generate report --- Cargo.lock | 23 +++++++++++++++++++++ aderyn_driver/Cargo.toml | 1 + aderyn_driver/src/driver.rs | 3 ++- aderyn_py/Cargo.toml | 3 ++- aderyn_py/example.py | 7 +++++++ aderyn_py/src/lib.rs | 41 ++++++++++++++++++++++++++----------- 6 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 aderyn_py/example.py diff --git a/Cargo.lock b/Cargo.lock index 2e1de133d..7c56d7151 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,7 @@ dependencies = [ "criterion", "cyfrin-foundry-compilers", "cyfrin-foundry-config", + "field_access", "rayon", "serde", "serde_json", @@ -80,6 +81,7 @@ name = "aderyn_py" version = "0.1.8" dependencies = [ "aderyn_driver", + "field_access", "pyo3", ] @@ -1198,6 +1200,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "field_access" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e623ab785a56a622537034c7109d47898c41cb9219803155759dcca1f19655c" +dependencies = [ + "field_access_derive", + "paste", +] + +[[package]] +name = "field_access_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917d5dcdd27ef8b8bd66913702385e92fa2a2a9fd6f7b94ffa03e884d847a8d9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.67", +] + [[package]] name = "figment" version = "0.10.19" diff --git a/aderyn_driver/Cargo.toml b/aderyn_driver/Cargo.toml index edebe3121..d8f729a24 100644 --- a/aderyn_driver/Cargo.toml +++ b/aderyn_driver/Cargo.toml @@ -17,6 +17,7 @@ serde = { version = "1.0.160", features = ["derive"] } serde_repr = "0.1.12" cyfrin-foundry-config = { version = "0.2.1" } toml = "0.8.13" +field_access = "0.1.8" [dev-dependencies] criterion = "0.5.1" diff --git a/aderyn_driver/src/driver.rs b/aderyn_driver/src/driver.rs index 3abef9b39..9ff0bb9e6 100644 --- a/aderyn_driver/src/driver.rs +++ b/aderyn_driver/src/driver.rs @@ -13,9 +13,10 @@ use aderyn_core::{ }, run, }; +use field_access::FieldAccess; use std::{collections::HashMap, error::Error, path::PathBuf}; -#[derive(Clone)] +#[derive(Clone, FieldAccess)] pub struct Args { pub root: String, pub output: String, diff --git a/aderyn_py/Cargo.toml b/aderyn_py/Cargo.toml index 5ce8abf01..0fdd4d9b9 100644 --- a/aderyn_py/Cargo.toml +++ b/aderyn_py/Cargo.toml @@ -15,8 +15,9 @@ crate-type = ["cdylib"] [dependencies] aderyn_driver = { path = "../aderyn_driver", version = "0.1.8" } +field_access = "0.1.8" [dependencies.pyo3] version = "0.22.2" # "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8 -features = ["abi3-py37"] \ No newline at end of file +features = ["abi3-py38"] \ No newline at end of file diff --git a/aderyn_py/example.py b/aderyn_py/example.py new file mode 100644 index 000000000..08d679619 --- /dev/null +++ b/aderyn_py/example.py @@ -0,0 +1,7 @@ +from aderynpy import generate_report + +generate_report("../tests/contract-playground", "./report.md") + +# generate_report("../tests/contract-playground", "./report.md", +# path_includes=["src/eth2", "src/inheritance"], +# ) \ No newline at end of file diff --git a/aderyn_py/src/lib.rs b/aderyn_py/src/lib.rs index 93c856ccb..882cf0c56 100644 --- a/aderyn_py/src/lib.rs +++ b/aderyn_py/src/lib.rs @@ -1,26 +1,43 @@ #![allow(unused)] use aderyn_driver::driver; +use field_access::{FieldAccess, FieldMut}; fn main() { use pyo3::prelude::*; + use pyo3::types::{PyBool, PyDict}; #[pyfunction] - fn generate_report(root: String, output: String) { - let args = driver::Args { + #[pyo3(signature = (root, output, **py_kwargs))] + fn generate_report(root: String, output: String, py_kwargs: Option<&Bound<'_, PyDict>>) { + let mut args = driver::Args { root, output, - src: None, // TODO support this later - no_snippets: false, // TODO support this later - skip_build: false, // TODO support this later - skip_cloc: false, // TODO support this later - path_includes: None, // TODO support this later - path_excludes: None, // TODO support this later - stdout: false, // TODO support this later - skip_update_check: false, // TODO support this later - auditor_mode: false, // TODO support this later - highs_only: false, // TODO support this later + src: None, + no_snippets: false, + skip_build: false, + skip_cloc: false, + path_includes: None, + path_excludes: None, + stdout: false, + skip_update_check: false, + auditor_mode: false, + highs_only: false, }; + + if let Some(kwargs) = py_kwargs { + kwargs.iter().for_each(|(py_key, py_value)| { + let rust_key: String = py_key.extract().unwrap(); + if py_value.is_instance_of::() { + let rust_value: bool = py_value.extract().unwrap(); + args.field_mut(&rust_key).unwrap().replace(rust_value); + } else { + let rust_value: Vec = py_value.extract().unwrap(); + args.field_mut(&rust_key).unwrap().replace(Some(rust_value)); + } + }) + } + driver::drive(args); } From 09acfc6901236477700bd2ac89e44d93b3e93138 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Tue, 13 Aug 2024 22:18:12 +0800 Subject: [PATCH 03/10] test new ci --- aderyn_py/tests/test_generate_report.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 aderyn_py/tests/test_generate_report.py diff --git a/aderyn_py/tests/test_generate_report.py b/aderyn_py/tests/test_generate_report.py new file mode 100644 index 000000000..d6bc3d297 --- /dev/null +++ b/aderyn_py/tests/test_generate_report.py @@ -0,0 +1,14 @@ +from unittest.mock import Mock +from aderynpy import generate_report + +# generate_report("../../tests/contract-playground", "./report.md") + +# generate_report() + +# generate_report("../tests/contract-playground", "./report.md", +# path_includes=["src/eth2", "src/inheritance"], +# ) + +# generate_report("../tests/contract-playground", "./report.md", +# path_includes=None, +# ) \ No newline at end of file From 97b089737891203229060699780f9907fb67e1c5 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Tue, 13 Aug 2024 22:24:19 +0800 Subject: [PATCH 04/10] fix --- .github/workflows/python.yml | 35 +++++++++++++++++++++++++++++++++++ Cargo.lock | 6 +++--- aderyn_py/example.py | 7 ------- aderyn_py/src/lib.rs | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/python.yml delete mode 100644 aderyn_py/example.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 000000000..c6ce903c6 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,35 @@ +name: CI + +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.8, 3.9, 3.10] + os: [ubuntu-latest] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + + - name: Install maturin + run: pip install maturin + + - name: Build and test + run: | + maturin develop + maturin test diff --git a/Cargo.lock b/Cargo.lock index eb5323f77..c4005d063 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1221,7 +1221,7 @@ checksum = "917d5dcdd27ef8b8bd66913702385e92fa2a2a9fd6f7b94ffa03e884d847a8d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.67", + "syn 2.0.72", ] [[package]] @@ -2660,7 +2660,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.67", + "syn 2.0.72", ] [[package]] @@ -2673,7 +2673,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.67", + "syn 2.0.72", ] [[package]] diff --git a/aderyn_py/example.py b/aderyn_py/example.py deleted file mode 100644 index 08d679619..000000000 --- a/aderyn_py/example.py +++ /dev/null @@ -1,7 +0,0 @@ -from aderynpy import generate_report - -generate_report("../tests/contract-playground", "./report.md") - -# generate_report("../tests/contract-playground", "./report.md", -# path_includes=["src/eth2", "src/inheritance"], -# ) \ No newline at end of file diff --git a/aderyn_py/src/lib.rs b/aderyn_py/src/lib.rs index 882cf0c56..f75501787 100644 --- a/aderyn_py/src/lib.rs +++ b/aderyn_py/src/lib.rs @@ -32,7 +32,7 @@ fn main() { let rust_value: bool = py_value.extract().unwrap(); args.field_mut(&rust_key).unwrap().replace(rust_value); } else { - let rust_value: Vec = py_value.extract().unwrap(); + let rust_value: Vec = py_value.extract().unwrap_or_default(); args.field_mut(&rust_key).unwrap().replace(Some(rust_value)); } }) From d6ca7ebb56667ec15dc5655e8b1453b3b2fb2b85 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 21:27:06 +0800 Subject: [PATCH 05/10] ci 2 --- .github/workflows/python.yml | 147 +++++++++++++++--- aderyn_py/requirements.txt | 2 + ...nerate_report.cpython-312-pytest-8.3.2.pyc | Bin 0 -> 2115 bytes aderyn_py/tests/test_generate_report.py | 37 +++-- 4 files changed, 156 insertions(+), 30 deletions(-) create mode 100644 aderyn_py/requirements.txt create mode 100644 aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c6ce903c6..f9371c259 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,35 +1,146 @@ -name: CI - on: [push, pull_request, workflow_dispatch] +name: Aderyn-py + jobs: - build: + check: + name: Check runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 - strategy: - matrix: - python-version: [3.8, 3.9, 3.10] - os: [ubuntu-latest] + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install git submodules + run: | + git submodule update --init --recursive + + - name: Run cargo check + uses: actions-rs/cargo@v1 + with: + command: check + test: + name: Tests + runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: foundry-toolchain + uses: foundry-rs/foundry-toolchain@v1.2.0 + + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - uses: Swatinem/rust-cache@v2 + - name: Run cargo build + run: | + cargo build + + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 8 + run_install: false - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - uses: actions/setup-node@v4 with: - python-version: ${{ matrix.python-version }} + node-version: 20 + cache: "npm" - - name: Install Rust + - name: Submodule init + run: | + git submodule update --init --recursive + + - uses: Swatinem/rust-cache@v2 + - name: Run cargo test + run: | + cargo test _by_loading_contract_directly + + - uses: Swatinem/rust-cache@v2 + - name: Run cargo test + run: | + cargo test -- --nocapture + + reports: + name: Check Reports + runs-on: ubuntu-latest + steps: + - name: foundry-toolchain + uses: foundry-rs/foundry-toolchain@v1.2.0 + + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: + profile: minimal toolchain: stable - components: clippy + override: true + + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" - - name: Install maturin - run: pip install maturin + - name: Setup virtual environment + run: | + python -m venv venv + source ./.venv/bin/activate + pip install -r ./aderyn_py/requirements.txt + + - name: Submodule init + run: | + git submodule update --init --recursive + + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: "npm" + + - uses: pnpm/action-setup@v3 + with: + version: 8 + + - uses: bahmutov/npm-install@v1 + with: + useLockFile: false + working-directory: tests/2024-05-Sablier/v2-core + + - uses: bahmutov/npm-install@v1 + with: + useLockFile: false + working-directory: tests/prb-math/ - - name: Build and test + - name: Run tests run: | + cd aderyn_py maturin develop - maturin test + pytest tests diff --git a/aderyn_py/requirements.txt b/aderyn_py/requirements.txt new file mode 100644 index 000000000..cb6f7b95b --- /dev/null +++ b/aderyn_py/requirements.txt @@ -0,0 +1,2 @@ +pytest==8.3.2 +maturin==1.7.0 \ No newline at end of file diff --git a/aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc b/aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0407ab8a6127a54c65da9e3b5882cc581f51169d GIT binary patch literal 2115 zcmb^x-)kI2cxHER??;k5(?m^3D`{8*FPmV)%D6@?a5C_Y(Y{R{jLd`YQL85ISe@>Wej$cuinyOXnb3(5J3ccXbDG9Yw0x&qn5Fh!m-3$G9yWPDGgBb zGOg@V79%&^oKy}6u=(r&R~XTk5i!2P>srhqscUFG5iX5(v1M*b>YRl|VcGRv>TtJ0 z-F85EI7)+nAD@jWD`jcn{$jDjUB+3d7WkYxHEy>(r@Kspj!(i#kjBa^fyEX9tEnBU z@_hNEJ-=YT>r}mlOGA6eg2g=BAujFuHV;~!?Za6vv1J^)T{&bWsM##=?0Umi!&c)vS7_6!-E#O!cwp#2#T?kwl6*(0PQ$Ll zzx4rdq2{=UnmCd?u@P-O;SzlsB%ed&zSR2~m$uRBp`NBHi4j-5gqo((7(kNZSw(?W z;<<;Hbq+lluV&Pzii+XCOTRJKlW6*SPj8MsX)CF|LDKzH&*-IA=YTSMCcDQAO0W5p z!Um9JdS)GythA|X>q&GZ$0wA|Ufr&`_#$FY5BYya*$iM$SGT9bno|P}g$*=)4CfD` z-b>d|UjIWcrS!Zi#l8SAARIHEFqMx8(8X}{tPU@xOQDR>p;#wFZ0;5YlJ zF0%6HLakT|b?D8_zhQ-=_F6z!>t3)1?Jo?{sMjq`n2eL4!z1WYx+$B(!rR*7qJ_iq zk-2uaY_Z&j2{OAlE3tWt6{*WR)UO4^&Gly&WB!80gh^f2@wlZ69TeqOmfJ#@cNlXi zj~tu=MPQz?3L?eYUV~HFN+QQP)iw=kE(0;`_(Er#3gi6S=g)}T;6Rakz1@|=r{YjC zUa2{rCkGX+1+BJ2T`>ycO10DQc*BQ)yZ|(qn5wXqpyQE9wX*C5RmZFNPRkY93UlhN z^dRzYL_szJ{|u!86%&ub#$m8S7 zzBo*r941c0MC|>gVd7;bAM31I+wYX#gS@d)Ghl9eC0ucW(rNc%sS4Lxt*tl>zZB2O z1XSAHWH3h=+BM0G?XH;IOF)mpp>m3_yRcnBkM^N`lQ&P_I{V4l+nooKNA6VbPg)xj z$G$$kQ8;zwt;Z%xf%x{^561I==cjI5xPIZsY~izso9};m;EuVGIr?*9`o`t!mlNZ~m1>sY4Hqga6C7VI16oV39Q@GOFBEzE3d?S&+9Z#$|w_LBFoi28UwrutYlH zQ8_8-xHL3lJCTWV+U~}UX|x==Dn_8YpkFv`gl?3tyNJSIL-YmMwllA`0@Cr^*Jv3? z`Ht8tuszZ-#=jzT4Lv~PKcTT-(Ba>3`s108W**|H`*`a1bAKZ9n6`yXP5&cbz=yU9 I3X7co1B*!$GXMYp literal 0 HcmV?d00001 diff --git a/aderyn_py/tests/test_generate_report.py b/aderyn_py/tests/test_generate_report.py index d6bc3d297..8d932c9f6 100644 --- a/aderyn_py/tests/test_generate_report.py +++ b/aderyn_py/tests/test_generate_report.py @@ -1,14 +1,27 @@ -from unittest.mock import Mock +import subprocess +import pytest from aderynpy import generate_report -# generate_report("../../tests/contract-playground", "./report.md") - -# generate_report() - -# generate_report("../tests/contract-playground", "./report.md", -# path_includes=["src/eth2", "src/inheritance"], -# ) - -# generate_report("../tests/contract-playground", "./report.md", -# path_includes=None, -# ) \ No newline at end of file +@pytest.mark.parametrize("root, report", [ + ("../tests/contract-playground", "../reports/report.md"), + ("../tests/2024-05-Sablier", "../reports/sablier-aderyn-toml-nested-root.md"), + ("../tests/adhoc-sol-files", "../reports/adhoc-sol-files-report.md"), + ("../tests/foundry-nft-f23", "../reports/nft-report.md"), + ("../tests/prb-math", "../reports/prb-math-report.md"), +]) +def test_generate_report(root, report): + # Define output file path + out_file = f"./{root.split('../')[-1]}-workflow.md" + + # Call the generate_report function + generate_report(root, out_file) + + # Run the diff command to compare the generated report with the original report + result = subprocess.run( + ["diff", str(out_file), report], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + # Check if diff command found any differences (result.returncode == 0 means no differences) + assert result.returncode == 1 From 3516f4cebef1ab99609cce8a8a01b4abea4e8a68 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 21:30:08 +0800 Subject: [PATCH 06/10] fix virtual env --- .github/workflows/python.yml | 2 +- ..._generate_report.cpython-312-pytest-8.3.2.pyc | Bin 2115 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f9371c259..562e108ea 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -110,7 +110,7 @@ jobs: - name: Setup virtual environment run: | - python -m venv venv + python -m venv .venv source ./.venv/bin/activate pip install -r ./aderyn_py/requirements.txt diff --git a/aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc b/aderyn_py/tests/__pycache__/test_generate_report.cpython-312-pytest-8.3.2.pyc deleted file mode 100644 index 0407ab8a6127a54c65da9e3b5882cc581f51169d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2115 zcmb^x-)kI2cxHER??;k5(?m^3D`{8*FPmV)%D6@?a5C_Y(Y{R{jLd`YQL85ISe@>Wej$cuinyOXnb3(5J3ccXbDG9Yw0x&qn5Fh!m-3$G9yWPDGgBb zGOg@V79%&^oKy}6u=(r&R~XTk5i!2P>srhqscUFG5iX5(v1M*b>YRl|VcGRv>TtJ0 z-F85EI7)+nAD@jWD`jcn{$jDjUB+3d7WkYxHEy>(r@Kspj!(i#kjBa^fyEX9tEnBU z@_hNEJ-=YT>r}mlOGA6eg2g=BAujFuHV;~!?Za6vv1J^)T{&bWsM##=?0Umi!&c)vS7_6!-E#O!cwp#2#T?kwl6*(0PQ$Ll zzx4rdq2{=UnmCd?u@P-O;SzlsB%ed&zSR2~m$uRBp`NBHi4j-5gqo((7(kNZSw(?W z;<<;Hbq+lluV&Pzii+XCOTRJKlW6*SPj8MsX)CF|LDKzH&*-IA=YTSMCcDQAO0W5p z!Um9JdS)GythA|X>q&GZ$0wA|Ufr&`_#$FY5BYya*$iM$SGT9bno|P}g$*=)4CfD` z-b>d|UjIWcrS!Zi#l8SAARIHEFqMx8(8X}{tPU@xOQDR>p;#wFZ0;5YlJ zF0%6HLakT|b?D8_zhQ-=_F6z!>t3)1?Jo?{sMjq`n2eL4!z1WYx+$B(!rR*7qJ_iq zk-2uaY_Z&j2{OAlE3tWt6{*WR)UO4^&Gly&WB!80gh^f2@wlZ69TeqOmfJ#@cNlXi zj~tu=MPQz?3L?eYUV~HFN+QQP)iw=kE(0;`_(Er#3gi6S=g)}T;6Rakz1@|=r{YjC zUa2{rCkGX+1+BJ2T`>ycO10DQc*BQ)yZ|(qn5wXqpyQE9wX*C5RmZFNPRkY93UlhN z^dRzYL_szJ{|u!86%&ub#$m8S7 zzBo*r941c0MC|>gVd7;bAM31I+wYX#gS@d)Ghl9eC0ucW(rNc%sS4Lxt*tl>zZB2O z1XSAHWH3h=+BM0G?XH;IOF)mpp>m3_yRcnBkM^N`lQ&P_I{V4l+nooKNA6VbPg)xj z$G$$kQ8;zwt;Z%xf%x{^561I==cjI5xPIZsY~izso9};m;EuVGIr?*9`o`t!mlNZ~m1>sY4Hqga6C7VI16oV39Q@GOFBEzE3d?S&+9Z#$|w_LBFoi28UwrutYlH zQ8_8-xHL3lJCTWV+U~}UX|x==Dn_8YpkFv`gl?3tyNJSIL-YmMwllA`0@Cr^*Jv3? z`Ht8tuszZ-#=jzT4Lv~PKcTT-(Ba>3`s108W**|H`*`a1bAKZ9n6`yXP5&cbz=yU9 I3X7co1B*!$GXMYp From 390790b07cc91d012f18fc4b822cb5d0aeade196 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 21:36:26 +0800 Subject: [PATCH 07/10] fix test step --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 562e108ea..d8c116d0f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -141,6 +141,7 @@ jobs: - name: Run tests run: | + source ./.venv/bin/activate cd aderyn_py maturin develop pytest tests From 3b69b03a631a16cc456c7211c2b7ff65883fca63 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 21:50:40 +0800 Subject: [PATCH 08/10] fix cache --- .github/workflows/python.yml | 56 +----------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d8c116d0f..852908dea 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -21,7 +21,6 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.11" - cache: "pip" - name: Install git submodules run: | @@ -32,59 +31,6 @@ jobs: with: command: check - test: - name: Tests - runs-on: ubuntu-latest - steps: - - name: foundry-toolchain - uses: foundry-rs/foundry-toolchain@v1.2.0 - - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.11" - cache: "pip" - - - uses: Swatinem/rust-cache@v2 - - name: Run cargo build - run: | - cargo build - - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - run_install: false - - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "npm" - - - name: Submodule init - run: | - git submodule update --init --recursive - - - uses: Swatinem/rust-cache@v2 - - name: Run cargo test - run: | - cargo test _by_loading_contract_directly - - - uses: Swatinem/rust-cache@v2 - - name: Run cargo test - run: | - cargo test -- --nocapture - reports: name: Check Reports runs-on: ubuntu-latest @@ -141,7 +87,7 @@ jobs: - name: Run tests run: | - source ./.venv/bin/activate + source .venv/bin/activate cd aderyn_py maturin develop pytest tests From a3860cc1832438605bdd6479c1cc733e319acda9 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 21:57:17 +0800 Subject: [PATCH 09/10] fix again --- .github/workflows/python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 852908dea..404381e4e 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -56,8 +56,8 @@ jobs: - name: Setup virtual environment run: | - python -m venv .venv - source ./.venv/bin/activate + python -m venv venv + source venv/bin/activate pip install -r ./aderyn_py/requirements.txt - name: Submodule init @@ -87,7 +87,7 @@ jobs: - name: Run tests run: | - source .venv/bin/activate + source venv/bin/activate cd aderyn_py maturin develop pytest tests From 17d0ac9294500fe19dca5a3cc535dfecb3cd9502 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 14 Aug 2024 22:01:38 +0800 Subject: [PATCH 10/10] adjust position --- .github/workflows/python.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 404381e4e..f8ea27a8c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -54,12 +54,6 @@ jobs: python-version: "3.11" cache: "pip" - - name: Setup virtual environment - run: | - python -m venv venv - source venv/bin/activate - pip install -r ./aderyn_py/requirements.txt - - name: Submodule init run: | git submodule update --init --recursive @@ -85,6 +79,12 @@ jobs: useLockFile: false working-directory: tests/prb-math/ + - name: Setup virtual environment + run: | + python -m venv venv + source venv/bin/activate + pip install -r ./aderyn_py/requirements.txt + - name: Run tests run: | source venv/bin/activate