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
ae654d67
Commit
ae654d67
authored
Sep 28, 2020
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit test
parent
b4ae96a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
66 deletions
+64
-66
superaccount_test.go
plugin/dapp/paracross/executor/superaccount_test.go
+5
-0
supervisionaccount.go
plugin/dapp/paracross/executor/supervisionaccount.go
+21
-45
supervisionaccount_test.go
plugin/dapp/paracross/executor/supervisionaccount_test.go
+38
-21
No files found.
plugin/dapp/paracross/executor/superaccount_test.go
View file @
ae654d67
...
...
@@ -25,8 +25,13 @@ var (
PrivKey14K
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
// 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
Account14K
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
applyAddrs
=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4,1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR,1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k,1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
PrivKey1KS
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
Account12Q
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
PrivKey12Q
=
"4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
PrivKey1Ku
=
"0xb1474387fe5beda4d6a9d999226bab561c708e07da15d74d575dad890e24cef0"
Account1Ku
=
"1KufZaLTKVAy37AsXNd9bsva5WZvP8w5uG"
PrivKey1M3
=
"0xa4ebb30bd017f3d8e60532dd4f7059704d7897071fc07482aa0681c57c88f874"
Account1M3
=
"1M3XCbWVxAPBH5AR8VmLky4ZtDdGgC6ugD"
)
// createRawNodeConfigTx create raw tx for node config
...
...
plugin/dapp/paracross/executor/supervisionaccount.go
View file @
ae654d67
...
...
@@ -182,7 +182,7 @@ func (a *action) checkValidSupervisionNode(config *pt.ParaNodeAddrConfig) (bool,
if
err
!=
nil
&&
!
isNotFound
(
err
)
{
return
false
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
config
.
Title
)
}
//有可能申请地址和配置地址不是同一个
if
validNode
(
config
.
Addr
,
nodes
)
{
return
true
,
nil
}
...
...
@@ -191,15 +191,15 @@ func (a *action) checkValidSupervisionNode(config *pt.ParaNodeAddrConfig) (bool,
func
(
a
*
action
)
checkSupervisionNodeGroupExist
(
title
string
)
error
{
key
:=
calcParaSupervisionNodeGroupAddrsKey
(
title
)
value
,
err
:=
a
.
db
.
Get
(
key
)
_
,
err
:=
a
.
db
.
Get
(
key
)
if
err
!=
nil
&&
!
isNotFound
(
err
)
{
return
err
}
if
value
!=
nil
{
clog
.
Error
(
"node group apply, group existed"
)
return
pt
.
ErrParaSupervisionNodeGroupExisted
}
//
if value != nil {
//
clog.Error("node group apply, group existed")
//
return pt.ErrParaSupervisionNodeGroupExisted
//
}
return
nil
}
...
...
@@ -227,10 +227,9 @@ func (a *action) supervisionNodeGroupCreate(status *pt.ParaNodeGroupStatus) (*ty
for
i
,
addr
:=
range
nodes
{
stat
:=
&
pt
.
ParaNodeIdStatus
{
Id
:
status
.
Id
+
"-"
+
strconv
.
Itoa
(
i
),
Status
:
pt
.
Para
ApplyClosed
,
Status
:
pt
.
Para
crossSupervisionNodeApprove
,
Title
:
status
.
Title
,
TargetAddr
:
addr
,
Votes
:
&
pt
.
ParaNodeVoteDetail
{
Addrs
:
[]
string
{
a
.
fromaddr
},
Votes
:
[]
string
{
"yes"
}},
CoinsFrozen
:
status
.
CoinsFrozen
,
FromAddr
:
status
.
FromAddr
,
Height
:
a
.
height
}
...
...
@@ -251,7 +250,7 @@ func (a *action) supervisionNodeGroupCreate(status *pt.ParaNodeGroupStatus) (*ty
//由于propasal id 和quit id分开,quit id不知道对应addr proposal id的coinfrozen信息,需要维护一个围绕addr的数据库结构信息
func
(
a
*
action
)
updateSupervisionNodeAddrStatus
(
stat
*
pt
.
ParaNodeIdStatus
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
//
cfg := a.api.GetConfig()
addrStat
,
err
:=
getSupervisionNodeAddr
(
a
.
db
,
stat
.
Title
,
stat
.
TargetAddr
)
if
err
!=
nil
{
if
!
isNotFound
(
err
)
{
...
...
@@ -261,41 +260,17 @@ func (a *action) updateSupervisionNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*ty
addrStat
.
Title
=
stat
.
Title
addrStat
.
Addr
=
stat
.
TargetAddr
addrStat
.
BlsPubKey
=
stat
.
BlsPubKey
addrStat
.
Status
=
pt
.
Para
ApplyJoined
addrStat
.
Status
=
pt
.
Para
crossSupervisionNodeApprove
addrStat
.
ProposalId
=
stat
.
Id
addrStat
.
QuitId
=
""
return
makeParaSupervisionNodeStatusReceipt
(
a
.
fromaddr
,
nil
,
addrStat
),
nil
}
preStat
:=
*
addrStat
if
stat
.
Status
==
pt
.
ParaApplyJoining
{
addrStat
.
Status
=
pt
.
ParaApplyJoined
addrStat
.
ProposalId
=
stat
.
Id
addrStat
.
QuitId
=
""
return
makeParaSupervisionNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
),
nil
}
if
stat
.
Status
==
pt
.
ParaApplyQuiting
{
proposalStat
,
err
:=
getNodeID
(
a
.
db
,
addrStat
.
ProposalId
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s quiting wrong proposeid:%s"
,
stat
.
TargetAddr
,
addrStat
.
ProposalId
)
}
addrStat
.
Status
=
pt
.
ParaApplyQuited
addrStat
.
QuitId
=
stat
.
Id
receipt
:=
makeParaSupervisionNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
)
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
proposalStat
.
FromAddr
,
proposalStat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
}
return
receipt
,
nil
}
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"nodeAddr:%s get wrong status:%d"
,
stat
.
TargetAddr
,
stat
.
Status
)
stat
.
Status
=
pt
.
ParacrossSupervisionNodeApprove
addrStat
.
ProposalId
=
stat
.
Id
addrStat
.
QuitId
=
""
return
makeParaSupervisionNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
),
nil
}
func
(
a
*
action
)
supervisionNodeGroupApply
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
...
...
@@ -305,17 +280,18 @@ func (a *action) supervisionNodeGroupApply(config *pt.ParaNodeAddrConfig) (*type
return
nil
,
err
}
if
addrExist
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s in super"
,
config
.
Addr
)
clog
.
Debug
(
"supervisionNodeGroup Apply"
,
"config.Addr"
,
config
.
Addr
,
"err"
,
"config.Addr existed in super group"
)
return
nil
,
pt
.
ErrParaNodeAddrExisted
}
// 是否已经申请
addrExist
,
err
=
a
.
checkValidSupervisionNode
(
config
)
if
err
!=
nil
{
//return nil, err
fmt
.
Println
(
"err:"
,
err
)
}
if
addrExist
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaSupervisionNodeAddrExisted
,
"nodeAddr existed:%s"
,
config
.
Addr
)
clog
.
Debug
(
"supervisionNodeGroup Apply"
,
"config.Addr"
,
config
.
Addr
,
"err"
,
"config.Addr existed in supervision group"
)
return
nil
,
pt
.
ErrParaSupervisionNodeAddrExisted
}
// 判断和监督组冻结金额是否一致
...
...
@@ -346,7 +322,7 @@ func (a *action) supervisionNodeGroupApply(config *pt.ParaNodeAddrConfig) (*type
if
err
!=
nil
&&
!
isNotFound
(
err
)
{
return
nil
,
errors
.
Wrapf
(
err
,
"nodeJoin get title=%s,nodeAddr=%s"
,
config
.
Title
,
config
.
Addr
)
}
if
addrStat
!=
nil
&&
addrStat
.
Status
!=
pt
.
Para
ApplyQuited
{
if
addrStat
!=
nil
&&
addrStat
.
Status
!=
pt
.
Para
crossSupervisionNodeQuit
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeJoin nodeAddr existed:%s,status:%d"
,
config
.
Addr
,
addrStat
.
Status
)
}
...
...
@@ -379,7 +355,7 @@ func (a *action) supervisionNodeGroupApprove(config *pt.ParaNodeAddrConfig) (*ty
cfg
:=
a
.
api
.
GetConfig
()
//只在主链检查
if
!
cfg
.
IsPara
()
&&
!
isSuperManager
(
cfg
,
a
.
fromaddr
)
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotAllow
,
"node group approve not super manager:%s"
,
a
.
fromaddr
)
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotAllow
,
"node group approve not super
vision
manager:%s"
,
a
.
fromaddr
)
}
id
,
err
:=
getSupervisionNodeGroupID
(
cfg
,
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
...
...
@@ -452,7 +428,7 @@ func (a *action) supervisionNodeGroupQuit(config *pt.ParaNodeAddrConfig) (*types
}
//approved or quited
if
status
.
Status
!=
pt
.
Paracross
NodeGroup
Apply
{
if
status
.
Status
!=
pt
.
Paracross
SupervisionNode
Apply
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"node group apply not apply:%d"
,
status
.
Status
)
}
...
...
@@ -470,7 +446,7 @@ func (a *action) supervisionNodeGroupQuit(config *pt.ParaNodeAddrConfig) (*types
}
copyStat
:=
*
status
status
.
Status
=
pt
.
Paracross
NodeGroup
Quit
status
.
Status
=
pt
.
Paracross
SupervisionNode
Quit
status
.
Height
=
a
.
height
r
:=
makeSupervisionNodeGroupIDReceipt
(
a
.
fromaddr
,
&
copyStat
,
status
)
...
...
plugin/dapp/paracross/executor/supervisionaccount_test.go
View file @
ae654d67
...
...
@@ -7,7 +7,7 @@ import (
)
// createRawSupervisionNodeConfigTx create raw tx for node config
func
createRawSupervisionNodeConfigTx
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Transaction
,
error
)
{
func
createRawSupervisionNodeConfigTx
(
config
*
pt
.
ParaNodeAddrConfig
)
*
types
.
Transaction
{
action
:=
&
pt
.
ParacrossAction
{
Ty
:
pt
.
ParacrossActionSupervisionNodeGroupConfig
,
Value
:
&
pt
.
ParacrossAction_SupervisionNodeGroupConfig
{
SupervisionNodeGroupConfig
:
config
},
...
...
@@ -16,12 +16,15 @@ func createRawSupervisionNodeConfigTx(config *pt.ParaNodeAddrConfig) (*types.Tra
Payload
:
types
.
Encode
(
action
),
Execer
:
[]
byte
(
config
.
Title
+
pt
.
ParaX
),
}
return
tx
,
nil
return
tx
}
func
(
suite
*
NodeManageTestSuite
)
testSupervisionExec
()
{
suite
.
testSupervisionNodeConfigQuit
()
suite
.
testSupervisionNodeConfigApprove
()
suite
.
testSupervisionNodeConfigApprove
(
Account14K
,
PrivKey14K
)
suite
.
testSupervisionNodeConfigApprove
(
Account1Ku
,
PrivKey1Ku
)
suite
.
testSupervisionNodeConfigApprove
(
Account1M3
,
PrivKey1M3
)
suite
.
testSupervisionNodeError
()
suite
.
testSupervisionQuery
()
}
...
...
@@ -32,14 +35,12 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigQuit() {
Op
:
pt
.
ParacrossSupervisionNodeApply
,
Addr
:
Account14K
,
}
tx
,
err
:=
createRawSupervisionNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
tx
:=
createRawSupervisionNodeConfigTx
(
config
)
receipt
:=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
checkSupervisionGroupApplyReceipt
(
suite
,
receipt
)
var
g
pt
.
ReceiptParaNodeGroupConfig
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
err
:
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
// Quit
...
...
@@ -48,27 +49,23 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigQuit() {
Op
:
pt
.
ParacrossSupervisionNodeQuit
,
Id
:
g
.
Current
.
Id
,
}
tx
,
err
=
createRawSupervisionNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
tx
=
createRawSupervisionNodeConfigTx
(
config
)
receipt
=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
}
func
(
suite
*
NodeManageTestSuite
)
testSupervisionNodeConfigApprove
()
{
func
(
suite
*
NodeManageTestSuite
)
testSupervisionNodeConfigApprove
(
addr
,
privKey
string
)
{
config
:=
&
pt
.
ParaNodeAddrConfig
{
Title
:
chain33TestCfg
.
GetTitle
(),
Op
:
pt
.
ParacrossSupervisionNodeApply
,
Addr
:
Account14K
,
Addr
:
addr
,
}
tx
,
err
:=
createRawSupervisionNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
tx
:=
createRawSupervisionNodeConfigTx
(
config
)
receipt
:=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
checkSupervisionGroupApplyReceipt
(
suite
,
receipt
)
var
g
pt
.
ReceiptParaNodeGroupConfig
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
err
:
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
config
=
&
pt
.
ParaNodeAddrConfig
{
...
...
@@ -76,13 +73,33 @@ func (suite *NodeManageTestSuite) testSupervisionNodeConfigApprove() {
Id
:
g
.
Current
.
Id
,
Op
:
pt
.
ParacrossSupervisionNodeApprove
,
}
tx
,
err
=
createRawSupervisionNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
receipt
=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
tx
=
createRawSupervisionNodeConfigTx
(
config
)
receipt
=
nodeCommit
(
suite
,
privKey
,
tx
)
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
}
func
(
suite
*
NodeManageTestSuite
)
testSupervisionNodeError
()
{
config
:=
&
pt
.
ParaNodeAddrConfig
{
Title
:
chain33TestCfg
.
GetTitle
(),
Op
:
pt
.
ParacrossSupervisionNodeApply
,
Addr
:
Account1M3
,
}
tx
:=
createRawSupervisionNodeConfigTx
(
config
)
tx
,
_
=
signTx
(
suite
.
Suite
,
tx
,
PrivKey1Ku
)
_
,
err
:=
suite
.
exec
.
Exec
(
tx
,
0
)
assert
.
Equal
(
suite
.
T
(),
err
,
pt
.
ErrParaSupervisionNodeAddrExisted
)
config
=
&
pt
.
ParaNodeAddrConfig
{
Title
:
chain33TestCfg
.
GetTitle
(),
Op
:
pt
.
ParacrossSupervisionNodeApply
,
Addr
:
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
,
}
tx
=
createRawSupervisionNodeConfigTx
(
config
)
tx
,
_
=
signTx
(
suite
.
Suite
,
tx
,
PrivKey1KS
)
_
,
err
=
suite
.
exec
.
Exec
(
tx
,
0
)
assert
.
Equal
(
suite
.
T
(),
err
,
pt
.
ErrParaNodeAddrExisted
)
}
func
checkSupervisionGroupApplyReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
...
...
@@ -95,7 +112,7 @@ func (suite *NodeManageTestSuite) testSupervisionQuery() {
suite
.
Nil
(
err
)
resp
,
ok
:=
ret
.
(
*
types
.
ReplyConfig
)
assert
.
Equal
(
suite
.
T
(),
ok
,
true
)
assert
.
Equal
(
suite
.
T
(),
resp
.
Value
,
Account14K
)
assert
.
Equal
(
suite
.
T
(),
resp
.
Value
,
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt,1KufZaLTKVAy37AsXNd9bsva5WZvP8w5uG,1M3XCbWVxAPBH5AR8VmLky4ZtDdGgC6ugD"
)
ret
,
err
=
suite
.
exec
.
Query_GetSupervisionNodeAddrInfo
(
&
pt
.
ReqParacrossNodeInfo
{
Title
:
chain33TestCfg
.
GetTitle
(),
Addr
:
Account14K
})
suite
.
Nil
(
err
)
...
...
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