Commit b626e711 authored by QM's avatar QM

fix autonomy unit test and rpc test

parent f1252ce0
...@@ -43,7 +43,12 @@ boardsAddr=( ...@@ -43,7 +43,12 @@ boardsAddr=(
"1HGPrjc6H7yBzFV5yCbibvnSUGUgdDNQi3" "1HGPrjc6H7yBzFV5yCbibvnSUGUgdDNQi3"
"19WGov4b7wLf4f8JHMRDnJsGVNMDzap38w" "19WGov4b7wLf4f8JHMRDnJsGVNMDzap38w"
"1HmRa1jAnzJ5SpJRrUWqUki6hx1u33Nbq4" "1HmRa1jAnzJ5SpJRrUWqUki6hx1u33Nbq4"
"168Sn1DXnLrZHTcAM9stD6t2P49fNuJfJ9"
"13KTf57aCkVVJYNJBXBBveiA5V811SrLcT"
"1JQwQWsShTHC4zxHzbUfYQK4kRBriUQdEe"
"1NHuKqoKe3hyv52PF8XBAyaTmJWAqA2Jbb"
) )
boardsPrKey=( boardsPrKey=(
"fa54751118c8159ade22c253f85945a4dd2030b1cf2502eaf785d0a4f5ad7e35" "fa54751118c8159ade22c253f85945a4dd2030b1cf2502eaf785d0a4f5ad7e35"
"da9371ea52f1fc9d72e75dbc9836774895cd0966fd53c83f5e2c92d878903693" "da9371ea52f1fc9d72e75dbc9836774895cd0966fd53c83f5e2c92d878903693"
...@@ -66,6 +71,10 @@ boardsPrKey=( ...@@ -66,6 +71,10 @@ boardsPrKey=(
"227df96a414e26e85c7d87a12296344e6a731ce73e424ba9845cb305ec963843" "227df96a414e26e85c7d87a12296344e6a731ce73e424ba9845cb305ec963843"
"64259075bf2e5a74334442f5048ceaf8427f6097e2dac99c0e463785c7768550" "64259075bf2e5a74334442f5048ceaf8427f6097e2dac99c0e463785c7768550"
"3b812d92b5c365d698255f55c3f0dca027c2f89f2409c51a6297bcf3343c11e6" "3b812d92b5c365d698255f55c3f0dca027c2f89f2409c51a6297bcf3343c11e6"
"0xcd284cd17456b73619fa609bb9e3105e8eff5d059c5e0b6eb1effbebd4d64144"
"0xe892212221b3b58211b90194365f4662764b6d5474ef2961ef77c909e31eeed3"
"0x9d19a2e9a440187010634f4f08ce36e2bc7b521581436a99f05568be94dc66ea"
"0x45d4ce009e25e6d5e00d8d3a50565944b2e3604aa473680a656b242d9acbff35"
) )
boards=' boards='
...@@ -116,8 +125,10 @@ handleBoards() { ...@@ -116,8 +125,10 @@ handleBoards() {
echo "${boardsPrKey[$i]}" echo "${boardsPrKey[$i]}"
lab="board_"${i} lab="board_"${i}
chain33_ImportPrivkey "${boardsPrKey[$i]}" "${boardsAddr[$i]}" "${lab}" "${ip}" chain33_ImportPrivkey "${boardsPrKey[$i]}" "${boardsAddr[$i]}" "${lab}" "${ip}"
chain33_applyCoins "${boardsAddr[$i]}" 100000000 "${ip}" chain33_applyCoins "${boardsAddr[$i]}" 5000000000 "${ip}"
chain33_SendToAddress "${boardsAddr[$i]}" "$EXECTOR_ADDR" 4000000000 "$HTTP"
done done
# 金额要转入合约中
} }
txQuery() { txQuery() {
...@@ -132,9 +143,9 @@ txQuery() { ...@@ -132,9 +143,9 @@ txQuery() {
proposalBoardTx() { proposalBoardTx() {
local start=$1 local start=$1
local end=$2 local end=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropBoard", "payload":{"boards": ['"${boards}"'],"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropBoard", "payload":{"boardUpdate": 3,"boards": ['"${boards}"'],"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}"
proposalBoardID=$RAW_TX_HASH proposalBoardID=$RAW_TX_HASH
echo "proposalBoardID = $proposalBoardID" echo "proposalBoardID = $proposalBoardID"
...@@ -144,9 +155,9 @@ proposalBoardTx() { ...@@ -144,9 +155,9 @@ proposalBoardTx() {
voteBoardTx() { voteBoardTx() {
local ID=$1 local ID=$1
local privk=$2 local privk=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropBoard", "payload":{"proposalID": "'"${ID}"'","approve": true}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropBoard", "payload":{"proposalID": "'"${ID}"'","voteOption":1}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -155,10 +166,11 @@ voteBoardTx() { ...@@ -155,10 +166,11 @@ voteBoardTx() {
revokeProposalTx() { revokeProposalTx() {
local ID=$1 local ID=$1
local funcName=$2 local funcName=$2
local key=$3
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"'"${funcName}"'", "payload":{"proposalID": "'"${ID}"'"}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"'"${funcName}"'", "payload":{"proposalID": "'"${ID}"'"}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${key}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
} }
...@@ -168,7 +180,7 @@ terminateProposalTx() { ...@@ -168,7 +180,7 @@ terminateProposalTx() {
local funcName=$2 local funcName=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"'"${funcName}"'", "payload":{"proposalID": "'"${ID}"'"}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"'"${funcName}"'", "payload":{"proposalID": "'"${ID}"'"}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -179,7 +191,7 @@ queryProposal() { ...@@ -179,7 +191,7 @@ queryProposal() {
local funcName=$2 local funcName=$2
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"'"${funcName}"'","payload":{"data":"'"${ID}"'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"'"${funcName}"'","payload":{"data":"'"${ID}"'"}}]}'
resok='(.error|not)' resok='(.error|not)'
chain33_Http "$req" ${HTTP} "$resok" "$FUNCNAME" chain33_Http "$req" "${HTTP}" "$resok" "$FUNCNAME"
} }
listProposal() { listProposal() {
...@@ -189,18 +201,19 @@ listProposal() { ...@@ -189,18 +201,19 @@ listProposal() {
local direct=0 local direct=0
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"'"${funcName}"'","payload":{"status":"'"${status}"'", "addr":"'"${addr}"'", "count":1, "direction":"'"${direct}"'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"'"${funcName}"'","payload":{"status":"'"${status}"'", "addr":"'"${addr}"'", "count":1, "direction":"'"${direct}"'"}}]}'
resok='(.error|not)' resok='(.error|not)'
chain33_Http "$req" ${HTTP} "$resok" "$FUNCNAME" chain33_Http "$req" "${HTTP}" "$resok" "$FUNCNAME ${funcName}"
} }
queryActivePropBoard() { queryActivePropBoard() {
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"GetActiveBoard","payload":{"data":"1"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"GetActiveBoard","payload":{"data":"1"}}]}'
resok='(.error|not)' resok='(.error|not)'
chain33_Http "$req" ${HTTP} "$resok" "$FUNCNAME" chain33_Http "$req" "${HTTP}" "$resok" "$FUNCNAME"
} }
testProposalBoard() { testProposalBoard() {
#proposal #proposal
chain33_LastBlockHeight ${HTTP} echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 20 + 720)) end=$((start + 20 + 720))
proposalBoardTx ${start} ${end} proposalBoardTx ${start} ${end}
...@@ -213,22 +226,23 @@ testProposalBoard() { ...@@ -213,22 +226,23 @@ testProposalBoard() {
queryActivePropBoard queryActivePropBoard
#test revoke #test revoke
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalBoardTx ${start} ${end} proposalBoardTx ${start} ${end}
revokeProposalTx "${proposalBoardID}" "RvkPropBoard" revokeProposalTx "${proposalBoardID}" "RvkPropBoard" "${propKey}"
queryProposal "${proposalBoardID}" "GetProposalBoard" queryProposal "${proposalBoardID}" "GetProposalBoard"
listProposal 2 "ListProposalBoard" listProposal 2 "ListProposalBoard"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
proposalRuleTx() { proposalRuleTx() {
local start=$1 local start=$1
local end=$2 local end=$2
local propAmount=$3 local propAmount=$3
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropRule", "payload":{"ruleCfg": {"proposalAmount" : '"${propAmount}"'},"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropRule", "payload":{"ruleCfg": {"proposalAmount" : '"${propAmount}"',"boardApproveRatio":50,"pubOpposeRatio":33,"largeProjectAmount":100000000000000,"publicPeriod":172800,"pubAttendRatio":60,"pubApproveRatio":60},"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}"
proposalRuleID=$RAW_TX_HASH proposalRuleID=$RAW_TX_HASH
echo "proposalRuleID = $proposalRuleID" echo "proposalRuleID = $proposalRuleID"
...@@ -238,9 +252,9 @@ proposalRuleTx() { ...@@ -238,9 +252,9 @@ proposalRuleTx() {
voteRuleTx() { voteRuleTx() {
local ID=$1 local ID=$1
local privk=$2 local privk=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropRule", "payload":{"proposalID": "'"${ID}"'","approve": true}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropRule", "payload":{"proposalID": "'"${ID}"'", "vote":1}}]}' # "approve": true,
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -249,12 +263,13 @@ voteRuleTx() { ...@@ -249,12 +263,13 @@ voteRuleTx() {
queryActivePropRule() { queryActivePropRule() {
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"GetActiveRule","payload":{"data":"1"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"GetActiveRule","payload":{"data":"1"}}]}'
resok='(.error|not)' resok='(.error|not)'
chain33_Http "$req" ${HTTP} "$resok" "$FUNCNAME" chain33_Http "$req" "${HTTP}" "$resok" "$FUNCNAME"
} }
testProposalRule() { testProposalRule() {
# proposal # proposal
chain33_LastBlockHeight ${HTTP} echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 20 + 720)) end=$((start + 20 + 720))
proposalRuleTx ${start} ${end} 2000000000 proposalRuleTx ${start} ${end} 2000000000
...@@ -267,13 +282,15 @@ testProposalRule() { ...@@ -267,13 +282,15 @@ testProposalRule() {
queryActivePropRule queryActivePropRule
#test revoke #test revoke
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalRuleTx ${start} ${end} 2000000000 proposalRuleTx ${start} ${end} 2000000000
revokeProposalTx "${proposalRuleID}" "RvkPropRule" revokeProposalTx "${proposalRuleID}" "RvkPropRule" "${propKey}"
queryProposal "${proposalRuleID}" "GetProposalRule" queryProposal "${proposalRuleID}" "GetProposalRule"
listProposal 2 "ListProposalRule" listProposal 2 "ListProposalRule"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
proposalProjectTx() { proposalProjectTx() {
...@@ -283,7 +300,7 @@ proposalProjectTx() { ...@@ -283,7 +300,7 @@ proposalProjectTx() {
local toAddr=$4 local toAddr=$4
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropProject", "payload":{"amount" : '"${amount}"', "toAddr" : "'"${toAddr}"'","startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropProject", "payload":{"amount" : '"${amount}"', "toAddr" : "'"${toAddr}"'","startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}"
proposalProjectID=$RAW_TX_HASH proposalProjectID=$RAW_TX_HASH
echo "proposalProjectID = $proposalProjectID" echo "proposalProjectID = $proposalProjectID"
...@@ -293,9 +310,9 @@ proposalProjectTx() { ...@@ -293,9 +310,9 @@ proposalProjectTx() {
voteProjectTx() { voteProjectTx() {
local ID=$1 local ID=$1
local privk=$2 local privk=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropProject", "payload":{"proposalID": "'"${ID}"'","approve": true}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropProject", "payload":{"proposalID": "'"${ID}"'","vote":1}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -303,7 +320,8 @@ voteProjectTx() { ...@@ -303,7 +320,8 @@ voteProjectTx() {
testProposalProject() { testProposalProject() {
# proposal # proposal
chain33_LastBlockHeight ${HTTP} echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 20 + 720)) end=$((start + 20 + 720))
proposalProjectTx ${start} ${end} 100000000 ${propAddr} proposalProjectTx ${start} ${end} 100000000 ${propAddr}
...@@ -316,13 +334,14 @@ testProposalProject() { ...@@ -316,13 +334,14 @@ testProposalProject() {
queryProposal "${proposalProjectID}" "GetProposalProject" queryProposal "${proposalProjectID}" "GetProposalProject"
listProposal 5 "ListProposalProject" listProposal 5 "ListProposalProject"
#test revoke #test revoke
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalProjectTx ${start} ${end} 100000000 ${propAddr} proposalProjectTx ${start} ${end} 100000000 ${propAddr}
revokeProposalTx "${proposalProjectID}" "RvkPropProject" revokeProposalTx "${proposalProjectID}" "RvkPropProject" "${propKey}"
queryProposal "${proposalProjectID}" "GetProposalProject" queryProposal "${proposalProjectID}" "GetProposalProject"
listProposal 2 "ListProposalProject" listProposal 2 "ListProposalProject"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
proposalChangeTx() { proposalChangeTx() {
...@@ -330,10 +349,11 @@ proposalChangeTx() { ...@@ -330,10 +349,11 @@ proposalChangeTx() {
local end=$2 local end=$2
local addr=$3 local addr=$3
local cancel=$4 local cancel=$4
local key=$5
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropChange", "payload":{"changes" : [{"cancel": '"${cancel}"', "addr":"'"${addr}"'"}],"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"PropChange", "payload":{"changes" : [{"cancel": '"${cancel}"', "addr":"'"${addr}"'"}],"startBlockHeight":'"${start}"',"endBlockHeight":'"${end}"'}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${propKey}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${key}" "${HTTP}"
proposalChangeID=$RAW_TX_HASH proposalChangeID=$RAW_TX_HASH
echo "proposalChangeID = $proposalChangeID" echo "proposalChangeID = $proposalChangeID"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -342,9 +362,9 @@ proposalChangeTx() { ...@@ -342,9 +362,9 @@ proposalChangeTx() {
voteChangeTx() { voteChangeTx() {
local ID=$1 local ID=$1
local privk=$2 local privk=$2
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropChange", "payload":{"proposalID": "'"${ID}"'","approve": true}}]}' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"VotePropChange", "payload":{"proposalID": "'"${ID}"'","vote":1}}]}'
echo "${req}" echo "${req}"
chain33_Http "$req" ${HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result" chain33_Http "$req" "${HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}" chain33_SignAndSendTx "${RETURN_RESP}" "${privk}" "${HTTP}"
echo "$RAW_TX_HASH" echo "$RAW_TX_HASH"
txQuery "$FUNCNAME" txQuery "$FUNCNAME"
...@@ -352,10 +372,11 @@ voteChangeTx() { ...@@ -352,10 +372,11 @@ voteChangeTx() {
testProposalChange() { testProposalChange() {
# proposal # proposal
chain33_LastBlockHeight ${HTTP} echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 20 + 720)) end=$((start + 20 + 720))
proposalChangeTx ${start} ${end} "${boardsAddr[20]}" true proposalChangeTx ${start} ${end} "${boardsAddr[21]}" true "${boardsPrKey[0]}"
chain33_BlockWait 100 "$HTTP" chain33_BlockWait 100 "$HTTP"
#vote #vote
for ((i = 0; i < 11; i++)); do for ((i = 0; i < 11; i++)); do
...@@ -366,36 +387,38 @@ testProposalChange() { ...@@ -366,36 +387,38 @@ testProposalChange() {
listProposal 4 "ListProposalChange" listProposal 4 "ListProposalChange"
#test revoke #test revoke
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalChangeTx ${start} ${end} "${boardsAddr[20]}" false proposalChangeTx ${start} ${end} "${boardsAddr[22]}" true "${boardsPrKey[1]}"
revokeProposalTx "${proposalChangeID}" "RvkPropChange" revokeProposalTx "${proposalChangeID}" "RvkPropChange" "${boardsPrKey[1]}"
queryProposal "${proposalChangeID}" "GetProposalChange" queryProposal "${proposalChangeID}" "GetProposalChange"
listProposal 2 "ListProposalChange" listProposal 2 "ListProposalChange"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
testProposalTerminate() { testProposalTerminate() {
#test terminate #test terminate
chain33_LastBlockHeight ${HTTP} echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalRuleTx ${start} ${end} 2000000000 proposalRuleTx ${start} ${end} 2000000000
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalBoardTx ${start} ${end} proposalBoardTx ${start} ${end}
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalProjectTx ${start} ${end} 100000000 ${propAddr} proposalProjectTx ${start} ${end} 100000000 ${propAddr}
chain33_LastBlockHeight ${HTTP} chain33_LastBlockHeight "${HTTP}"
start=$((LAST_BLOCK_HEIGHT + 100)) start=$((LAST_BLOCK_HEIGHT + 100))
end=$((start + 120 + 720)) end=$((start + 120 + 720))
proposalChangeTx ${start} ${end} "${boardsAddr[20]}" false proposalChangeTx ${start} ${end} "${boardsAddr[23]}" true "${boardsPrKey[2]}"
chain33_BlockWait 940 "$HTTP" chain33_BlockWait 940 "$HTTP"
...@@ -414,10 +437,12 @@ testProposalTerminate() { ...@@ -414,10 +437,12 @@ testProposalTerminate() {
terminateProposalTx "${proposalChangeID}" "TmintPropChange" terminateProposalTx "${proposalChangeID}" "TmintPropChange"
queryProposal "${proposalChangeID}" "GetProposalChange" queryProposal "${proposalChangeID}" "GetProposalChange"
listProposal 4 "ListProposalChange" listProposal 4 "ListProposalChange"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
function run_testcases() { function run_testcases() {
echo "run_testcases" echo "run_testcases"
testProposalRule testProposalRule
testProposalBoard testProposalBoard
testProposalProject testProposalProject
...@@ -430,14 +455,14 @@ init() { ...@@ -430,14 +455,14 @@ init() {
echo "ipara=$ispara" echo "ipara=$ispara"
if [ "$ispara" == true ]; then if [ "$ispara" == true ]; then
EXECTOR_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.autonomy"}]}' ${HTTP} | jq -r ".result") EXECTOR_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.autonomy"}]}' "${HTTP}" | jq -r ".result")
EXECTOR="user.p.para.autonomy" EXECTOR="user.p.para.autonomy"
TICKET_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.ticket"}]}' ${HTTP} | jq -r ".result") TICKET_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.ticket"}]}' "${HTTP}" | jq -r ".result")
TICKET_EXECTOR="user.p.para.ticket" TICKET_EXECTOR="user.p.para.ticket"
else else
EXECTOR_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"autonomy"}]}' ${HTTP} | jq -r ".result") EXECTOR_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"autonomy"}]}' "${HTTP}" | jq -r ".result")
EXECTOR="autonomy" EXECTOR="autonomy"
TICKET_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"ticket"}]}' ${HTTP} | jq -r ".result") TICKET_ADDR=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"ticket"}]}' "${HTTP}" | jq -r ".result")
TICKET_EXECTOR="ticket" TICKET_EXECTOR="ticket"
fi fi
echo "EXECTOR_ADDR=$EXECTOR_ADDR" echo "EXECTOR_ADDR=$EXECTOR_ADDR"
......
...@@ -237,16 +237,55 @@ func TestPropBoard(t *testing.T) { ...@@ -237,16 +237,55 @@ func TestPropBoard(t *testing.T) {
StartBlockHeight: env.blockHeight + 5, StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10, EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
}, },
{ // ErrNotFound
BoardUpdate: auty.BoardUpdate_DELBoard,
Boards: []string{"18e1nfiux7aVSfN2zYUZhbidMRokbBSPA6"},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
{ // ErrNotFound
BoardUpdate: auty.BoardUpdate_DELBoard,
Boards: []string{Addr17, "18e1nfiux7aVSfN2zYUZhbidMRokbBSPA6"},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
{ // ErrBoardNumber
BoardUpdate: auty.BoardUpdate_DELBoard,
Boards: []string{Addr16, Addr17},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
{ // ErrRepeatAddr
BoardUpdate: auty.BoardUpdate_DELBoard,
Boards: []string{Addr17, Addr17},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
{ // 正常
BoardUpdate: auty.BoardUpdate_DELBoard,
Boards: []string{Addr17},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
} }
result := []error{ result := []error{
auty.ErrRepeatAddr, auty.ErrRepeatAddr,
auty.ErrRepeatAddr, auty.ErrRepeatAddr,
auty.ErrBoardNumber, auty.ErrBoardNumber,
nil, nil,
auty.ErrRepeatAddr, auty.ErrRepeatAddr,
auty.ErrBoardNumber, auty.ErrBoardNumber,
nil, nil,
types.ErrNotFound,
types.ErrNotFound,
auty.ErrBoardNumber,
auty.ErrRepeatAddr,
nil,
} }
lenBoards := []int{0, 0, 0, 22, 0, 0, 21, 0, 0, 0, 0, 20}
InitBoard(stateDB) InitBoard(stateDB)
exec.SetStateDB(stateDB) exec.SetStateDB(stateDB)
...@@ -256,9 +295,14 @@ func TestPropBoard(t *testing.T) { ...@@ -256,9 +295,14 @@ func TestPropBoard(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
pbtx, err = signTx(pbtx, PrivKeyA) pbtx, err = signTx(pbtx, PrivKeyA)
assert.NoError(t, err) assert.NoError(t, err)
_, err = exec.Exec(pbtx, i) receipt, err := exec.Exec(pbtx, i)
assert.Equal(t, errors.Cause(err), result[i]) assert.Equal(t, errors.Cause(err), result[i])
if receipt != nil {
var stat auty.AutonomyProposalBoard
err := types.Decode(receipt.KV[1].Value, &stat)
assert.NoError(t, err)
assert.Equal(t, len(stat.Board.Boards), lenBoards[i])
}
} }
} }
......
...@@ -7,11 +7,11 @@ package executor ...@@ -7,11 +7,11 @@ package executor
import ( import (
"sort" "sort"
"github.com/pkg/errors"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
auty "github.com/33cn/plugin/plugin/dapp/autonomy/types" auty "github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/pkg/errors"
) )
func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) { func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) {
...@@ -368,6 +368,10 @@ func (a *action) replaceBoard(act *auty.ActiveBoard, change []*auty.Change) (*au ...@@ -368,6 +368,10 @@ func (a *action) replaceBoard(act *auty.ActiveBoard, change []*auty.Change) (*au
return nil, errors.Wrapf(types.ErrInvalidParam, "cancel=false not allow to addr=%s", change[0].Addr) return nil, errors.Wrapf(types.ErrInvalidParam, "cancel=false not allow to addr=%s", change[0].Addr)
} }
if err := address.CheckAddress(change[0].Addr); err != nil {
return nil, err
}
mpBd := make(map[string]struct{}) mpBd := make(map[string]struct{})
mpRbd := make(map[string]struct{}) mpRbd := make(map[string]struct{})
for _, b := range act.Boards { for _, b := range act.Boards {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package executor package executor
import ( import (
"github.com/33cn/chain33/util"
"testing" "testing"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
...@@ -593,6 +594,43 @@ func TestCheckChangeable(t *testing.T) { ...@@ -593,6 +594,43 @@ func TestCheckChangeable(t *testing.T) {
assert.Equal(t, err, auty.ErrChangeBoardAddr) assert.Equal(t, err, auty.ErrChangeBoardAddr)
} }
func TestReplaceBoard(t *testing.T) {
at := newTestAutonomy()
signer := util.HexToPrivkey(PrivKeyA)
tx := &types.Transaction{}
tx.Sign(types.SECP256K1, signer)
action := newAction(at, tx, 0)
act := &auty.ActiveBoard{
Boards: boards,
}
// 一个成员只允许替换一个新的
changes := []*auty.Change{
{Cancel: true, Addr: Addr18},
{Cancel: true, Addr: Addr19},
}
_, err := action.replaceBoard(act, changes)
assert.ErrorIs(t, err, types.ErrInvalidParam)
// 只允许替换,不允许恢复操作
changes = []*auty.Change{{Cancel: false, Addr: Addr18}}
_, err = action.replaceBoard(act, changes)
assert.ErrorIs(t, err, types.ErrInvalidParam)
// 替换一个不存在地址
changes = []*auty.Change{{Cancel: true, Addr: "0x1111111111"}}
_, err = action.replaceBoard(act, changes)
assert.NotNil(t, err)
// 正常替换一个地址
changes = []*auty.Change{{Cancel: true, Addr: Addr18}}
cur, err := action.replaceBoard(act, changes)
assert.NoError(t, err)
assert.Equal(t, cur.Boards[0], Addr18)
assert.Equal(t, cur.Revboards[0], AddrA)
}
func TestCopyAutonomyProposalChange(t *testing.T) { func TestCopyAutonomyProposalChange(t *testing.T) {
assert.Nil(t, copyAutonomyProposalChange(nil)) assert.Nil(t, copyAutonomyProposalChange(nil))
cur := &auty.AutonomyProposalChange{ cur := &auty.AutonomyProposalChange{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment