forked from bEsPoKeN-tOkEns/token-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·43 lines (33 loc) · 1.39 KB
/
script.sh
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
#!/bin/bash
function_selector_0x=$1
amount_of_tokens=$2
token_names_csv=$3
# current directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# create the python-out directory if it doesn't exist
mkdir -p $DIR/python-out
# split the token names into an array, using comma delimiter
IFS=',' read -r -a token_names <<< "$token_names_csv"
for element in "${token_names[@]}"
do
echo "$element"
done
# parse additional input
amount_of_tokens=${amount_of_tokens#*x}
function_selector=${function_selector_0x#*x}
function_selector=${function_selector%*00000000000000000000000000000000000000000000000000000000}
# search for the human-readable function name from the foundry out/ ABI
function_name=$(grep -r "${function_selector}" out | grep "test" | cut -d: -f2 | cut -d\" -f2 | cut -d\( -f1 )
# use for loop based on range 0..$2
# start at 1 because forge test treats 0 = no token
for i in $(seq 1 1 $amount_of_tokens)
do
FORGE_TOKEN_TESTER_ID=$i forge test --mt $function_name --silent --ffi > /dev/null 2>&1
result=$(echo $?)
echo $result "Token ${token_names[$i-1]}"
# ternary conversion of exit code to `success` or `failure`
# (exit code 0 is success, 1 is failure)
class=$( [ "${result}" -eq 1 ] && echo "failure" || echo "success" )
python3 $DIR/runner.py --test-name $function_name --token-name ${token_names[$i-1]} --result $class
wait
done