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
4d5579cb
Commit
4d5579cb
authored
May 31, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add dapp-test-common
parent
22daf0c7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
221 deletions
+120
-221
dapp-test-common.sh
build/dapp-test-common.sh
+115
-0
dapp-test-rpc.sh
build/dapp-test-rpc.sh
+2
-0
test-rpc.sh
plugin/dapp/pokerbull/cmd/build/test-rpc.sh
+2
-112
test-rpc.sh
plugin/dapp/retrieve/cmd/build/test-rpc.sh
+1
-109
No files found.
build/dapp-test-common.sh
0 → 100644
View file @
4d5579cb
#!/usr/bin/env bash
echo_rst
()
{
if
[
"
$2
"
==
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"FAIL"
fi
}
function
block_wait
()
{
local
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
local
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
}
sendTx
()
{
echo
"send tx '
$1
' begin"
signedTx
=
$1
type
=
$2
local
req
=
'"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]'
resp
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
query_tx
"
$txhash
"
if
[
"
$type
"
==
"start"
]
;
then
GAME_ID
=
$txhash
fi
else
echo
"send tx error:
$err
"
fi
echo
"send tx '
$1
' end"
}
Chain33_SendToAddress
()
{
echo
"send '
$3
' from '
$1
' to '
$2
' begin"
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
req
=
'"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
-r
".result.hash"
<<<
"
$resp
"
)
query_tx
"
$hash
"
echo
"send '
$3
' from '
$1
' to '
$2
' end"
}
chain33_ImportPrivkey
()
{
local
pri
=
$2
local
acc
=
$3
local
req
=
'"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'
"
$pri
"
'", "label":"pokerbullimportkey1"}]'
echo
"#request:
$req
"
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo
"#response:
$resp
"
ok
=
$(
jq
'(.error|not) and (.result.label=="pokerbullimportkey1") and (.result.acc.addr == "'
"
$acc
"
'")'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
signrawtx
()
{
echo
"sign tx '
$1
' begin"
txHex
=
"
$1
"
priKey
=
"
$2
"
type
=
"
$3
"
local
req
=
'"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]'
signedTx
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result"
)
if
[
"
$signedTx
"
!=
null
]
;
then
sendTx
"
$signedTx
"
"
$3
"
else
echo
"signedTx null error"
fi
echo
"sign tx '
$1
' end"
}
\ No newline at end of file
build/dapp-test-rpc.sh
View file @
4d5579cb
...
...
@@ -2,11 +2,13 @@
# shellcheck disable=SC2128
RPC_TESTFILE
=
test-rpc.sh
DAPP_TEST_COMMON
=
dapp-test-common.sh
function
dapp_test_rpc
()
{
local
ip
=
$1
echo
"============ # dapp rpc test begin ============="
if
[
-d
dapptest
]
;
then
cp
$DAPP_TEST_COMMON
dapptest/
cd
dapptest
||
return
dir
=
$(
find
.
-maxdepth
1
-type
d
!
-name
dapptest
!
-name
.
|
sed
's/^\.\///'
)
for
app
in
$dir
;
do
...
...
plugin/dapp/pokerbull/cmd/build/test-rpc.sh
View file @
4d5579cb
...
...
@@ -12,56 +12,7 @@ RED='\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
echo_rst
()
{
if
[
"
$2
"
==
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"FAIL"
fi
}
function
block_wait
()
{
local
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
local
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
}
source
../dapp-test-common.sh
pokerbull_PlayRawTx
()
{
echo
"========== # pokerbull play tx begin =========="
...
...
@@ -145,68 +96,6 @@ pokerbull_QueryResult() {
echo
"========== # pokerbull query result end =========="
}
chain33_ImportPrivkey
()
{
local
pri
=
$2
local
acc
=
$3
local
req
=
'"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'
"
$pri
"
'", "label":"pokerbullimportkey1"}]'
echo
"#request:
$req
"
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo
"#response:
$resp
"
ok
=
$(
jq
'(.error|not) and (.result.label=="pokerbullimportkey1") and (.result.acc.addr == "'
"
$acc
"
'")'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
signrawtx
()
{
echo
"sign tx '
$1
' begin"
txHex
=
"
$1
"
priKey
=
"
$2
"
type
=
"
$3
"
local
req
=
'"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"120s"}]'
signedTx
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
}
| jq
-r
".result"
)
if
[
"
$signedTx
"
!=
null
]
;
then
sendTx
"
$signedTx
"
"
$3
"
else
echo
"signedTx null error"
fi
echo
"sign tx '
$1
' end"
}
sendTx
()
{
echo
"send tx '
$1
' begin"
signedTx
=
$1
type
=
$2
local
req
=
'"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'
"
$signedTx
"
'"}]'
resp
=
$(
curl
-ksd
"{
$req
}"
${
MAIN_HTTP
})
err
=
$(
jq
'(.error)'
<<<
"
$resp
"
)
txhash
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
if
[
"
$err
"
==
null
]
;
then
query_tx
"
$txhash
"
if
[
"
$type
"
==
"start"
]
;
then
GAME_ID
=
$txhash
fi
else
echo
"send tx error:
$err
"
fi
echo
"send tx '
$1
' end"
}
Chain33_SendToAddress
()
{
echo
"send '
$3
' from '
$1
' to '
$2
' begin"
local
from
=
"
$1
"
local
to
=
"
$2
"
local
amount
=
$3
local
req
=
'"method":"Chain33.SendToAddress", "params":[{"from":"'
"
$from
"
'","to":"'
"
$to
"
'", "amount":'
"
$amount
"
', "note":"test\n"}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
)
ok
=
$(
jq
'(.error|not) and (.result.hash|length==66)'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
hash
=
$(
jq
-r
".result.hash"
<<<
"
$resp
"
)
query_tx
"
$hash
"
echo
"send '
$3
' from '
$1
' to '
$2
' end"
}
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo
"ipara=
$ispara
"
...
...
@@ -237,6 +126,7 @@ function run_test() {
pokerbull_QueryResult
}
function
main
()
{
MAIN_HTTP
=
"
$1
"
echo
"=========== # pokerbull rpc test ============="
...
...
plugin/dapp/retrieve/cmd/build/test-rpc.sh
View file @
4d5579cb
...
...
@@ -11,56 +11,7 @@ RED='\033[1;31m'
GRE
=
'\033[1;32m'
NOC
=
'\033[0m'
echo_rst
()
{
if
[
"
$2
"
==
0
]
;
then
echo
-e
"
${
GRE
}
$1
ok
${
NOC
}
"
else
echo
-e
"
${
RED
}
$1
fail
${
NOC
}
"
CASE_ERR
=
"FAIL"
fi
}
function
block_wait
()
{
local
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
local
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
}
source
../dapp-test-common.sh
retrieve_Backup
()
{
echo
"========== # retrieve backup begin =========="
...
...
@@ -152,65 +103,6 @@ retrieve_QueryResult() {
echo
"========== # retrieve query result end =========="
}
chain33_ImportPrivkey
()
{
local
pri
=
$2
local
acc
=
$3
local
req
=
'"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'
"
$pri
"
'", "label":"retrieveimportkey1"}]'
echo
"#request:
$req
"
resp
=
$(
curl
-ksd
"{
$req
}"
"
$1
"
)
echo
"#response:
$resp
"
ok
=
$(
jq
'(.error|not) and (.result.label=="retrieveimportkey1") and (.result.acc.addr == "'
"
$acc
"
'")'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
}
signrawtx
()
{
txHex
=
"
$1
"
priKey
=
"
$2
"
local
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
sendTx
"
$signedTx
"
else
echo
"signedTx null error"
fi
}
sendTx
()
{
signedTx
=
$1
local
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
}
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
-r
".result.hash"
<<<
"
$resp
"
)
query_tx
"
$hash
"
}
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo
"ipara=
$ispara
"
...
...
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