Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Fix test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
elmato committed Aug 29, 2018
1 parent 0e95f99 commit b1ec32e
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 63 deletions.
2 changes: 1 addition & 1 deletion eosio.unregd/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def ref_block(block_id):
f.write(tx_json)

with open(os.devnull, 'w') as devnull:
cmd = ["cleos","sign","-p","-k","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3",tmpf]
cmd = ["cleos","sign","-p","-k","5JNxyTXH4Uu4nxfBG97aQKoKYxTcmeyGjqds5LHHNh88xCTjSTw",tmpf]
p = Popen(cmd, stdout=PIPE, stderr=devnull)
output, err = p.communicate("")

Expand Down
96 changes: 90 additions & 6 deletions eosio.unregd/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
rm -rf ~/eosio-wallet/./default.wallet
cleos wallet create 2>&1 | tail -n1 | tail -c+2 | head -c-2 > /tmp/pass

cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
#cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos wallet import --private-key 5KFDkQMpWu9chAEfgQNiEDwRdJePEVJiK92jx6vvUrQA8qFBXUd
cleos wallet import --private-key 5KB513vWai23JYUVB6U8e6oN3z1jApaDDXhp33NuA3urCxgZGMR

cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio eosio.bpay EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio eosio.msig EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
Expand All @@ -19,17 +21,99 @@ cleos push action eosio.token create '[ "eosio", "10000000000.0000 EOS"]' -p eos
cleos push action eosio.token issue '[ "eosio", "1000000000.0000 EOS"]' -p eosio
cleos set contract eosio.msig ~/eos/build/contracts/eosio.msig -p eosio.msig

cleos create account eosio eosio.unregd EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio eosio.unregd EOS5BQS4J7f5MKdhTKEXuZQpfwwJDYsikVShaKbVJTmGbDXUvTnXw EOS5BQS4J7f5MKdhTKEXuZQpfwwJDYsikVShaKbVJTmGbDXUvTnXw
cleos set code eosio.unregd ./eosio.unregd.wasm -p eosio.unregd
cleos set abi eosio.unregd ./eosio.unregd.abi -p eosio.unregd
cleos push action eosio.unregd setmaxeos '["1.5000 EOS"]' -p eosio.unregd

cleos set contract eosio ~/dev/eos/build/contracts/eosio.system -p eosio
cleos push action eosio setpriv '["eosio.unregd",1]' -p eosio
cleos transfer eosio eosio.unregd "500000.0000 EOS" "sum(unreg_EOS[i])" -p eosio

cleos system newaccount \
--buy-ram-kbytes 4 \
--stake-net "0.2000 EOS" \
--stake-cpu "0.2000 EOS" \
eosio eosio.regram \
EOS6qKoPuTnXK1bh3wHZ6jcuSnJT5T2Ruhkoou8fFKGwRrWqUtB8h \
EOS6qKoPuTnXK1bh3wHZ6jcuSnJT5T2Ruhkoou8fFKGwRrWqUtB8h
cleos transfer eosio eosio.regram "500000.0000 EOS" "para vos" -p eosio

cleos system newaccount \
--buy-ram-kbytes 8 \
--stake-net "2.5000 EOS" \
--stake-cpu "2.5000 EOS" \
eosio thisisatesta \
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV \
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
EOS6dS7ERirP2UKoBwVt3C29DVZ1u9Jj1CH9EAVqhzUvgmykncEcY \
EOS6dS7ERirP2UKoBwVt3C29DVZ1u9Jj1CH9EAVqhzUvgmykncEcY

#Add eosio.unregd@eosio.code to eosio.unreg@active
tmp=$(mktemp)
cat > $tmp <<EOF
{
"expiration": "$(date -d '+1 hour' -u +%Y-%m-%dT%H:%M:%S)",
"ref_block_num": 0,
"ref_block_prefix": 0,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [
{
"account": "eosio",
"name": "updateauth",
"authorization": [
{
"actor": "eosio.unregd",
"permission": "active"
}
],
"data": "9098ba5303ea305500000000a8ed32320000000080ab26a70100000001000226686e87e1a5752cf8cb85db0477eb4ecaee897044801383c24063e1b442be840100019098ba5303ea305500804a1401ea3055010000"
}
],
"transaction_extensions": [],
"signatures": [],
"context_free_data": []
}
EOF
cleos sign -p -k 5KFDkQMpWu9chAEfgQNiEDwRdJePEVJiK92jx6vvUrQA8qFBXUd $tmp 2>&1 > /dev/null

#Set eosio.regram@[active,owner] to eosio.unregd@eosio.code
cat > $tmp <<EOF
{
"expiration": "$(date -d '+1 hour' -u +%Y-%m-%dT%H:%M:%S)",
"ref_block_num": 0,
"ref_block_prefix": 0,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [
{
"account": "eosio",
"name": "updateauth",
"authorization": [
{
"actor": "eosio.regram",
"permission": "active"
}
],
"data": "20cd65ea02ea305500000000a8ed32320000000080ab26a70100000000019098ba5303ea305500804a1401ea3055010000"
},
{
"account": "eosio",
"name": "updateauth",
"authorization": [
{
"actor": "eosio.regram",
"permission": "owner"
}
],
"data": "20cd65ea02ea30550000000080ab26a700000000000000000100000000019098ba5303ea305500804a1401ea3055010000"
}
],
"transaction_extensions": [],
"signatures": [],
"context_free_data": []
}
EOF
cleos sign -p -k 5KB513vWai23JYUVB6U8e6oN3z1jApaDDXhp33NuA3urCxgZGMR $tmp 2>&1 > /dev/null
129 changes: 73 additions & 56 deletions eosio.unregd/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,95 +18,112 @@ ACCOUNT=$(openssl rand -hex 32 | base32 | tr '[:upper:]' '[:lower:]' | head -c12
ADDY=$(python get_eth_address.py $PRIV)
AMOUNT=$(python -c 'import random; print "%.4f" % (random.random()*1000)')

echo "########################################################################"
echo "# Simulating claim of $GREEN$AMOUNT$NC for account $GREEN$ACCOUNT$NC"
echo "# using private-key: $RED$PRIV$NC "
echo "########################################################################"

MAXEOS=$(cleos get table eosio.unregd eosio.unregd settings | jq -r '.rows[0].max_eos_for_8k_of_ram')
echo "* Max amount of EOS for 8kb of RAM $RED$MAXEOS$NC"

# Add test unregd data for this address
echo "* Adding $GREEN$ACCOUNT$NC to eosio.unregd db with $GREEN$AMOUNT EOS$NC"
cleos push action eosio.unregd add '["'$ADDY'","'$AMOUNT' EOS"]' -p eosio.unregd > /dev/null 2>&1
# cleos transfer eosio eosio.unregd "$AMOUNT EOS" -p eosio > /dev/null 2>&1

# Print eosio.unregd balance
SUPPLY_BEFORE=$(cleos get currency stats eosio.token eos | jq -r '.EOS.supply')
echo "* EOS supply before claim $BLUE$SUPPLY_BEFORE$NC"

# Add test unregd data for this address
echo "* Adding $ACCOUNT to eosio.unregd db with $GREEN$AMOUNT EOS$NC"
cleos push action eosio.unregd add '["'$ADDY'","'$AMOUNT' EOS"]' -p eosio.unregd > /dev/null 2>&1
cleos transfer eosio eosio.unregd "$AMOUNT EOS" -p eosio > /dev/null 2>&1
EOSIOREGRAM_BEFORE=$(cleos get currency balance eosio.token eosio.regram EOS)
echo "* $BLUE""eosio.regram$NC balance before claim $BLUE$EOSIOREGRAM_BEFORE$NC"
EOSIOUNREGD_BEFORE=$(cleos get currency balance eosio.token eosio.unregd EOS)
echo "* $BLUE""eosio.unregd$NC balance before claim $BLUE$EOSIOUNREGD_BEFORE$NC"

TMP=$(mktemp)
cleos create key > $TMP
EOSPRIV=$(head -n1 $TMP | awk '{n=split($0,a," "); print a[n];}')
EOSPUB=$(tail -n1 $TMP | awk '{n=split($0,a," "); print a[n];}')

echo "* Using $EOSPUB for account $ACCOUNT"
echo "* Using $RED$EOSPUB$NC for account $GREEN$ACCOUNT$NC"

# Claim
while true; do
RES=$(python claim.py $PRIV_HEX $ACCOUNT $EOSPUB)
if [ $? -eq 0 ]; then
break
fi
echo "Error: press ENTER to try again"
read dummy
#echo "Error: press ENTER to try again"
#read dummy
done
#echo $RES
USAGE=$(cat $RES | jq '.processed.receipt.cpu_usage_us')
echo "* $ACCOUNT claimed $GREEN$AMOUNT EOS$NC in $YELLOW$USAGE$NC [us]"
echo "* $GREEN$ACCOUNT$NC claimed $GREEN$AMOUNT EOS$NC in $YELLOW$USAGE$NC [us]"

TOTAL_ISSUED=$(cat $RES | jq -r '.processed.action_traces[].inline_traces[0].act.data.quantity')
echo "* Total new EOS issued $RED$TOTAL_ISSUED$NC"
# TOTAL_ISSUED=$(cat $RES | jq -r '.processed.action_traces[].inline_traces[0].act.data.quantity')
# echo "* Total new EOS issued $RED$TOTAL_ISSUED$NC"

RAMCOST=$(cat $RES | jq -r '.processed.action_traces[].inline_traces[2].act.data.quant')
RAMCOST=$(cat $RES | jq -r '.processed.action_traces[].inline_traces[1].act.data.quant')
echo "* EOS payed for 8192 [bytes] of RAM $RED$RAMCOST$NC"

# Transfer to test privkey
echo -n "* Using private key to make a transfer on EOS .... "
cleos wallet import $EOSPRIV > /dev/null 2>&1
cleos transfer $ACCOUNT thisisatesta "0.0001 EOS" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$GREEN""OK$NC"
else
echo "$RED""ERROR$NC"
fi

# Print eosio balance
SUPPLY_AFTER=$(cleos get currency stats eosio.token eos | jq -r '.EOS.supply')
echo "* EOS supply after claim $BLUE$SUPPLY_AFTER$NC"
EOSIOREGRAM_AFTER=$(cleos get currency balance eosio.token eosio.regram EOS)
echo "* $BLUE""eosio.regram$NC balance after claim $BLUE$EOSIOREGRAM_AFTER$NC"
EOSIOUNREGD_AFTER=$(cleos get currency balance eosio.token eosio.unregd EOS)
echo "* $BLUE""eosio.unregd$NC balance after claim $BLUE$EOSIOUNREGD_AFTER$NC"

# Print account RAM
RAMQUOTA=$(cleos get account -j $ACCOUNT | jq -r '.ram_quota')
echo "* $ACCOUNT ram quota $YELLOW$RAMQUOTA$NC [bytes]"

#!/bin/bash
python -c '
import sys
# Transfer to test privkey
echo -n "* Using private key to make a transfer on EOS .... "
cleos wallet import --private-key $EOSPRIV > /dev/null 2>&1
cleos transfer $ACCOUNT thisisatesta "0.0001 EOS" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$GREEN""OK$NC"
else
echo "$RED""ERROR$NC"
fi

def red(s):
sys.stdout.write("\b\x1b[0;31m" + s + "\x1b[0m\n")
sys.stdout.flush()
def green(s):
sys.stdout.write("\b\x1b[0;32m" + s + "\x1b[0m\n")
sys.stdout.flush()
def asset2int(amountstr):
try:
parts = amountstr.split()
if len(parts) != 2 or not parts[1].isupper() or len(parts[1]) > 7: raise
inx = parts[0].rindex(".")
if parts[0].index(".") != inx: raise
if len(parts[0]) - inx - 1 != 4: raise
v = parts[0].replace(".","")
return int(v)
except:
raise InvalidAsset("Invalid string amount '%s'" % amountstr)
def int2asset(amountint, symbol="EOS"):
s = "%d" % amountint
if( len(s) < 5 ):
s = (5-len(s))*"0" + s
return s[:-4] +"."+ s[-4:] + " " + symbol
diff=int2asset(asset2int(sys.argv[1])-asset2int(sys.argv[2]))
sys.stdout.write("* EOS supply difference : "); red(diff)
diff2=int2asset(asset2int(sys.argv[1])-asset2int(sys.argv[2])-asset2int(sys.argv[3]))
sys.stdout.write("* EOS supply difference without RAM costs : "); green(diff2)
' "$SUPPLY_AFTER" "$SUPPLY_BEFORE" "$RAMCOST"
# #!/bin/bash
# python -c '
# import sys

# def red(s):
# sys.stdout.write("\b\x1b[0;31m" + s + "\x1b[0m\n")
# sys.stdout.flush()

# def green(s):
# sys.stdout.write("\b\x1b[0;32m" + s + "\x1b[0m\n")
# sys.stdout.flush()

# def asset2int(amountstr):
# try:
# parts = amountstr.split()
# if len(parts) != 2 or not parts[1].isupper() or len(parts[1]) > 7: raise
# inx = parts[0].rindex(".")
# if parts[0].index(".") != inx: raise
# if len(parts[0]) - inx - 1 != 4: raise
# v = parts[0].replace(".","")
# return int(v)
# except:
# raise Exception("Invalid string amount '%s'" % amountstr)

# def int2asset(amountint, symbol="EOS"):
# s = "%d" % amountint
# if( len(s) < 5 ):
# s = (5-len(s))*"0" + s
# return s[:-4] +"."+ s[-4:] + " " + symbol

# diff=int2asset(asset2int(sys.argv[1])-asset2int(sys.argv[2]))
# sys.stdout.write("* EOS supply difference : "); red(diff)

# diff2=int2asset(asset2int(sys.argv[1])-asset2int(sys.argv[2])-asset2int(sys.argv[3]))
# sys.stdout.write("* EOS supply difference without RAM costs : "); green(diff2)
# ' "$SUPPLY_AFTER" "$SUPPLY_BEFORE" "$RAMCOST"

#echo $GREEN
echo
Expand Down

0 comments on commit b1ec32e

Please # to comment.