Repository navigation
Expand file tree
/
Copy pathcontest.sh
More file actions
executable file
·149 lines (124 loc) · 3.71 KB
/
Copy pathcontest.sh
File metadata and controls
executable file
·149 lines (124 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
set -euo pipefail
# Run an integration test described in a JSON file
# Check for input file
if [[ $# -lt 1 ]]; then
echo "Usage: $0 file.json [options]"
exit 1
fi
# Setup file paths
file=$1
shift
if [[ ! -f "$file" ]]; then
echo "Error: File '$file' not found"
exit 1
fi
echo "Processing: $file"
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
test_dir=$(dirname $file)
build_dir="$root_dir/build"
base=$(basename "$file" .json)
src="$test_dir/$base.sol"
create=true
# Allow overriding testrunner location (useful for Nix builds)
if [[ -z "${testrunner_exe:-}" ]]; then
if [[ -x "$root_dir/build/test/testrunner/testrunner" ]]; then
testrunner_exe="$root_dir/build/test/testrunner/testrunner"
else
testrunner_exe="$root_dir/test/testrunner/testrunner"
fi
fi
# Allow overriding evmone location (useful for Nix builds)
if [[ -z "${evmone:-}" ]]; then
evmone_candidates=(
"$root_dir/result/lib/libevmone.so"
"$HOME/.local/lib/libevmone.so"
"$HOME/.local/lib/libevmone.dylib"
"/opt/homebrew/lib/libevmone.dylib"
"/usr/local/lib/libevmone.dylib"
"/usr/local/lib/libevmone.so"
"/lib/x86_64-linux-gnu/libevmone.so"
"/usr/lib/x86_64-linux-gnu/libevmone.so"
"/usr/lib/libevmone.so"
)
for candidate in "${evmone_candidates[@]}"; do
if [[ -f "$candidate" ]]; then
evmone="$candidate"
break
fi
done
fi
if [[ -z "${evmone:-}" ]]; then
echo "Error: libevmone not found. Set evmone=/path/to/libevmone.{so,dylib}"
exit 1
fi
if [[ ! -f "$evmone" ]]; then
echo "Error: evmone library not found at '$evmone'"
exit 1
fi
if [[ ! -x "$testrunner_exe" ]]; then
echo "Error: testrunner not found or not executable at '$testrunner_exe'"
exit 1
fi
presuite=$(jq keys[0] $file)
suite=$(echo $presuite | tr -d '"')
#echo json: $file
#echo src: $src
#echo hex: $hexfile
#echo suite: $suite
# Execute compilation pipeline
echo "Compiling to Hull..."
# Allow overriding sol-core command (useful for Nix builds)
: ${SOLCORE_CMD:="cabal run exe:sol-core --"}
mkdir -p "$build_dir"
work_root="$build_dir/.contest-work"
mkdir -p "$work_root"
work_dir="$(mktemp -d "$work_root/run.XXXXXX")"
work_marker="$work_dir/.owned-by-contest"
touch "$work_marker"
hull="$work_dir/output1.hull"
yulfile="$work_dir/output.yul"
hexfile="$work_dir/output.hex"
runner_input="$work_dir/runner-input.json"
runner_output="$work_dir/runner-output.json"
cleanup_work_dir() {
if [[ -z "${work_dir:-}" ]]; then
return
fi
if [[ "$work_dir" != "$work_root"/run.* || ! -f "$work_marker" ]]; then
echo "Error: refusing to clean unverified contest work directory '$work_dir'" >&2
return 1
fi
rm -rf -- "$work_dir"
}
trap cleanup_work_dir EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
if ! $SOLCORE_CMD -f "$src" -o "$work_dir"; then
echo "Error: sol-core compilation failed"
exit 1
fi
if [[ ! -f "$hull" ]]; then
echo "Error: sol-core did not produce output1.hull"
exit 1
fi
echo "Generating Yul..."
# Allow overriding yule command (useful for Nix builds)
: ${YULE_CMD:="cabal run exe:yule --"}
yule_args=("$hull" -o "$yulfile")
if [[ "$create" == "false" ]]; then
yule_args+=(--nodeploy)
fi
if ! $YULE_CMD "${yule_args[@]}"; then
echo "Error: yule generation failed"
exit 1
fi
echo "Compiling to bytecode..."
if ! solc --strict-assembly --bin --optimize "$yulfile" | tail -1 | tr -d '\n' > "$hexfile"; then
echo "Error: solc compilation failed"
exit 1
fi
echo "Hex output: $hexfile"
jq ".$suite.bytecode |= \"$(cat $hexfile)\" " $file > "$runner_input"
"$testrunner_exe" "$evmone" "$runner_input" "$runner_output"