Skip to content

User Accounts with PDA (internal) #1129

User Accounts with PDA (internal)

User Accounts with PDA (internal) #1129

Workflow file for this run

name: Test
on:
push:
branches:
- main
pull_request:
branches:
- "*"
defaults:
run:
shell: bash
working-directory: .
env:
RUST_TOOLCHAIN: 1.79.0
SOLANA_CLI_VERSION: 2.1.20
ANCHOR_CLI_VERSION: 0.31.1
ANCHOR_SHA: e6d7dafe12da661a36ad1b4f3b5970e8986e5321
CARGO_TERM_COLOR: always
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Rust Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/base-setup/
with:
include-anchor: "false"
- run: cargo fmt -- --check
- run: ./scripts/lint.sh
test-unit:
name: Rust Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/base-setup/
with:
include-anchor: "false"
- run: cargo test --lib
build-and-test-workspace:
name: Build & Test Anchor Programs
runs-on: ubuntu-latest
needs: [ test-unit ]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/base-setup/
# TODO cache transfer hook and mocks here instead of rebuilding them each time...
- uses: ./.github/actions/build-workspace/
# ─── Cache cargo-nextest ─────────────────────────────────────────────
- name: Cache cargo-nextest binary
uses: actions/cache@v3
id: cache-nextest
with:
path: ~/.cargo/bin/cargo-nextest
key: cargo-nextest-${{ runner.os }}-v0.9.81
- name: Install cargo-nextest
if: steps.cache-nextest.outputs.cache-hit != 'true'
run: |
cargo install cargo-nextest --version "0.9.81" --locked
shell: bash
- run: ./scripts/test-program.sh all --sane
fuzz:
name: Fuzz The marginfi Program
runs-on: ubuntu-latest
needs: [ test-unit ]
defaults:
run:
shell: bash
working-directory: ./programs/marginfi/fuzz
steps:
- uses: actions/checkout@v3
# ─── Cache Cargo registry ─────────────────────────────────────────────
- name: Cache Cargo registry & index
uses: actions/cache@v3
id: cache-cargo-registry
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-registry-${{ runner.os }}-${{ hashFiles('programs/marginfi/fuzz/Cargo.lock') }}
# ─── Cache nightly Rust toolchain ───────────────────────────────
- name: Cache Rust nightly toolchain
uses: actions/cache@v3
id: cache-nightly
with:
path: ~/.rustup/toolchains/nightly-2024-06-05-x86_64-unknown-linux-gnu
key: rust-nightly-${{ runner.os }}-nightly-20240605
- name: Install nightly Rust + rust-src
if: steps.cache-nightly.outputs.cache-hit != 'true'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-06-05
components: rust-src
# ─── Cache cargo fuzz ----- ─────────────────────────────────────────────
- name: Cache cargo-fuzz
uses: actions/cache@v3
id: cache-cargo-fuzz
with:
path: ~/.cargo/bin/cargo-fuzz
key: cargo-fuzz-${{ runner.os }}-nightly-20240605
- name: Install cargo-fuzz
if: steps.cache-cargo-fuzz.outputs.cache-hit != 'true'
run: cargo install cargo-fuzz --locked
# ─── Cache compiled fuzz target ─────────────────────────────────────────────
- name: Cache fuzz target build
uses: actions/cache@v3
id: cache-fuzz-build
with:
path: target/fuzz/lend
key: fuzz-build-${{ runner.os }}-${{ hashFiles('programs/marginfi/fuzz/**/*.rs') }}
- name: Generate corpus
run: python ./generate_corpus.py
- name: Run fuzz tests
run: |
cargo +nightly-2024-06-05 fuzz run lend \
-Zbuild-std --strip-dead-code --no-cfg-fuzzing \
-- -max_total_time=150 \
-timeout_exitcode=100 \
-error_exitcode=101 \
-print_pcs=0 \
-print_final_stats=1 \
-close_fd_mask=1 \
-jobs=2 \
-workers=2
- name: Pass after fuzzing
run: echo "✅ Fuzzing completed"
localnet-test-marginfi:
name: Anchor Localnet Tests (Marginfi)
runs-on: ubuntu-latest
needs: [ test-unit ]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/base-setup/
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '23.0.0'
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
- name: Install JS deps
run: yarn install --frozen-lockfile --prefer-offline
# ─── Cache transfer hook ─────────────────────────────────────────────
- name: Cache transfer-hook build
uses: actions/cache@v3
id: cache-transfer
with:
path: target/deploy/test_transfer_hook.so
key: anchor-transfer-hook-${{ runner.os }}-${{ env.ANCHOR_SHA }}-${{ hashFiles('programs/test_transfer_hook/**/*') }}
- name: Build transfer hook
if: steps.cache-transfer.outputs.cache-hit != 'true'
run: anchor build -p test_transfer_hook --no-idl
# ─── Cache mocks program ─────────────────────────────────────────────
- name: Cache mocks build & IDL
uses: actions/cache@v3
id: cache-mocks
with:
path: |
target/deploy/mocks.so
target/idl/mocks.json
target/types/mocks.ts
key: anchor-mocks-${{ runner.os }}-${{ env.ANCHOR_SHA }}-${{ hashFiles('programs/mocks/**/*') }}
- name: Build mocks
if: steps.cache-mocks.outputs.cache-hit != 'true'
run: anchor build -p mocks
# ─── Marginfi always builds from scratch ─────────────────────────
- name: Build marginfi
run: anchor build -p marginfi -- --no-default-features
- name: Run Anchor tests (retry on segfault)
run: |
set +e
run_tests() {
anchor test --skip-build 2>&1 | tee test_output.log
return $?
}
run_tests
CODE=$?
if [ $CODE -eq 139 ]; then
echo "⚠️ Segmentation fault detected. Retrying tests once…"
run_tests
CODE=$?
fi
set -e
if grep -q "failing" test_output.log; then
echo "❌ Real test failure detected."
exit 1
fi
if grep -q "No such file or directory (os error 2)" test_output.log \
&& [ $CODE -ne 139 ]; then
echo "ℹ️ Extraneous OS-error-2 detected; ignoring it."
exit 0
fi
echo "✅ Tests finished with exit code $CODE"
exit $CODE