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
c8a9694d
Commit
c8a9694d
authored
Jun 03, 2019
by
mdj33
Committed by
vipwzw
Jun 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ut
parent
e8562201
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
47 deletions
+71
-47
reward.go
plugin/dapp/paracross/executor/reward.go
+4
-2
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+13
-15
superaccount_test.go
plugin/dapp/paracross/executor/superaccount_test.go
+54
-30
No files found.
plugin/dapp/paracross/executor/reward.go
View file @
c8a9694d
...
...
@@ -62,8 +62,10 @@ func getMiners(detail *pt.ParacrossStatusDetails, blockHash []byte) []string {
//
func
mergeReceipt
(
receipt1
,
receipt2
*
types
.
Receipt
)
*
types
.
Receipt
{
if
receipt2
!=
nil
{
receipt1
.
KV
=
append
(
receipt1
.
KV
,
receipt2
.
KV
...
)
receipt1
.
Logs
=
append
(
receipt1
.
Logs
,
receipt2
.
Logs
...
)
}
receipt1
.
KV
=
append
(
receipt1
.
KV
,
receipt2
.
KV
...
)
receipt1
.
Logs
=
append
(
receipt1
.
Logs
,
receipt2
.
Logs
...
)
return
receipt1
}
plugin/dapp/paracross/executor/superaccount.go
View file @
c8a9694d
...
...
@@ -455,56 +455,54 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
clog
.
Info
(
"paracross.nodeVote ----pass"
,
"most"
,
most
,
"pass"
,
vote
)
var
receiptGroup
*
types
.
Receipt
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
vote
==
pt
.
ParaNodeVoteNo
{
// 对已经在group里面的node,直接投票remove,对正在申请中的adding or quiting状态保持不变,对quited的保持不变
if
stat
.
Status
==
pt
.
ParacrossNodeJoined
{
r
eceiptGroup
,
err
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
r
,
err
:
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
=
mergeReceipt
(
receipt
,
r
)
stat
.
Status
=
pt
.
ParacrossNodeQuited
if
!
types
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
}
receiptGroup
.
KV
=
append
(
receiptGroup
.
KV
,
r
.
KV
...
)
receiptGroup
.
Logs
=
append
(
receiptGroup
.
Logs
,
r
.
Logs
...
)
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
}
else
{
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
r
eceiptGroup
,
err
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
true
)
r
,
err
:
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
stat
.
Status
=
pt
.
ParacrossNodeJoined
receipt
=
mergeReceipt
(
receipt
,
r
)
}
else
if
stat
.
Status
==
pt
.
ParacrossNodeQuiting
{
r
eceiptGroup
,
err
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
r
,
err
:
=
unpdateNodeGroup
(
a
.
db
,
config
.
Title
,
stat
.
TargetAddr
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
stat
.
Status
=
pt
.
ParacrossNodeQuited
receipt
=
mergeReceipt
(
receipt
,
r
)
if
!
types
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
}
receiptGroup
.
KV
=
append
(
receiptGroup
.
KV
,
r
.
KV
...
)
receiptGroup
.
Logs
=
append
(
receiptGroup
.
Logs
,
r
.
Logs
...
)
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
}
receipt
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
if
receiptGroup
!=
nil
{
receipt
.
KV
=
append
(
receipt
.
KV
,
receiptGroup
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
receiptGroup
.
Logs
...
)
}
r
:=
makeNodeConfigReceipt
(
a
.
fromaddr
,
config
,
&
copyStat
,
stat
)
receipt
=
mergeReceipt
(
receipt
,
r
)
receiptDone
:=
makeVoteDoneReceipt
(
stat
,
len
(
nodes
),
len
(
stat
.
Votes
.
Addrs
),
most
,
pt
.
ParaNodeVoteStr
[
vote
],
stat
.
Status
)
receipt
.
KV
=
append
(
receipt
.
KV
,
receiptDone
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
receiptDone
.
Logs
...
)
receipt
=
mergeReceipt
(
receipt
,
receiptDone
)
return
receipt
,
nil
}
...
...
plugin/dapp/paracross/executor/superaccount_test.go
View file @
c8a9694d
...
...
@@ -96,6 +96,11 @@ func nodeCommitImpl(suite suite.Suite, exec *Paracross, privkeyStr string, tx *t
assert
.
NotNil
(
suite
.
T
(),
receipt
)
assert
.
Nil
(
suite
.
T
(),
err
)
for
_
,
v
:=
range
receipt
.
KV
{
if
err
:=
exec
.
GetStateDB
()
.
Set
(
v
.
Key
,
v
.
Value
);
err
!=
nil
{
panic
(
err
)
}
}
return
}
...
...
@@ -115,23 +120,24 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
func
checkGroupApproveReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
6
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
6
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
11
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
7
)
len
:=
len
(
receipt
.
KV
)
var
stat
pt
.
ParaNodeIdStatus
err
:=
types
.
Decode
(
receipt
.
KV
[
len
-
1
]
.
Value
,
&
stat
)
assert
.
Nil
(
suite
.
T
(),
err
,
"decode ParaNodeAddrStatus failed"
)
//suite.T().Log("t
itleHeight", titleHeight
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
TyLogParaNodeGroup
Config
),
receipt
.
Logs
[
len
-
1
]
.
Ty
)
//suite.T().Log("t
y len-1", receipt.Logs[lenLogs-1].Ty,"len",lenLogs
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
TyLogParaNodeGroup
StatusUpdate
),
receipt
.
Logs
[
7
-
1
]
.
Ty
)
assert
.
Equal
(
suite
.
T
(),
int32
(
pt
.
ParacrossNodeGroupApprove
),
stat
.
Status
)
}
func
checkJoinReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
...
...
@@ -146,7 +152,7 @@ func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
func
checkQuitReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
...
...
@@ -161,8 +167,6 @@ func checkQuitReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
func
checkVoteReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
,
count
int
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
1
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
1
)
var
stat
pt
.
ParaNodeIdStatus
err
:=
types
.
Decode
(
receipt
.
KV
[
0
]
.
Value
,
&
stat
)
...
...
@@ -172,43 +176,47 @@ func checkVoteReceipt(suite *NodeManageTestSuite, receipt *types.Receipt, count
}
func
checkVoteDoneReceipt
(
suite
*
NodeManageTestSuite
,
receipt
*
types
.
Receipt
,
count
int
,
join
bool
)
{
suite
.
NotNil
(
receipt
)
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
3
)
var
stat
pt
.
ParaNodeIdStatus
err
:=
types
.
Decode
(
receipt
.
KV
[
0
]
.
Value
,
&
stat
)
assert
.
Nil
(
suite
.
T
(),
err
,
"decode ParaNodeAddrStatus failed"
)
assert
.
Len
(
suite
.
T
(),
stat
.
Votes
.
Votes
,
count
)
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
receipt
.
KV
[
1
]
.
Value
,
&
item
)
assert
.
Nil
(
suite
.
T
(),
err
,
"decode ParaNodeAddrStatus failed"
)
suite
.
T
()
.
Log
(
"checkVoteDoneReceipt"
,
"kvlen"
,
len
(
receipt
.
KV
))
_
,
arry
,
err
:=
getParacrossNodes
(
suite
.
stateDB
,
Title
)
suite
.
Suite
.
Nil
(
err
)
if
join
{
suite
.
Contains
(
item
.
GetArr
()
.
Value
,
Account14K
)
suite
.
Contains
(
arry
,
Account14K
)
}
else
{
suite
.
NotContains
(
item
.
GetArr
()
.
Value
,
Account14K
)
suite
.
NotContains
(
arry
,
Account14K
)
}
}
func
voteTest
(
suite
*
NodeManageTestSuite
,
addr
string
,
join
bool
)
{
func
voteTest
(
suite
*
NodeManageTestSuite
,
id
string
,
join
bool
)
{
var
count
int
=
1
config
:=
&
pt
.
ParaNodeAddrConfig
{
Op
:
pt
.
ParaNodeVote
,
Addr
:
addr
,
Id
:
id
,
Value
:
pt
.
ParaNodeVoteYes
,
}
tx
,
err
:=
pt
.
CreateRawNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
receipt
:=
nodeCommit
(
suite
,
PrivKeyA
,
tx
)
checkVoteReceipt
(
suite
,
receipt
,
1
)
checkVoteReceipt
(
suite
,
receipt
,
count
)
count
++
receipt
=
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
checkVoteReceipt
(
suite
,
receipt
,
2
)
checkVoteReceipt
(
suite
,
receipt
,
count
)
count
++
if
!
join
{
receipt
=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
checkVoteReceipt
(
suite
,
receipt
,
count
)
count
++
}
receipt
=
nodeCommit
(
suite
,
PrivKeyC
,
tx
)
checkVoteDoneReceipt
(
suite
,
receipt
,
3
,
join
)
checkVoteDoneReceipt
(
suite
,
receipt
,
count
,
join
)
}
func
(
suite
*
NodeManageTestSuite
)
testNodeGroupConfigQuit
()
{
...
...
@@ -222,8 +230,13 @@ func (suite *NodeManageTestSuite) testNodeGroupConfigQuit() {
receipt
:=
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
checkGroupApplyReceipt
(
suite
,
receipt
)
suite
.
Equal
(
int32
(
pt
.
TyLogParaNodeGroupConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
var
g
pt
.
ReceiptParaNodeGroupConfig
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
config
=
&
pt
.
ParaNodeGroupConfig
{
Addrs
:
applyAddrs
,
Id
:
g
.
Current
.
Id
,
Op
:
pt
.
ParacrossNodeGroupQuit
,
}
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
...
...
@@ -247,8 +260,14 @@ func (suite *NodeManageTestSuite) testNodeGroupConfig() {
receipt
:=
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
checkGroupApplyReceipt
(
suite
,
receipt
)
suite
.
Equal
(
int32
(
pt
.
TyLogParaNodeGroupConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
var
g
pt
.
ReceiptParaNodeGroupConfig
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
config
=
&
pt
.
ParaNodeGroupConfig
{
Addrs
:
applyAddrs
,
Id
:
g
.
Current
.
Id
,
Op
:
pt
.
ParacrossNodeGroupApprove
,
}
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
...
...
@@ -271,13 +290,18 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
receipt
:=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
checkJoinReceipt
(
suite
,
receipt
)
suite
.
Equal
(
int32
(
pt
.
TyLogParaNodeConfig
),
receipt
.
Logs
[
0
]
.
Ty
)
var
g
pt
.
ReceiptParaNodeConfig
err
=
types
.
Decode
(
receipt
.
Logs
[
0
]
.
Log
,
&
g
)
suite
.
Nil
(
err
)
//vote test
voteTest
(
suite
,
Account14K
,
true
)
voteTest
(
suite
,
g
.
Current
.
Id
,
true
)
//Quit test
config
=
&
pt
.
ParaNodeAddrConfig
{
Op
:
pt
.
ParaNodeQuit
,
Addr
:
Account1MC
,
Id
:
g
.
Current
.
Id
,
}
tx
,
err
=
pt
.
CreateRawNodeConfigTx
(
config
)
suite
.
Nil
(
err
)
...
...
@@ -285,7 +309,7 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
checkQuitReceipt
(
suite
,
receipt
)
//vote test
voteTest
(
suite
,
Account1MC
,
false
)
voteTest
(
suite
,
g
.
Current
.
Id
,
false
)
}
func
(
suite
*
NodeManageTestSuite
)
TestExec
()
{
...
...
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