Skip to content

Commit

Permalink
adding two convenience scripts: one builds obsidian, runs it on one o…
Browse files Browse the repository at this point in the history
…f the files in GanacheTests, and pretty prints the output via solc; the other throws a binary representation a program to ganache-cli and reports the result. these more or less break up the travis tests in ganache-tests.sh so that it's easier to use in development locally
  • Loading branch information
ivoysey committed Apr 9, 2021
1 parent 646dfe8 commit 3fed30c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bin/run_obs_yul.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

if [ ! $(basename $(pwd -P)) == "Obsidian" ]
then
echo "don't run this unless you're in the obsidian tld"
exit 1
fi


DIR="resources/tests/GanacheTests"

if [ ! "$1" ]
then
echo "provide an argument! your options are:"
ls -1 "$DIR"/*.obs | xargs basename -s ".obs"
exit 1
fi

TEST="$DIR/$1.obs"

if [ ! -e "$TEST" ]
then
echo "$TEST does not exist"
exit 1
fi

if [ -d "$1" ]
then
rm -f "$1/$1.yul"
rmdir "$1"
fi

sbt "runMain edu.cmu.cs.obsidian.Main --yul $TEST" || exit 1

SOLC_OUT=$(docker run -v "$( pwd -P )/$1":/sources ethereum/solc:stable --strict-assembly "/sources/$1.yul")

TOP=$(echo "$SOLC_OUT" | grep -n "Pretty printed source:" | cut -f1 -d:)
BOT=$(echo "$SOLC_OUT" | grep -n "Binary representation:" | cut -f1 -d:)
TOP=$((TOP+1))
BOT=$((BOT-1))

echo "*********"
echo "THIS OUTPUT IS PRETTY-PRINTED BY SOLC, IT IS NOT LITERALLY WHAT WE PRODUCE"
echo "*********"

echo "$SOLC_OUT" | sed -n $TOP','$BOT'p' | sed '/^[[:space:]]*$/d'
69 changes: 69 additions & 0 deletions bin/throw_evm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

GAS=30000000 # this is a magic number (issue #302)
GAS_HEX=$(printf '%x' $GAS)
GAS_PRICE='0x9184e72a000' # this is a magic number from the YUL docs (issue #302)
START_ETH=5000000 # this is a magic number (issue #302)
NUM_ACCT=1

# start up ganache
echo "starting ganache-cli"
ganache-cli --gasLimit "$GAS" --accounts="$NUM_ACCT" --defaultBalanceEther="$START_ETH" &> /dev/null &

# form the JSON object to ask for the list of accounts
ACCT_DATA=$( jq -ncM \
--arg "jn" "2.0" \
--arg "mn" "eth_accounts" \
--argjson "pn" "[]" \
--arg "idn" "1" \
'{"jsonrpc":$jn,"method":$mn,"params":$pn,"id":$idn}'
)

# we'll keep querying for the accounts until we get a good result, this
# will also block until ganache-cli comes up.
echo "querying ganache-cli until accounts are available"
KEEPGOING=1
ACCTS=""
until [ "$KEEPGOING" -eq 0 ] ;
do
ACCTS=$(curl --silent -X POST --data "$ACCT_DATA" http://localhost:8545)
KEEPGOING=$?
sleep 1
done
echo

# todo: i'm not sure what account to mark as the "to" account. i think i
# can use that later to test the output of running more complicated
# contracts. i'll need to make more than one account when i start up
# ganache. (issue #302)
ACCT=`echo $ACCTS | jq '.result[0]' | tr -d '"'`
echo "ACCT is $ACCT"

# todo what's that 0x0 mean?
PARAMS=$( jq -ncM \
--arg "fn" "$ACCT" \
--arg "gn" "0x$GAS_HEX" \
--arg "gpn" "$GAS_PRICE" \
--arg "vn" "0x0" \
--arg "dn" "0x$1" \
'{"from":$fn,"gas":$gn,"gasPrice":$gpn,"value":$vn,"data":$dn}'
)

SEND_DATA=$( jq -ncM \
--arg "jn" "2.0" \
--arg "mn" "eth_sendTransaction" \
--argjson "pn" "$PARAMS" \
--arg "idn" "1" \
'{"jsonrpc":$jn,"method":$mn,"params":$pn,"id":$idn}'
)

echo "transaction being sent is given by"
echo "$SEND_DATA" | jq
echo

RESP=$(curl -s -X POST --data "$SEND_DATA" http://localhost:8545)
echo "response from ganache is"
((echo "$RESP" | tr -d '\n') ; echo) | jq # (issue #302)
echo "killing ganache-cli"
kill -9 $(lsof -t -i:8545)

0 comments on commit 3fed30c

Please sign in to comment.