Skip to content

Commit 9d85394

Browse files
committed
chore: add script to compare bytecode
Signed-off-by: Tomás Migone <[email protected]>
1 parent a32f413 commit 9d85394

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

scripts/bytecode-diff.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [ "$#" -ne 2 ]; then
6+
echo "Usage: $0 <artifacts-dir-1> <artifacts-dir-2>"
7+
exit 1
8+
fi
9+
10+
DIR1="$1"
11+
DIR2="$2"
12+
13+
TMPDIR=$(mktemp -d)
14+
15+
# Function to extract, strip metadata, and chunk bytecode
16+
process() {
17+
local file="$1"
18+
local out="$2"
19+
20+
jq -r '.deployedBytecode' "$file" | fold -w 64 > "$out"
21+
}
22+
23+
# Find all JSON files in DIR1
24+
find "$DIR1" -type f -name '*.json' ! -name '*dbg.json' ! -name 'I*.json' | while read -r file1; do
25+
# Get relative path
26+
rel_path="${file1#$DIR1/}"
27+
file2="$DIR2/$rel_path"
28+
29+
if [ ! -f "$file2" ]; then
30+
echo "⚠️ Missing in second dir: $rel_path"
31+
continue
32+
fi
33+
34+
tmp1="$TMPDIR/1"
35+
tmp2="$TMPDIR/2"
36+
37+
process "$file1" "$tmp1"
38+
process "$file2" "$tmp2"
39+
40+
if ! diff -q "$tmp1" "$tmp2" > /dev/null; then
41+
echo "🧨 Difference found in: $rel_path"
42+
if command -v colordiff &> /dev/null; then
43+
colordiff -u "$tmp1" "$tmp2"
44+
else
45+
diff -u "$tmp1" "$tmp2"
46+
fi
47+
echo
48+
fi
49+
done
50+
51+
rm -rf "$TMPDIR"

0 commit comments

Comments
 (0)