Skip to content

Commit

Permalink
Testing: Allow proving of blocks in CI
Browse files Browse the repository at this point in the history
Problem: Currently there is no way to run the `prove_block` command against several blocks in the CI.
Solution: Implement a way to start pathfinder and prove blocks.
  • Loading branch information
whichqua committed Aug 23, 2024
1 parent 53cf19d commit 31ceedb
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/prove_block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Prove Blocks

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install required packages
run: |
sudo apt-get update
sudo apt-get install -y curl git python3 python3-venv python3-dev build-essential libgmp-dev pkg-config libssl-dev zstd
- name: Cache Db
id: cache-db
uses: actions/cache@v3
with:
path: |
$HOME/pathfinder-data/testnet-sepolia.sqlite
- name: Download and extract database file
if: ${{ steps.cache-db.outputs.cache-hit != 'true' }}
run: |
mkdir -p $HOME/pathfinder-data
curl -L https://pub-1fac64c3c0334cda85b45bcc02635c32.r2.dev/sepolia-testnet_0.13.0_74494_archive.sqlite.zst -o sepolia-testnet.sqlite.zst
zstd -d sepolia-testnet.sqlite.zst -o $HOME/pathfinder-data/testnet-sepolia.sqlite
- name: Pull Pathfinder Docker image
run: |
docker pull odesenfans/pathfinder:latest
- name: Run Pathfinder container in the background
run: |
docker run \
--name pathfinder \
--detach \
-p 127.0.0.1:9545:9545 \
--user "$(id -u):$(id -g)" \
-e RUST_LOG=info \
-e PATHFINDER_ETHEREUM_API_URL=${{ secrets.PATHFINDER_ETHEREUM_API_URL }} \
-v $HOME/pathfinder-data:/usr/share/pathfinder/data \
odesenfans/pathfinder:latest \
--storage.state-tries=archive
- name: Wait for Pathfinder to be ready
run: |
until curl -s http://127.0.0.1:9545; do
echo "Waiting for Pathfinder to start..."
docker logs pathfinder
sleep 5
done
echo "Pathfinder is up!"
docker logs pathfinder
- name: "Install Rust"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"

- name: "Cache cargo"
id: cache-cargo
uses: "actions/cache@v4"
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
save-always: true
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Create and activate Python virtual environment
run: |
python3 -m venv venv
source venv/bin/activate
- name: Setup the tests
run: |
source venv/bin/activate
pip install cairo-lang==0.13.1 "sympy<1.13.0"
bash scripts/setup-tests.sh
- name: Prove Blocks
run: bash scripts/prove-blocks.sh -p http://127.0.0.1:9545 -b 33911,33922,33928
40 changes: 40 additions & 0 deletions scripts/prove-blocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Function to show usage
usage() {
echo "Usage: $0 -p <rpc-provider> -b <block-number1,block-number2,...>"
exit 1
}

# Parse command-line options
while getopts "p:b:" opt; do
case ${opt} in
p )
PROVIDER=$OPTARG
;;
b )
IFS=',' read -r -a BLOCK_NUMBERS <<< "$OPTARG"
;;
* )
usage
;;
esac done

# Check if both provider and block numbers are provided
if [ -z "$PROVIDER" ] || [ -z "$BLOCK_NUMBERS" ]; then
usage
fi

# Loop through each block number and execute the cargo command
for BLOCK_NUMBER in "${BLOCK_NUMBERS[@]}"; do
echo "Executing for block number: $BLOCK_NUMBER"
cargo run -p prove_block -- --block-number "$BLOCK_NUMBER" --rpc-provider "$PROVIDER"

# Check if the cargo command failed
if [ $? -ne 0 ]; then
echo "Command failed for block number: $BLOCK_NUMBER. Exiting."
exit 1
fi
done

echo "All blocks proved successfully."

0 comments on commit 31ceedb

Please sign in to comment.