#python-bindings #testing #chia #wheel #blockchain #create #type

macro chia_py_streamable_macro

Derive macro to create python bindings for Chia types

12 releases (4 breaking)

0.6.0 Mar 21, 2024
0.5.1 Feb 4, 2024
0.3.0 Dec 6, 2023
0.2.14 Dec 4, 2023
0.1.2 Nov 18, 2022

#27 in #chia

Download history 10/week @ 2023-12-06 7/week @ 2024-01-31 8/week @ 2024-02-14 33/week @ 2024-02-21 17/week @ 2024-02-28 2/week @ 2024-03-06 3/week @ 2024-03-13 120/week @ 2024-03-20

150 downloads per month
Used in 3 crates

Apache-2.0

16KB
300 lines

This cargo workspace contains code useful for working with the Chia network.

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
<make change>
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 crates/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 <name-of-fuzzer>

Dependencies

~3MB
~59K SLoC