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
9e89ebca
Commit
9e89ebca
authored
Jul 30, 2020
by
madengji
Committed by
33cn
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ci test cases
parent
ce76e9bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
210 additions
and
3 deletions
+210
-3
dapp-test-common.sh
build/dapp-test-common.sh
+1
-1
test-rpc.sh
plugin/dapp/paracross/cmd/test/test-rpc.sh
+74
-2
reward_test.go
plugin/dapp/paracross/executor/reward_test.go
+135
-0
No files found.
build/dapp-test-common.sh
View file @
9e89ebca
...
...
@@ -58,7 +58,7 @@ chain33_BlockWait() {
break
fi
count
=
$((
count
+
1
))
sleep
0.
1
sleep
1
done
echo
"wait new block
$count
/10 s, cur height=
$expect
,old=
$cur_height
"
}
...
...
plugin/dapp/paracross/cmd/test/test-rpc.sh
View file @
9e89ebca
...
...
@@ -463,13 +463,13 @@ paracross_testSelfConsensStages() {
fi
chainheight
=
$(
jq
-r
'(.result.chainHeight)'
<<<
"
$resp
"
)
newHeight
=
$((
chainheight
+
2000
))
echo
"apply stage startHeight=
$newHeight
"
echo
"
1.
apply stage startHeight=
$newHeight
"
req
=
'"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "SelfStageConfig","payload" : {"title":"user.p.para.","ty" : "1", "stage" : {"startHeight":'
"
$newHeight
"
',"enable":2} }}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
para_ip
}
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignAndSendTx
"
$rawtx
"
"
$para_test_prikey
"
"
${
para_ip
}
"
echo
"get stage apply id"
echo
"
2.
get stage apply id"
req
=
'"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"ListSelfStages","payload":{"status":1,"count":1}}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
para_ip
}
"
)
echo
"
$resp
"
...
...
@@ -520,6 +520,75 @@ paracross_testSelfConsensStages() {
local
rst
=
$?
echo_rst
"
$FUNCNAME
"
"
$rst
"
}
addr1q9
=
"1Q9sQwothzM1gKSzkVZ8Dt1tqKX1uzSagx"
priv1q9
=
"0x1c3e6cac2f887e1ab9180e2d5772dc4ba01accb8d4df434faba097003eb35482"
nodeAddr
=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
paracross_testBind
()
{
local
para_ip
=
$1
echo
"bind miner"
echo
"1. create tx"
req
=
'"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "ParaBindMiner","payload" : {"bindAction":"1","bindCoins":5, "targetNode":"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
para_ip
}
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignAndSendTxWait
"
$rawtx
"
"
${
priv1q9
}
"
"
${
para_ip
}
"
echo
"2. get bind"
chain33_Http
'{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeBindMinerList","payload":{"data":"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]}'
${
para_ip
}
'(.error|not) and (.result.List.SuperNode| [has("1KSBd17H7Z"),true])'
"
$FUNCNAME
"
'(.result.List)'
chain33_Http
'{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeBindMinerList","payload":{"data":"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]}'
${
para_ip
}
'(.error|not) and (.result.List.Miners| [has("1Q9sQw"),true])'
"
$FUNCNAME
"
'(.result.List)'
}
paracross_testUnBind
()
{
local
para_ip
=
$1
echo
"unBind miner"
echo
"1. create tx"
req
=
'"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "ParaBindMiner","payload" : {"bindAction":"2", "targetNode" : "1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]'
resp
=
$(
curl
-ksd
"{
$req
}"
"
${
para_ip
}
"
)
rawtx
=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignAndSendTxWait
"
$rawtx
"
"
${
priv1q9
}
"
"
${
para_ip
}
"
echo
"2. get bind"
# req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeBindMinerList","payload":{"data":$nodeAddr}]'
# resp=$(curl -ksd "{$req}" "${para_ip}")
# echo "$resp"
# superNode=$(jq -r ".result.List.SuperNode" <<<"$resp")
# miners=$(jq -r ".result.List.Miners" <<<"$resp")
chain33_Http
'{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeBindMinerList","payload":{"data":"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]}'
${
para_ip
}
'(.error|not) and (.result.List.SuperNode| [has("1KSBd17H7Z"),true])'
"
$FUNCNAME
"
'(.result.List)'
chain33_Http
'{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeBindMinerList","payload":{"data":"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}}]}'
${
para_ip
}
'(.error|not) and (.result.List.Miners| [has("1Q9sQw"),false])'
"
$FUNCNAME
"
'(.result.List)'
}
paracross_testBindMiner
()
{
#bind node
paracross_testBind
$1
#unbind
paracross_testUnBind
$1
#bind agin
paracross_testBind
$1
}
function
apply_coins
(){
local
main_ip
=
${
UNIT_HTTP
//8901/8801
}
chain33_applyCoins
"
${
addr1q9
}
"
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
addr1q9
}
"
"
$main_ip
"
local
para_ip
=
"
${
UNIT_HTTP
}
"
chain33_applyCoins
"
${
addr1q9
}
"
1000000000
"
${
para_ip
}
"
chain33_QueryBalance
"
${
addr1q9
}
"
"
$para_ip
"
chain33_ImportPrivkey
"
$priv1q9
"
"
$addr1q9
"
"bindminer"
"
$para_ip
"
local
para_exec_addr
=
""
para_exec_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.paracross"}]}'
${
para_ip
}
| jq
-r
".result"
)
chain33_SendToAddress
"
$addr1q9
"
"
${
para_exec_addr
}
"
900000000
"
${
para_ip
}
"
chain33_QueryExecBalance
"
${
addr1q9
}
"
"user.p.para.paracross"
"
$para_ip
"
}
function
run_testcases
()
{
paracross_GetBlock2MainInfo
paracross_IsSync
...
...
@@ -530,6 +599,8 @@ function run_testcases() {
paracross_ListNodeGroupStatus
paracross_ListNodeStatus
paracross_Transfer_Withdraw
paracross_testBindMiner
"
$UNIT_HTTP
"
paracross_testTxGroup
"
$UNIT_HTTP
"
paracross_testTxGroupFail
"
$UNIT_HTTP
"
#paracross_testParaAssetWithdrawFail "$UNIT_HTTP"
...
...
@@ -559,6 +630,7 @@ function main() {
else
if
[
"
$IS_PARA
"
==
"true"
]
;
then
echo
"=========== # paracross rpc test ============="
apply_coins
run_testcases
fi
fi
...
...
plugin/dapp/paracross/executor/reward_test.go
0 → 100644
View file @
9e89ebca
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
"testing"
apimock
"github.com/33cn/chain33/client/mocks"
dbm
"github.com/33cn/chain33/common/db"
dbmock
"github.com/33cn/chain33/common/db/mocks"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin/crypto/bls"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
)
// 构造一个4个节点的平行链数据, 进行测试
var
()
type
RewardTestSuite
struct
{
suite
.
Suite
stateDB
dbm
.
KV
localDB
*
dbmock
.
KVDB
api
*
apimock
.
QueueProtocolAPI
exec
*
Paracross
action
*
action
}
//func init() {
// log.SetFileLog(nil)
// log.SetLogLevel("debug")
// Init(pt.ParaX, chain33TestCfg, nil)
//}
func
(
suite
*
RewardTestSuite
)
SetupSuite
()
{
suite
.
stateDB
,
_
=
dbm
.
NewGoMemDB
(
"state"
,
"state"
,
1024
)
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite
.
localDB
=
new
(
dbmock
.
KVDB
)
suite
.
api
=
new
(
apimock
.
QueueProtocolAPI
)
suite
.
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
accountdb
:=
suite
.
exec
.
GetCoinsAccount
()
suite
.
action
=
&
action
{
coinsAccount
:
accountdb
,
db
:
suite
.
stateDB
}
//// TODO, more fields
//// setup block
//blockDetail := &types.BlockDetail{
// Block: &types.Block{},
//}
//MainBlockHash10 = blockDetail.Block.Hash(chain33TestCfg)
//blockDetail.Block.MainHash = MainBlockHash10
//
//// setup title nodes : len = 4
//nodeConfigKey := calcManageConfigNodesKey(Title)
//nodeValue := makeNodeInfo(Title, Title, 4)
//suite.stateDB.Set(nodeConfigKey, types.Encode(nodeValue))
//value, err := suite.stateDB.Get(nodeConfigKey)
//if err != nil {
// suite.T().Error("get setup title failed", err)
// return
//}
//assert.Equal(suite.T(), value, types.Encode(nodeValue))
}
//func (suite *RewardTestSuite) TestSetup() {
// nodeConfigKey := calcManageConfigNodesKey(Title)
// suite.T().Log(string(nodeConfigKey))
// _, err := suite.stateDB.Get(nodeConfigKey)
// if err != nil {
// suite.T().Error("get setup title failed", err)
// return
// }
//}
func
TestRewardSuite
(
t
*
testing
.
T
)
{
suite
.
Run
(
t
,
new
(
RewardTestSuite
))
}
func
(
s
*
RewardTestSuite
)
TestRewardBindAddr
()
{
node
:=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
addr
:=
"1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
key
:=
calcParaBindMinerAddr
(
node
,
addr
)
newer
:=
&
pt
.
ParaBindMinerInfo
{
Addr
:
addr
,
BindStatus
:
opBind
,
BindCoins
:
100
,
BlockTime
:
100
,
BlockHeight
:
1
,
TargetNode
:
node
,
}
data
:=
types
.
Encode
(
newer
)
s
.
stateDB
.
Set
(
key
,
data
)
rst
,
err
:=
s
.
stateDB
.
Get
(
key
)
if
err
!=
nil
{
s
.
T
()
.
Error
(
"get setup title failed"
,
err
)
return
}
var
info
pt
.
ParaBindMinerInfo
types
.
Decode
(
rst
,
&
info
)
s
.
Equal
(
info
.
BindCoins
,
newer
.
BindCoins
)
addr2
:=
"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
new2
:=
*
newer
new2
.
Addr
=
addr2
data
=
types
.
Encode
(
&
new2
)
key
=
calcParaBindMinerAddr
(
node
,
addr2
)
s
.
stateDB
.
Set
(
key
,
data
)
list
:=
&
pt
.
ParaNodeBindList
{
SuperNode
:
node
,
Miners
:
[]
string
{
addr
,
addr2
},
}
lists
:=
[]
*
pt
.
ParaNodeBindList
{
list
}
recp
,
change
,
err
:=
s
.
action
.
rewardBindAddr
(
50000005
,
lists
,
1
)
s
.
Nil
(
err
)
s
.
Equal
(
int64
(
5
),
change
)
s
.
Equal
(
int32
(
types
.
ExecOk
),
recp
.
Ty
)
}
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