Skip to content

Commit

Permalink
Merge pull request #19 from EOS-BP-Developers/msig
Browse files Browse the repository at this point in the history
Add msig test script
  • Loading branch information
pete001 authored Jun 28, 2018
2 parents 2ec430e + 4e33f35 commit 3c0c46a
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ before_install:
- cp config.json.ci config.json

script:
- docker-compose exec keosd bash -c "apt-get update && apt-get install -y jq bc && cd /opt/app && ./start.sh"
- docker-compose exec keosd bash -c "apt-get update && apt-get install -y jq bc && cd /opt/app && ./start.sh ci"
1 change: 0 additions & 1 deletion log/tmp_std_err_2.log
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
04323
1 change: 1 addition & 0 deletions null/nodeos.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
31517
1 change: 1 addition & 0 deletions null/stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/vagrant/Code/EOS-Test-Cave/producing-nodes/start.sh: line 26: /usr/local/bin/nodeos: No such file or directory
File renamed without changes.
8 changes: 7 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ STARTTIME=$(/bin/date +%s.%N)

#########################################################################################################################
#########################################################################################################################

startCategoryTest "tests/01_wallet"
startCategoryTest "tests/02_contracts"
startCategoryTest "tests/03_account"
Expand All @@ -111,6 +110,13 @@ startCategoryTest "tests/05_transfers"
startCategoryTest "tests/06_proxy_and_vote"
startCategoryTest "tests/07_name_bids"
startCategoryTest "tests/08_permissions"

if [ "$1" != "ci" ]; then
startCategoryTest "tests/09_msig"
sleep 126;
startCategoryTest "tests/10_claimrewards"
fi

#########################################################################################################################
#########################################################################################################################

Expand Down
2 changes: 1 addition & 1 deletion tests/03_account/08_not_a_test_just_resign_eosio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ do
CMD=$($GLOBALPATH/bin/cleos.sh push action eosio updateauth '{"account": "'$account'", "permission": "active", "parent": "owner", "auth": { "threshold": 1, "keys": [], "waits": [], "accounts": [{ "weight": 1, "permission": {"actor": "'$controller'", "permission": "active"} }] } }' -p $account@active 2>$tpm_stderr)
done

echo "1: $TEST_NAME"
echo "1:$TEST_NAME"
3 changes: 1 addition & 2 deletions tests/05_transfers/01_distribute_tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ NAME="$( jq -r '.abp_account_name' "$config" )"
#----------------------

accounts=( testaccounta testaccountb testaccountc testaccountd testaccounte testaccountf testaccountg testaccounth testaccounti testaccountj testaccountk testaccountl testaccountm testaccountn testaccounto testaccountp testaccountq testaccountr testaccounts testaccountt testaccountu testaccountv );
for account in "${accounts[@]}"
do
for account in "${accounts[@]}"; do
CMD2=$( $GLOBALPATH/bin/cleos.sh get currency balance eosio.token $account | sed 's/[^0-9]*//g'>$tpm_stderr_2)
VAL_OLD=$(cat $tpm_stderr_2)
CMD=$( $GLOBALPATH/bin/cleos.sh transfer $NAME $account "150000.0000 EOS" "free tokens" -p $NAME 2>$tpm_stderr)
Expand Down
29 changes: 29 additions & 0 deletions tests/09_msig/01_create_msig_account.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
TEST_NAME="Create msig account for multisig test"

. ../runner.sh

accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );

#----------------------
PUB_KEY=$( cat $GLOBALPATH/log/wallet_name_testwallet_key.dat | cut -d' ' -f1)
for NAME in "${accounts[@]}"; do
CMD=$( $GLOBALPATH/bin/cleos.sh system newaccount eosio $NAME $PUB_KEY --stake-net "1000.0000 EOS" --stake-cpu "1000.0000 EOS" --buy-ram "1.0000 EOS" --transfer 2>$tpm_stderr )

ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1
fi

sleep 2

CMD=$( $GLOBALPATH/bin/cleos.sh transfer eosio $NAME "1000.0000 EOS" "msig test tokens" -p eosio 2>$tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi
done
echo "1:$TEST_NAME"
38 changes: 38 additions & 0 deletions tests/09_msig/02_import_msig_account_in_wallet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TEST_NAME="Import msig account private key in wallet"

. ../runner.sh

accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );

#----------------------
PUB_KEY=$( cat $GLOBALPATH/log/wallet_name_testwallet_key.dat | cut -d' ' -f1)
PRIV_KEY=$( cat $GLOBALPATH/log/wallet_name_testwallet_key.dat | cut -d' ' -f2)

for NAME in "${accounts[@]}"; do
# Check Wallet
CMD=$( $GLOBALPATH/bin/cleos.sh wallet create -n $NAME 2> $tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != "" ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1
else
WALLET_PASS=$(echo $CMD | awk -F\" '{ print $2 }')
echo $WALLET_PASS > "$GLOBALPATH/log/wallet_name_"$NAME"_password.dat"
fi

CMD=$( $GLOBALPATH/bin/cleos.sh wallet import -n $NAME $PRIV_KEY 2> $tpm_stderr )
ERR=$(cat $tpm_stderr)
CHK_KEY=$(echo $CMD | awk '{print $5}')
if [[ $ERR != "" ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1
elif [[ $CHK_KEY != $PUB_KEY ]]; then
failed "$ERR"
echo "$CHK_KEY / $PUB_KEY"
rm $tpm_stderr;
exit 1
fi
done
echo "1:$TEST_NAME"
33 changes: 33 additions & 0 deletions tests/09_msig/03_set_msig_perm_active.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
TEST_NAME="Set Multisig Active Permission"

. ../runner.sh


#----------------------
# Usage : cleos set account permission [OPTIONS] account permission authority [parent]

# generate json for active multisig
accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
msig_json="$GLOBALPATH/log/tmp_msig.json"
NAME=${accounts[0]}

echo '{"threshold":2,"keys":[],"accounts":[' > $msig_json
for ((x=1;x<=3;x++)); do
if [ $x -eq 3 ]; then
echo '{"permission":{"actor":"'${accounts[$x]}'","permission":"active"},"weight":1}' >> $msig_json
else
echo '{"permission":{"actor":"'${accounts[$x]}'","permission":"active"},"weight":1},' >> $msig_json
fi
done
echo '], "waits":[]}' >> $msig_json

CMD=$( $GLOBALPATH/bin/cleos.sh set account permission ${NAME} active "$(cat $msig_json)" owner -p ${NAME}@owner 2>${tpm_stderr})

ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi

echo "1:$TEST_NAME"
31 changes: 31 additions & 0 deletions tests/09_msig/04_set_msig_perm_owner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
TEST_NAME="Set Multisig Owner Permission"

. ../runner.sh

#----------------------
# Usage : cleos set account permission [OPTIONS] account permission authority [parent]

# generate json for owner multisig
accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
msig_json="$GLOBALPATH/log/tmp_msig.json"
NAME=${accounts[0]}

echo '{"threshold":2,"keys":[],"accounts":[' > $msig_json
for ((x=1;x<=3;x++)); do
if [ $x -eq 3 ]; then
echo '{"permission":{"actor":"'${accounts[$x]}'","permission":"owner"},"weight":1}' >> $msig_json
else
echo '{"permission":{"actor":"'${accounts[$x]}'","permission":"owner"},"weight":1},' >> $msig_json
fi
done
echo '], "waits":[]}' >> $msig_json

CMD=$( $GLOBALPATH/bin/cleos.sh set account permission ${NAME} owner "$(cat $msig_json)" -p ${NAME}@owner 2>${tpm_stderr})

ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi
echo "1:$TEST_NAME"
29 changes: 29 additions & 0 deletions tests/09_msig/05_transfer_msig_propose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
TEST_NAME="Simple Transfer Multi Signature Propose"

. ../runner.sh

# multisig propose [OPTIONS] proposal_name requested_permissions trx_permissions contract action data [proposer] [proposal_expiration]

accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
NAME=${accounts[0]}
msig_json="$GLOBALPATH/log/tmp_msig.json"
echo '[' > $msig_json
#----------------------
for((x=1;x<=3;x++)); do
CONFIRMER=${accounts[$x]}
if [ $x -eq 3 ]; then
echo ' {"actor":"'$CONFIRMER'","permission":"active"}]' >> $msig_json
else
echo ' {"actor":"'$CONFIRMER'","permission":"active"},' >> $msig_json
fi
done

CMD=$( $GLOBALPATH/bin/cleos.sh multisig propose testmultisig "$(cat $msig_json)" '[{"actor": "'$NAME'", "permission": "active"}]' eosio.token transfer '{"from":"'$NAME'", "to":"'$CONFIRMER'", "quantity":"25.0000 EOS", "memo":"transfer test with multi signature confirm"}' -p ${CONFIRMER}@active 2> ${tpm_stderr} )

ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi
echo "1:$TEST_NAME"
19 changes: 19 additions & 0 deletions tests/09_msig/06_propose_review.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TEST_NAME="Multisig Propose Review"

. ../runner.sh

# Usage: cleos multisig review [OPTIONS] proposer proposal_name
accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
NAME=${accounts[0]}
#----------------------
# get variable on end of accounts array
proposer=${accounts[${#accounts[@]}-1]}
sleep 1;
CMD=$( $GLOBALPATH/bin/cleos.sh multisig review ${proposer} $NAME 2> $tpm_stderr | jq -r .proposal_name )
ERR=$(cat $tpm_stderr)
if [[ $CMD != "$NAME" ]]; then
failed "$ERR"
rm $tpm_stderr
exit 1;
fi
echo "1:$TEST_NAME"
21 changes: 21 additions & 0 deletions tests/09_msig/07_msig_approve.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
TEST_NAME="Multisig Propose Approve sign"

. ../runner.sh

# Usage: cleos multisig approve [OPTIONS] proposer proposal_name permissions
#../../bin/cleos.sh multisig approve msigconfirm3 testmultisig '{"actor":"msigconfirm1", "permission":"active"}' -p msigconfirm1@active

accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
NAME=${accounts[0]}
proposer=${accounts[${#accounts[@]}-1]}

for((x=1;x<${#accounts[@]};x++)); do
CMD=$( $GLOBALPATH/bin/cleos.sh multisig approve $proposer $NAME '{"actor":"'${accounts[$x]}'","permission":"active"}' -p ${accounts[$x]}@active 2>$tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "${accounts[$x]} - $ERR"
rm $tpm_stderr;
exit 1;
fi
done
echo "1:$TEST_NAME"
20 changes: 20 additions & 0 deletions tests/09_msig/08_msig_unapprove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TEST_NAME="Multisig Propose unapprove sign"

. ../runner.sh

# Usage: cleos multisig approve [OPTIONS] proposer proposal_name permissions
#../../bin/cleos.sh multisig approve msigconfirm3 testmultisig '{"actor":"msigconfirm1", "permission":"active"}' -p msigconfirm1@active
sleep 1
accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
NAME=${accounts[0]}
proposer=${accounts[${#accounts[@]}-1]}
unapprove=${accounts[2]}

CMD=$( $GLOBALPATH/bin/cleos.sh multisig unapprove $proposer $NAME '{"actor":"'${unapprove}'","permission":"active"}' -p ${unapprove}@active 2> $tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi
echo "1:$TEST_NAME"
32 changes: 32 additions & 0 deletions tests/09_msig/09_execute_propose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TEST_NAME="Execute Approved Multisign Transation"

. ../runner.sh

# Usage: cleos multisig exec [OPTIONS] proposer proposal_name [executer]

accounts=( testmultisig msigconfirm1 msigconfirm2 msigconfirm3 );
NAME=${accounts[0]}
proposer=${accounts[${#accounts[@]}-1]}
executer=${accounts[1]}

CMD=$( $GLOBALPATH/bin/cleos.sh multisig exec $proposer $NAME -p ${executer}@active 2> $tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != *"executed transaction"* ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
fi
sleep 1;
CMD=$( $GLOBALPATH/bin/cleos.sh get currency balance eosio.token msigconfirm3 EOS | awk '{print $1}' | sed "s/\.//g" 2> $tpm_stderr )
ERR=$(cat $tpm_stderr)
if [[ $ERR != "" ]]; then
failed "$ERR"
rm $tpm_stderr;
exit 1;
elif [[ $CMD -ne 10250000 ]]; then
failed "msigconfirm3 account balance is not right. maybe multisig execute is not work."
rm $tpm_stderr;
exit 1;
fi

echo "1:$TEST_NAME"
3 changes: 1 addition & 2 deletions tests/10_claimrewards/01_claimrewards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ TEST_NAME="Claim rewards"
#----------------------

accounts=( testaccountb testaccountc testaccountd testaccounte testaccountf testaccountg testaccounth testaccounti testaccountj testaccountk testaccountl testaccountm testaccountn testaccounto testaccountp testaccountq testaccountr testaccounts testaccountt testaccountu testaccountv );
for account in "${accounts[@]}"
do
for account in "${accounts[@]}"; do
CMD2=$( $GLOBALPATH/bin/cleos.sh get currency balance eosio.token $account | sed 's/[^0-9]*//g'>$tpm_stderr_2)
VAL_OLD=$(cat $tpm_stderr_2)
CMD=$( $GLOBALPATH/bin/cleos.sh system claimrewards $account -p $account 2>$tpm_stderr)
Expand Down

0 comments on commit 3c0c46a

Please sign in to comment.