Skip to content

Commit

Permalink
travis
Browse files Browse the repository at this point in the history
  • Loading branch information
lk2684753 committed Jun 10, 2019
1 parent 1e487a0 commit 17b3fa1
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
- DIGITAL_IDENTITY_DIR=DigitalIdentityCert
- DEPOSIT_DIR=deposit
- GAS_TOKEN_DIR=gasToken
- MEDIATOR_VOTE_DIR=meidatorvote
- LOG_NAME=log.html
- REPORT_NAME=report.html
########## control testcase ##############
Expand All @@ -25,6 +26,7 @@ env:
- IS_RUN_DIGITAL=true
- IS_RUN_VOTE=true
- IS_RUN_GASTOKEN=true
- IS_RUN_MEDIATOR_VOTE=true
- GO111MODULE=on
- IS_UPLOAD = FALSE
# - 'SFTP_KEY=[base64-encoded-rsa-key]'
Expand Down Expand Up @@ -108,6 +110,14 @@ matrix:
sleep 15;
python -m robot.run -d ${BDD_LOG_PATH}/${GAS_TOKEN_DIR} ./testcases;
fi

- if [ $IS_RUN_MEDIATOR_VOTE == 'true' ]; then
cd ../mediator-vote;
chmod +x ./init.sh;
./init.sh;
sleep 15;
python -m robot.run -d ${BDD_LOG_PATH}/${MEDIATOR_VOTE_DIR} .;
fi

after_script:
- killall gptn
Expand Down
36 changes: 36 additions & 0 deletions bdd/mediator-vote/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#pkill gptn
#tskill gptn
#cd ../../cmd/gptn && go build
cd ../../
#rm -rf ./bdd/GasToken/node/*
#cp ./cmd/gptn/gptn ./bdd/GasToken/node
cd ./bdd/GasToken/node
chmod +x gptn

# new genesis
./gptn newgenesis "" fasle << EOF
y
1
1
EOF

# edit genesis json
gasToken="WWW"
jsonFile="ptn-genesis.json"
if [ -e "$jsonFile" ]; then
#file already exist, modify
sed -i "s/\"gasToken\": \"PTN\"/\"gasToken\": \"$gasToken\"/g" $jsonFile
else
#file not found, new file
echo "no $jsonFile"
exit -1
fi

# gptn init
./gptn init << EOF
1
EOF

# start gptn
nohup ./gptn &
81 changes: 81 additions & 0 deletions bdd/mediator-vote/pubFuncs.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
*** Settings ***
Resource pubVariables.robot

*** Keywords ***
newAccount
${params}= Create List 1
${respJson}= sendRpcPost personal_newAccount ${params} newAccount
Dictionary Should Contain Key ${respJson} result
[Return] ${respJson["result"]}

transferPTN
[Arguments] ${to}
${params}= Create List ${tokenHolder} ${to} ${amount} ${fee} ${null}
... ${pwd}
${respJson}= sendRpcPost ${transerferPTNMethod} ${params} transferPTN
Dictionary Should Contain Key ${respJson} result

transferPTN2
[Arguments] ${to}
${params}= Create List ${tokenHolder} ${to} ${amount2} ${fee} ${null}
... ${pwd}
${respJson}= sendRpcPost ${transerferPTNMethod} ${params} transferPTN
Dictionary Should Contain Key ${respJson} result

transferPTN3
[Arguments] ${to}
${params}= Create List ${tokenHolder} ${to} ${amount3} ${fee} ${null}
... ${pwd}
${respJson}= sendRpcPost ${transerferPTNMethod} ${params} transferPTN
Dictionary Should Contain Key ${respJson} result

transferPTN4
[Arguments] ${to}
${params}= Create List ${tokenHolder} ${to} ${amount4} ${fee} ${null}
... ${pwd}
${respJson}= sendRpcPost ${transerferPTNMethod} ${params} transferPTN
Dictionary Should Contain Key ${respJson} result

transferPTN5
[Arguments] ${to}
${params}= Create List ${tokenHolder} ${to} ${amount5} ${fee} ${null}
... ${pwd}
${respJson}= sendRpcPost ${transerferPTNMethod} ${params} transferPTN
Dictionary Should Contain Key ${respJson} result

getBalance
[Arguments] ${addr}
${params}= Create List ${addr}
${respJson}= sendRpcPost ${getBalanceMethod} ${params} getBalance
Dictionary Should Contain Key ${respJson} result
Dictionary Should Contain Key ${respJson["result"]} PTN
[Return] ${respJson["result"]["PTN"]}

unlockAccount
[Arguments] ${addr}
${params}= Create List ${addr} ${pwd} ${600000000}
${respJson}= sendRpcPost ${unlockAccountMethod} ${params} unlockAccount
[Return] ${respJson}

sendRpcPost
[Arguments] ${method} ${params} ${alias}
${header}= Create Dictionary Content-Type application/json
${data} Create Dictionary jsonrpc=2.0 method=${method} params=${params} id=1
Create Session ${alias} http://127.0.0.1:8545
${resp} Post Request ${alias} http://127.0.0.1:8545 data=${data} headers=${header}
${respJson} To Json ${resp.content}
[Return] ${respJson}

queryTokenHolder
${args}= Create List
${params}= Create List
${respJson}= sendRpcPost ${personalListAccountsMethod} ${params} queryTokenHolder
Dictionary Should Contain Key ${respJson} result
${accounts}= Get From Dictionary ${respJson} result
${firstAddr}= Get From List ${accounts} 0
Set Global Variable ${tokenHolder} ${firstAddr}
log ${tokenHolder}

wait for transaction being packaged
Log wait for transaction being packaged
Sleep 10
45 changes: 45 additions & 0 deletions bdd/mediator-vote/pubVariables.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
*** Settings ***
Library RequestsLibrary

*** Variables ***
${host} http://localhost:8545/
# methods
${transerferPTNMethod} wallet_transferPtn
${getBalanceMethod} wallet_getBalance
${unlockAccountMethod} personal_unlockAccount
${checkMediatorList} mediator_listAll
${viewMediatorActives} mediator_listActives
${voteMediator} mediator_vote
${mediatorVoteResults} mediator_listVoteResults
${personalListAccountsMethod} personal_listAccounts
${IsActiveMediator} mediator_isActive
# common variables
${userAccount} ${null}
${userAccount2} ${null}
${userAccount3} ${null}
${userAccount4} ${null}
${userAccount5} ${null}
${tokenHolder} ${null}
${mediatorHolder1} ${null}
${mediatorHolder2} ${null}
${mediatorHolder3} ${null}
${mediatorHolder4} ${null}
${mediatorHolder5} ${null}
${mediatorActives1} ${null}
${mediatorActives2} ${null}
${mediatorActives3} ${null}
${mediator1Result} ${null}
${mediator2Result} ${null}
${mediator3Result} ${null}
${mediator4Result} ${null}
${mediator5Result} ${null}
${activeAccount1} ${null}
${activeAccount2} ${null}
${amount} 10000
${amount2} 20000
${amount3} 30000
${amount4} 40000
${amount5} 50000
${fee} 1
${pwd} 1
${duration} 600000000
55 changes: 55 additions & 0 deletions bdd/mediator-vote/setups.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
*** Settings ***
Resource pubVariables.robot
Resource pubFuncs.robot
Library Collections

*** Keywords ***
beforeVote
queryTokenHolder
newAccounts
transferPTNToUser

newAccounts
# create a user for the poll
${user1}= newAccount
Set Global Variable ${userAccount} ${user1}
Sleep 1
${user2}= newAccount
Set Global Variable ${userAccount2} ${user2}
Sleep 1
${user3}= newAccount
Set Global Variable ${userAccount3} ${user3}
Sleep 1
${user4}= newAccount
Set Global Variable ${userAccount4} ${user4}
Sleep 1
${user5}= newAccount
Set Global Variable ${userAccount5} ${user5}

transferPTNToUser
# transfer PTN to user for the poll
transferPTN ${userAccount}
Log wait for tx being packaged into unit
Sleep 5 # should sleep, because transaction has not been packaged into unit
${balance}= getBalance ${userAccount}
Should Be Equal ${balance} ${amount}
transferPTN2 ${userAccount2}
Log wait for tx being packaged into unit
Sleep 5 # should sleep, because transaction has not been packaged into unit
${balance2}= getBalance ${userAccount2}
Should Be Equal ${balance2} ${amount2}
transferPTN3 ${userAccount3}
Log wait for tx being packaged into unit
Sleep 5 # should sleep, because transaction has not been packaged into unit
${balance3}= getBalance ${userAccount3}
Should Be Equal ${balance3} ${amount3}
transferPTN4 ${userAccount4}
Log wait for tx being packaged into unit
Sleep 5 # should sleep, because transaction has not been packaged into unit
${balance4}= getBalance ${userAccount4}
Should Be Equal ${balance4} ${amount4}
transferPTN5 ${userAccount5}
Log wait for tx being packaged into unit
Sleep 5 # should sleep, because transaction has not been packaged into unit
${balance5}= getBalance ${userAccount5}
Should Be Equal ${balance5} ${amount5}
75 changes: 75 additions & 0 deletions bdd/mediator-vote/step-Mediator-change/step1-voteMediator.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
*** Settings ***
Test Setup beforeVote
Library Collections
Resource ../pubVariables.robot
Resource ../pubFuncs.robot
Resource ../setups.robot

*** Test Cases ***
mediatorvote
Given user unlock its account succeed
When check mediator list
and wait for transaction being packaged
and check mediator list
and check mediator actives list
Then vote mediator account

*** Keywords ***
user unlock its account succeed
Log " user unlock its account succeed"
${respJson}= unlockAccount ${userAccount}
${respJson2}= unlockAccount ${userAccount2}
${respJson3}= unlockAccount ${userAccount3}
${respJson4}= unlockAccount ${userAccount4}
${respJson5}= unlockAccount ${userAccount5}
log ${respJson}
Dictionary Should Contain Key ${respJson} result
Should Be Equal ${respJson["result"]} ${true}

check mediator list
Log "check mediator list succeed"
${args}= Create List
${params}= Create List
${resp}= sendRpcPost ${checkMediatorList} ${params} check mediator list
${mediatorAddrs}= Get From Dictionary ${resp} result
${firstAddr}= Get From List ${mediatorAddrs} 0
${secondAddr}= Get From List ${mediatorAddrs} 1
${thirdAddr}= Get From List ${mediatorAddrs} 2
${fourthAddr}= Get From List ${mediatorAddrs} 3
${fifthAddr}= Get From List ${mediatorAddrs} 4
Set Global Variable ${mediatorHolder1} ${firstAddr}
Set Global Variable ${mediatorHolder2} ${secondAddr}
Set Global Variable ${mediatorHolder3} ${thirdAddr}
Set Global Variable ${mediatorHolder4} ${fourthAddr}
Set Global Variable ${mediatorHolder5} ${fifthAddr}

check mediator actives list
Log "check mediator list succeed"
${args}= Create List
${params}= Create List
${resp}= sendRpcPost ${viewMediatorActives} ${params} view mediator actives
${mediatorAddrs}= Get From Dictionary ${resp} result
${firstAddr}= Get From List ${mediatorAddrs} 0
${secondAddr}= Get From List ${mediatorAddrs} 1
${thirdAddr}= Get From List ${mediatorAddrs} 2
Set Global Variable ${mediatorActives1} ${firstAddr}
Set Global Variable ${mediatorActives2} ${secondAddr}
Set Global Variable ${mediatorActives3} ${thirdAddr}

vote mediator account
${args1} run keyword if '${mediatorHolder1}'!='${mediatorActives1}'and'${mediatorHolder1}'!='${mediatorActives2}'and'${mediatorHolder1}'!='${mediatorActives3}' Create List ${mediatorHolder1}
${params1}= Create List ${userAccount} ${args1}
${resp}= sendRpcPost ${voteMediator} ${params1} vote mediator
${args2} run keyword if '${mediatorHolder2}'!='${mediatorActives1}'and'${mediatorHolder2}'!='${mediatorActives2}'and'${mediatorHolder2}'!='${mediatorActives3}' Create List ${mediatorHolder2}
${params2}= Create List ${userAccount2} ${args2}
${resp}= sendRpcPost ${voteMediator} ${params2} vote mediator
${args3} run keyword if '${mediatorHolder3}'!='${mediatorActives1}'and'${mediatorHolder3}'!='${mediatorActives2}'and'${mediatorHolder3}'!='${mediatorActives3}' Create List ${mediatorHolder3}
${params3}= Create List ${userAccount3} ${args3}
${resp}= sendRpcPost ${voteMediator} ${params3} vote mediator
${args4} run keyword if '${mediatorHolder4}'!='${mediatorActives1}'and'${mediatorHolder4}'!='${mediatorActives2}'and'${mediatorHolder4}'!='${mediatorActives3}' Create List ${mediatorHolder4}
${params4}= Create List ${userAccount4} ${args4}
${resp}= sendRpcPost ${voteMediator} ${params4} vote mediator
${args5} run keyword if '${mediatorHolder5}'!='${mediatorActives1}'and'${mediatorHolder5}'!='${mediatorActives2}'and'${mediatorHolder5}'!='${mediatorActives3}' Create List ${mediatorHolder5}
${params5}= Create List ${userAccount5} ${args5}
${resp}= sendRpcPost ${voteMediator} ${params5} vote mediator
log ${resp}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
*** Settings ***
Library Collections
Resource ../pubVariables.robot
Resource ../pubFuncs.robot
Resource ../setups.robot

*** Test Cases ***
mediatorvote
Given view vote results
When wait for the change of mediator
and choose the winner of mediator
Then determine if the change mediator

*** Keywords ***
view vote results
Log wait for transaction being packaged
Sleep 5
${args}= Create List
${params}= Create List
${resp}= sendRpcPost ${mediatorVoteResults} ${params} view mediator results
${resultAddrs}= Get From Dictionary ${resp} result
Dictionary Should Contain Key ${resp} result
${voteResult1} set variable ${resultAddrs['${mediatorHolder1}']}
${voteResult2} set variable ${resultAddrs['${mediatorHolder2}']}
${voteResult3} set variable ${resultAddrs['${mediatorHolder3}']}
${voteResult4} set variable ${resultAddrs['${mediatorHolder4}']}
${voteResult5} set variable ${resultAddrs['${mediatorHolder5}']}
Set Global Variable ${mediator1Result} ${voteResult1}
Set Global Variable ${mediator2Result} ${voteResult2}
Set Global Variable ${mediator3Result} ${voteResult3}
Set Global Variable ${mediator4Result} ${voteResult4}
Set Global Variable ${mediator5Result} ${voteResult5}

wait for the change of mediator
Log wait for 100s
Sleep 200

choose the winner of mediator
#票数高的应该成为活跃的mediator
${isActive}= Create List
run keyword if ${mediator1Result}>0 Append To List ${isActive} ${mediatorHolder1}
run keyword if ${mediator2Result}>0 Append To List ${isActive} ${mediatorHolder2}
run keyword if ${mediator3Result}>0 Append To List ${isActive} ${mediatorHolder3}
run keyword if ${mediator4Result}>0 Append To List ${isActive} ${mediatorHolder4}
run keyword if ${mediator5Result}>0 Append To List ${isActive} ${mediatorHolder5}
${firstAddr}= Get From List ${isActive} 0
${secondAddr}= Get From List ${isActive} 1
Set Global Variable ${activeAccount1} ${firstAddr}
Set Global Variable ${activeAccount2} ${secondAddr}
log ${activeAccount1} INFO
log ${activeAccount2} INFO

determine if the change mediator
${params}= Create List ${activeAccount1}
${respJson}= sendRpcPost ${IsActiveMediator} ${params} JudgingResults
${res} set variable ${respJson["result"]}
${params1}= Create List ${activeAccount1}
${respJson1}= sendRpcPost ${IsActiveMediator} ${params1} JudgingResults
${res1} set variable ${respJson["result"]}
Should Be Equal ${res} ${true}
Should Be Equal ${res1} ${true}
log ${res} INFO
Loading

0 comments on commit 17b3fa1

Please sign in to comment.