Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Aug 11, 2023
1 parent 0f5cc16 commit 3576702
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ oasis: $(shell find . -name "*.go" -type f) go.sum go.mod
@$(PRINT) "$(MAGENTA)*** Building Go code...$(OFF)\n"
@$(GO) build -v -o oasis $(GOFLAGS) $(GO_EXTRA_FLAGS)

examples: oasis $(EXAMPLES)
examples: $(EXAMPLES)

examples/%.out: examples/%.in oasis
examples/%.out: examples/%.in oasis scripts/gen_example.sh
@rm -f $@
scripts/gen_example.sh $< $@
@scripts/gen_example.sh $< $@

clean-examples:
@rm -f examples/*/*.out
Expand Down
41 changes: 18 additions & 23 deletions scripts/gen_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ set -euo pipefail

OASIS_CMD=$(readlink -f ./oasis)
IN=$(readlink -f $1)
touch "$2" # XXX MacOS: readlink -f does not work if file does not exist. readlink -m is not implemented yet.
OUT=$(readlink -f $2)
EXAMPLE_NAME=$(echo $(basename $(dirname $IN)))
EXAMPLE_NAME="$(basename $(dirname $IN))"
USER_CFG_DIR="${HOME}/.config/oasis"
CUSTOM_CFG_DIR="$(dirname $IN)/config"
CFG_DIR="/tmp/cli_examples/${EXAMPLE_NAME}"
Expand All @@ -24,10 +25,12 @@ if [ "$(echo "$IN" | cut -d "." -f 2)" == "y" ]; then
YES_FLAG="-y -o /dev/null"
fi

echo "Running ${EXAMPLE_NAME}/$(basename $IN):"

# Prepare clean config file for the example or take the example-specific one, if it exists.
function init_cfg() {
# Init config in the first scenario step only.
if [ "$IN" != "$(ls $(dirname $IN)/* | head -n1)" ]; then
if [ "$IN" != "$(ls $(dirname $IN)/*.in | head -n1)" ]; then
return
fi

Expand All @@ -53,6 +56,9 @@ function init_cfg() {
${OASIS_CMD} network ls >/dev/null
wait

ls "${USER_CFG_DIR}"
cat "${USER_CFG_DIR}/*"

# Use the fresh config for our example.
mv "${USER_CFG_DIR}" "${CFG_DIR}"

Expand All @@ -66,35 +72,24 @@ init_cfg

# Replace "oasis" with the actual path to the Oasis CLI executable.
CMD="$(sed "s#oasis#$OASIS_CMD#" $IN) ${CFG_FLAG} ${YES_FLAG}"

echo "Running ${EXAMPLE_NAME}/$(basename $IN):"
echo " ${CMD}"

# Use UTC timezone.
export TZ=UTC

# Execute the Oasis CLI and store the PID.
cd $(dirname ${IN})
${CMD} > ${OUT} &

PID=$!
while ! test -f ${OUT} || ! grep -q "Sign this transaction" "${OUT}" && ps -p ${PID} > /dev/null
do
sleep 0.5
done

kill -9 ${PID} 2&>/dev/null || true

# Trim the transaction submission notice (In case you are using a hardware-based signer...).
if [ "$YES_FLAG" != "" ]
then
head -n -1 ${OUT} > ${OUT}.tmp
mv ${OUT}.tmp ${OUT}
fi
${CMD} > ${OUT}

# Trim "Sign this transaction" prompt, if present.
if tail -n 1 ${OUT} | grep -q "Sign this transaction"
# Trim last two lines, if in non-interactive mode ("Sign this transaction?" and "In case you are using a hardware-based signer...").
if [ "$YES_FLAG" != "" ] && grep -q "Sign this transaction?" "${OUT}"
then
head -n -1 ${OUT} > ${OUT}.tmp
echo "trimming"
echo $(cat ${OUT})
echo $(wc -l ${OUT})
echo $(cat ${OUT} | wc -l)
echo $(( $(cat ${OUT} | wc -l)-2 ))
OUT_LINES=$(( $(cat ${OUT} | wc -l)-2 )) # XXX MacOS: head -n -2 is not implemented yet
head -n ${OUT_LINES} ${OUT} > ${OUT}.tmp
mv ${OUT}.tmp ${OUT}
fi

0 comments on commit 3576702

Please sign in to comment.