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
e720e6de
Commit
e720e6de
authored
Jul 19, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ruleaction test
parent
5e5226b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
19 deletions
+128
-19
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+28
-18
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+100
-1
No files found.
plugin/dapp/autonomy/executor/ruleaction.go
View file @
e720e6de
...
@@ -31,22 +31,6 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
...
@@ -31,22 +31,6 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
return
nil
,
err
return
nil
,
err
}
}
if
prob
.
RuleCfg
.
BoardAttendRatio
>
0
{
rule
.
BoardAttendRatio
=
prob
.
RuleCfg
.
BoardAttendRatio
}
if
prob
.
RuleCfg
.
BoardApproveRatio
>
0
{
rule
.
BoardApproveRatio
=
prob
.
RuleCfg
.
BoardApproveRatio
}
if
prob
.
RuleCfg
.
PubOpposeRatio
>
0
{
rule
.
BoardApproveRatio
=
prob
.
RuleCfg
.
PubOpposeRatio
}
if
prob
.
RuleCfg
.
ProposalAmount
>
0
{
rule
.
ProposalAmount
=
prob
.
RuleCfg
.
ProposalAmount
}
if
prob
.
RuleCfg
.
LargeProjectAmount
>
0
{
rule
.
LargeProjectAmount
=
prob
.
RuleCfg
.
LargeProjectAmount
}
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
rule
.
ProposalAmount
)
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
rule
.
ProposalAmount
)
if
err
!=
nil
{
if
err
!=
nil
{
alog
.
Error
(
"propRule "
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"ExecFrozen amount"
,
rule
.
ProposalAmount
)
alog
.
Error
(
"propRule "
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"ExecFrozen amount"
,
rule
.
ProposalAmount
)
...
@@ -219,7 +203,8 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
...
@@ -219,7 +203,8 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
// 更新系统规则
// 更新系统规则
if
cur
.
VoteResult
.
Pass
{
if
cur
.
VoteResult
.
Pass
{
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
activeRuleID
(),
Value
:
types
.
Encode
(
cur
.
Rule
)})
upRule
:=
upgradeRule
(
cur
.
Rule
,
cur
.
PropRule
.
RuleCfg
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
activeRuleID
(),
Value
:
types
.
Encode
(
upRule
)})
}
}
ty
:=
auty
.
TyLogVotePropRule
ty
:=
auty
.
TyLogVotePropRule
...
@@ -292,7 +277,8 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re
...
@@ -292,7 +277,8 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re
// 更新系统规则
// 更新系统规则
if
cur
.
VoteResult
.
Pass
{
if
cur
.
VoteResult
.
Pass
{
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
activeRuleID
(),
Value
:
types
.
Encode
(
cur
.
Rule
)})
upRule
:=
upgradeRule
(
cur
.
Rule
,
cur
.
PropRule
.
RuleCfg
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
activeRuleID
(),
Value
:
types
.
Encode
(
upRule
)})
}
}
getRuleReceiptLog
(
pre
,
cur
,
auty
.
TyLogTmintPropRule
)
getRuleReceiptLog
(
pre
,
cur
,
auty
.
TyLogTmintPropRule
)
...
@@ -343,3 +329,27 @@ func copyAutonomyProposalRule(cur *auty.AutonomyProposalRule) *auty.AutonomyProp
...
@@ -343,3 +329,27 @@ func copyAutonomyProposalRule(cur *auty.AutonomyProposalRule) *auty.AutonomyProp
return
&
newAut
return
&
newAut
}
}
func
upgradeRule
(
cur
,
modify
*
auty
.
RuleConfig
)
*
auty
.
RuleConfig
{
if
cur
==
nil
||
modify
==
nil
{
return
nil
}
new
:=
*
cur
if
modify
.
BoardAttendRatio
>
0
{
new
.
BoardAttendRatio
=
modify
.
BoardAttendRatio
}
if
modify
.
BoardApproveRatio
>
0
{
new
.
BoardApproveRatio
=
modify
.
BoardApproveRatio
}
if
modify
.
PubOpposeRatio
>
0
{
new
.
PubOpposeRatio
=
modify
.
PubOpposeRatio
}
if
modify
.
ProposalAmount
>
0
{
new
.
ProposalAmount
=
modify
.
ProposalAmount
}
if
modify
.
LargeProjectAmount
>
0
{
new
.
LargeProjectAmount
=
modify
.
LargeProjectAmount
}
return
&
new
}
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
e720e6de
...
@@ -20,6 +20,13 @@ import (
...
@@ -20,6 +20,13 @@ import (
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
)
)
const
(
testBoardAttendRatio
int32
=
60
testBoardApproveRatio
int32
=
60
testPubOpposeRatio
int32
=
30
testProposalAmount
int64
=
0
testLargeProjectAmount
int64
=
1
)
func
TestRevokeProposalRule
(
t
*
testing
.
T
)
{
func
TestRevokeProposalRule
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
...
@@ -50,7 +57,14 @@ func testPropRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB dbm.K
...
@@ -50,7 +57,14 @@ func testPropRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB dbm.K
Year
:
2019
,
Year
:
2019
,
Month
:
7
,
Month
:
7
,
Day
:
10
,
Day
:
10
,
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
60
},
RuleCfg
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
testBoardAttendRatio
,
BoardApproveRatio
:
testBoardApproveRatio
,
PubOpposeRatio
:
testPubOpposeRatio
,
ProposalAmount
:
testProposalAmount
,
LargeProjectAmount
:
testLargeProjectAmount
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
}
}
...
@@ -135,6 +149,20 @@ func revokeProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB
...
@@ -135,6 +149,20 @@ func revokeProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB
accCoin
.
SetDB
(
stateDB
)
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check rule
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
boardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
}
}
func
revokeProposalRuleTx
(
parm
*
auty
.
RevokeProposalRule
)
(
*
types
.
Transaction
,
error
)
{
func
revokeProposalRuleTx
(
parm
*
auty
.
RevokeProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
@@ -243,6 +271,20 @@ func voteProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB d
...
@@ -243,6 +271,20 @@ func voteProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB d
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropRule
),
cur
.
Status
)
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropRule
),
cur
.
Status
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
require
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
require
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
// check rule
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
testBoardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
testBoardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
testPubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
testLargeProjectAmount
)
}
}
func
voteProposalRuleTx
(
parm
*
auty
.
VoteProposalRule
)
(
*
types
.
Transaction
,
error
)
{
func
voteProposalRuleTx
(
parm
*
auty
.
VoteProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
@@ -305,6 +347,21 @@ func terminateProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stat
...
@@ -305,6 +347,21 @@ func terminateProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stat
accCoin
.
SetDB
(
stateDB
)
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check rule
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
boardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
}
}
func
terminateProposalRuleTx
(
parm
*
auty
.
TerminateProposalRule
)
(
*
types
.
Transaction
,
error
)
{
func
terminateProposalRuleTx
(
parm
*
auty
.
TerminateProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
@@ -365,4 +422,45 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
...
@@ -365,4 +422,45 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
require
.
Equal
(
t
,
80
,
int
(
new
.
PropRule
.
RuleCfg
.
BoardApproveRatio
))
require
.
Equal
(
t
,
80
,
int
(
new
.
PropRule
.
RuleCfg
.
BoardApproveRatio
))
require
.
Equal
(
t
,
100
,
int
(
new
.
Rule
.
BoardApproveRatio
))
require
.
Equal
(
t
,
100
,
int
(
new
.
Rule
.
BoardApproveRatio
))
}
func
TestUpgradeRule
(
t
*
testing
.
T
)
{
new
:=
upgradeRule
(
nil
,
&
auty
.
RuleConfig
{})
require
.
Nil
(
t
,
new
)
cur
:=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
1
,
BoardApproveRatio
:
2
,
PubOpposeRatio
:
3
,
ProposalAmount
:
4
,
LargeProjectAmount
:
5
,
}
modify
:=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
0
,
BoardApproveRatio
:
-
1
,
PubOpposeRatio
:
0
,
ProposalAmount
:
-
1
,
LargeProjectAmount
:
0
,
}
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
require
.
Equal
(
t
,
new
.
BoardAttendRatio
,
cur
.
BoardAttendRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
cur
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
cur
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
cur
.
ProposalAmount
)
require
.
Equal
(
t
,
new
.
LargeProjectAmount
,
cur
.
LargeProjectAmount
)
modify
=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
10
,
BoardApproveRatio
:
20
,
PubOpposeRatio
:
30
,
ProposalAmount
:
40
,
LargeProjectAmount
:
50
,
}
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
require
.
Equal
(
t
,
new
.
BoardAttendRatio
,
modify
.
BoardAttendRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
modify
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
modify
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
modify
.
ProposalAmount
)
require
.
Equal
(
t
,
new
.
LargeProjectAmount
,
modify
.
LargeProjectAmount
)
}
}
\ No newline at end of file
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