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
c2820b66
Unverified
Commit
c2820b66
authored
Jun 21, 2019
by
vipwzw
Committed by
GitHub
Jun 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #531 from freek99/para_rpc_test
Add para RPC testcase
parents
fba11d83
b798b774
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
2 deletions
+204
-2
test-rpc.sh
plugin/dapp/paracross/cmd/build/test-rpc.sh
+203
-2
testcase.sh
plugin/dapp/paracross/cmd/build/testcase.sh
+1
-0
No files found.
plugin/dapp/paracross/cmd/build/test-rpc.sh
View file @
c2820b66
...
...
@@ -18,31 +18,224 @@ echo_rst() {
}
paracross_GetBlock2MainInfo
()
{
local
height
height
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
}
| jq
-r
".result.items[1].height"
)
[
"
$height
"
-eq
2
]
rst
=
$?
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
chain33_lock
()
{
local
ok
ok
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"Chain33.Lock","params":[]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
}
| jq
-r
".result.isOK"
)
[
"
$ok
"
==
true
]
rst
=
$?
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
chain33_unlock
()
{
local
ok
ok
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
}
| jq
-r
".result.isOK"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_SignAndSend
()
{
local
signedTx
local
sendedTx
signedTx
=
$(
curl
-ksd
'{"method":"Chain33.SignRawTx","params":[{"expire":"120s","fee":'
"
$1
"
',"privkey":"'
"
$2
"
'","txHex":"'
"
$3
"
'"}]}'
${
UNIT_HTTP
}
| jq
-r
".result"
)
#echo "signedTx:$signedTx"
sendedTx
=
$(
curl
-ksd
'{"method":"Chain33.SendTransaction","params":[{"data":"'
"
$signedTx
"
'"}]}'
${
UNIT_HTTP
}
| jq
-r
".result"
)
echo
"sendedTx:
$sendedTx
"
}
function
paracross_QueryBalance
()
{
local
req
local
resp
local
balance
req
=
'{"method":"Chain33.GetBalance", "params":[{"addresses" : ["'
"
$1
"
'"], "execer" : "paracross","asset_exec":"paracross","asset_symbol":"coins.bty"}]}'
resp
=
$(
curl
-ksd
"
$req
"
"
${
UNIT_HTTP
}
"
)
balance
=
$(
jq
-r
'.result[0].balance'
<<<
"
$resp
"
)
echo
"
$balance
"
return
$?
}
function
paracross_Transfer_Withdraw
()
{
echo
"=========== ## para cross transfer/withdraw (main to para) test start"
#fromAddr 跨链资产转移地址
local
fromAddr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
#privkey 地址签名
local
privkey
=
"0x4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
#paracrossAddr 合约地址
local
paracrossAddr
=
"1HPkPopVe3ERfvaAgedDtJQ792taZFEHCe"
#amount_save 存钱到合约地址
local
amount_save
=
100000000
#amount_should 应转移金额
local
amount_should
=
27000000
#withdraw_should 应取款金额
local
withdraw_should
=
13000000
#fee 交易费
local
fee
=
1000000
#转移前余额
local
para_balance_before
#转移后余额
local
para_balance_after
#取钱后余额
local
para_balance_withdraw_after
#构造交易哈希
local
tx_hash
#实际转移金额
local
amount_real
#实际取钱金额
local
withdraw_real
#1. 查询资产转移前余额状态
para_balance_before
=
$(
paracross_QueryBalance
"
$fromAddr
"
)
echo
"before transferring:
$para_balance_before
"
#2 存钱到合约地址
tx_hash
=
$(
curl
-ksd
'{"method":"Chain33.CreateRawTransaction","params":[{"to":"'
"
$paracrossAddr
"
'","amount":'
$amount_save
'}]}'
${
UNIT_HTTP
}
| jq
-r
".result"
)
##echo "tx:$tx"
paracross_SignAndSend
$fee
"
$privkey
"
"
$tx_hash
"
#3 资产从主链转移到平行链
tx_hash
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"paracross","actionName":"ParacrossAssetTransfer","payload":{"execer":"user.p.para.paracross","execName":"user.p.para.paracross","to":"'
"
$fromAddr
"
'","amount":'
$amount_should
'}}]}'
${
UNIT_HTTP
}
| jq
-r
".result"
)
#echo "rawTx:$rawTx"
paracross_SignAndSend
$fee
"
$privkey
"
"
$tx_hash
"
sleep
30
#4 查询转移后余额状态
para_balance_after
=
$(
paracross_QueryBalance
"
$fromAddr
"
)
echo
"after transferring:
$para_balance_after
"
#real_amount 实际转移金额
amount_real
=
$((
para_balance_after
-
para_balance_before
))
#5 取钱
tx_hash
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"paracross","actionName":"ParacrossAssetWithdraw","payload":{"IsWithdraw":true,"execer":"user.p.para.paracross","execName":"user.p.para.paracross","to":"'
"
$fromAddr
"
'","amount":'
$withdraw_should
'}}]}'
${
UNIT_HTTP
}
| jq
-r
".result"
)
#echo "rawTx:$rawTx"
paracross_SignAndSend
$fee
"
$privkey
"
"
$tx_hash
"
sleep
15
#6 查询取钱后余额状态
para_balance_withdraw_after
=
$(
paracross_QueryBalance
"
$fromAddr
"
)
echo
"after withdrawing :
$para_balance_withdraw_after
"
#实际取钱金额
withdraw_real
=
$((
para_balance_after
-
para_balance_withdraw_after
))
#echo $withdraw_real
#7 验证转移是否正确
[
"
$amount_real
"
==
"
$amount_should
"
]
&&
[
"
$withdraw_should
"
==
"
$withdraw_real
"
]
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
echo
"=========== ## para cross transfer/withdraw (main to para) test start end"
}
function
paracross_IsSync
()
{
local
ok
ok
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.IsSync","params":[]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
}
| jq
-r
".result"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_ListTitles
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.ListTitles","params":[]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("titles"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_GetHeight
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.GetHeight","params":[]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("consensHeight"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_GetNodeGroupAddrs
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("key","value"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_GetNodeGroupStatus
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("status"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_ListNodeGroupStatus
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("status"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
paracross_ListNodeStatus
()
{
local
resp
local
ok
resp
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}'
-H
'content-type:text/plain;'
${
UNIT_HTTP
})
#echo $resp
ok
=
$(
jq
'(.error|not) and (.result| [has("status"),true])'
<<<
"
$resp
"
)
[
"
$ok
"
==
true
]
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
function
run_main_testcases
()
{
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
#paracross_IsSync
paracross_ListTitles
#paracross_GetHeight
paracross_GetNodeGroupAddrs
paracross_GetNodeGroupStatus
paracross_ListNodeGroupStatus
paracross_ListNodeStatus
#paracross_Transfer_Withdraw
}
...
...
@@ -50,6 +243,14 @@ function run_para_testcases() {
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
paracross_IsSync
paracross_ListTitles
paracross_GetHeight
paracross_GetNodeGroupAddrs
paracross_GetNodeGroupStatus
paracross_ListNodeGroupStatus
paracross_ListNodeStatus
paracross_Transfer_Withdraw
}
...
...
plugin/dapp/paracross/cmd/build/testcase.sh
View file @
c2820b66
...
...
@@ -914,6 +914,7 @@ function paracross() {
elif
[
"
${
2
}
"
==
"test"
]
;
then
para_test
"
${
1
}
"
dapp_rpc_test
"
${
3
}
"
fi
if
[
"
${
2
}
"
==
"forkInit"
]
;
then
...
...
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