Skip to content

Commit

Permalink
clean up script, fixture, hints
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed May 10, 2024
1 parent dc32e39 commit 357dcee
Show file tree
Hide file tree
Showing 39 changed files with 52 additions and 4,543 deletions.
3 changes: 1 addition & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ echo "Setting up the environment..."
[tasks.integration-test]
workspace = false
description = "Run integration tests. Specify the folder name through the INTEGRATION_ARGS environment variable."
env = { INTEGRATION_ARGS = "storage" }
script = '''
echo "Running integration tests with arguments: $INTEGRATION_ARGS"
chmod +x ./scripts/integration.sh
./scripts/integration.sh $INTEGRATION_ARGS
./scripts/integration.sh
'''

[tasks.reset-setup]
Expand Down
107 changes: 51 additions & 56 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
@@ -1,61 +1,56 @@
#!/bin/bash

prepare_cairo_enviroment() {
# Function to run tests on a given Cairo file
run_tests() {
local input_file="$1"
local temp_output=$(mktemp)

# Activate the virtual environment
source ./venv/bin/activate
# Check if cairo-run is installed
cairo-run --version
source ./venv/bin/activate

# Attempt to run the compiled program and capture output
local start_time=$(date +%s)

# Extract the directory path from the input file
local input_dir=$(dirname "$input_file")

# Run the cairo-run command
cairo-run \
--program=compiled_cairo/hdp.json \
--layout=starknet_with_keccak \
--program_input="$input_file" \
--cairo_pie_output "$temp_output" \
--print_info

local status=$?
if [ $status -eq 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Successfully prepared"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - Failed to prepared"
return $status
fi
local end_time=$(date +%s)
local duration=$((end_time - start_time))

if [ $status -eq 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Successful $input_file: Duration ${duration} seconds"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - Failed: $input_file"
fi

rm -f "$temp_output" # Clean up temporary file

return $status
}
# Call the function to ensure the virtual environment is activated
prepare_cairo_enviroment

# Echoing arguments for debugging
echo "Arguments received: $@"

# Base directory where the folders 'storage' and 'account' and 'header' are located
BASE_DIR="fixtures"

TARGET_DIRS=("$@")

echo "Running integration tests on directories: ${TARGET_DIRS[@]}"

# Loop through specified directories
for dir in $TARGET_DIRS; do
# Find all directories within the main directories
find "${BASE_DIR}/${dir}" -type d | while read -r subDir; do
# Check for the existence of the input.json file after run.sh has completed
inputFilePath="${subDir}/input.json"
if [[ -f "${inputFilePath}" ]]; then
# Extract the base directory and subfolder name from the input file path
baseDir=$(dirname "${inputFilePath}")
subFolder=$(basename "${baseDir}")

# Define the output .pie file path
pieFilePath="${baseDir}/${subFolder}.pie"

# Run the cairo-run command
cairo-run \
--program=compiled_cairo/hdp.json \
--layout=starknet_with_keccak \
--program_input="${inputFilePath}" \
--cairo_pie_output "${pieFilePath}" \
--print_output

# Check if cairo-run was successful
if [ $? -ne 0 ]; then
echo "Error processing file: ${inputFilePath}"
else
echo "Successfully processed file: ${inputFilePath}"
fi
else
echo "No input.json found in ${subDir} after running run.sh"
fi
done
done

export -f run_tests

echo "Starting tests..."

# Find all input.json files in the /fixtures folder and its subfolders
find ./fixtures -name "input.json" | parallel run_tests "$file"

# Capture the exit status of parallel
exit_status=$?

if [ $exit_status -eq 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Success: Parallel execution exited"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - Failed: Parallel execution exited"
fi

exit $exit_status
92 changes: 0 additions & 92 deletions tests/cairo_programs/account_decoder.cairo

This file was deleted.

Loading

0 comments on commit 357dcee

Please sign in to comment.