diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 8e59a3f..ddf8085 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -1,10 +1,9 @@ -name: Za Warudo Book +name: Satoru Book on: push: branches: - main - pull_request: jobs: book: @@ -14,17 +13,31 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Check for changes in the book directory + id: check_changes + run: | + if git diff --quiet --exit-code HEAD^ HEAD -- book; then + echo "No changes in the 'book' directory. Exiting..." + exit 0 + else + echo "Changes detected in the book directory. Continuing..." + fi + continue-on-error: true + - name: Setup mdBook + if: steps.check_changes.outcome == 'success' uses: peaceiris/actions-mdbook@v1 with: mdbook-version: "latest" - - run: mdbook build + - name: Build mdBook + if: steps.check_changes.outcome == 'success' + run: mdbook build working-directory: ./book - name: Deploy + if: ${{ github.ref == 'refs/heads/main' }} && steps.check_changes.outcome == 'success' uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./book/book diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f740c5..21fe54a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,31 +1,18 @@ -on: - pull_request: - branches: - - main - push: - branches: - - main +name: Build + +on: [push, pull_request] + env: - SCARB_VERSION: 0.6.1+nightly-2023-08-16 + SCARB_VERSION: 0.7.0 -# For the moment we will use nightly versions of scarb to be able to use latest features of Cairo. -# The installation process will be a bit different than when using non nightly versions. -# Once Cairo and Scarb will be stable, we will use the stable versions and the `software-mansion/setup-scarb` action. -name: Build jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Scarb - #uses: software-mansion/setup-scarb@v1 - # Install Scarb from a nightly release - run: | - NIGHTLY_DATE=$(echo ${SCARB_VERSION} | cut -d '+' -f 2) - wget https://github.com/software-mansion/scarb-nightlies/releases/download/${NIGHTLY_DATE}/scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz - tar -xvf scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz - sudo mv scarb-v${SCARB_VERSION}-x86_64-unknown-linux-gnu/bin/scarb /usr/local/bin - + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "0.7.0" - name: Check cairo format run: scarb fmt --check - name: Build cairo programs diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 275c968..50d2b9b 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,17 +1,16 @@ -on: - pull_request: - branches: - - main - push: - branches: - - main - name: Security + +on: [push, pull_request] + jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "0.7.0" + - name: Install Semgrep run: | pip install semgrep @@ -21,4 +20,31 @@ jobs: uses: actions/upload-artifact@v3 with: name: semgrep-cairo - path: semgrep-output.txt \ No newline at end of file + path: semgrep-output.txt + + - name: Build cairo programs + run: scarb build + + - name: Cache Cargo dependencies + uses: actions/cache@v2 + with: + path: | + ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Check if Caracal is installed + id: check-caracal + run: | + if ! command -v caracal &> /dev/null; then + echo "Caracal is not installed. Installing..." + cargo install --git https://github.com/crytic/caracal --profile release --force + else + echo "Caracal is already installed." + fi + - name: Run Caracal + run: caracal detect . > caracal-output.txt + - name: Save Caracal Output as an Artifact + uses: actions/upload-artifact@v3 + with: + name: caracal-cairo + path: caracal-output.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a75933b..50de7e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,28 +1,19 @@ -on: - pull_request: - branches: - - main - push: - branches: - - main +name: Test + +on: [push, pull_request] + env: - SCARB_VERSION: 0.6.1+nightly-2023-08-16 - STARKNET_FOUNDRY_VERSION: 0.3.0 + SCARB_VERSION: 0.7.0 + STARKNET_FOUNDRY_VERSION: 0.5.0 -name: Test jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Scarb - #ses: software-mansion/setup-scarb@v1 - # Install Scarb from a nightly release - run: | - NIGHTLY_DATE=$(echo ${SCARB_VERSION} | cut -d '+' -f 2) - wget https://github.com/software-mansion/scarb-nightlies/releases/download/${NIGHTLY_DATE}/scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz - tar -xvf scarb-${NIGHTLY_DATE}-x86_64-unknown-linux-gnu.tar.gz - sudo mv scarb-v${SCARB_VERSION}-x86_64-unknown-linux-gnu/bin/scarb /usr/local/bin + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "0.7.0" - name: Install starknet foundry run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh -s -- -v ${STARKNET_FOUNDRY_VERSION} - name: Run cairo tests diff --git a/.tool-versions b/.tool-versions index 46b52fd..ce84f33 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 0.6.2 \ No newline at end of file +scarb 0.7.0 \ No newline at end of file diff --git a/Scarb.toml b/Scarb.toml index f9077ae..89fe97d 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -19,6 +19,8 @@ sierra-replace-ids = true [dependencies] starknet = ">=2.1.0" +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" } + [tool.snforge] exit_first = false diff --git a/tests/test_lockup_linear.cairo b/tests/test_lockup_linear.cairo index 6068cfd..956ca29 100644 --- a/tests/test_lockup_linear.cairo +++ b/tests/test_lockup_linear.cairo @@ -14,7 +14,10 @@ use starknet::{ ClassHash, }; use debug::PrintTrait; -use cheatcodes::PreparedContract; + +// Starknet Foundry imports. +use snforge_std::{declare, start_prank, stop_prank, ContractClassTrait}; + // Local imports. use za_warudo::core::lockup_linear::{ @@ -108,12 +111,8 @@ fn setup_contracts(caller_address: ContractAddress) -> (IZaWarudoLockupLinearSaf /// Utility function to deploy a `ZaWarudoLockupLinear` contract and return its address. fn deploy_za_warudo(initial_admin: ContractAddress) -> ContractAddress { - let class_hash = declare('ZaWarudoLockupLinear'); - let mut constructor_calldata = array![]; - constructor_calldata.append(initial_admin.into()); - let prepared = PreparedContract { - class_hash: class_hash, constructor_calldata: @constructor_calldata - }; - deploy(prepared).unwrap() + let za_warudo_contract = declare('ZaWarudoLockupLinear'); + let mut constructor_calldata = array![initial_admin.into()]; + za_warudo_contract.deploy(@constructor_calldata).unwrap() }