-
Notifications
You must be signed in to change notification settings - Fork 324
/
seth-debug
executable file
·66 lines (58 loc) · 2.21 KB
/
seth-debug
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
#!/usr/bin/env bash
### seth-debug -- debug a transaction in hevm interactive
### Usage: seth debug <tx-hash> [<options>]
###
### Runs all the transactions in the block to get the correct state
### then executes the given transaction in debug mode
###
### Unless `--no-src` is given, source code for the `to` address
### will be passed along to hevm for better debugging xp
set -e
state=$(TMPDIR=. mktemp -d hevm.libs.XXXXX -p /tmp)
export GIT_CONFIG_NOSYSTEM=1
export GIT_AUTHOR_NAME=hevm
export GIT_AUTHOR_EMAIL=hevm@dapphub.com
export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL
gitopts=(-q --no-verify --no-gpg-sign --allow-empty -m "dapp test")
( cd "$state" || exit ; git init -q && git add . && git commit "${gitopts[@]}" )
targetTx=$(seth tx "$1")
# TODO: scary rm -rf
tidy() {
[[ "$SRCDIR" ]] && rm -rf "$SRCDIR"
rm -rf "$state"
}
trap tidy SIGINT SIGTERM
if [[ -z "$SETH_NOSRC" ]]; then
echo >&2 "${0##*/}: info: fetching contract source from etherscan..."
SRCDIR=$(TMPDIR=. mktemp -d seth.debug.XXXX -p /tmp)
if seth bundle-source "$(<<< "$targetTx" seth --field to)" --dir "$SRCDIR" > "$SRCDIR"/standard.json ; then
opts=(--source "$SRCDIR"/standard.json);
else
echo >&2 "${0##*/}: warning: no source available"
fi
fi
index="$(<<< "$targetTx" seth --field transactionIndex)"
block=$(seth block "$(<<< "$targetTx" seth --field blockNumber)" --full)
txs=($(<<< "$block" seth --field transactions | seth --show-json))
timestamp="$(<<< "$block" seth --field timestamp)"
j=0
for i in "${txs[@]}"; do
tx=$(<<< "$i" seth --show-json)
hash=$(<<< "$tx" seth --field hash)
if [[ "$1" = "$hash" ]]; then
echo -e >&2 "\r${0##*/}: info: transaction ($j/$index)"
seth run-tx "$hash" --state "$state" --debug "${opts[@]}"
tidy
break
else
[[ $SETH_VERBOSE ]] &&
echo -e >&2 "\r${0##*/}: info: transaction ($j/$index)" ||
echo -en >&2 "\r${0##*/}: info: transaction ($j/$index)"
# exit code 2 means REVERT or otherwise acceptable failure
seth run-tx "$hash" --state "$state" --timestamp "$timestamp" > /dev/null ||
[[ $? == 2 ]] ||
(tidy; echo ""; seth --fail "${0##*/}: error: hevm error while executing tx: $hash")
j=$((j + 1))
fi
done