Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
74c34e0f
Commit
74c34e0f
authored
May 18, 2019
by
linj
Committed by
vipwzw
May 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unfreeze rpc test
parent
536064b3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
254 additions
and
0 deletions
+254
-0
test-rpc.sh
plugin/dapp/unfreeze/cmd/build/test-rpc.sh
+254
-0
No files found.
plugin/dapp/unfreeze/cmd/build/test-rpc.sh
0 → 100755
View file @
74c34e0f
#!/usr/bin/env bash
# shellcheck disable=SC2128
MAIN_HTTP
=
""
CASE_ERR
=
""
#color
RED
=
'\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
# base functions
# $2=0 means true, other false
function
echo_rst
()
{
if
[
"
$2
"
-eq
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"err"
fi
}
function
Chain33_SendToAddress
()
{
from
=
"
$1
"
to
=
"
$2
"
amount
=
$3
req
=
'{"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]}'
# echo "#request: $req"
resp
=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "#response: $resp"
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
'(.result.hash)'
<<<
"
$resp
"
)
echo
"hash=
$hash
"
# query_tx "$hash"
}
function
sign_raw_tx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
req
=
'{"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]}'
# echo "#request SignRawTx: $req"
signedTx
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
-r
".result"
)
# echo "signedTx=$signedTx"
if
[
"
$signedTx
"
!=
null
]
;
then
send_tx
"
$signedTx
"
else
echo
"signedTx null error"
fi
}
function
send_tx
()
{
signedTx
=
$1
req
=
'{"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]}'
# echo "#request sendTx: $req"
# curl -ksd "$req" ${MAIN_HTTP}
resp
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
# echo "tx hash: $txhash"
query_tx
"
$txhash
"
else
echo
"send tx error:
$err
"
fi
}
function
block_wait
()
{
req
=
'{"method":"Chain33.GetLastHeader","params":[{}]}'
cur_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
expect
=
$((
cur_height
+
${
1
}))
local
count
=
0
while
true
;
do
new_height
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
".result.height"
)
if
[
"
${
new_height
}
"
-ge
"
${
expect
}
"
]
;
then
break
fi
count
=
$((
count
+
1
))
sleep
1
done
echo
"wait new block
$count
s, cur height=
$expect
,old=
$cur_height
"
}
function
query_tx
()
{
block_wait 1
txhash
=
"
$1
"
local
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
# echo "req=$req"
local times
=
10
while
true
;
do
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
| jq
-r
".result.tx.hash"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
ret
}
"
!=
"
${
1
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$1
failed"
echo
"req=
$req
"
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
exit
1
fi
else
echo
"====query tx=
$1
success"
break
fi
done
}
function
query_unfreezeID
()
{
block_wait 1
local
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
# echo "req=$req"
local times
=
10
while
true
;
do
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
tx
=
$(
jq
-r
".result.tx.hash"
<<<
"
$ret
"
)
echo
"====query tx=
${
txhash
}
, return=
$ret
"
if
[
"
${
tx
}
"
!=
"
${
txhash
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$txhash
failed"
echo
"req=
$req
"
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
exit
1
fi
else
unfreeze_id
=
$(
jq
'(.result.receipt.logs[2].log.current.unfreezeID)'
<<<
"
$ret
"
)
#echo "${unfreeze_id}"
unfreeze_id2
=
${
unfreeze_id
#\
"mavl-unfreeze-}
uid=
${
unfreeze_id2
%\
"}
echo "
====query tx=
$1
success
"
break
fi
done
}
function init() {
ispara=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo "
ipara
=
$ispara
"
local relay_addr=""
exec_name="
unfreeze
"
if [ "
$ispara
" == true ]; then
exec_name="
user
.p.para.
"
${
exec_name
}
fi
exec_addr=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'
${
exec_name
}
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
echo "
exec_addr
=
${
exec_addr
}
"
beneficiary=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
beneficiary_key=0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
owner=14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
#unfreeze_exec_addr=15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H
Chain33_SendToAddress "
$owner
" "
$exec_addr
" 500000000
Chain33_SendToAddress "
$beneficiary
" "
$exec_addr
" 500000000
block_wait 1
}
function CreateRawUnfreezeCreate() {
req='{"
jsonrpc
": "
2
.0
", "
method
" : "
Chain33
.CreateTransaction
" , "
params
":[ {"
execer
" : "
unfreeze
", "
actionName
" :"
createUnfreeze
","
payload
":{"
startTime
":10000,"
assetExec
":"
coins
","
assetSymbol
":"
bty
","
totalCount
":400000000,"
beneficiary
":"
'$beneficiary'
","
means
":"
FixAmount
","
fixAmount
": {"
period
":10,"
amount
":100000000}}}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
$owner_key
"
query_unfreezeID
}
function CreateRawUnfreezeWithdraw() {
sleep 10
req='{"
method
":"
unfreeze
.CreateRawUnfreezeWithdraw
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
${
beneficiary_key
}
"
}
function CreateRawUnfreezeTerminate() {
req='{"
method
":"
unfreeze
.CreateRawUnfreezeTerminate
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx "
$rawtx
" "
$owner_key
"
block_wait 2
}
function GetUnfreeze() {
req='{"
method
":"
unfreeze
.GetUnfreeze
","
params
":[{"
data
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
}
function GetUnfreezeWithdraw() {
req='{"
method
":"
unfreeze
.GetUnfreezeWithdraw
","
params
":[{"
data
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
}
function run_testcases() {
CreateRawUnfreezeCreate
CreateRawUnfreezeWithdraw
GetUnfreeze
GetUnfreezeWithdraw
CreateRawUnfreezeTerminate
}
function rpc_test() {
set -x
MAIN_HTTP="
http
://
$1
:8801
"
echo "
main_ip
=
$MAIN_HTTP
"
init
run_testcases
if [ -n "
$CASE_ERR
" ]; then
echo "
=======unfreeze rpc test error ===========
"
exit 1
else
echo "
====== unfreeze rpc test pass ===========
"
fi
set +x
}
rpc_test "
$1
"
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment