check-examples.sh 1.89 KB
Newer Older
#!/usr/bin/env bash
Hero Bird's avatar
Hero Bird committed

# Run this script from the workspace root!
#
# This script iterates through all examples under `examples/lang` folder
# and runs the most important actions performed on an ink! smart contract:
#
# - compile to a Wasm blob using `no_std` environment
# - run offchain tests `test-env`
# - generate ABI file using `ink-generate-abi`
#
# Afterwards the script prints out a summary report.
#
# Exits with `0` if all tests completed successfully or `1` otherwise.

declare -A results_test
declare -A results_wasm
declare -A results_abi

all_checks_passed=0
for example in $(ls examples/lang); do
    cargo build --release --no-default-features --target=wasm32-unknown-unknown --verbose --manifest-path examples/lang/$example/Cargo.toml
    result_wasm=$?
    let "all_checks_passed |= $result_wasm"
    if [ $result_wasm -eq 0 ]
    then
        results_wasm[$example]="ok"
    else
        results_wasm[$example]="ERROR"
    fi
    cargo test --verbose --manifest-path examples/lang/$example/Cargo.toml
    result_test=$?
    let "all_checks_passed |= $result_test"
    if [ $result_test -eq 0 ]
    then
        results_test[$example]="ok"
    else
        results_test[$example]="ERROR"
    fi
    cargo run --package abi-gen --manifest-path examples/lang/$example/Cargo.toml
    result_abi=$?
    let "all_checks_passed |= $result_abi"
    if [ $result_abi -eq 0 ]
    then
        results_abi[$example]="ok"
    else
        results_abi[$example]="ERROR"
    fi
done

Hero Bird's avatar
Hero Bird committed
banner="---------------"
Hero Bird's avatar
Hero Bird committed
echo "Example Results"
Hero Bird's avatar
Hero Bird committed
echo "$banner"
Hero Bird's avatar
Hero Bird committed
for entry in ${!results_wasm[@]}; do
    echo "- $entry (wasm): ${results_wasm[$entry]}"
    echo "- $entry (test): ${results_test[$entry]}"
    echo "- $entry (abi) : ${results_abi[$entry]}"
done
echo ""
if [ $all_checks_passed -eq 0 ]
then
    echo "examples: All checks passed"
Hero Bird's avatar
Hero Bird committed
    echo "$banner"
Hero Bird's avatar
Hero Bird committed
    exit 0
else
    echo "examples: Some checks failed"
Hero Bird's avatar
Hero Bird committed
    echo "$banner"
Hero Bird's avatar
Hero Bird committed
    exit 1
fi