-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ reference test against nutshell implementation
- Loading branch information
1 parent
e1930b9
commit 57f8862
Showing
7 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,7 @@ Cargo.lock | |
*.pyd | ||
*.pyo | ||
*.pyd | ||
**/__pycache__/ | ||
**/__pycache__/ | ||
|
||
**/target | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
S1_Blinded_message_x | ||
S1_Blinded_message_y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Set up variables | ||
WORKING_DIR=$(pwd) | ||
TARGET_DIR="$WORKING_DIR/tests/references/target" | ||
CAIRO_LOG="$TARGET_DIR/cairo_output.log" | ||
NUTSHELL_LOG="$TARGET_DIR/nutshell_output.log" | ||
PATTERNS_FILE="$WORKING_DIR/tests/references/patterns.txt" | ||
RESULTS_FILE="$TARGET_DIR/results.json" | ||
REPORT_FILE="$TARGET_DIR/report.txt" | ||
|
||
# Create target directory if it doesn't exist | ||
mkdir -p "$TARGET_DIR" | ||
|
||
# Function to run tests and save logs | ||
run_tests() { | ||
echo "Running Cairo implementation..." | ||
cd "$WORKING_DIR" | ||
scarb cairo-run --available-gas=200000000 > "$CAIRO_LOG" 2>&1 | ||
|
||
echo "Running Nutshell implementation..." | ||
cd "$WORKING_DIR/tests/references/bdhke-nutshell" | ||
./run_nutshell.sh > "$NUTSHELL_LOG" 2>&1 | ||
} | ||
|
||
# Function to extract values from logs | ||
extract_values() { | ||
local log_file=$1 | ||
local pattern=$2 | ||
grep "$pattern" "$log_file" | cut -d':' -f2 | tr -d ' ' | ||
} | ||
|
||
# Function to compare values and update results | ||
compare_values() { | ||
local pattern=$1 | ||
local cairo_value=$(extract_values "$CAIRO_LOG" "$pattern") | ||
local nutshell_value=$(extract_values "$NUTSHELL_LOG" "$pattern") | ||
|
||
echo "Pattern: $pattern" >> "$REPORT_FILE" | ||
echo "Cairo value: $cairo_value" >> "$REPORT_FILE" | ||
echo "Nutshell value: $nutshell_value" >> "$REPORT_FILE" | ||
|
||
if [ -z "$cairo_value" ] && [ -z "$nutshell_value" ]; then | ||
echo " \"$pattern\": false," >> "$RESULTS_FILE" | ||
echo "❌ $pattern: Missing value in both implementations" >> "$REPORT_FILE" | ||
elif [ -z "$cairo_value" ]; then | ||
echo " \"$pattern\": false," >> "$RESULTS_FILE" | ||
echo "❌ $pattern: Missing value in Cairo implementation" >> "$REPORT_FILE" | ||
elif [ -z "$nutshell_value" ]; then | ||
echo " \"$pattern\": false," >> "$RESULTS_FILE" | ||
echo "❌ $pattern: Missing value in Nutshell implementation" >> "$REPORT_FILE" | ||
elif [ "$cairo_value" = "$nutshell_value" ]; then | ||
echo " \"$pattern\": true," >> "$RESULTS_FILE" | ||
echo "✅ $pattern: Match" >> "$REPORT_FILE" | ||
else | ||
echo " \"$pattern\": false," >> "$RESULTS_FILE" | ||
echo "❌ $pattern: Mismatch" >> "$REPORT_FILE" | ||
echo " Cairo: $cairo_value" >> "$REPORT_FILE" | ||
echo " Nutshell: $nutshell_value" >> "$REPORT_FILE" | ||
fi | ||
echo "" >> "$REPORT_FILE" | ||
} | ||
|
||
# Main execution | ||
echo "Starting reference tests..." | ||
|
||
# Run tests | ||
run_tests | ||
|
||
# Initialize results file | ||
echo "{" > "$RESULTS_FILE" | ||
|
||
# Initialize report file | ||
echo "Reference Test Report" > "$REPORT_FILE" | ||
echo "=====================" >> "$REPORT_FILE" | ||
echo "" >> "$REPORT_FILE" | ||
|
||
# Compare values for each pattern | ||
while IFS= read -r pattern | ||
do | ||
compare_values "$pattern" | ||
done < "$PATTERNS_FILE" | ||
|
||
# Finalize results file | ||
sed -i '' '$ s/,$//' "$RESULTS_FILE" # Remove trailing comma | ||
echo "}" >> "$RESULTS_FILE" | ||
|
||
# Calculate and add summary to report | ||
total_patterns=$(wc -l < "$PATTERNS_FILE") | ||
matching_patterns=$(grep -c "true" "$RESULTS_FILE") | ||
echo "Summary:" >> "$REPORT_FILE" | ||
echo "--------" >> "$REPORT_FILE" | ||
echo "Total patterns: $total_patterns" >> "$REPORT_FILE" | ||
echo "Matching patterns: $matching_patterns" >> "$REPORT_FILE" | ||
|
||
if [ "$total_patterns" -eq "$matching_patterns" ]; then | ||
echo "✅ All patterns match" >> "$REPORT_FILE" | ||
test_result=0 | ||
else | ||
echo "❌ Some patterns do not match" >> "$REPORT_FILE" | ||
test_result=1 | ||
fi | ||
|
||
# Display report | ||
cat "$REPORT_FILE" | ||
|
||
echo "Reference tests completed. See $REPORT_FILE for full report." | ||
|
||
# Exit with the appropriate status | ||
exit $test_result |