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
5b29261b
Commit
5b29261b
authored
Jul 19, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test
parent
e720e6de
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
540 additions
and
38 deletions
+540
-38
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+12
-4
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+9
-6
projectaction.go
plugin/dapp/autonomy/executor/projectaction.go
+18
-8
projectaction_test.go
plugin/dapp/autonomy/executor/projectaction_test.go
+477
-0
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+16
-12
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+8
-8
No files found.
plugin/dapp/autonomy/executor/boardaction.go
View file @
5b29261b
...
...
@@ -403,10 +403,18 @@ func copyAutonomyProposalBoard(cur *auty.AutonomyProposalBoard) *auty.AutonomyPr
return
nil
}
newAut
:=
*
cur
newBoard
:=
*
cur
.
GetPropBoard
()
newRes
:=
*
cur
.
GetVoteResult
()
newAut
.
PropBoard
=
&
newBoard
newAut
.
VoteResult
=
&
newRes
if
cur
.
PropBoard
!=
nil
{
newBoard
:=
*
cur
.
GetPropBoard
()
newAut
.
PropBoard
=
&
newBoard
}
if
cur
.
CurRule
!=
nil
{
newRule
:=
*
cur
.
GetCurRule
()
newAut
.
CurRule
=
&
newRule
}
if
cur
.
VoteResult
!=
nil
{
newRes
:=
*
cur
.
GetVoteResult
()
newAut
.
VoteResult
=
&
newRes
}
return
&
newAut
}
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
5b29261b
...
...
@@ -460,22 +460,25 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
require
.
Nil
(
t
,
copyAutonomyProposalBoard
(
nil
))
cur
:=
&
auty
.
AutonomyProposalBoard
{
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1900
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
100
},
VoteResult
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
2
,
Address
:
"123"
,
}
new
:=
copyAutonomyProposalBoard
(
cur
)
pre
:=
copyAutonomyProposalBoard
(
cur
)
cur
.
PropBoard
.
Year
=
1800
cur
.
PropBoard
.
Month
=
2
cur
.
CurRule
.
BoardAttendRatio
=
90
cur
.
VoteResult
.
TotalVotes
=
50
cur
.
Address
=
"234"
cur
.
Status
=
1
require
.
Equal
(
t
,
1900
,
int
(
new
.
PropBoard
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
new
.
PropBoard
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
new
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
new
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
require
.
Equal
(
t
,
1900
,
int
(
pre
.
PropBoard
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropBoard
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardAttendRatio
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
...
...
plugin/dapp/autonomy/executor/projectaction.go
View file @
5b29261b
...
...
@@ -15,8 +15,8 @@ import (
func
(
a
*
action
)
propProject
(
prob
*
auty
.
ProposalProject
)
(
*
types
.
Receipt
,
error
)
{
if
err
:=
address
.
CheckAddress
(
prob
.
ToAddr
);
err
!=
nil
{
alog
.
Error
(
"propProject "
,
"check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalid
Param
alog
.
Error
(
"propProject "
,
"
addr"
,
prob
.
ToAddr
,
"
check toAddr error"
,
err
)
return
nil
,
types
.
ErrInvalid
Address
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
Amount
<=
0
{
...
...
@@ -465,12 +465,22 @@ func copyAutonomyProposalProject(cur *auty.AutonomyProposalProject) *auty.Autono
return
nil
}
newAut
:=
*
cur
newProject
:=
*
cur
.
GetPropProject
()
newRes
:=
*
cur
.
GetBoardVoteRes
()
newPub
:=
*
cur
.
GetPubVote
()
newAut
.
PropProject
=
&
newProject
newAut
.
BoardVoteRes
=
&
newRes
newAut
.
PubVote
=
&
newPub
if
cur
.
PropProject
!=
nil
{
newProject
:=
*
cur
.
GetPropProject
()
newAut
.
PropProject
=
&
newProject
}
if
cur
.
CurRule
!=
nil
{
newRule
:=
*
cur
.
GetCurRule
()
newAut
.
CurRule
=
&
newRule
}
if
cur
.
BoardVoteRes
!=
nil
{
newRes
:=
*
cur
.
GetBoardVoteRes
()
newAut
.
BoardVoteRes
=
&
newRes
}
if
cur
.
PubVote
!=
nil
{
newPub
:=
*
cur
.
GetPubVote
()
newAut
.
PubVote
=
&
newPub
}
return
&
newAut
}
plugin/dapp/autonomy/executor/projectaction_test.go
0 → 100644
View file @
5b29261b
// 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"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/require"
"github.com/33cn/chain33/types"
apimock
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/account"
_
"github.com/33cn/chain33/system"
"github.com/stretchr/testify/mock"
"github.com/33cn/chain33/common/address"
drivers
"github.com/33cn/chain33/system/dapp"
)
//const (
// testBoardAttendRatio int32 = 60
// testBoardApproveRatio int32 = 60
// testPubOpposeRatio int32 = 30
// testProposalAmount int64 = 0
// testLargeProjectAmount int64 = 1
//)
func
InitProject
(
stateDB
dbm
.
KV
)
{
// add active board
board
:=
&
auty
.
ProposalBoard
{
Year
:
2019
,
Month
:
11
,
Day
:
1
,
Boards
:
[]
string
{
AddrA
,
AddrB
,
AddrC
,
AddrD
},
StartBlockHeight
:
1
,
EndBlockHeight
:
10
,
RealEndBlockHeight
:
5
,
}
stateDB
.
Set
(
activeBoardID
(),
types
.
Encode
(
board
))
}
func
TestPropProject
(
t
*
testing
.
T
)
{
env
,
exec
,
_
,
_
:=
InitEnv
()
opts
:=
[]
*
auty
.
ProposalProject
{
&
auty
.
ProposalProject
{
// check toaddr
ToAddr
:
"1111111111"
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
},
&
auty
.
ProposalProject
{
// check amount
Amount
:
0
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
},
&
auty
.
ProposalProject
{
// check StartBlockHeight EndBlockHeight
Amount
:
10
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
-
1
,
EndBlockHeight
:
env
.
blockHeight
-
1
,
},
&
auty
.
ProposalProject
{
// check activeboard
Amount
:
100
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
},
}
result
:=
[]
error
{
types
.
ErrInvalidAddress
,
types
.
ErrInvalidParam
,
types
.
ErrInvalidParam
,
types
.
ErrNotFound
,
}
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
for
i
,
tcase
:=
range
opts
{
pbtx
,
err
:=
propProjectTx
(
tcase
)
require
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
_
,
err
=
exec
.
Exec
(
pbtx
,
int
(
i
))
require
.
Error
(
t
,
err
,
result
[
i
])
}
}
func
TestRevokeProposalProject
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
InitProject
(
stateDB
)
// PropProject
testPropProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
//RevokeProposalProject
revokeProposalProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
false
)
}
func
TestVoteProposalProject
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
InitProject
(
stateDB
)
// PropProject
testPropProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
//voteProposalProject
voteProposalProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
}
func
TestTerminateProposalProject
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
InitProject
(
stateDB
)
// PropProject
testPropProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
//terminateProposalProject
terminateProposalProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
}
func
testPropProject
(
t
*
testing
.
T
,
env
*
execEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
opt1
:=
&
auty
.
ProposalProject
{
Year
:
2019
,
Month
:
7
,
Day
:
10
,
Amount
:
types
.
Coin
*
100
,
ToAddr
:
AddrD
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
}
pbtx
,
err
:=
propProjectTx
(
opt1
)
require
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
pbtx
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
pbtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
// 更新tahash
env
.
txHash
=
common
.
ToHex
(
pbtx
.
Hash
())
env
.
startHeight
=
opt1
.
StartBlockHeight
env
.
endHeight
=
opt1
.
EndBlockHeight
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
}
func
propProjectTx
(
parm
*
auty
.
ProposalProject
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
auty
.
AutonomyAction
{
Ty
:
auty
.
AutonomyActionPropProject
,
Value
:
&
auty
.
AutonomyAction_PropProject
{
PropProject
:
parm
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
}
func
revokeProposalProject
(
t
*
testing
.
T
,
env
*
execEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
proposalID
:=
env
.
txHash
opt2
:=
&
auty
.
RevokeProposalProject
{
ProposalID
:
proposalID
,
}
rtx
,
err
:=
revokeProposalProjectTx
(
opt2
)
require
.
NoError
(
t
,
err
)
rtx
,
err
=
signTx
(
rtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
rtx
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
rtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check Project
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
//action := newAction(au, &types.Transaction{}, 0)
}
func
revokeProposalProjectTx
(
parm
*
auty
.
RevokeProposalProject
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
auty
.
AutonomyAction
{
Ty
:
auty
.
AutonomyActionRvkPropProject
,
Value
:
&
auty
.
AutonomyAction_RvkPropProject
{
RvkPropProject
:
parm
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
}
func
voteProposalProject
(
t
*
testing
.
T
,
env
*
execEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"StoreList"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreListReply
{},
nil
)
api
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
types
.
Header
{
StateHash
:
[]
byte
(
""
)},
nil
)
hear
:=
&
types
.
Header
{
StateHash
:
[]
byte
(
""
)}
api
.
On
(
"GetHeaders"
,
mock
.
Anything
)
.
Return
(
&
types
.
Headers
{
Items
:
[]
*
types
.
Header
{
hear
}},
nil
)
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
*
4
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
acc
=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
}
val1
:=
types
.
Encode
(
acc
)
values1
:=
[][]
byte
{
val1
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values1
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
proposalID
:=
env
.
txHash
// 4人参与投票,3人赞成票,1人反对票
type
record
struct
{
priv
string
appr
bool
}
records
:=
[]
record
{
{
PrivKeyA
,
false
},
{
PrivKeyB
,
false
},
{
PrivKeyC
,
true
},
{
PrivKeyD
,
true
},
}
for
_
,
record
:=
range
records
{
opt
:=
&
auty
.
VoteProposalProject
{
ProposalID
:
proposalID
,
Approve
:
record
.
appr
,
}
tx
,
err
:=
voteProposalProjectTx
(
opt
)
require
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
// 设定当前高度为投票高度
exec
.
SetEnv
(
env
.
startHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
tx
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
}
// check
// balance
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propProjectID
(
proposalID
))
require
.
NoError
(
t
,
err
)
cur
:=
&
auty
.
AutonomyProposalProject
{}
err
=
types
.
Decode
(
value
,
cur
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropProject
),
cur
.
Status
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
//require.Equal(t, true, cur.VoteResult.Pass)
// check Project
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
//action := newAction(au, &types.Transaction{}, 0)
}
func
voteProposalProjectTx
(
parm
*
auty
.
VoteProposalProject
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
auty
.
AutonomyAction
{
Ty
:
auty
.
AutonomyActionVotePropProject
,
Value
:
&
auty
.
AutonomyAction_VotePropProject
{
VotePropProject
:
parm
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
}
func
terminateProposalProject
(
t
*
testing
.
T
,
env
*
execEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"StoreList"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreListReply
{},
nil
)
api
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
types
.
Header
{
StateHash
:
[]
byte
(
""
)},
nil
)
hear
:=
&
types
.
Header
{
StateHash
:
[]
byte
(
""
)}
api
.
On
(
"GetHeaders"
,
mock
.
Anything
)
.
Return
(
&
types
.
Headers
{
Items
:
[]
*
types
.
Header
{
hear
}},
nil
)
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
*
4
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
proposalID
:=
env
.
txHash
opt
:=
&
auty
.
TerminateProposalProject
{
ProposalID
:
proposalID
,
}
tx
,
err
:=
terminateProposalProjectTx
(
opt
)
require
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
exec
.
SetEnv
(
env
.
endHeight
+
1
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
tx
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
}
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check Project
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
}
au
.
SetStateDB
(
stateDB
)
au
.
SetLocalDB
(
kvdb
)
//action := newAction(au, &types.Transaction{}, 0)
}
func
terminateProposalProjectTx
(
parm
*
auty
.
TerminateProposalProject
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
auty
.
AutonomyAction
{
Ty
:
auty
.
AutonomyActionTmintPropProject
,
Value
:
&
auty
.
AutonomyAction_TmintPropProject
{
TmintPropProject
:
parm
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
}
func
TestGetProjectReceiptLog
(
t
*
testing
.
T
)
{
pre
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
80
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
1
,
Address
:
"121"
,
}
cur
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1900
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
90
},
Boards
:
[]
string
{
"555"
,
"666"
,
"777"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
Status
:
2
,
Address
:
"123"
,
}
log
:=
getProjectReceiptLog
(
pre
,
cur
,
2
)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
recpt
:=
&
auty
.
ReceiptProposalProject
{}
err
:=
types
.
Decode
(
log
.
Log
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropProject
.
Year
)
require
.
Equal
(
t
,
int32
(
80
),
recpt
.
Prev
.
CurRule
.
BoardAttendRatio
)
require
.
Equal
(
t
,
int32
(
90
),
recpt
.
Current
.
CurRule
.
BoardAttendRatio
)
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
recpt
.
Prev
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
recpt
.
Current
.
Boards
)
}
func
TestCopyAutonomyProposalProject
(
t
*
testing
.
T
)
{
require
.
Nil
(
t
,
copyAutonomyProposalProject
(
nil
))
cur
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
80
},
Boards
:
[]
string
{
"111"
,
"222"
,
"333"
},
BoardVoteRes
:
&
auty
.
VoteResult
{
TotalVotes
:
100
},
PubVote
:
&
auty
.
PublicVote
{
Publicity
:
true
},
Status
:
2
,
Address
:
"123"
,
}
pre
:=
copyAutonomyProposalProject
(
cur
)
cur
.
PropProject
.
Year
=
1900
cur
.
PropProject
.
Month
=
2
cur
.
CurRule
.
BoardAttendRatio
=
90
cur
.
Boards
=
[]
string
{
"555"
,
"666"
,
"777"
}
cur
.
BoardVoteRes
.
TotalVotes
=
90
cur
.
PubVote
.
Publicity
=
false
cur
.
Address
=
"234"
cur
.
Status
=
1
require
.
Equal
(
t
,
1800
,
int
(
pre
.
PropProject
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropProject
.
Month
))
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
pre
.
Boards
)
require
.
Equal
(
t
,
80
,
int
(
pre
.
CurRule
.
BoardAttendRatio
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
BoardVoteRes
.
TotalVotes
))
require
.
Equal
(
t
,
true
,
pre
.
PubVote
.
Publicity
)
require
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
cur
.
Boards
)
}
\ No newline at end of file
plugin/dapp/autonomy/executor/ruleaction.go
View file @
5b29261b
...
...
@@ -314,18 +314,22 @@ func copyAutonomyProposalRule(cur *auty.AutonomyProposalRule) *auty.AutonomyProp
return
nil
}
newAut
:=
*
cur
newPropRule
:=
*
cur
.
GetPropRule
()
var
newCfg
*
auty
.
RuleConfig
if
newPropRule
.
RuleCfg
!=
nil
{
cfg
:=
*
cur
.
GetPropRule
()
.
GetRuleCfg
()
newCfg
=
&
cfg
}
newRule
:=
*
cur
.
GetRule
()
newRes
:=
*
cur
.
GetVoteResult
()
newAut
.
PropRule
=
&
newPropRule
newAut
.
PropRule
.
RuleCfg
=
newCfg
newAut
.
Rule
=
&
newRule
newAut
.
VoteResult
=
&
newRes
if
cur
.
PropRule
!=
nil
{
newPropRule
:=
*
cur
.
GetPropRule
()
newAut
.
PropRule
=
&
newPropRule
if
cur
.
PropRule
.
RuleCfg
!=
nil
{
cfg
:=
*
cur
.
GetPropRule
()
.
GetRuleCfg
()
newAut
.
PropRule
.
RuleCfg
=
&
cfg
}
}
if
cur
.
Rule
!=
nil
{
newRule
:=
*
cur
.
GetRule
()
newAut
.
Rule
=
&
newRule
}
if
cur
.
VoteResult
!=
nil
{
newRes
:=
*
cur
.
GetVoteResult
()
newAut
.
VoteResult
=
&
newRes
}
return
&
newAut
}
...
...
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
5b29261b
...
...
@@ -406,7 +406,7 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
Status
:
2
,
Address
:
"123"
,
}
new
:=
copyAutonomyProposalRule
(
cur
)
pre
:=
copyAutonomyProposalRule
(
cur
)
cur
.
PropRule
.
Year
=
1800
cur
.
PropRule
.
Month
=
2
cur
.
PropRule
.
RuleCfg
.
BoardApproveRatio
=
90
...
...
@@ -415,13 +415,13 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
cur
.
Address
=
"234"
cur
.
Status
=
1
require
.
Equal
(
t
,
1900
,
int
(
new
.
PropRule
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
new
.
PropRule
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
new
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
new
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
require
.
Equal
(
t
,
80
,
int
(
new
.
PropRule
.
RuleCfg
.
BoardApproveRatio
))
require
.
Equal
(
t
,
100
,
int
(
new
.
Rule
.
BoardApproveRatio
))
require
.
Equal
(
t
,
1900
,
int
(
pre
.
PropRule
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropRule
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
require
.
Equal
(
t
,
80
,
int
(
pre
.
PropRule
.
RuleCfg
.
BoardApproveRatio
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
Rule
.
BoardApproveRatio
))
}
func
TestUpgradeRule
(
t
*
testing
.
T
)
{
...
...
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