-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
bdd/mediator-vote/step-Mediator-change/step1-voteMediator.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
62 changes: 62 additions & 0 deletions
62
bdd/mediator-vote/step-Mediator-change/step2-viewMediatorInfo.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.