From 11169ef26c18856dc626f554eb61407c8eb6f521 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 23 Feb 2024 13:00:45 +0100 Subject: [PATCH 1/3] fix clippy warnings --- src/gen/test_generators.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gen/test_generators.rs b/src/gen/test_generators.rs index f42c5b00e..2a3986c5f 100644 --- a/src/gen/test_generators.rs +++ b/src/gen/test_generators.rs @@ -6,7 +6,6 @@ use chia_protocol::{Bytes, Bytes48}; use clvmr::allocator::NodePtr; use clvmr::Allocator; use std::iter::zip; -use std::string::String; use text_diff::diff; use text_diff::Difference; From 01a749ecd8605632d71b50e1ee850c7e08417f49 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 23 Feb 2024 13:07:59 +0100 Subject: [PATCH 2/3] add pre-commit config file --- .github/workflows/build-test.yml | 4 +-- .pre-commit-config.yaml | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 19e82519f..cf02ecac6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -288,7 +288,7 @@ jobs: uses: dtolnay/rust-toolchain with: components: rustfmt, clippy - + - name: fmt run: | cargo fmt --all -- --files-with-diff --check @@ -302,7 +302,7 @@ jobs: - uses: dtolnay/rust-toolchain with: components: clippy - + - name: workspace run: | cargo clippy --workspace --all-features -- -Dwarnings diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..aad8d3954 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,52 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: check-yaml + - id: check-added-large-files +- repo: local + hooks: + - id: fmt + name: fmt + description: run cargo fmt on the workspace + entry: cargo fmt --all -- --color always + language: system + pass_filenames: false + - id: clippy + name: clippy + description: run cargo clippy on the workspace + stages: [pre-push] + entry: cargo clippy --workspace --all-features -- -Dwarnings + language: system + pass_filenames: false + - id: build + name: build + description: run cargo build on the workspace + stages: [pre-push] + entry: cargo build --all-features --workspace + language: system + pass_filenames: false + - id: benchmarks + name: build benchmarks + description: run cargo bench on the workspace + stages: [pre-push] + entry: cargo bench --no-run --workspace + language: system + pass_filenames: false + - id: tests + name: run tests + description: run cargo test on the workspace + stages: [pre-push] + entry: cargo test --workspace + language: system + pass_filenames: false + - id: wheel + name: build wheel + description: run maturin develop on the wheel + stages: [pre-push] + entry: cd wheel && maturin develop + language: system + pass_filenames: false From 81131eff64cb7ee654537513489ff0628818f344 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 23 Feb 2024 17:00:12 +0100 Subject: [PATCH 3/3] update README --- .pre-commit-config.yaml | 2 +- README.md | 100 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aad8d3954..344d98626 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,6 +47,6 @@ repos: name: build wheel description: run maturin develop on the wheel stages: [pre-push] - entry: cd wheel && maturin develop + entry: sh -c "cd wheel && maturin develop" language: system pass_filenames: false diff --git a/README.md b/README.md index 4484bc5be..70e2ece6f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,102 @@ This cargo workspace contains code useful for working with the Chia network. -It contains a rust crate `chia` (here), a python wheel api `chia_rs` (in `wheel`), and web assembly (in `wasm`). +# Tests + +To run tests: + +``` +cargo test --all +``` + +Some slow tests are only enabled in optimized builds, so it may also be a good +idea to run the tests in release mode: + +``` +cargo test --all --release +``` + +You may need a python virtual environment activated for the tests to link. +This seems to be caused by the pyo3 dependency in the `wheel`. + +# Benchmarks + +To run benchmarks for a specific crate: + +``` +cargo bench -- --save-baseline before + +cargo bench -- --save-baseline after +critcmp after before +``` + +You can also run all the benchmarks by including `--workspace` on the command +line. + +# pre-commit + +This repository has a pre-commit configuration, which is hooked into git by +running: + +``` +pre-commit install --hook-type pre-commit --hook-type pre-push +``` + +It runs `cargo fmt` on all crates on every commit, and runs clippy and builds on +push. + +To run all checks explicitly (without pushing), run: + +``` +pre-commit run --all --hook-stage pre-push +``` + +# python bindings + +The `wheel` crate is a single python wheel that exports the functionality of +all crates in the repository. + +It's built with `maturin`. You need to have activated a python virtual +environment for the build to work. + +``` +pip install maturin +cd wheel +maturin develop +``` + +Once built, the python tests can be run, from the root of the repository. Note +that the tests require that `chia-blockchain` and `blspy` wheels are installed. + +``` +pytest tests +``` + +# Fuzzers + +Fuzzers can't be run or listed for the whole workspace, but only for individual +crates. There is a tool to generate a fuzzing corpus from a blockchain database. +It's run like this: + +``` +cd chia-tools +cargo run --release --bin gen-corpus -- --help +``` + +The following crates have fuzzers: + +* chia-bls +* chia-protocol +* chia-wallet +* clvm-utils +* chia (the root crate) + +To list and run fuzzers: + +``` +cargo fuzz list +``` + +``` +cargo fuzz run +```