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
b84ff0b4
Commit
b84ff0b4
authored
Jun 05, 2019
by
linj
Committed by
vipwzw
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update js rpc test
parent
705a07e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
113 deletions
+4
-113
test-rpc.sh
plugin/dapp/js/cmd/build/test-rpc.sh
+4
-113
No files found.
plugin/dapp/js/cmd/build/test-rpc.sh
View file @
b84ff0b4
#!/usr/bin/env bash
# shellcheck disable=SC2128
source
../dapp-test-common.sh
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
()
{
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
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"
resp
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
signedTx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
# 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
"
# echo "req=$req"
local times
=
10
while
true
;
do
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
tx
=
$(
jq
-r
".result.tx.hash"
<<<
"
$ret
"
)
echo
"====query tx=
${
1
}
, return=
$ret
"
if
[
"
${
tx
}
"
!=
"
${
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
exec_ok
=
$(
jq
'(.result.receipt.tyName == "ExecOk")'
<<<
"
$ret
"
)
[
"
$exec_ok
"
==
true
]
echo_rst
"query tx=
$1
"
$?
break
fi
done
}
function
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
...
...
@@ -149,7 +40,7 @@ function configJSCreator() {
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
super_manager
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
super_manager
}
"
"
${
MAIN_HTTP
}
"
}
function
createJSContract
()
{
...
...
@@ -161,7 +52,7 @@ function createJSContract() {
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
beneficiary_key
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
beneficiary_key
}
"
"
${
MAIN_HTTP
}
"
}
function
callJS
()
{
...
...
@@ -174,7 +65,7 @@ function callJS() {
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
sign_raw_tx
"
$rawtx
"
"
${
beneficiary_key
}
"
chain33_SignRawTx
"
$rawtx
"
"
${
beneficiary_key
}
"
"
${
MAIN_HTTP
}
"
}
function
queryJS
()
{
...
...
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