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
05b8ae47
Commit
05b8ae47
authored
Aug 22, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify test
parent
ae572080
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
147 additions
and
45 deletions
+147
-45
proposal_project.go
plugin/dapp/autonomy/commands/proposal_project.go
+1
-1
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+15
-1
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+84
-5
projectaction.go
plugin/dapp/autonomy/executor/projectaction.go
+7
-1
projectaction_test.go
plugin/dapp/autonomy/executor/projectaction_test.go
+24
-20
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+8
-1
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+6
-16
errors.go
plugin/dapp/autonomy/types/errors.go
+2
-0
No files found.
plugin/dapp/autonomy/commands/proposal_project.go
View file @
05b8ae47
...
@@ -201,7 +201,7 @@ func PubVoteProposalProjectCmd() *cobra.Command {
...
@@ -201,7 +201,7 @@ func PubVoteProposalProjectCmd() *cobra.Command {
func
addPubVoteProposalProjectFlags
(
cmd
*
cobra
.
Command
)
{
func
addPubVoteProposalProjectFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
MarkFlagRequired
(
"proposalID"
)
cmd
.
MarkFlagRequired
(
"proposalID"
)
cmd
.
Flags
()
.
Int32P
(
"oppose"
,
"
o
"
,
1
,
"is oppose, default true"
)
cmd
.
Flags
()
.
Int32P
(
"oppose"
,
"
s
"
,
1
,
"is oppose, default true"
)
cmd
.
Flags
()
.
StringP
(
"originAddr"
,
"o"
,
""
,
"origin address: addr1-addr2......addrN"
)
cmd
.
Flags
()
.
StringP
(
"originAddr"
,
"o"
,
""
,
"origin address: addr1-addr2......addrN"
)
}
}
...
...
plugin/dapp/autonomy/executor/boardaction.go
View file @
05b8ae47
...
@@ -62,11 +62,19 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
...
@@ -62,11 +62,19 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
mpBd
:=
make
(
map
[
string
]
struct
{})
for
_
,
board
:=
range
prob
.
Boards
{
for
_
,
board
:=
range
prob
.
Boards
{
if
err
:=
address
.
CheckAddress
(
board
);
err
!=
nil
{
if
err
:=
address
.
CheckAddress
(
board
);
err
!=
nil
{
alog
.
Error
(
"propBoard "
,
"addr"
,
board
,
"check toAddr error"
,
err
)
alog
.
Error
(
"propBoard "
,
"addr"
,
board
,
"check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalidAddress
return
nil
,
types
.
ErrInvalidAddress
}
}
// 提案board重复地址去重复
if
_
,
ok
:=
mpBd
[
board
];
ok
{
err
:=
auty
.
ErrRepeatAddr
alog
.
Error
(
"propBoard "
,
"addr"
,
board
,
"propBoard have repeat addr "
,
err
)
return
nil
,
err
}
mpBd
[
board
]
=
struct
{}{}
}
}
// 获取当前生效提案规则
// 获取当前生效提案规则
...
@@ -188,8 +196,14 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
...
@@ -188,8 +196,14 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
return
nil
,
err
return
nil
,
err
}
}
// 挖矿地址验证
if
len
(
voteProb
.
OriginAddr
)
>
0
{
if
len
(
voteProb
.
OriginAddr
)
>
0
{
for
_
,
board
:=
range
voteProb
.
OriginAddr
{
if
err
:=
address
.
CheckAddress
(
board
);
err
!=
nil
{
alog
.
Error
(
"votePropBoard "
,
"addr"
,
board
,
"check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalidAddress
}
}
// 挖矿地址验证
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
if
err
!=
nil
{
if
err
!=
nil
{
alog
.
Error
(
"votePropBoard "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
alog
.
Error
(
"votePropBoard "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
...
...
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
05b8ae47
...
@@ -22,6 +22,8 @@ import (
...
@@ -22,6 +22,8 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
ticketTy
"github.com/33cn/plugin/plugin/dapp/ticket/types"
ticket
"github.com/33cn/plugin/plugin/dapp/ticket/executor"
)
)
// ExecEnv exec environment
// ExecEnv exec environment
...
@@ -45,7 +47,42 @@ var (
...
@@ -45,7 +47,42 @@ var (
AddrC
=
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
AddrC
=
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
AddrD
=
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
AddrD
=
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
boards
=
[]
string
{
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
,
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
,
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
}
PrivKey1
=
"0x9d4f8ab11361be596468b265cb66946c87873d4a119713fd0c3d8302eae0a8e4"
PrivKey2
=
"0xd165c84ed37c2a427fea487470ee671b7a0495d68d82607cafbc6348bf23bec5"
PrivKey3
=
"0xc21d38be90493512a5c2417d565269a8b23ce8152010e404ff4f75efead8183a"
PrivKey4
=
"0xfdf2bbff853ecff2e7b86b2a8b45726c6538ca7d1403dc94e50131ef379bdca0"
PrivKey5
=
"0x794443611e7369a57b078881445b93b754cbc9b9b8f526535ab9c6d21d29203d"
PrivKey6
=
"0xf2cc48d30560e4c92e84821df68cf1086de82ee6a5725fc2a590a58d6ffe4fc5"
PrivKey7
=
"0xeb4738a7c685a7ccf5471c3335a2d7ebe284b11d8a1717d814904b8d1ba936d9"
PrivKey8
=
"0x9d315182e56fde7fadb94408d360203894e5134216944e858f9b31f70e9ecf40"
PrivKey9
=
"0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1"
PrivKey10
=
"0x1c3e6cac2f887e1ab9180e2d5772dc4ba01accb8d4df434faba097003eb35482"
boards
=
[]
string
{
AddrA
,
AddrB
,
AddrC
,
AddrD
,
"12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
,
"1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
,
"12cjnN5D4DPdBQSwh6vjwJbtsW4EJALTMv"
,
"1Luh4AziYyaC5zP3hUXtXFZS873xAxm6rH"
,
"1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB"
,
"1L1puAUjfmtDECKo2C1qLWsAMZtDGTBWf6"
,
"1LNf9AVXzUMQkQM5hgGLhkdrVtD8UMBSUm"
,
"1PcGKYYoLn1PLLJJodc1UpgWGeFAQasAkx"
,
"1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu"
,
"1Q9sQwothzM1gKSzkVZ8Dt1tqKX1uzSagx"
,
"15VUiygdxMSZ3rykwe742yomp2cPJ9Tfve"
,
"1DyR84CU5AHbGXLEnhHMwMvWNMeunLZsuJ"
,
"132pBvrgSYgHASxzoeL3bqnsqUpaBbUktm"
,
"1DEV4XwdBUWRkMuy4ARRiEAoxQ2LoDByNG"
,
"18Y87cw2hiYC71bvpD872oYMYXtw66Qp6o"
,
"1Fghq6cgdJEDr6gQBmvba3t6aXAkyZyjr2"
,
"142KsfJLvEA5FJxAgKm9ZDtFVjkRaPdu82"
,
}
total
=
types
.
Coin
*
30000
total
=
types
.
Coin
*
30000
)
)
...
@@ -277,7 +314,7 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
...
@@ -277,7 +314,7 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
{
PrivKeyA
,
false
},
{
PrivKeyA
,
false
},
{
PrivKeyB
,
true
},
{
PrivKeyB
,
true
},
{
PrivKeyC
,
true
},
{
PrivKeyC
,
true
},
//
{PrivKeyD, true},
{
PrivKeyD
,
true
},
}
}
for
_
,
record
:=
range
records
{
for
_
,
record
:=
range
records
{
...
@@ -475,7 +512,7 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
...
@@ -475,7 +512,7 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
require
.
Nil
(
t
,
copyAutonomyProposalBoard
(
nil
))
require
.
Nil
(
t
,
copyAutonomyProposalBoard
(
nil
))
cur
:=
&
auty
.
AutonomyProposalBoard
{
cur
:=
&
auty
.
AutonomyProposalBoard
{
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1900
,
Month
:
1
},
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1900
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
ttend
Ratio
:
100
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
pprove
Ratio
:
100
},
VoteResult
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
VoteResult
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
2
,
Status
:
2
,
Address
:
"123"
,
Address
:
"123"
,
...
@@ -483,19 +520,61 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
...
@@ -483,19 +520,61 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
pre
:=
copyAutonomyProposalBoard
(
cur
)
pre
:=
copyAutonomyProposalBoard
(
cur
)
cur
.
PropBoard
.
Year
=
1800
cur
.
PropBoard
.
Year
=
1800
cur
.
PropBoard
.
Month
=
2
cur
.
PropBoard
.
Month
=
2
cur
.
CurRule
.
BoardA
ttend
Ratio
=
90
cur
.
CurRule
.
BoardA
pprove
Ratio
=
90
cur
.
VoteResult
.
TotalVotes
=
50
cur
.
VoteResult
.
TotalVotes
=
50
cur
.
Address
=
"234"
cur
.
Address
=
"234"
cur
.
Status
=
1
cur
.
Status
=
1
require
.
Equal
(
t
,
1900
,
int
(
pre
.
PropBoard
.
Year
))
require
.
Equal
(
t
,
1900
,
int
(
pre
.
PropBoard
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropBoard
.
Month
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropBoard
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardA
ttend
Ratio
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardA
pprove
Ratio
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
}
}
func
TestVerifyMinerAddr
(
t
*
testing
.
T
)
{
at
:=
newAutonomy
()
.
(
*
Autonomy
)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"state"
,
"state"
,
100
)
at
.
SetStateDB
(
stateDB
)
tx
:=
&
types
.
Transaction
{}
action
:=
newAction
(
at
,
tx
,
0
)
addrs
:=
[]
string
{
AddrA
,
AddrB
,
AddrC
,
}
// 授权地址AddrD
for
_
,
addr
:=
range
addrs
{
tkBind
:=
&
ticketTy
.
TicketBind
{
MinerAddress
:
AddrD
,
ReturnAddress
:
addr
,
}
stateDB
.
Set
(
ticket
.
BindKey
(
addr
),
types
.
Encode
(
tkBind
))
}
_
,
err
:=
action
.
verifyMinerAddr
(
addrs
,
AddrD
)
require
.
NoError
(
t
,
err
)
// ErrMinerAddr
testf
:=
"12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
addrs
=
[]
string
{
testf
}
addr
,
err
:=
action
.
verifyMinerAddr
(
addrs
,
AddrD
)
require
.
Equal
(
t
,
auty
.
ErrMinerAddr
,
err
)
require
.
Equal
(
t
,
testf
,
addr
)
// ErrBindAddr
testf
=
"1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
tkBind
:=
&
ticketTy
.
TicketBind
{
MinerAddress
:
AddrA
,
ReturnAddress
:
testf
,
}
stateDB
.
Set
(
ticket
.
BindKey
(
testf
),
types
.
Encode
(
tkBind
))
addrs
=
[]
string
{
testf
}
addr
,
err
=
action
.
verifyMinerAddr
(
addrs
,
AddrD
)
require
.
Equal
(
t
,
auty
.
ErrBindAddr
,
err
)
require
.
Equal
(
t
,
testf
,
addr
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
auty
.
AutonomyX
,
signType
))
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
auty
.
AutonomyX
,
signType
))
...
...
plugin/dapp/autonomy/executor/projectaction.go
View file @
05b8ae47
...
@@ -317,8 +317,14 @@ func (a *action) pubVotePropProject(voteProb *auty.PubVoteProposalProject) (*typ
...
@@ -317,8 +317,14 @@ func (a *action) pubVotePropProject(voteProb *auty.PubVoteProposalProject) (*typ
return
nil
,
err
return
nil
,
err
}
}
// 挖矿地址验证
if
len
(
voteProb
.
OriginAddr
)
>
0
{
if
len
(
voteProb
.
OriginAddr
)
>
0
{
for
_
,
board
:=
range
voteProb
.
OriginAddr
{
if
err
:=
address
.
CheckAddress
(
board
);
err
!=
nil
{
alog
.
Error
(
"pubVotePropProject "
,
"addr"
,
board
,
"check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalidAddress
}
}
// 挖矿地址验证
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
if
err
!=
nil
{
if
err
!=
nil
{
alog
.
Error
(
"pubVotePropProject "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
alog
.
Error
(
"pubVotePropProject "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
...
...
plugin/dapp/autonomy/executor/projectaction_test.go
View file @
05b8ae47
...
@@ -36,22 +36,15 @@ const (
...
@@ -36,22 +36,15 @@ const (
func
InitBoard
(
stateDB
dbm
.
KV
)
{
func
InitBoard
(
stateDB
dbm
.
KV
)
{
// add active board
// add active board
board
:=
&
auty
.
ProposalBoard
{
act
:=
&
auty
.
ActiveBoard
{
Year
:
2019
,
Boards
:
boards
,
Month
:
11
,
}
Day
:
1
,
stateDB
.
Set
(
activeBoardID
(),
types
.
Encode
(
act
))
Boards
:
[]
string
{
AddrA
,
AddrB
,
AddrC
,
AddrD
},
StartBlockHeight
:
1
,
EndBlockHeight
:
10
,
RealEndBlockHeight
:
5
,
}
stateDB
.
Set
(
activeBoardID
(),
types
.
Encode
(
board
))
}
}
func
InitRule
(
stateDB
dbm
.
KV
)
{
func
InitRule
(
stateDB
dbm
.
KV
)
{
// add active rule
// add active rule
rule
:=
&
auty
.
RuleConfig
{
rule
:=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
boardAttendRatio
,
BoardApproveRatio
:
boardApproveRatio
,
BoardApproveRatio
:
boardApproveRatio
,
PubOpposeRatio
:
pubOpposeRatio
,
PubOpposeRatio
:
pubOpposeRatio
,
ProposalAmount
:
proposalAmount
,
ProposalAmount
:
proposalAmount
,
...
@@ -317,10 +310,21 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
...
@@ -317,10 +310,21 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
appr
bool
appr
bool
}
}
records
:=
[]
record
{
records
:=
[]
record
{
{
PrivKeyA
,
fals
e
},
{
PrivKeyA
,
tru
e
},
{
PrivKeyB
,
true
},
{
PrivKeyB
,
true
},
{
PrivKeyC
,
true
},
{
PrivKeyC
,
true
},
//{PrivKeyD, true},
{
PrivKeyD
,
true
},
{
PrivKey1
,
true
},
{
PrivKey2
,
true
},
{
PrivKey3
,
true
},
{
PrivKey4
,
true
},
{
PrivKey5
,
true
},
{
PrivKey6
,
true
},
{
PrivKey7
,
true
},
{
PrivKey8
,
true
},
{
PrivKey9
,
true
},
{
PrivKey10
,
true
},
}
}
for
_
,
record
:=
range
records
{
for
_
,
record
:=
range
records
{
...
@@ -590,7 +594,7 @@ func terminateProposalProjectTx(parm *auty.TerminateProposalProject) (*types.Tra
...
@@ -590,7 +594,7 @@ func terminateProposalProjectTx(parm *auty.TerminateProposalProject) (*types.Tra
func
TestGetProjectReceiptLog
(
t
*
testing
.
T
)
{
func
TestGetProjectReceiptLog
(
t
*
testing
.
T
)
{
pre
:=
&
auty
.
AutonomyProposalProject
{
pre
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
ttend
Ratio
:
80
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
pprove
Ratio
:
80
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
1
,
Status
:
1
,
...
@@ -598,7 +602,7 @@ func TestGetProjectReceiptLog(t *testing.T) {
...
@@ -598,7 +602,7 @@ func TestGetProjectReceiptLog(t *testing.T) {
}
}
cur
:=
&
auty
.
AutonomyProposalProject
{
cur
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1900
,
Month
:
1
},
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1900
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
ttend
Ratio
:
90
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
pprove
Ratio
:
90
},
Boards
:
[]
string
{
"555"
,
"666"
,
"777"
},
Boards
:
[]
string
{
"555"
,
"666"
,
"777"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
2
,
Status
:
2
,
...
@@ -611,8 +615,8 @@ func TestGetProjectReceiptLog(t *testing.T) {
...
@@ -611,8 +615,8 @@ func TestGetProjectReceiptLog(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
80
),
recpt
.
Prev
.
CurRule
.
BoardA
ttend
Ratio
)
require
.
Equal
(
t
,
int32
(
80
),
recpt
.
Prev
.
CurRule
.
BoardA
pprove
Ratio
)
require
.
Equal
(
t
,
int32
(
90
),
recpt
.
Current
.
CurRule
.
BoardA
ttend
Ratio
)
require
.
Equal
(
t
,
int32
(
90
),
recpt
.
Current
.
CurRule
.
BoardA
pprove
Ratio
)
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
recpt
.
Prev
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
recpt
.
Prev
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
recpt
.
Current
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
recpt
.
Current
.
Boards
)
}
}
...
@@ -621,7 +625,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
...
@@ -621,7 +625,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
require
.
Nil
(
t
,
copyAutonomyProposalProject
(
nil
))
require
.
Nil
(
t
,
copyAutonomyProposalProject
(
nil
))
cur
:=
&
auty
.
AutonomyProposalProject
{
cur
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
ttend
Ratio
:
80
},
CurRule
:
&
auty
.
RuleConfig
{
BoardA
pprove
Ratio
:
80
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
PubVote
:
&
auty
.
PublicVote
{
Publicity
:
true
},
PubVote
:
&
auty
.
PublicVote
{
Publicity
:
true
},
...
@@ -631,7 +635,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
...
@@ -631,7 +635,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
pre
:=
copyAutonomyProposalProject
(
cur
)
pre
:=
copyAutonomyProposalProject
(
cur
)
cur
.
PropProject
.
Year
=
1900
cur
.
PropProject
.
Year
=
1900
cur
.
PropProject
.
Month
=
2
cur
.
PropProject
.
Month
=
2
cur
.
CurRule
.
BoardA
ttend
Ratio
=
90
cur
.
CurRule
.
BoardA
pprove
Ratio
=
90
cur
.
Boards
=
[]
string
{
"555"
,
"666"
,
"777"
}
cur
.
Boards
=
[]
string
{
"555"
,
"666"
,
"777"
}
cur
.
BoardVoteRes
.
TotalVotes
=
90
cur
.
BoardVoteRes
.
TotalVotes
=
90
cur
.
PubVote
.
Publicity
=
false
cur
.
PubVote
.
Publicity
=
false
...
@@ -641,7 +645,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
...
@@ -641,7 +645,7 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
require
.
Equal
(
t
,
1800
,
int
(
pre
.
PropProject
.
Year
))
require
.
Equal
(
t
,
1800
,
int
(
pre
.
PropProject
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropProject
.
Month
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropProject
.
Month
))
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
pre
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
pre
.
Boards
)
require
.
Equal
(
t
,
80
,
int
(
pre
.
CurRule
.
BoardA
ttend
Ratio
))
require
.
Equal
(
t
,
80
,
int
(
pre
.
CurRule
.
BoardA
pprove
Ratio
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
BoardVoteRes
.
TotalVotes
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
BoardVoteRes
.
TotalVotes
))
...
...
plugin/dapp/autonomy/executor/ruleaction.go
View file @
05b8ae47
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/common/address"
)
)
const
(
const
(
...
@@ -178,8 +179,14 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
...
@@ -178,8 +179,14 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
return
nil
,
err
return
nil
,
err
}
}
// 挖矿地址验证
if
len
(
voteProb
.
OriginAddr
)
>
0
{
if
len
(
voteProb
.
OriginAddr
)
>
0
{
for
_
,
board
:=
range
voteProb
.
OriginAddr
{
if
err
:=
address
.
CheckAddress
(
board
);
err
!=
nil
{
alog
.
Error
(
"votePropRule "
,
"addr"
,
board
,
"check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalidAddress
}
}
// 挖矿地址验证
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
addr
,
err
:=
a
.
verifyMinerAddr
(
voteProb
.
OriginAddr
,
a
.
fromaddr
)
if
err
!=
nil
{
if
err
!=
nil
{
alog
.
Error
(
"votePropRule "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
alog
.
Error
(
"votePropRule "
,
"from addr"
,
a
.
fromaddr
,
"error addr"
,
addr
,
"ProposalID"
,
...
...
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
05b8ae47
...
@@ -21,12 +21,11 @@ import (
...
@@ -21,12 +21,11 @@ import (
)
)
const
(
const
(
testBoardAttendRatio
int32
=
60
testBoardApproveRatio
int32
=
60
testBoardApproveRatio
int32
=
60
testPubOpposeRatio
int32
=
3
0
testPubOpposeRatio
int32
=
3
5
testProposalAmount
int64
=
0
testProposalAmount
=
minProposalAmount
*
2
testLargeProjectAmount
int64
=
1
testLargeProjectAmount
=
minLargeProjectAmount
*
2
testPublicPeriod
int32
=
100
testPublicPeriod
=
minPublicPeriod
)
)
func
TestRevokeProposalRule
(
t
*
testing
.
T
)
{
func
TestRevokeProposalRule
(
t
*
testing
.
T
)
{
...
@@ -59,7 +58,6 @@ func testPropRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.K
...
@@ -59,7 +58,6 @@ func testPropRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.K
Month
:
7
,
Month
:
7
,
Day
:
10
,
Day
:
10
,
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
testBoardAttendRatio
,
BoardApproveRatio
:
testBoardApproveRatio
,
BoardApproveRatio
:
testBoardApproveRatio
,
PubOpposeRatio
:
testPubOpposeRatio
,
PubOpposeRatio
:
testPubOpposeRatio
,
ProposalAmount
:
testProposalAmount
,
ProposalAmount
:
testProposalAmount
,
...
@@ -164,7 +162,6 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
...
@@ -164,7 +162,6 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
boardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
...
@@ -218,7 +215,7 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
...
@@ -218,7 +215,7 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
{
PrivKeyA
,
false
},
{
PrivKeyA
,
false
},
{
PrivKeyB
,
true
},
{
PrivKeyB
,
true
},
{
PrivKeyC
,
true
},
{
PrivKeyC
,
true
},
//
{PrivKeyD, true},
{
PrivKeyD
,
true
},
}
}
for
_
,
record
:=
range
records
{
for
_
,
record
:=
range
records
{
...
@@ -291,10 +288,9 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
...
@@ -291,10 +288,9 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
testBoardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
testBoardApproveRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
testBoardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
testPubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
testPubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
p
roposalAmount
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
testP
roposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
testLargeProjectAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
testLargeProjectAmount
)
require
.
Equal
(
t
,
rule
.
PublicPeriod
,
testPublicPeriod
)
require
.
Equal
(
t
,
rule
.
PublicPeriod
,
testPublicPeriod
)
}
}
...
@@ -373,7 +369,6 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
...
@@ -373,7 +369,6 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardAttendRatio
,
boardAttendRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
...
@@ -445,7 +440,6 @@ func TestUpgradeRule(t *testing.T) {
...
@@ -445,7 +440,6 @@ func TestUpgradeRule(t *testing.T) {
new
:=
upgradeRule
(
nil
,
&
auty
.
RuleConfig
{})
new
:=
upgradeRule
(
nil
,
&
auty
.
RuleConfig
{})
require
.
Nil
(
t
,
new
)
require
.
Nil
(
t
,
new
)
cur
:=
&
auty
.
RuleConfig
{
cur
:=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
1
,
BoardApproveRatio
:
2
,
BoardApproveRatio
:
2
,
PubOpposeRatio
:
3
,
PubOpposeRatio
:
3
,
ProposalAmount
:
4
,
ProposalAmount
:
4
,
...
@@ -453,7 +447,6 @@ func TestUpgradeRule(t *testing.T) {
...
@@ -453,7 +447,6 @@ func TestUpgradeRule(t *testing.T) {
PublicPeriod
:
6
,
PublicPeriod
:
6
,
}
}
modify
:=
&
auty
.
RuleConfig
{
modify
:=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
0
,
BoardApproveRatio
:
-
1
,
BoardApproveRatio
:
-
1
,
PubOpposeRatio
:
0
,
PubOpposeRatio
:
0
,
ProposalAmount
:
-
1
,
ProposalAmount
:
-
1
,
...
@@ -462,7 +455,6 @@ func TestUpgradeRule(t *testing.T) {
...
@@ -462,7 +455,6 @@ func TestUpgradeRule(t *testing.T) {
}
}
new
=
upgradeRule
(
cur
,
modify
)
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
require
.
NotNil
(
t
,
new
)
require
.
Equal
(
t
,
new
.
BoardAttendRatio
,
cur
.
BoardAttendRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
cur
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
cur
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
cur
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
cur
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
cur
.
ProposalAmount
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
cur
.
ProposalAmount
)
...
@@ -470,7 +462,6 @@ func TestUpgradeRule(t *testing.T) {
...
@@ -470,7 +462,6 @@ func TestUpgradeRule(t *testing.T) {
require
.
Equal
(
t
,
new
.
PublicPeriod
,
cur
.
PublicPeriod
)
require
.
Equal
(
t
,
new
.
PublicPeriod
,
cur
.
PublicPeriod
)
modify
=
&
auty
.
RuleConfig
{
modify
=
&
auty
.
RuleConfig
{
BoardAttendRatio
:
10
,
BoardApproveRatio
:
20
,
BoardApproveRatio
:
20
,
PubOpposeRatio
:
30
,
PubOpposeRatio
:
30
,
ProposalAmount
:
40
,
ProposalAmount
:
40
,
...
@@ -479,7 +470,6 @@ func TestUpgradeRule(t *testing.T) {
...
@@ -479,7 +470,6 @@ func TestUpgradeRule(t *testing.T) {
}
}
new
=
upgradeRule
(
cur
,
modify
)
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
require
.
NotNil
(
t
,
new
)
require
.
Equal
(
t
,
new
.
BoardAttendRatio
,
modify
.
BoardAttendRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
modify
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
BoardApproveRatio
,
modify
.
BoardApproveRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
modify
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
PubOpposeRatio
,
modify
.
PubOpposeRatio
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
modify
.
ProposalAmount
)
require
.
Equal
(
t
,
new
.
ProposalAmount
,
modify
.
ProposalAmount
)
...
...
plugin/dapp/autonomy/types/errors.go
View file @
05b8ae47
...
@@ -33,4 +33,6 @@ var (
...
@@ -33,4 +33,6 @@ var (
ErrChangeBoardAddr
=
errors
.
New
(
"ErrChangeBoardAddr"
)
ErrChangeBoardAddr
=
errors
.
New
(
"ErrChangeBoardAddr"
)
// ErrBoardNumber 董事会成员数错误
// ErrBoardNumber 董事会成员数错误
ErrBoardNumber
=
errors
.
New
(
"ErrBoardNumber"
)
ErrBoardNumber
=
errors
.
New
(
"ErrBoardNumber"
)
// ErrRepeatAddr 重复地址
ErrRepeatAddr
=
errors
.
New
(
"ErrRepeatAddr"
)
)
)
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