From 30d3f493448e0fc0e96ffe3723352c50931aec25 Mon Sep 17 00:00:00 2001 From: Rigidity <35380458+Rigidity@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:44:53 -0400 Subject: [PATCH] Add Prettier formatting (#437) * Add Prettier * Add .prettierrc * Apply Prettier --- .github/workflows/audit-check.yaml | 6 +- .github/workflows/benchmark.yml | 97 +++++----- .github/workflows/build-arm64-wheels.yml | 106 +++++----- .github/workflows/build-crate.yml | 44 ++--- .github/workflows/build-m1-wheel.yml | 140 +++++++------- .github/workflows/build-npm.yml | 64 +++--- .github/workflows/build-test.yml | 236 +++++++++++------------ .github/workflows/dependency-review.yml | 6 +- .github/workflows/prettier.yml | 31 +++ .github/workflows/stale-issue.yml | 20 +- .gitignore | 4 + .prettierrc | 4 + README.md | 6 +- docs/new-operator-checklist.md | 21 +- package-lock.json | 28 +++ package.json | 10 + tools/data/proof.json | 47 +++-- tools/data/public.json | 4 +- tools/data/verification_key.json | 165 ++++++++-------- wasm/README.md | 10 +- wasm/tests/index.js | 211 ++++++++++---------- wheel/README.md | 6 +- 22 files changed, 663 insertions(+), 603 deletions(-) create mode 100644 .github/workflows/prettier.yml create mode 100644 .prettierrc create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.github/workflows/audit-check.yaml b/.github/workflows/audit-check.yaml index 1818efeb..6c440c1c 100644 --- a/.github/workflows/audit-check.yaml +++ b/.github/workflows/audit-check.yaml @@ -1,9 +1,9 @@ name: Security audit on: push: - paths: - - '**/Cargo.toml' - - '**/Cargo.lock' + paths: + - "**/Cargo.toml" + - "**/Cargo.lock" jobs: security_audit: runs-on: ubuntu-latest diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 0d61240e..696b8635 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,4 +1,3 @@ - name: Run benchmarks on: @@ -7,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" jobs: benchmark: @@ -22,64 +21,64 @@ jobs: os: [macos-12, ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 1 + - uses: actions/checkout@v4 + with: + fetch-depth: 1 - - uses: chia-network/actions/setup-python@main - name: Install Python 3.9 - with: - python-version: 3.9 + - uses: chia-network/actions/setup-python@main + name: Install Python 3.9 + with: + python-version: 3.9 - - name: Update pip - run: | + - name: Update pip + run: | python -m pip install --upgrade pip - - name: Set up rust - uses: dtolnay/rust-toolchain@stable + - name: Set up rust + uses: dtolnay/rust-toolchain@stable - - name: Run benchmarks - run: cargo bench + - name: Run benchmarks + run: cargo bench max-cost-checks: name: Cost checks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 1 + - uses: actions/checkout@v4 + with: + fetch-depth: 1 - - uses: chia-network/actions/setup-python@main - name: Install Python 3.9 - with: - python-version: 3.9 + - uses: chia-network/actions/setup-python@main + name: Install Python 3.9 + with: + python-version: 3.9 - - name: Update pip - run: | + - name: Update pip + run: | python -m pip install --upgrade pip - - name: Set up rust - uses: dtolnay/rust-toolchain@stable - - - name: Install dependencies - run: | - python -m pip install maturin - rustup target add x86_64-unknown-linux-musl - - - name: Build - env: - CC: gcc - run: | - python -m venv venv - ln -s venv/bin/activate - . ./activate - python -m pip install colorama - maturin develop -m wheel/Cargo.toml --release --features=openssl - - - name: Run cost checks - run: | - . ./activate - cd tests - ./generate-programs.py - ./run-programs.py + - name: Set up rust + uses: dtolnay/rust-toolchain@stable + + - name: Install dependencies + run: | + python -m pip install maturin + rustup target add x86_64-unknown-linux-musl + + - name: Build + env: + CC: gcc + run: | + python -m venv venv + ln -s venv/bin/activate + . ./activate + python -m pip install colorama + maturin develop -m wheel/Cargo.toml --release --features=openssl + + - name: Run cost checks + run: | + . ./activate + cd tests + ./generate-programs.py + ./run-programs.py diff --git a/.github/workflows/build-arm64-wheels.yml b/.github/workflows/build-arm64-wheels.yml index 9731979d..be14c75d 100644 --- a/.github/workflows/build-arm64-wheels.yml +++ b/.github/workflows/build-arm64-wheels.yml @@ -6,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" permissions: contents: read @@ -24,60 +24,60 @@ jobs: os: [[ARM64, Linux]] steps: - - uses: Chia-Network/actions/clean-workspace@main + - uses: Chia-Network/actions/clean-workspace@main - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 - - name: Build Python wheels - run: | - docker run --rm \ - -v ${{ github.workspace }}:/ws --workdir=/ws \ - quay.io/pypa/manylinux_2_28_aarch64 \ - bash -exc '\ - echo $PATH && \ - curl -L https://sh.rustup.rs > rustup-init.sh && \ - sh rustup-init.sh -y && \ - yum -y install openssl-devel && \ - source $HOME/.cargo/env && \ - rustup target add aarch64-unknown-linux-musl && \ - rm -rf venv && \ - export PATH=/opt/python/cp310-cp310/bin/:$PATH && \ - export PATH=/opt/python/cp39-cp39/bin/:$PATH && \ - export PATH=/opt/python/cp38-cp38/bin/:$PATH && \ - /opt/python/cp38-cp38/bin/python -m venv venv && \ - if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi && \ - . ./activate && \ - pip install maturin && \ - CC=gcc maturin build -m wheel/Cargo.toml --release --strip --manylinux 2_28 --features=openssl \ - ' + - name: Build Python wheels + run: | + docker run --rm \ + -v ${{ github.workspace }}:/ws --workdir=/ws \ + quay.io/pypa/manylinux_2_28_aarch64 \ + bash -exc '\ + echo $PATH && \ + curl -L https://sh.rustup.rs > rustup-init.sh && \ + sh rustup-init.sh -y && \ + yum -y install openssl-devel && \ + source $HOME/.cargo/env && \ + rustup target add aarch64-unknown-linux-musl && \ + rm -rf venv && \ + export PATH=/opt/python/cp310-cp310/bin/:$PATH && \ + export PATH=/opt/python/cp39-cp39/bin/:$PATH && \ + export PATH=/opt/python/cp38-cp38/bin/:$PATH && \ + /opt/python/cp38-cp38/bin/python -m venv venv && \ + if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi && \ + . ./activate && \ + pip install maturin && \ + CC=gcc maturin build -m wheel/Cargo.toml --release --strip --manylinux 2_28 --features=openssl \ + ' - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: wheels - path: target/wheels/ + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: wheels + path: target/wheels/ - - name: Install Twine - run: | - if [ ! -f "venv" ]; then sudo rm -rf venv; fi - sudo apt-get install python3-venv python3-pip -y - python3 -m venv venv - if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi - . ./activate - pip install setuptools_rust + - name: Install Twine + run: | + if [ ! -f "venv" ]; then sudo rm -rf venv; fi + sudo apt-get install python3-venv python3-pip -y + python3 -m venv venv + if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi + . ./activate + pip install setuptools_rust - - name: publish (PyPi) - if: startsWith(github.event.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages-dir: target/wheels/ - skip-existing: true + - name: publish (PyPi) + if: startsWith(github.event.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: target/wheels/ + skip-existing: true - - name: Clean up AMR64 - if: startsWith(matrix.os, 'ARM64') - run: | - rm -rf venv - rm -rf dist + - name: Clean up AMR64 + if: startsWith(matrix.os, 'ARM64') + run: | + rm -rf venv + rm -rf dist diff --git a/.github/workflows/build-crate.yml b/.github/workflows/build-crate.yml index e9f4a11f..fb646bc6 100644 --- a/.github/workflows/build-crate.yml +++ b/.github/workflows/build-crate.yml @@ -6,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" jobs: build_crate: @@ -19,26 +19,26 @@ jobs: fail-fast: false steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Set up rusts - uses: dtolnay/rust-toolchain@stable + - name: Set up rusts + uses: dtolnay/rust-toolchain@stable - - name: fmt (stable) - run: cargo +stable fmt -- --files-with-diff --check - - name: clippy (stable) - run: cargo +stable clippy - - name: tests - run: cargo test && cargo test --release - - name: build - run: cargo build --release - - name: dry-run of `cargo publish` - run: cargo publish --dry-run + - name: fmt (stable) + run: cargo +stable fmt -- --files-with-diff --check + - name: clippy (stable) + run: cargo +stable clippy + - name: tests + run: cargo test && cargo test --release + - name: build + run: cargo build --release + - name: dry-run of `cargo publish` + run: cargo publish --dry-run - - name: publish to crates.io if tagged - if: startsWith(github.event.ref, 'refs/tags') - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.cargo_registry_token }} - run: cargo publish + - name: publish to crates.io if tagged + if: startsWith(github.event.ref, 'refs/tags') + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.cargo_registry_token }} + run: cargo publish diff --git a/.github/workflows/build-m1-wheel.yml b/.github/workflows/build-m1-wheel.yml index a68a2365..9e2e725e 100644 --- a/.github/workflows/build-m1-wheel.yml +++ b/.github/workflows/build-m1-wheel.yml @@ -6,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" concurrency: group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}--${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }} @@ -27,77 +27,77 @@ jobs: fail-fast: false steps: - - uses: Chia-Network/actions/clean-workspace@main - - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up rust - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust.sh - sh rust.sh -y - - - name: Build m1 wheels - run: | - python3 -m venv venv - . ./venv/bin/activate - export PATH=~/.cargo/bin:$PATH - pip install maturin - maturin build -m wheel/Cargo.toml -i python --release --strip --features=openssl - - - name: Install clvm_rs wheel - run: | - . ./venv/bin/activate - ls ./target/wheels/ - pip install ./target/wheels/clvm_rs*.whl - - - name: Install other wheels - run: | - . ./venv/bin/activate - python -m pip install pytest - python -m pip install blspy - - - name: Run tests from wheel - run: | - . ./venv/bin/activate - cd wheel/python - pytest --import-mode append tests - # we use `append` because otherwise the `clvm_rs` source is added - # to `sys.path` and it uses that instead of the wheel (and so - # ignoring `clvm_rs.so`, which is pretty important) - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: wheels - path: ./target/wheels/ + - uses: Chia-Network/actions/clean-workspace@main + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up rust + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust.sh + sh rust.sh -y + + - name: Build m1 wheels + run: | + python3 -m venv venv + . ./venv/bin/activate + export PATH=~/.cargo/bin:$PATH + pip install maturin + maturin build -m wheel/Cargo.toml -i python --release --strip --features=openssl + + - name: Install clvm_rs wheel + run: | + . ./venv/bin/activate + ls ./target/wheels/ + pip install ./target/wheels/clvm_rs*.whl + + - name: Install other wheels + run: | + . ./venv/bin/activate + python -m pip install pytest + python -m pip install blspy + + - name: Run tests from wheel + run: | + . ./venv/bin/activate + cd wheel/python + pytest --import-mode append tests + # we use `append` because otherwise the `clvm_rs` source is added + # to `sys.path` and it uses that instead of the wheel (and so + # ignoring `clvm_rs.so`, which is pretty important) + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: wheels + path: ./target/wheels/ upload: name: Upload to PyPI runs-on: ubuntu-latest needs: build_wheels steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install python - uses: Chia-Network/actions/setup-python@main - with: - python-version: "3.10" - - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: wheels - path: ./target/wheels/ - - - name: publish (PyPi) - if: startsWith(github.event.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages-dir: target/wheels/ - skip-existing: true + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install python + uses: Chia-Network/actions/setup-python@main + with: + python-version: "3.10" + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: wheels + path: ./target/wheels/ + + - name: publish (PyPi) + if: startsWith(github.event.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: target/wheels/ + skip-existing: true diff --git a/.github/workflows/build-npm.yml b/.github/workflows/build-npm.yml index dc967e39..0ab3e560 100644 --- a/.github/workflows/build-npm.yml +++ b/.github/workflows/build-npm.yml @@ -6,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" jobs: build_crate: @@ -19,33 +19,33 @@ jobs: fail-fast: false steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: install wasm-pack - run: cargo install wasm-pack - - - name: wasm-pack build and pack - run: wasm-pack build --release --target=nodejs wasm && wasm-pack pack wasm - - - name: Setup Node 16.x - uses: actions/setup-node@v4 - with: - node-version: '16.x' - - - name: Test wasm - run: node wasm/tests/index.js - - - name: Upload npm pkg artifacts - uses: actions/upload-artifact@v4 - with: - name: npm-pkg - path: ./wasm/pkg/clvm_wasm-*.tgz - - - name: publish to npmjs.com if tagged - if: startsWith(github.event.ref, 'refs/tags') - uses: JS-DevTools/npm-publish@v3 - with: - token: ${{ secrets.node_auth_token }} - package: wasm/pkg/package.json + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: install wasm-pack + run: cargo install wasm-pack + + - name: wasm-pack build and pack + run: wasm-pack build --release --target=nodejs wasm && wasm-pack pack wasm + + - name: Setup Node 16.x + uses: actions/setup-node@v4 + with: + node-version: "16.x" + + - name: Test wasm + run: node wasm/tests/index.js + + - name: Upload npm pkg artifacts + uses: actions/upload-artifact@v4 + with: + name: npm-pkg + path: ./wasm/pkg/clvm_wasm-*.tgz + + - name: publish to npmjs.com if tagged + if: startsWith(github.event.ref, 'refs/tags') + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.node_auth_token }} + package: wasm/pkg/package.json diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index cea3d887..a3c15bb6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -6,10 +6,10 @@ on: - main - dev tags: - - '**' + - "**" pull_request: branches: - - '**' + - "**" permissions: contents: read @@ -26,139 +26,139 @@ jobs: python: [3.8] steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - uses: chia-network/actions/setup-python@main - name: Install Python ${{ matrix.python }} - with: - python-version: ${{ matrix.python }} + - uses: chia-network/actions/setup-python@main + name: Install Python ${{ matrix.python }} + with: + python-version: ${{ matrix.python }} - - name: Update pip - run: | + - name: Update pip + run: | python -m pip install --upgrade pip - - name: Set up rust - uses: dtolnay/rust-toolchain@stable + - name: Set up rust + uses: dtolnay/rust-toolchain@stable - - name: Install dependencies - run: | + - name: Install dependencies + run: | python -m pip install maturin - - name: Build MacOs with maturin on Python ${{ matrix.python }} - if: startsWith(matrix.os, 'macos') - env: - MACOSX_DEPLOYMENT_TARGET: '10.14' - run: | - python -m venv venv - ln -s venv/bin/activate - . ./activate - maturin build -m wheel/Cargo.toml --sdist -i python --release --strip --features=openssl + - name: Build MacOs with maturin on Python ${{ matrix.python }} + if: startsWith(matrix.os, 'macos') + env: + MACOSX_DEPLOYMENT_TARGET: "10.14" + run: | + python -m venv venv + ln -s venv/bin/activate + . ./activate + maturin build -m wheel/Cargo.toml --sdist -i python --release --strip --features=openssl - - name: Build Linux in manylinux_2_28 with maturin on Python ${{ matrix.python }} - if: startsWith(matrix.os, 'ubuntu') - run: | - docker run --rm \ - -v ${{ github.workspace }}:/ws --workdir=/ws \ - quay.io/pypa/manylinux_2_28_x86_64 \ - bash -exc '\ - curl -L https://sh.rustup.rs > rustup-init.sh && \ - sh rustup-init.sh -y && \ - yum -y --disablerepo=epel install openssl-devel && \ - source $HOME/.cargo/env && \ - rustup target add x86_64-unknown-linux-musl && \ - PY_VERSION=${{ matrix.python }} - PY_VERSION=${PY_VERSION/.} && \ - echo "Python version with dot removed is $PY_VERSION" && \ - if [ "$PY_VERSION" = "38" ]; \ - then export SCND_VERSION="${PY_VERSION}m"; \ - else export SCND_VERSION="$PY_VERSION"; fi && \ - echo "Exporting path /opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin" && \ - export PATH=/opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin/:$PATH && \ - /opt/python/cp38-cp38/bin/python -m venv /venv && \ - . /venv/bin/activate && \ - pip install --upgrade pip && \ - pip install maturin && \ - CC=gcc maturin build -m wheel/Cargo.toml --release --strip --manylinux 2_28 --features=openssl \ - ' - python -m venv venv - ln -s venv/bin/activate + - name: Build Linux in manylinux_2_28 with maturin on Python ${{ matrix.python }} + if: startsWith(matrix.os, 'ubuntu') + run: | + docker run --rm \ + -v ${{ github.workspace }}:/ws --workdir=/ws \ + quay.io/pypa/manylinux_2_28_x86_64 \ + bash -exc '\ + curl -L https://sh.rustup.rs > rustup-init.sh && \ + sh rustup-init.sh -y && \ + yum -y --disablerepo=epel install openssl-devel && \ + source $HOME/.cargo/env && \ + rustup target add x86_64-unknown-linux-musl && \ + PY_VERSION=${{ matrix.python }} + PY_VERSION=${PY_VERSION/.} && \ + echo "Python version with dot removed is $PY_VERSION" && \ + if [ "$PY_VERSION" = "38" ]; \ + then export SCND_VERSION="${PY_VERSION}m"; \ + else export SCND_VERSION="$PY_VERSION"; fi && \ + echo "Exporting path /opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin" && \ + export PATH=/opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin/:$PATH && \ + /opt/python/cp38-cp38/bin/python -m venv /venv && \ + . /venv/bin/activate && \ + pip install --upgrade pip && \ + pip install maturin && \ + CC=gcc maturin build -m wheel/Cargo.toml --release --strip --manylinux 2_28 --features=openssl \ + ' + python -m venv venv + ln -s venv/bin/activate - - name: Build Windows with maturin on Python ${{ matrix.python }} - if: startsWith(matrix.os, 'windows') - run: | - python -m venv venv - . .\venv\Scripts\Activate.ps1 - ln -s venv\Scripts\Activate.ps1 activate - maturin build -m wheel/Cargo.toml -i python --release --strip - # this will install into the venv - # it'd be better to use the wheel, but I can't figure out how to do that - # TODO: figure this out - # this does NOT work: pip install target/wheels/clvm_rs-*.whl - maturin develop --release -m wheel/Cargo.toml - # the line above also doesn't seem to work + - name: Build Windows with maturin on Python ${{ matrix.python }} + if: startsWith(matrix.os, 'windows') + run: | + python -m venv venv + . .\venv\Scripts\Activate.ps1 + ln -s venv\Scripts\Activate.ps1 activate + maturin build -m wheel/Cargo.toml -i python --release --strip + # this will install into the venv + # it'd be better to use the wheel, but I can't figure out how to do that + # TODO: figure this out + # this does NOT work: pip install target/wheels/clvm_rs-*.whl + maturin develop --release -m wheel/Cargo.toml + # the line above also doesn't seem to work - - name: Install clvm_rs wheel - if: ${{ !startsWith(matrix.os, 'windows') }} - run: | - . ./activate - ls target/wheels/ - # this mess puts the name of the `.whl` file into `$WHEEL_PATH` - # remove the dot, use the `glob` lib to grab the file from the directory - WHEEL_PATH=$(echo ${{ matrix.python }} | python -c 'DOTLESS=input().replace(".", ""); import glob; print(" ".join(glob.glob("target/wheels/clvm_rs-*-cp%s-abi3-*.whl" % DOTLESS)))' ) - echo ${WHEEL_PATH} - pip install ${WHEEL_PATH} + - name: Install clvm_rs wheel + if: ${{ !startsWith(matrix.os, 'windows') }} + run: | + . ./activate + ls target/wheels/ + # this mess puts the name of the `.whl` file into `$WHEEL_PATH` + # remove the dot, use the `glob` lib to grab the file from the directory + WHEEL_PATH=$(echo ${{ matrix.python }} | python -c 'DOTLESS=input().replace(".", ""); import glob; print(" ".join(glob.glob("target/wheels/clvm_rs-*-cp%s-abi3-*.whl" % DOTLESS)))' ) + echo ${WHEEL_PATH} + pip install ${WHEEL_PATH} - - name: Install other wheels - run: | - . ./activate - python -m pip install pytest - python -m pip install blspy + - name: Install other wheels + run: | + . ./activate + python -m pip install pytest + python -m pip install blspy - - name: Run tests from wheel - run: | - . ./activate - cd wheel/python - pytest --import-mode append tests - # we use `append` because otherwise the `clvm_rs` source is added - # to `sys.path` and it uses that instead of the wheel (and so - # ignoring `clvm_rs.so`, which is pretty important) + - name: Run tests from wheel + run: | + . ./activate + cd wheel/python + pytest --import-mode append tests + # we use `append` because otherwise the `clvm_rs` source is added + # to `sys.path` and it uses that instead of the wheel (and so + # ignoring `clvm_rs.so`, which is pretty important) - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: wheels-${{ matrix.os }}-py-${{ matrix.python }} - path: ./target/wheels/ + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: wheels-${{ matrix.os }}-py-${{ matrix.python }} + path: ./target/wheels/ upload: name: Upload to PyPI runs-on: ubuntu-latest needs: build_wheels steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Install python - uses: Chia-Network/actions/setup-python@main - with: - python-version: "3.10" + - name: Install python + uses: Chia-Network/actions/setup-python@main + with: + python-version: "3.10" - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - merge-multiple: true - pattern: wheels-* - path: ./target/wheels/ + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + merge-multiple: true + pattern: wheels-* + path: ./target/wheels/ - - name: publish (PyPi) - if: startsWith(github.event.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages-dir: target/wheels/ - skip-existing: true + - name: publish (PyPi) + if: startsWith(github.event.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: target/wheels/ + skip-existing: true checks: runs-on: ubuntu-20.04 @@ -170,7 +170,7 @@ jobs: - name: Install rust uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy + components: rustfmt, clippy - name: Clippy run: cargo clippy --all-targets --workspace -- -D warnings - name: fmt @@ -193,8 +193,8 @@ jobs: - name: Install rust uses: dtolnay/rust-toolchain@master with: - toolchain: nightly - components: rustfmt, clippy + toolchain: nightly + components: rustfmt, clippy - name: fmt run: | cd fuzz @@ -228,7 +228,7 @@ jobs: - name: Install rust uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy + components: rustfmt, clippy - name: build run: cargo build --workspace --exclude clvm_rs-fuzz @@ -277,4 +277,4 @@ jobs: env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} with: - path-to-lcov: './lcov.info' + path-to-lcov: "./lcov.info" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 84b93709..0385c9e0 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -4,7 +4,7 @@ # # Source repository: https://github.com/actions/dependency-review-action # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement -name: 'Dependency Review' +name: "Dependency Review" on: [pull_request] permissions: @@ -14,9 +14,9 @@ jobs: dependency-review: runs-on: ubuntu-latest steps: - - name: 'Checkout Repository' + - name: "Checkout Repository" uses: actions/checkout@v4 - - name: 'Dependency Review' + - name: "Dependency Review" uses: actions/dependency-review-action@v4 with: allow-ghsas: GHSA-xphf-cx8h-7q9g diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 00000000..f5351aeb --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,31 @@ +name: Prettier + +on: + push: + branches: + - main + - dev + tags: + - "**" + pull_request: + branches: + - "**" + +jobs: + prettier: + name: Prettier + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + + - name: Install dependencies + run: npm install + + - name: Run Prettier + run: npm run prettier diff --git a/.github/workflows/stale-issue.yml b/.github/workflows/stale-issue.yml index e3668dba..8e614924 100755 --- a/.github/workflows/stale-issue.yml +++ b/.github/workflows/stale-issue.yml @@ -1,8 +1,8 @@ --- -name: 'Close stale issues' +name: "Close stale issues" on: schedule: - - cron: '0 11 * * *' + - cron: "0 11 * * *" jobs: stale: @@ -23,13 +23,13 @@ jobs: stale-pr-label: stale-pr remove-stale-when-updated: true stale-issue-message: > - 'This issue has been flagged as stale as there has been no - activity on it in 14 days. If this issue is still affecting you - and in need of review, please update it to keep it open.' + 'This issue has been flagged as stale as there has been no + activity on it in 14 days. If this issue is still affecting you + and in need of review, please update it to keep it open.' close-issue-message: > - 'This issue was automatically closed because it has been flagged - as stale and subsequently passed 7 days with no further activity.' + 'This issue was automatically closed because it has been flagged + as stale and subsequently passed 7 days with no further activity.' stale-pr-message: > - 'This PR has been flagged as stale due to no activity for over 60 - days. It will not be automatically closed, but it has been given - a stale-pr label and should be manually reviewed.' + 'This PR has been flagged as stale due to no activity for over 60 + days. It will not be automatically closed, but it has been given + a stale-pr label and should be manually reviewed.' diff --git a/.gitignore b/.gitignore index 1d283102..9bb6c7b8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ target/ # python ignore /venv /.venv + +# Node.js +/target +/node_modules diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..8973894d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "useTabs": false, + "tabWidth": 2 +} diff --git a/README.md b/README.md index 27684f50..f41dcd90 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,15 @@ The cargo workspace includes an rlib crate, for use with rust or other applicati The python wheel is in `wheel`. The npm package is in `wasm`. +## TESTS -TESTS ------ In order to run the unit tests, run: ``` cargo test ``` -Fuzzing -------- +## Fuzzing The fuzzing infrastructure for `clvm_rs` uses [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz). diff --git a/docs/new-operator-checklist.md b/docs/new-operator-checklist.md index 77f318e1..ea4f4f6d 100644 --- a/docs/new-operator-checklist.md +++ b/docs/new-operator-checklist.md @@ -1,5 +1,6 @@ # Adding new operators ----------------------- + +--- There are two approaches to soft-forking in support for new operators: @@ -15,25 +16,25 @@ something. Follow this checklist when adding operators: -* Add test cases in a new file under `op-tests/`. Make sure to include all +- Add test cases in a new file under `op-tests/`. Make sure to include all possible ways the operator(s) can fail. -* If relevant, write a script that generates test vectors, printing them into a +- If relevant, write a script that generates test vectors, printing them into a file under `op-tests/` (see `tools/generate-bls-tests.py`). This is to ensure the new operator's behavior match at least one other implementation. -* Include the new operators in the fuzzer `fuzz/fuzz_targets/operators.rs` -* Include the new operators and their signatures in `tools/src/bin/generate-fuzz-corpus.rs`. +- Include the new operators in the fuzzer `fuzz/fuzz_targets/operators.rs` +- Include the new operators and their signatures in `tools/src/bin/generate-fuzz-corpus.rs`. Make sure to run this and fuzz for some time before landing the PR. -* extend the benchmark-clvm-cost.rs to include benchmarks for the new operator, +- extend the benchmark-clvm-cost.rs to include benchmarks for the new operator, to establish its cost. -* The opcode decoding and dispatching happens in `src/ChiaDialect.rs` -* Add a new flag (in `src/chia_dialect.rs`) that controls whether the +- The opcode decoding and dispatching happens in `src/ChiaDialect.rs` +- Add a new flag (in `src/chia_dialect.rs`) that controls whether the operators are activated or not. This is required in order for the chain to exist - in a state *before* your soft-fork has activated, and behave consistently with + in a state _before_ your soft-fork has activated, and behave consistently with versions of the node that doesn't know about your new operators. Make sure the value of the flag does not collide with any of the flags in [chia_rs](https://github.com/Chia-Network/chia_rs/blob/main/src/gen/flags.rs). This is a quirk where both of these repos share the same flags space. -* Once a soft-fork has activated, if everything on chain before the softfork is +- Once a soft-fork has activated, if everything on chain before the softfork is compatible with the new rules (which is likely and ought to be the ambition with all soft-forks), all logic surrounding activating or deactivating the soft-fork should be removed. diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..ceba34a9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "clvm-rs", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier": "^3.3.2" + } + }, + "node_modules/prettier": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz", + "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..0e5e7447 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "scripts": { + "prettier": "prettier --check .", + "fmt": "prettier --write ." + }, + "devDependencies": { + "prettier": "^3.3.2" + } +} diff --git a/tools/data/proof.json b/tools/data/proof.json index 76e26b7c..8c1ee97d 100644 --- a/tools/data/proof.json +++ b/tools/data/proof.json @@ -1,28 +1,25 @@ { - "pi_a": [ - "2448972748141989272536367560659697170734634088573614916679357916264488049700372778155603853824786623305387094546369", - "2613221712984417828767835104274024828239341398418470730553885155357439750821374624630210264872985961930235777347104", - "1" - ], - "pi_b": [ - [ - "3708254411817616046496599112503459290131712318992805100196099293124450895778668562366777707942755580648476411528616", - "1615373645805710633948600413508988659344946361996638390351319550905473691532825592955678648251052813842459992431813" + "pi_a": [ + "2448972748141989272536367560659697170734634088573614916679357916264488049700372778155603853824786623305387094546369", + "2613221712984417828767835104274024828239341398418470730553885155357439750821374624630210264872985961930235777347104", + "1" ], - [ - "2001495116686267442302054141712026804161251446824505371797990860144851289966066534281669278894973744357520656326919", - "1341482890450207545789724195498464169941018957781713961603436195744234605397631185080983084054424258281861049763542" + "pi_b": [ + [ + "3708254411817616046496599112503459290131712318992805100196099293124450895778668562366777707942755580648476411528616", + "1615373645805710633948600413508988659344946361996638390351319550905473691532825592955678648251052813842459992431813" + ], + [ + "2001495116686267442302054141712026804161251446824505371797990860144851289966066534281669278894973744357520656326919", + "1341482890450207545789724195498464169941018957781713961603436195744234605397631185080983084054424258281861049763542" + ], + ["1", "0"] ], - [ - "1", - "0" - ] - ], - "pi_c": [ - "3029498251172243945704453776550289972710027563944505099878777570942300616351648238243169819882261150555837899543624", - "3369937544529554744574272044068942679061743305676782825796582255803972813518101160644118161590230148923409065282626", - "1" - ], - "protocol": "groth16", - "curve": "bls12381" -} \ No newline at end of file + "pi_c": [ + "3029498251172243945704453776550289972710027563944505099878777570942300616351648238243169819882261150555837899543624", + "3369937544529554744574272044068942679061743305676782825796582255803972813518101160644118161590230148923409065282626", + "1" + ], + "protocol": "groth16", + "curve": "bls12381" +} diff --git a/tools/data/public.json b/tools/data/public.json index edddc3e2..e78c04a2 100644 --- a/tools/data/public.json +++ b/tools/data/public.json @@ -1,3 +1,3 @@ [ - "15744006038856998268181219516291113434365469909648022488288672656450282844855" -] \ No newline at end of file + "15744006038856998268181219516291113434365469909648022488288672656450282844855" +] diff --git a/tools/data/verification_key.json b/tools/data/verification_key.json index 24eeaa0f..2276de33 100644 --- a/tools/data/verification_key.json +++ b/tools/data/verification_key.json @@ -1,94 +1,85 @@ { - "protocol": "groth16", - "curve": "bls12381", - "nPublic": 1, - "vk_alpha_1": [ - "3687990602627480788576278326778684068346499502295437145891072024790539587089059507329252689410539273728007931173343", - "2691609246889571927545472613612306448566845944689354319490588876705534279625652314844953252469547550362023064748953", - "1" - ], - "vk_beta_2": [ - [ - "2608641754095668628654511081770632612569796850505052942197090784708482913082697973366799224986199956634486073060199", - "89228168523230122473878930637028667136418498377368837726462188398136487986559177833403891300545206849263721046238" + "protocol": "groth16", + "curve": "bls12381", + "nPublic": 1, + "vk_alpha_1": [ + "3687990602627480788576278326778684068346499502295437145891072024790539587089059507329252689410539273728007931173343", + "2691609246889571927545472613612306448566845944689354319490588876705534279625652314844953252469547550362023064748953", + "1" ], - [ - "41546066546231073094970759775221151302737154809289359952977752591405008468272119343489892173609247914574253145019", - "1073496232887667728611248773592182301683863569516966096481458702792361423011100241892970384222710119575879538773631" + "vk_beta_2": [ + [ + "2608641754095668628654511081770632612569796850505052942197090784708482913082697973366799224986199956634486073060199", + "89228168523230122473878930637028667136418498377368837726462188398136487986559177833403891300545206849263721046238" + ], + [ + "41546066546231073094970759775221151302737154809289359952977752591405008468272119343489892173609247914574253145019", + "1073496232887667728611248773592182301683863569516966096481458702792361423011100241892970384222710119575879538773631" + ], + ["1", "0"] ], - [ - "1", - "0" - ] - ], - "vk_gamma_2": [ - [ - "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160", - "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758" - ], - [ - "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905", - "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582" - ], - [ - "1", - "0" - ] - ], - "vk_delta_2": [ - [ - "2302708795135883755295689012757758746531394778684760845557415078964262613319745952046265901445936183734832887419314", - "3084780362642599240218688073008885474013386097145303880494731842809534952957928683302064241771259067324907482804535" + "vk_gamma_2": [ + [ + "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160", + "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758" + ], + [ + "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905", + "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582" + ], + ["1", "0"] ], - [ - "2353281801229749567454967639478048114084038149642432168712668513087247657105865478271864938520646795729273580954373", - "3946758327447072982383197368123140665753687006919351726238936862294926911822209283838500408364423349160285940132546" + "vk_delta_2": [ + [ + "2302708795135883755295689012757758746531394778684760845557415078964262613319745952046265901445936183734832887419314", + "3084780362642599240218688073008885474013386097145303880494731842809534952957928683302064241771259067324907482804535" + ], + [ + "2353281801229749567454967639478048114084038149642432168712668513087247657105865478271864938520646795729273580954373", + "3946758327447072982383197368123140665753687006919351726238936862294926911822209283838500408364423349160285940132546" + ], + ["1", "0"] ], - [ - "1", - "0" - ] - ], - "vk_alphabeta_12": [ - [ - [ - "3646922899734621031309198643792122859755051285299968901190456847922062309516344525965903754151703713929910803018723", - "3787264463476506417753905333017140683881970278885692947093103102190734933948009040062419894798125099171961993441585" - ], - [ - "888591976801838355558310496304482240721117286293757254042783018082905268796780457128037898191123107332073390969306", - "193551792940402175998097385264246078420044892736093193471826013538673041275411949024638134205343639644439406295978" - ], - [ - "1317889796712672053878879651236837007079529832659749901543207138507635113785380816474503253440740877839206481081138", - "68492254186446573347883950975645044908957072900012067873632406930630971765229261191765781341134978015638910128690" - ] - ], - [ - [ - "2516694800776785349103641204442847315220092352707018103618606902656552402169819493388195598701143922571277337980272", - "96623648346070294868753263474971669617108833331306255390212761619996570553190757977722341498313064273906964152134" - ], - [ - "2502317210664014936951176356618294055923532685127730693917839807090502831127716870590666308945251016529938493301293", - "1269831695938094358083014213758376386842407521241795645485130044447135656806386120537823082192926908937323744695066" - ], - [ - "2096572493157417726452007018982901557663874671746322246164788364050706635296947426419903916849105863115688337239000", - "1736417117473120462831776778505826154107507679154832319336687186056350388252408161606715924310118176458088198747427" - ] - ] - ], - "IC": [ - [ - "1071823547084176756430637039762682182586478148082321678474568557380586500897665218485348420354524434569648761461634", - "2684952160352532512645026212843511021778883533927836353068736374874296422762544669022406839997640419830394096116948", - "1" + "vk_alphabeta_12": [ + [ + [ + "3646922899734621031309198643792122859755051285299968901190456847922062309516344525965903754151703713929910803018723", + "3787264463476506417753905333017140683881970278885692947093103102190734933948009040062419894798125099171961993441585" + ], + [ + "888591976801838355558310496304482240721117286293757254042783018082905268796780457128037898191123107332073390969306", + "193551792940402175998097385264246078420044892736093193471826013538673041275411949024638134205343639644439406295978" + ], + [ + "1317889796712672053878879651236837007079529832659749901543207138507635113785380816474503253440740877839206481081138", + "68492254186446573347883950975645044908957072900012067873632406930630971765229261191765781341134978015638910128690" + ] + ], + [ + [ + "2516694800776785349103641204442847315220092352707018103618606902656552402169819493388195598701143922571277337980272", + "96623648346070294868753263474971669617108833331306255390212761619996570553190757977722341498313064273906964152134" + ], + [ + "2502317210664014936951176356618294055923532685127730693917839807090502831127716870590666308945251016529938493301293", + "1269831695938094358083014213758376386842407521241795645485130044447135656806386120537823082192926908937323744695066" + ], + [ + "2096572493157417726452007018982901557663874671746322246164788364050706635296947426419903916849105863115688337239000", + "1736417117473120462831776778505826154107507679154832319336687186056350388252408161606715924310118176458088198747427" + ] + ] ], - [ - "2839260942033980200881629479143771629126097863497154112088469889816939528519692319012782094539984411463350527566132", - "2039646667501610214724415985007403112148409765841539023420972305120615285033331651618581255120345157629653223270351", - "1" + "IC": [ + [ + "1071823547084176756430637039762682182586478148082321678474568557380586500897665218485348420354524434569648761461634", + "2684952160352532512645026212843511021778883533927836353068736374874296422762544669022406839997640419830394096116948", + "1" + ], + [ + "2839260942033980200881629479143771629126097863497154112088469889816939528519692319012782094539984411463350527566132", + "2039646667501610214724415985007403112148409765841539023420972305120615285033331651618581255120345157629653223270351", + "1" + ] ] - ] -} \ No newline at end of file +} diff --git a/wasm/README.md b/wasm/README.md index 5566b86f..0e928a23 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -1,8 +1,7 @@ The `clvm_rs` package has JavaScript bindings for the rust implementation of clvm in wasm. -This project is very immature, and only some test API is available for the moment. Pull requests are welcome. +This project is very immature, and only some test API is available for the moment. Pull requests are welcome. -Build ------ +## Build Use `wasm-pack` to build the wasm `pkg` file used with npm. Install it with: @@ -17,9 +16,10 @@ Then build with wasm-pack build --release --target=nodejs ``` -Test ------ +## Test + Prerequisite: + - NodeJS >= 16 - Wasm files built by `wasm-pack` command exist at `/wasm/pkg/` diff --git a/wasm/tests/index.js b/wasm/tests/index.js index 34dfd308..701ece9f 100644 --- a/wasm/tests/index.js +++ b/wasm/tests/index.js @@ -1,135 +1,134 @@ const wasm = require("../pkg/clvm_wasm.js"); -function expect_equal(challenge, expected){ - if(challenge !== expected){ - throw new Error(`Assertion Error: Expected "${expected}" but actual value was "${challenge}"`); - } +function expect_equal(challenge, expected) { + if (challenge !== expected) { + throw new Error( + `Assertion Error: Expected "${expected}" but actual value was "${challenge}"`, + ); + } } -function expect_throw(callback){ - let is_error = undefined; - try{ - callback(); - } - catch(e){ - is_error = e; - } +function expect_throw(callback) { + let is_error = undefined; + try { + callback(); + } catch (e) { + is_error = e; + } - if(!is_error){ - throw new Error('Expected an exception but it was not thrown'); - } + if (!is_error) { + throw new Error("Expected an exception but it was not thrown"); + } } -function bytesFromHex(hex){ - return Uint8Array.from(Buffer.from(hex, "hex")); +function bytesFromHex(hex) { + return Uint8Array.from(Buffer.from(hex, "hex")); } -function numsToByteStr(numArray){ - return Uint8Array.from(numArray).toString(); +function numsToByteStr(numArray) { + return Uint8Array.from(numArray).toString(); } let current_test_number = 0; -function test_case(testTitle, test){ - const testNo = ++current_test_number; - console.log(`Case#${testNo} ${testTitle}`); - try{ - test(); - console.log(`✓ Successfully finished case#${testNo}`); - } - catch(e){ - console.error(`❌ Failed Case#${testNo}`); - console.error(`${e.name}: ${e.message}`); - process.exit(1); - } +function test_case(testTitle, test) { + const testNo = ++current_test_number; + console.log(`Case#${testNo} ${testTitle}`); + try { + test(); + console.log(`✓ Successfully finished case#${testNo}`); + } catch (e) { + console.error(`❌ Failed Case#${testNo}`); + console.error(`${e.name}: ${e.message}`); + process.exit(1); + } } // ----------------------------------------------------- // -test_case("Test '(q . 127)' '()'", function(){ - // (q . 127) - const prog = bytesFromHex("ff017f"); - // () - const arg = bytesFromHex("80"); - // 100,000,000,000 - const max_cost = BigInt("100000000000"); - const flag = 0; - const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); - expect_equal(sexp.atom.toString(), "127"); +test_case("Test '(q . 127)' '()'", function () { + // (q . 127) + const prog = bytesFromHex("ff017f"); + // () + const arg = bytesFromHex("80"); + // 100,000,000,000 + const max_cost = BigInt("100000000000"); + const flag = 0; + const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); + expect_equal(sexp.atom.toString(), "127"); }); -test_case("Test '(+ 1 (q . 3))' '2'", function(){ - // (+ 1 (q . 3)) - const prog = bytesFromHex("ff10ff01ffff010380"); - // 2 - const arg = bytesFromHex("02"); - // 100,000,000,000 - const max_cost = BigInt("100000000000"); - const flag = 0; - const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); - expect_equal(sexp.atom.toString(), "5"); +test_case("Test '(+ 1 (q . 3))' '2'", function () { + // (+ 1 (q . 3)) + const prog = bytesFromHex("ff10ff01ffff010380"); + // 2 + const arg = bytesFromHex("02"); + // 100,000,000,000 + const max_cost = BigInt("100000000000"); + const flag = 0; + const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); + expect_equal(sexp.atom.toString(), "5"); }); -test_case("Test '(+ 7 (q . 3))' '(() . (() . 2))'", function(){ - // (+ 7 (q . 3)) - const prog = bytesFromHex("ff10ff07ffff010380"); - // (() . (() . 2)) - const arg = bytesFromHex("ff80ff8002"); - // 100,000,000,000 - const max_cost = BigInt("100000000000"); - const flag = 0; - const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); - expect_equal(sexp.atom.toString(), "5"); +test_case("Test '(+ 7 (q . 3))' '(() . (() . 2))'", function () { + // (+ 7 (q . 3)) + const prog = bytesFromHex("ff10ff07ffff010380"); + // (() . (() . 2)) + const arg = bytesFromHex("ff80ff8002"); + // 100,000,000,000 + const max_cost = BigInt("100000000000"); + const flag = 0; + const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); + expect_equal(sexp.atom.toString(), "5"); }); -test_case("Test max_cost too low", function(){ - // (q . 127) - const prog = bytesFromHex("ff017f"); - // () - const arg = bytesFromHex("80"); - // MaxCost too low - const max_cost = BigInt("1"); - const flag = 0; - expect_throw(function(){ - wasm.run_chia_program(prog, arg, max_cost, flag); - }); +test_case("Test max_cost too low", function () { + // (q . 127) + const prog = bytesFromHex("ff017f"); + // () + const arg = bytesFromHex("80"); + // MaxCost too low + const max_cost = BigInt("1"); + const flag = 0; + expect_throw(function () { + wasm.run_chia_program(prog, arg, max_cost, flag); + }); }); -test_case("Test divmod", function(){ - // (divmod (q . 5) (q . -3)) - const prog = bytesFromHex("ff14ffff0105ffff0181fd80"); - // () - const arg = bytesFromHex("80"); - // 100,000,000,000 - const max_cost = BigInt("100000000000"); - const flag = 0; - const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); - expect_equal(sexp.pair[0].atom.toString(), numsToByteStr([-2])); - expect_equal(sexp.pair[1].atom.toString(), numsToByteStr([-1])); +test_case("Test divmod", function () { + // (divmod (q . 5) (q . -3)) + const prog = bytesFromHex("ff14ffff0105ffff0181fd80"); + // () + const arg = bytesFromHex("80"); + // 100,000,000,000 + const max_cost = BigInt("100000000000"); + const flag = 0; + const [cost, sexp] = wasm.run_chia_program(prog, arg, max_cost, flag); + expect_equal(sexp.pair[0].atom.toString(), numsToByteStr([-2])); + expect_equal(sexp.pair[1].atom.toString(), numsToByteStr([-1])); }); -test_case("Test negative div", function(){ - // (/ (q . 5) (q . -3)) - const prog = bytesFromHex("ff13ffff0105ffff0181fd80"); - // () - const arg = bytesFromHex("80"); - // 100,000,000,000 - const max_cost = BigInt("100000000000"); - expect_throw(function(){ - wasm.run_chia_program(prog, arg, max_cost, 0); - }); +test_case("Test negative div", function () { + // (/ (q . 5) (q . -3)) + const prog = bytesFromHex("ff13ffff0105ffff0181fd80"); + // () + const arg = bytesFromHex("80"); + // 100,000,000,000 + const max_cost = BigInt("100000000000"); + expect_throw(function () { + wasm.run_chia_program(prog, arg, max_cost, 0); + }); }); -test_case("Test serialized_length", function(){ - // (q . 127) - const prog = bytesFromHex("ff017f"); - expect_equal(wasm.serialized_length(prog), BigInt("3")); - expect_throw(function(){ - wasm.serialized_length(bytesFromHex("abcdef0123")); - }); - try { - wasm.serialized_length(bytesFromHex("abcdef0123")); - } - catch (e) { - expect_equal(e, "bad encoding"); - } +test_case("Test serialized_length", function () { + // (q . 127) + const prog = bytesFromHex("ff017f"); + expect_equal(wasm.serialized_length(prog), BigInt("3")); + expect_throw(function () { + wasm.serialized_length(bytesFromHex("abcdef0123")); + }); + try { + wasm.serialized_length(bytesFromHex("abcdef0123")); + } catch (e) { + expect_equal(e, "bad encoding"); + } }); diff --git a/wheel/README.md b/wheel/README.md index 271aa4fd..f57faf55 100644 --- a/wheel/README.md +++ b/wheel/README.md @@ -1,7 +1,6 @@ The `clvm_rs` wheel has python bindings for the rust implementation of clvm. -Build ------ +## Build Use `maturin` to build the python interface. First, install into current virtualenv with @@ -22,12 +21,11 @@ with OpenSSL. $ maturin develop --release --features=openssl ``` - To build the wheel, do ``` $ maturin build --release -```` +``` or