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
6f4f7852
Commit
6f4f7852
authored
Aug 23, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add change test
parent
9771febb
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
744 additions
and
589 deletions
+744
-589
round_state.go
plugin/consensus/tendermint/types/round_state.go
+3
-3
board_test.go
plugin/dapp/autonomy/executor/board_test.go
+45
-46
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+13
-11
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+92
-77
change_test.go
plugin/dapp/autonomy/executor/change_test.go
+45
-46
changeaction.go
plugin/dapp/autonomy/executor/changeaction.go
+2
-1
changeaction_test.go
plugin/dapp/autonomy/executor/changeaction_test.go
+59
-60
project_test.go
plugin/dapp/autonomy/executor/project_test.go
+45
-46
projectaction.go
plugin/dapp/autonomy/executor/projectaction.go
+3
-2
projectaction_test.go
plugin/dapp/autonomy/executor/projectaction_test.go
+159
-97
rule_test.go
plugin/dapp/autonomy/executor/rule_test.go
+75
-76
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+2
-1
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+195
-117
certutils.go
...rt/authority/tools/cryptogen/generator/utils/certutils.go
+6
-6
No files found.
plugin/consensus/tendermint/types/round_state.go
View file @
6f4f7852
...
...
@@ -117,9 +117,9 @@ type RoundState struct {
// RoundStateMessage ...
func
(
rs
*
RoundState
)
RoundStateMessage
()
*
tmtypes
.
NewRoundStepMsg
{
return
&
tmtypes
.
NewRoundStepMsg
{
Height
:
rs
.
Height
,
Round
:
int32
(
rs
.
Round
),
Step
:
int32
(
rs
.
Step
),
Height
:
rs
.
Height
,
Round
:
int32
(
rs
.
Round
),
Step
:
int32
(
rs
.
Step
),
SecondsSinceStartTime
:
int32
(
time
.
Since
(
rs
.
StartTime
)
.
Seconds
()),
LastCommitRound
:
int32
(
rs
.
LastCommit
.
Round
()),
}
...
...
plugin/dapp/autonomy/executor/board_test.go
View file @
6f4f7852
...
...
@@ -13,7 +13,6 @@ import (
"github.com/33cn/chain33/util"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestExecLocalBoard
(
t
*
testing
.
T
)
{
...
...
@@ -49,14 +48,14 @@ func testexecLocalBoard(t *testing.T, auto bool) {
var
err
error
if
!
auto
{
set
,
err
=
au
.
execLocalBoard
(
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalBoard
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -78,8 +77,8 @@ func testexecLocalBoard(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropBoard
,
Log
:
types
.
Encode
(
receiptBoard1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -89,8 +88,8 @@ func testexecLocalBoard(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropBoard
,
Log
:
types
.
Encode
(
receiptBoard1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -114,8 +113,8 @@ func testexecLocalBoard(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropBoard
,
Log
:
types
.
Encode
(
receiptBoard2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -125,8 +124,8 @@ func testexecLocalBoard(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropBoard
,
Log
:
types
.
Encode
(
receiptBoard2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -168,13 +167,13 @@ func testexecDelLocalBoard(t *testing.T) {
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
:=
au
.
execAutoLocalBoard
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
...
...
@@ -206,8 +205,8 @@ func testexecDelLocalBoard(t *testing.T) {
tx
,
err
=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalBoard
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// 正常测试退回
...
...
@@ -215,15 +214,15 @@ func testexecDelLocalBoard(t *testing.T) {
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalBoard
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalBoard
(
t
,
kvdb
,
cur
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalBoard
(
t
,
kvdb
,
pre1
)
...
...
@@ -238,9 +237,9 @@ func TestGetProposalBoard(t *testing.T) {
tx
:=
"1111111111111111111"
storedb
.
Set
(
propBoardID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalBoard
{}))
rsp
,
err
:=
au
.
getProposalBoard
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
rsp
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
}
func
TestListProposalBoard
(
t
*
testing
.
T
)
{
...
...
@@ -288,9 +287,9 @@ func TestListProposalBoard(t *testing.T) {
cur
.
Index
=
int32
(
tcase
.
index
)
err
:=
table
.
Replace
(
cur
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kv
,
err
:=
table
.
Save
()
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kvs
=
append
(
kvs
,
kv
...
)
}
...
...
@@ -303,12 +302,12 @@ func TestListProposalBoard(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
:=
au
.
listProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
k
:=
2
for
_
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
k
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
k
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
k
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
k
]
.
Index
,
int32
(
tcase
.
index
))
k
--
}
...
...
@@ -320,11 +319,11 @@ func TestListProposalBoard(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
i
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
i
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
i
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
i
]
.
Index
,
int32
(
tcase
.
index
))
}
// 翻页查找
...
...
@@ -335,12 +334,12 @@ func TestListProposalBoard(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Height
index
:=
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Index
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
assert
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
assert
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
req
=
&
auty
.
ReqQueryProposalBoard
{
Status
:
auty
.
AutonomyStatusProposalBoard
,
...
...
@@ -350,12 +349,12 @@ func TestListProposalBoard(t *testing.T) {
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
2
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
}
func
checkExecLocalBoard
(
t
*
testing
.
T
,
kvdb
db
.
KVDB
,
cur
*
auty
.
AutonomyProposalBoard
)
{
...
...
plugin/dapp/autonomy/executor/boardaction.go
View file @
6f4f7852
...
...
@@ -19,16 +19,17 @@ import (
)
const
(
minBoards
=
20
maxBoards
=
40
publicPeriod
int32
=
17280
*
7
// 公示一周时间,以区块高度计算
ticketPrice
=
types
.
Coin
*
3000
// 单张票价
largeProjectAmount
=
types
.
Coin
*
100
*
10000
// 重大项目公示金额阈值
proposalAmount
=
types
.
Coin
*
500
// 创建者消耗金额
boardApproveRatio
int32
=
66
// 董事会成员赞成率,以%计,可修改
pubAttendRatio
int32
=
75
// 全体持票人参与率,以%计
pubApproveRatio
int32
=
66
// 全体持票人赞成率,以%计
pubOpposeRatio
int32
=
33
// 全体持票人否决率,以%计
minBoards
=
20
maxBoards
=
40
publicPeriod
int32
=
17280
*
7
// 公示一周时间,以区块高度计算
ticketPrice
=
types
.
Coin
*
3000
// 单张票价
largeProjectAmount
=
types
.
Coin
*
100
*
10000
// 重大项目公示金额阈值
proposalAmount
=
types
.
Coin
*
500
// 创建者消耗金额
boardApproveRatio
int32
=
66
// 董事会成员赞成率,以%计,可修改
pubAttendRatio
int32
=
75
// 全体持票人参与率,以%计
pubApproveRatio
int32
=
66
// 全体持票人赞成率,以%计
pubOpposeRatio
int32
=
33
// 全体持票人否决率,以%计
startEndBlockPeriod
=
720
// 提案开始结束最小周期
)
type
action
struct
{
...
...
@@ -56,7 +57,8 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
return
nil
,
types
.
ErrInvalidParam
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
{
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
StartBlockHeight
+
startEndBlockPeriod
>
prob
.
EndBlockHeight
{
alog
.
Error
(
"propBoard height invaild"
,
"StartBlockHeight"
,
prob
.
StartBlockHeight
,
"EndBlockHeight"
,
prob
.
EndBlockHeight
,
"height"
,
a
.
height
)
return
nil
,
types
.
ErrInvalidParam
...
...
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
6f4f7852
...
...
@@ -22,8 +22,8 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
ticket
"github.com/33cn/plugin/plugin/dapp/ticket/executor"
ticketTy
"github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
// ExecEnv exec environment
...
...
@@ -173,6 +173,16 @@ func InitEnv() (*ExecEnv, drivers.Driver, dbm.KV, dbm.KVDB) {
return
env
,
exec
,
stateDB
,
kvdb
}
func
InitMinerAddr
(
stateDB
dbm
.
KV
,
addrs
[]
string
,
bind
string
)
{
for
_
,
addr
:=
range
addrs
{
tkBind
:=
&
ticketTy
.
TicketBind
{
MinerAddress
:
bind
,
ReturnAddress
:
addr
,
}
stateDB
.
Set
(
ticket
.
BindKey
(
addr
),
types
.
Encode
(
tkBind
))
}
}
func
TestRevokeProposalBoard
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
// PropBoard
...
...
@@ -204,17 +214,17 @@ func testPropBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.
Day
:
10
,
Boards
:
boards
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
}
pbtx
,
err
:=
propBoardTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
...
...
@@ -225,8 +235,8 @@ func testPropBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.
// local
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -242,7 +252,7 @@ func testPropBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
assert
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
}
func
propBoardTx
(
parm
*
auty
.
ProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -262,13 +272,13 @@ func revokeProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
ProposalID
:
proposalID
,
}
rtx
,
err
:=
revokeProposalBoardTx
(
opt2
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
rtx
,
err
=
signTx
(
rtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -277,8 +287,8 @@ func revokeProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -286,13 +296,13 @@ func revokeProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
rtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
}
func
revokeProposalBoardTx
(
parm
*
auty
.
RevokeProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -334,31 +344,32 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
proposalID
:=
env
.
txHash
// 4人参与投票,3人赞成票,1人反对票
type
record
struct
{
priv
string
appr
bool
priv
string
appr
bool
origin
[]
string
}
records
:=
[]
record
{
{
PrivKeyA
,
false
},
{
PrivKeyB
,
true
},
{
PrivKeyC
,
true
},
{
PrivKeyD
,
true
},
{
priv
:
PrivKeyA
,
appr
:
false
},
{
priv
:
PrivKey1
,
appr
:
true
,
origin
:
[]
string
{
AddrB
,
AddrC
,
AddrD
}},
}
InitMinerAddr
(
stateDB
,
[]
string
{
AddrB
,
AddrC
,
AddrD
},
Addr1
)
for
_
,
record
:=
range
records
{
for
i
,
record
:=
range
records
{
opt
:=
&
auty
.
VoteProposalBoard
{
ProposalID
:
proposalID
,
Approve
:
record
.
appr
,
OriginAddr
:
record
.
origin
,
}
tx
,
err
:=
voteProposalBoardTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -366,8 +377,8 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -375,36 +386,40 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// 每次需要重新设置,对于下一个是多个授权地址的需要设置多次
if
i
+
1
<
len
(
records
)
{
for
j
:=
0
;
j
<
len
(
records
[
i
+
1
]
.
origin
);
j
++
{
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
}
}
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
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
assert
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propBoardID
(
proposalID
))
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
cur
:=
&
auty
.
AutonomyProposalBoard
{}
err
=
types
.
Decode
(
value
,
cur
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropBoard
),
cur
.
Status
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
require
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropBoard
),
cur
.
Status
)
assert
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
assert
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
}
func
voteProposalBoardTx
(
parm
*
auty
.
VoteProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -440,13 +455,13 @@ func terminateProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
ProposalID
:
proposalID
,
}
tx
,
err
:=
terminateProposalBoardTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -455,8 +470,8 @@ func terminateProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -464,13 +479,13 @@ func terminateProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
}
func
terminateProposalBoardTx
(
parm
*
auty
.
TerminateProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -508,9 +523,9 @@ func TestGetStartHeightVoteAccount(t *testing.T) {
Return
(
&
types
.
Headers
{
Items
:
[]
*
types
.
Header
{
hear
}},
nil
)
account
,
err
:=
action
.
getStartHeightVoteAccount
(
addr
,
""
,
0
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
account
)
require
.
Equal
(
t
,
types
.
Coin
,
account
.
Balance
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
account
)
assert
.
Equal
(
t
,
types
.
Coin
,
account
.
Balance
)
}
func
TestGetReceiptLog
(
t
*
testing
.
T
)
{
...
...
@@ -527,16 +542,16 @@ func TestGetReceiptLog(t *testing.T) {
Address
:
"123"
,
}
log
:=
getReceiptLog
(
pre
,
cur
,
2
)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
assert
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
recpt
:=
&
auty
.
ReceiptProposalBoard
{}
err
:=
types
.
Decode
(
log
.
Log
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropBoard
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropBoard
.
Year
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropBoard
.
Year
)
assert
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropBoard
.
Year
)
}
func
TestCopyAutonomyProposalBoard
(
t
*
testing
.
T
)
{
require
.
Nil
(
t
,
copyAutonomyProposalBoard
(
nil
))
assert
.
Nil
(
t
,
copyAutonomyProposalBoard
(
nil
))
cur
:=
&
auty
.
AutonomyProposalBoard
{
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1900
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
100
},
...
...
@@ -552,12 +567,12 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
cur
.
Address
=
"234"
cur
.
Status
=
1
require
.
Equal
(
t
,
1900
,
int
(
pre
.
PropBoard
.
Year
))
require
.
Equal
(
t
,
1
,
int
(
pre
.
PropBoard
.
Month
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardApproveRatio
))
require
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
require
.
Equal
(
t
,
"123"
,
pre
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
assert
.
Equal
(
t
,
1900
,
int
(
pre
.
PropBoard
.
Year
))
assert
.
Equal
(
t
,
1
,
int
(
pre
.
PropBoard
.
Month
))
assert
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardApproveRatio
))
assert
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
assert
.
Equal
(
t
,
"123"
,
pre
.
Address
)
assert
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
}
func
TestVerifyMinerAddr
(
t
*
testing
.
T
)
{
...
...
@@ -580,14 +595,14 @@ func TestVerifyMinerAddr(t *testing.T) {
stateDB
.
Set
(
ticket
.
BindKey
(
addr
),
types
.
Encode
(
tkBind
))
}
_
,
err
:=
action
.
verifyMinerAddr
(
addrs
,
AddrD
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
Equal
(
t
,
auty
.
ErrMinerAddr
,
err
)
assert
.
Equal
(
t
,
testf
,
addr
)
// ErrBindAddr
testf
=
"1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
...
...
@@ -598,8 +613,8 @@ func TestVerifyMinerAddr(t *testing.T) {
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
)
assert
.
Equal
(
t
,
auty
.
ErrBindAddr
,
err
)
assert
.
Equal
(
t
,
testf
,
addr
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
...
...
plugin/dapp/autonomy/executor/change_test.go
View file @
6f4f7852
...
...
@@ -13,7 +13,6 @@ import (
"github.com/33cn/chain33/util"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestExecLocalChange
(
t
*
testing
.
T
)
{
...
...
@@ -49,14 +48,14 @@ func testexecLocalChange(t *testing.T, auto bool) {
var
err
error
if
!
auto
{
set
,
err
=
au
.
execLocalChange
(
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalChange
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -78,8 +77,8 @@ func testexecLocalChange(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropChange
,
Log
:
types
.
Encode
(
receiptChange1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -89,8 +88,8 @@ func testexecLocalChange(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropChange
,
Log
:
types
.
Encode
(
receiptChange1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -114,8 +113,8 @@ func testexecLocalChange(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropChange
,
Log
:
types
.
Encode
(
receiptChange2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -125,8 +124,8 @@ func testexecLocalChange(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropChange
,
Log
:
types
.
Encode
(
receiptChange2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -168,13 +167,13 @@ func testexecDelLocalChange(t *testing.T) {
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
:=
au
.
execAutoLocalChange
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
...
...
@@ -206,8 +205,8 @@ func testexecDelLocalChange(t *testing.T) {
tx
,
err
=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalChange
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// 正常测试退回
...
...
@@ -215,15 +214,15 @@ func testexecDelLocalChange(t *testing.T) {
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalChange
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalChange
(
t
,
kvdb
,
cur
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalChange
(
t
,
kvdb
,
pre1
)
...
...
@@ -238,9 +237,9 @@ func TestGetProposalChange(t *testing.T) {
tx
:=
"1111111111111111111"
storedb
.
Set
(
propChangeID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalChange
{}))
rsp
,
err
:=
au
.
getProposalChange
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
rsp
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
1
)
}
func
TestListProposalChange
(
t
*
testing
.
T
)
{
...
...
@@ -288,9 +287,9 @@ func TestListProposalChange(t *testing.T) {
cur
.
Index
=
int32
(
tcase
.
index
)
err
:=
table
.
Replace
(
cur
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kv
,
err
:=
table
.
Save
()
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kvs
=
append
(
kvs
,
kv
...
)
}
...
...
@@ -303,12 +302,12 @@ func TestListProposalChange(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
:=
au
.
listProposalChange
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
len
(
testcase2
))
k
:=
2
for
_
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
k
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
k
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
k
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
k
]
.
Index
,
int32
(
tcase
.
index
))
k
--
}
...
...
@@ -320,11 +319,11 @@ func TestListProposalChange(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalChange
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
i
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
i
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
i
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
i
]
.
Index
,
int32
(
tcase
.
index
))
}
// 翻页查找
...
...
@@ -335,12 +334,12 @@ func TestListProposalChange(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalChange
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Height
index
:=
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Index
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
assert
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
assert
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
req
=
&
auty
.
ReqQueryProposalChange
{
Status
:
auty
.
AutonomyStatusProposalChange
,
...
...
@@ -350,12 +349,12 @@ func TestListProposalChange(t *testing.T) {
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalChange
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
),
2
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalChange
)
.
PropChanges
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
}
func
checkExecLocalChange
(
t
*
testing
.
T
,
kvdb
db
.
KVDB
,
cur
*
auty
.
AutonomyProposalChange
)
{
...
...
plugin/dapp/autonomy/executor/changeaction.go
View file @
6f4f7852
...
...
@@ -16,7 +16,8 @@ func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) {
alog
.
Error
(
"propChange "
,
"ProposalChange ChangeCfg invaild or have no modify param"
,
prob
)
return
nil
,
types
.
ErrInvalidParam
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
{
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
StartBlockHeight
+
startEndBlockPeriod
>
prob
.
EndBlockHeight
{
alog
.
Error
(
"propChange height invaild"
,
"StartBlockHeight"
,
prob
.
StartBlockHeight
,
"EndBlockHeight"
,
prob
.
EndBlockHeight
,
"height"
,
a
.
height
)
return
nil
,
types
.
ErrInvalidParam
...
...
plugin/dapp/autonomy/executor/changeaction_test.go
View file @
6f4f7852
...
...
@@ -18,7 +18,6 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func
InitChange
(
t
*
testing
.
T
,
stateDB
dbm
.
KV
)
{
...
...
@@ -63,17 +62,17 @@ func testPropChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm
Day
:
10
,
Changes
:
[]
*
auty
.
Change
{{
Cancel
:
true
,
Addr
:
AddrA
}},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
}
pbtx
,
err
:=
propChangeTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
...
...
@@ -84,8 +83,8 @@ func testPropChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm
// local
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -101,7 +100,7 @@ func testPropChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
assert
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
}
func
propChangeTx
(
parm
*
auty
.
ProposalChange
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -121,13 +120,13 @@ func revokeProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, state
ProposalID
:
proposalID
,
}
rtx
,
err
:=
revokeProposalChangeTx
(
opt2
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
rtx
,
err
=
signTx
(
rtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -136,8 +135,8 @@ func revokeProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, state
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -145,13 +144,13 @@ func revokeProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, state
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
rtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
}
func
revokeProposalChangeTx
(
parm
*
auty
.
RevokeProposalChange
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -221,15 +220,15 @@ func voteProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
Approve
:
record
.
appr
,
}
tx
,
err
:=
voteProposalChangeTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -237,8 +236,8 @@ func voteProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -246,8 +245,8 @@ func voteProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// 每次需要重新设置
acc
:=
&
types
.
Account
{
...
...
@@ -264,26 +263,26 @@ func voteProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
assert
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propChangeID
(
proposalID
))
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
cur
:=
&
auty
.
AutonomyProposalChange
{}
err
=
types
.
Decode
(
value
,
cur
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropChange
),
cur
.
Status
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
require
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropChange
),
cur
.
Status
)
assert
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
assert
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
value
,
err
=
stateDB
.
Get
(
activeBoardID
())
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
act
:=
&
auty
.
ActiveBoard
{}
err
=
types
.
Decode
(
value
,
act
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
act
.
Revboards
[
0
],
AddrA
)
require
.
Equal
(
t
,
len
(
act
.
Boards
),
len
(
boards
)
-
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
act
.
Revboards
[
0
],
AddrA
)
assert
.
Equal
(
t
,
len
(
act
.
Boards
),
len
(
boards
)
-
1
)
}
func
voteProposalChangeTx
(
parm
*
auty
.
VoteProposalChange
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -319,13 +318,13 @@ func terminateProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, st
ProposalID
:
proposalID
,
}
tx
,
err
:=
terminateProposalChangeTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -334,8 +333,8 @@ func terminateProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, st
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -343,13 +342,13 @@ func terminateProposalChange(t *testing.T, env *ExecEnv, exec drivers.Driver, st
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
}
func
terminateProposalChangeTx
(
parm
*
auty
.
TerminateProposalChange
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -377,12 +376,12 @@ func TestGetChangeReceiptLog(t *testing.T) {
Address
:
"123"
,
}
log
:=
getChangeReceiptLog
(
pre
,
cur
,
2
)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
assert
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
recpt
:=
&
auty
.
ReceiptProposalChange
{}
err
:=
types
.
Decode
(
log
.
Log
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropChange
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropChange
.
Year
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropChange
.
Year
)
assert
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropChange
.
Year
)
}
func
TestCheckChangeable
(
t
*
testing
.
T
)
{
...
...
@@ -397,18 +396,18 @@ func TestCheckChangeable(t *testing.T) {
// 正常撤销一个地址
changes
:=
[]
*
auty
.
Change
{{
Cancel
:
true
,
Addr
:
AddrA
}}
cur
,
err
:=
action
.
checkChangeable
(
act
,
changes
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
cur
.
Boards
),
len
(
boards
)
-
1
)
require
.
Equal
(
t
,
cur
.
Revboards
[
0
],
AddrA
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
cur
.
Boards
),
len
(
boards
)
-
1
)
assert
.
Equal
(
t
,
cur
.
Revboards
[
0
],
AddrA
)
// 恢复撤销地址
changes
=
[]
*
auty
.
Change
{
{
Cancel
:
false
,
Addr
:
AddrA
},
}
ncur
,
err
:=
action
.
checkChangeable
(
cur
,
changes
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
ncur
.
Boards
),
len
(
boards
))
require
.
Equal
(
t
,
len
(
ncur
.
Revboards
),
0
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
ncur
.
Boards
),
len
(
boards
))
assert
.
Equal
(
t
,
len
(
ncur
.
Revboards
),
0
)
// 撤销两个地址,撤销不够最小minBoards
changes
=
[]
*
auty
.
Change
{
...
...
@@ -416,25 +415,25 @@ func TestCheckChangeable(t *testing.T) {
{
Cancel
:
true
,
Addr
:
AddrB
},
}
_
,
err
=
action
.
checkChangeable
(
act
,
changes
)
require
.
Equal
(
t
,
err
,
auty
.
ErrBoardNumber
)
assert
.
Equal
(
t
,
err
,
auty
.
ErrBoardNumber
)
// 恢复一个没有被撤销的地址
changes
=
[]
*
auty
.
Change
{
{
Cancel
:
false
,
Addr
:
AddrA
},
}
_
,
err
=
action
.
checkChangeable
(
act
,
changes
)
require
.
Equal
(
t
,
err
,
auty
.
ErrChangeBoardAddr
)
assert
.
Equal
(
t
,
err
,
auty
.
ErrChangeBoardAddr
)
// 撤销一个不存在地址
changes
=
[]
*
auty
.
Change
{
{
Cancel
:
true
,
Addr
:
"1111111111"
},
}
_
,
err
=
action
.
checkChangeable
(
act
,
changes
)
require
.
Equal
(
t
,
err
,
auty
.
ErrChangeBoardAddr
)
assert
.
Equal
(
t
,
err
,
auty
.
ErrChangeBoardAddr
)
}
func
TestCopyAutonomyProposalChange
(
t
*
testing
.
T
)
{
require
.
Nil
(
t
,
copyAutonomyProposalChange
(
nil
))
assert
.
Nil
(
t
,
copyAutonomyProposalChange
(
nil
))
cur
:=
&
auty
.
AutonomyProposalChange
{
PropChange
:
&
auty
.
ProposalChange
{
Year
:
1900
,
...
...
plugin/dapp/autonomy/executor/project_test.go
View file @
6f4f7852
...
...
@@ -13,7 +13,6 @@ import (
"github.com/33cn/chain33/util"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestExecLocalProject
(
t
*
testing
.
T
)
{
...
...
@@ -51,14 +50,14 @@ func testexecLocalProject(t *testing.T, auto bool) {
var
err
error
if
!
auto
{
set
,
err
=
au
.
execLocalProject
(
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalProject
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -81,8 +80,8 @@ func testexecLocalProject(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropProject
,
Log
:
types
.
Encode
(
receiptProject1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -92,8 +91,8 @@ func testexecLocalProject(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropProject
,
Log
:
types
.
Encode
(
receiptProject1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -118,8 +117,8 @@ func testexecLocalProject(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropProject
,
Log
:
types
.
Encode
(
receiptProject2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -129,8 +128,8 @@ func testexecLocalProject(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropProject
,
Log
:
types
.
Encode
(
receiptProject2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -174,13 +173,13 @@ func testexecDelLocalProject(t *testing.T) {
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
:=
au
.
execAutoLocalProject
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
...
...
@@ -211,8 +210,8 @@ func testexecDelLocalProject(t *testing.T) {
tx
,
err
=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalProject
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// 正常测试退回
...
...
@@ -220,15 +219,15 @@ func testexecDelLocalProject(t *testing.T) {
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalProject
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalProject
(
t
,
kvdb
,
cur
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
checkExecLocalProject
(
t
,
kvdb
,
pre1
)
...
...
@@ -243,9 +242,9 @@ func TestGetProposalProject(t *testing.T) {
tx
:=
"1111111111111111111"
storedb
.
Set
(
propProjectID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalProject
{}))
rsp
,
err
:=
au
.
getProposalProject
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
rsp
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
}
func
TestListProposalProject
(
t
*
testing
.
T
)
{
...
...
@@ -295,9 +294,9 @@ func TestListProposalProject(t *testing.T) {
cur
.
Index
=
int32
(
tcase
.
index
)
err
:=
table
.
Replace
(
cur
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kv
,
err
:=
table
.
Save
()
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kvs
=
append
(
kvs
,
kv
...
)
}
saveKvs
(
sdb
,
kvs
)
...
...
@@ -310,12 +309,12 @@ func TestListProposalProject(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
:=
au
.
listProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
k
:=
2
for
_
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
k
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
k
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
k
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
k
]
.
Index
,
int32
(
tcase
.
index
))
k
--
}
...
...
@@ -327,11 +326,11 @@ func TestListProposalProject(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
i
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
i
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
i
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
i
]
.
Index
,
int32
(
tcase
.
index
))
}
// 翻页查找
...
...
@@ -342,12 +341,12 @@ func TestListProposalProject(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Height
index
:=
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Index
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
assert
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
assert
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
req
=
&
auty
.
ReqQueryProposalProject
{
Status
:
auty
.
AutonomyStatusProposalProject
,
...
...
@@ -357,12 +356,12 @@ func TestListProposalProject(t *testing.T) {
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
2
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
}
func
checkExecLocalProject
(
t
*
testing
.
T
,
kvdb
db
.
KVDB
,
cur
*
auty
.
AutonomyProposalProject
)
{
...
...
plugin/dapp/autonomy/executor/projectaction.go
View file @
6f4f7852
...
...
@@ -23,7 +23,8 @@ func (a *action) propProject(prob *auty.ProposalProject) (*types.Receipt, error)
return
nil
,
types
.
ErrInvalidAddress
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
Amount
<=
0
{
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
Amount
<=
0
||
prob
.
StartBlockHeight
+
startEndBlockPeriod
>
prob
.
EndBlockHeight
{
alog
.
Error
(
"propProject height or amount invaild"
,
"StartBlockHeight"
,
prob
.
StartBlockHeight
,
"EndBlockHeight"
,
prob
.
EndBlockHeight
,
"height"
,
a
.
height
,
"amount"
,
prob
.
Amount
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -593,7 +594,7 @@ func (a *action) checkPeriodAmount(act *auty.ActiveBoard, amount int64) bool {
if
act
==
nil
{
return
false
}
if
act
.
Amount
+
amount
>
=
maxBoardPeriodAmount
{
if
act
.
Amount
+
amount
>
maxBoardPeriodAmount
{
return
false
}
return
true
...
...
plugin/dapp/autonomy/executor/projectaction_test.go
View file @
6f4f7852
...
...
@@ -16,8 +16,8 @@ import (
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
//const (
...
...
@@ -66,19 +66,19 @@ func InitFund(stateDB dbm.KV, amount int64) {
}
func
TestPropProject
(
t
*
testing
.
T
)
{
env
,
exec
,
_
,
_
:=
InitEnv
()
env
,
exec
,
stateDB
,
_
:=
InitEnv
()
opts
:=
[]
*
auty
.
ProposalProject
{
{
// check toaddr
ToAddr
:
"1111111111"
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// check amount
Amount
:
0
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// check StartBlockHeight EndBlockHeight
Amount
:
10
,
...
...
@@ -90,7 +90,13 @@ func TestPropProject(t *testing.T) {
Amount
:
100
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// checkPeriodAmount
Amount
:
100
,
ToAddr
:
AddrA
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
}
...
...
@@ -99,17 +105,26 @@ func TestPropProject(t *testing.T) {
types
.
ErrInvalidParam
,
types
.
ErrInvalidParam
,
types
.
ErrNotFound
,
auty
.
ErrNoPeriodAmount
,
}
exec
.
SetStateDB
(
stateDB
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
for
i
,
tcase
:=
range
opts
{
pbtx
,
err
:=
propProjectTx
(
tcase
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
if
i
==
4
{
act
:=
&
auty
.
ActiveBoard
{
Boards
:
boards
,
Amount
:
maxBoardPeriodAmount
,
}
err
:=
stateDB
.
Set
(
activeBoardID
(),
types
.
Encode
(
act
))
assert
.
NoError
(
t
,
err
)
}
_
,
err
=
exec
.
Exec
(
pbtx
,
int
(
i
))
require
.
Error
(
t
,
err
,
result
[
i
])
assert
.
Equal
(
t
,
err
,
result
[
i
])
}
}
...
...
@@ -161,6 +176,48 @@ func TestTerminateProposalProject(t *testing.T) {
terminateProposalProject
(
t
,
env
,
exec
,
stateDB
,
kvdb
,
true
)
}
func
TestBoardPeriodAmount
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
_
:=
InitEnv
()
InitFund
(
stateDB
,
testProjectAmount
)
act
:=
&
auty
.
ActiveBoard
{
Boards
:
boards
,
Amount
:
maxBoardPeriodAmount
-
100
,
StartHeight
:
10
,
}
stateDB
.
Set
(
activeBoardID
(),
types
.
Encode
(
act
))
opt1
:=
&
auty
.
ProposalProject
{
Year
:
2019
,
Month
:
7
,
Day
:
10
,
Amount
:
testProjectAmount
,
ToAddr
:
AddrD
,
StartBlockHeight
:
env
.
blockHeight
+
boardPeriod
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
boardPeriod
+
startEndBlockPeriod
+
10
,
}
pbtx
,
err
:=
propProjectTx
(
opt1
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
assert
.
NoError
(
t
,
err
)
exec
.
SetEnv
(
env
.
blockHeight
+
boardPeriod
+
1
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
pbtx
,
int
(
1
))
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// check
value
,
err
:=
stateDB
.
Get
(
activeBoardID
())
assert
.
NoError
(
t
,
err
)
nact
:=
&
auty
.
ActiveBoard
{}
types
.
Decode
(
value
,
nact
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
0
),
nact
.
Amount
)
}
func
testPropProject
(
t
*
testing
.
T
,
env
*
ExecEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
opt1
:=
&
auty
.
ProposalProject
{
Year
:
2019
,
...
...
@@ -169,17 +226,17 @@ func testPropProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB db
Amount
:
testProjectAmount
,
ToAddr
:
AddrD
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
}
pbtx
,
err
:=
propProjectTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
...
...
@@ -189,8 +246,8 @@ func testPropProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB db
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -206,7 +263,7 @@ func testPropProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB db
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
assert
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
}
func
propProjectTx
(
parm
*
auty
.
ProposalProject
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -226,13 +283,13 @@ func revokeProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
ProposalID
:
proposalID
,
}
rtx
,
err
:=
revokeProposalProjectTx
(
opt2
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
rtx
,
err
=
signTx
(
rtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -241,8 +298,8 @@ func revokeProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -250,14 +307,14 @@ func revokeProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
rtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check Project
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
...
...
@@ -333,15 +390,15 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
Approve
:
record
.
appr
,
}
tx
,
err
:=
voteProposalProjectTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -349,8 +406,8 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
}
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -358,8 +415,8 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// 每次需要重新设置
acc
:=
&
types
.
Account
{
...
...
@@ -390,17 +447,17 @@ func checkVoteProposalProjectResult(t *testing.T, stateDB dbm.KV, proposalID str
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
assert
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propProjectID
(
proposalID
))
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropProject
),
cur
.
Status
)
assert
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
}
func
pubVoteProposalProject
(
t
*
testing
.
T
,
env
*
ExecEnv
,
exec
drivers
.
Driver
,
stateDB
dbm
.
KV
,
kvdb
dbm
.
KVDB
,
save
bool
)
{
...
...
@@ -431,31 +488,32 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
proposalID
:=
env
.
txHash
// 4人参与投票,3人赞成票,1人反对票
type
record
struct
{
priv
string
appr
bool
priv
string
appr
bool
origin
[]
string
}
records
:=
[]
record
{
{
PrivKeyA
,
true
},
{
PrivKeyB
,
false
},
{
PrivKeyC
,
true
},
//{PrivKeyD, true},
{
priv
:
PrivKeyA
,
appr
:
false
},
{
priv
:
PrivKey1
,
appr
:
true
,
origin
:
[]
string
{
AddrB
,
AddrC
}},
}
InitMinerAddr
(
stateDB
,
[]
string
{
AddrB
,
AddrC
},
Addr1
)
for
_
,
record
:=
range
records
{
for
i
,
record
:=
range
records
{
opt
:=
&
auty
.
PubVoteProposalProject
{
ProposalID
:
proposalID
,
Oppose
:
record
.
appr
,
OriginAddr
:
record
.
origin
,
}
tx
,
err
:=
pubVoteProposalProjectTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -463,8 +521,8 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
}
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -472,18 +530,22 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// 每次需要重新设置,对于下一个是多个授权地址的需要设置多次
if
i
+
1
<
len
(
records
)
{
for
j
:=
0
;
j
<
len
(
records
[
i
+
1
]
.
origin
);
j
++
{
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
}
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
}
}
...
...
@@ -493,17 +555,17 @@ func checkPubVoteProposalProjectResult(t *testing.T, stateDB dbm.KV, proposalID
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
)
+
testProjectAmount
,
account
.
Balance
)
assert
.
Equal
(
t
,
int64
(
proposalAmount
)
+
testProjectAmount
,
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propProjectID
(
proposalID
))
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropProject
),
cur
.
Status
)
assert
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
}
func
pubVoteProposalProjectTx
(
parm
*
auty
.
PubVoteProposalProject
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -539,13 +601,13 @@ func terminateProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, s
ProposalID
:
proposalID
,
}
tx
,
err
:=
terminateProposalProjectTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -554,8 +616,8 @@ func terminateProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, s
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -563,13 +625,13 @@ func terminateProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, s
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check Project
au
:=
&
Autonomy
{
...
...
@@ -609,20 +671,20 @@ func TestGetProjectReceiptLog(t *testing.T) {
Address
:
"123"
,
}
log
:=
getProjectReceiptLog
(
pre
,
cur
,
2
)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
assert
.
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
.
BoardApproveRatio
)
require
.
Equal
(
t
,
int32
(
90
),
recpt
.
Current
.
CurRule
.
BoardApproveRatio
)
require
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
recpt
.
Prev
.
Boards
)
require
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
recpt
.
Current
.
Boards
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropProject
.
Year
)
assert
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropProject
.
Year
)
assert
.
Equal
(
t
,
int32
(
80
),
recpt
.
Prev
.
CurRule
.
BoardApproveRatio
)
assert
.
Equal
(
t
,
int32
(
90
),
recpt
.
Current
.
CurRule
.
BoardApproveRatio
)
assert
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
recpt
.
Prev
.
Boards
)
assert
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
recpt
.
Current
.
Boards
)
}
func
TestCopyAutonomyProposalProject
(
t
*
testing
.
T
)
{
require
.
Nil
(
t
,
copyAutonomyProposalProject
(
nil
))
assert
.
Nil
(
t
,
copyAutonomyProposalProject
(
nil
))
cur
:=
&
auty
.
AutonomyProposalProject
{
PropProject
:
&
auty
.
ProposalProject
{
Year
:
1800
,
Month
:
1
},
CurRule
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
80
},
...
...
@@ -642,13 +704,13 @@ func TestCopyAutonomyProposalProject(t *testing.T) {
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
.
BoardApproveRatio
))
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
)
assert
.
Equal
(
t
,
1800
,
int
(
pre
.
PropProject
.
Year
))
assert
.
Equal
(
t
,
1
,
int
(
pre
.
PropProject
.
Month
))
assert
.
Equal
(
t
,
[]
string
{
"111"
,
"222"
,
"333"
},
pre
.
Boards
)
assert
.
Equal
(
t
,
80
,
int
(
pre
.
CurRule
.
BoardApproveRatio
))
assert
.
Equal
(
t
,
"123"
,
pre
.
Address
)
assert
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
assert
.
Equal
(
t
,
100
,
int
(
pre
.
BoardVoteRes
.
TotalVotes
))
assert
.
Equal
(
t
,
true
,
pre
.
PubVote
.
Publicity
)
assert
.
Equal
(
t
,
[]
string
{
"555"
,
"666"
,
"777"
},
cur
.
Boards
)
}
plugin/dapp/autonomy/executor/rule_test.go
View file @
6f4f7852
...
...
@@ -13,7 +13,6 @@ import (
"github.com/33cn/chain33/util"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestExecLocalRule
(
t
*
testing
.
T
)
{
...
...
@@ -49,14 +48,14 @@ func testexecLocalRule(t *testing.T, auto bool) {
if
!
auto
{
set
,
err
=
au
.
execLocalRule
(
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalRule
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -78,8 +77,8 @@ func testexecLocalRule(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropRule
,
Log
:
types
.
Encode
(
receiptRule1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -89,8 +88,8 @@ func testexecLocalRule(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogRvkPropRule
,
Log
:
types
.
Encode
(
receiptRule1
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -114,8 +113,8 @@ func testexecLocalRule(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropRule
,
Log
:
types
.
Encode
(
receiptRule2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
...
...
@@ -125,8 +124,8 @@ func testexecLocalRule(t *testing.T, auto bool) {
{
Ty
:
auty
.
TyLogVotePropRule
,
Log
:
types
.
Encode
(
receiptRule2
)},
},
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
//save to database
...
...
@@ -168,13 +167,13 @@ func testexecDelLocalRule(t *testing.T) {
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
:=
au
.
execAutoLocalRule
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
...
...
@@ -206,8 +205,8 @@ func testexecDelLocalRule(t *testing.T) {
tx
,
err
=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalRule
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// 正常测试退回
...
...
@@ -215,15 +214,15 @@ func testexecDelLocalRule(t *testing.T) {
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalRule
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
checkExecLocalRule
(
t
,
kvdb
,
cur
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
// check
...
...
@@ -268,9 +267,9 @@ func TestGetProposalRule(t *testing.T) {
tx
:=
"1111111111111111111"
storedb
.
Set
(
propRuleID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalRule
{}))
rsp
,
err
:=
au
.
getProposalRule
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
rsp
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
}
func
TestListProposalRule
(
t
*
testing
.
T
)
{
...
...
@@ -318,9 +317,9 @@ func TestListProposalRule(t *testing.T) {
cur
.
Index
=
int32
(
tcase
.
index
)
err
:=
table
.
Replace
(
cur
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kv
,
err
:=
table
.
Save
()
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
kvs
=
append
(
kvs
,
kv
...
)
}
saveKvs
(
sdb
,
kvs
)
...
...
@@ -333,12 +332,12 @@ func TestListProposalRule(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
:=
au
.
listProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
k
:=
2
for
_
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
k
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
k
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
k
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
k
]
.
Index
,
int32
(
tcase
.
index
))
k
--
}
...
...
@@ -350,11 +349,11 @@ func TestListProposalRule(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
i
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
i
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
i
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
i
]
.
Index
,
int32
(
tcase
.
index
))
}
// 翻页查找
...
...
@@ -365,12 +364,12 @@ func TestListProposalRule(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Height
index
:=
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Index
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
assert
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
assert
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
req
=
&
auty
.
ReqQueryProposalRule
{
Status
:
auty
.
AutonomyStatusProposalRule
,
...
...
@@ -380,12 +379,12 @@ func TestListProposalRule(t *testing.T) {
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
2
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
}
func
TestExecLocalCommentProp
(
t
*
testing
.
T
)
{
...
...
@@ -418,19 +417,19 @@ func testexecLocalCommentProp(t *testing.T, auto bool) {
var
err
error
if
!
auto
{
set
,
err
=
au
.
execLocalCommentProp
(
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
else
{
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
nil
)
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalCommentProp
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
}
require
.
Equal
(
t
,
set
.
KV
[
0
]
.
Key
,
calcCommentHeight
(
propID
,
assert
.
Equal
(
t
,
set
.
KV
[
0
]
.
Key
,
calcCommentHeight
(
propID
,
dapp
.
HeightIndexStr
(
receiptCmt
.
Height
,
int64
(
receiptCmt
.
Index
))))
require
.
NotNil
(
t
,
set
.
KV
[
0
]
.
Value
)
assert
.
NotNil
(
t
,
set
.
KV
[
0
]
.
Value
)
}
func
TestExecDelLocalCommentProp
(
t
*
testing
.
T
)
{
...
...
@@ -465,18 +464,18 @@ func testexecDelLocalCommentProp(t *testing.T) {
assert
.
NoError
(
t
,
err
)
set
,
err
=
au
.
execAutoLocalCommentProp
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
saveKvs
(
sdb
,
set
.
KV
)
set
,
err
=
au
.
execAutoDelLocal
(
tx
,
receipt
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
require
.
Equal
(
t
,
set
.
KV
[
0
]
.
Key
,
calcCommentHeight
(
propID
,
assert
.
Equal
(
t
,
set
.
KV
[
0
]
.
Key
,
calcCommentHeight
(
propID
,
dapp
.
HeightIndexStr
(
receiptCmt
.
Height
,
int64
(
receiptCmt
.
Index
))))
require
.
Nil
(
t
,
set
.
KV
[
0
]
.
Value
)
assert
.
Nil
(
t
,
set
.
KV
[
0
]
.
Value
)
}
func
TestListProposalComment
(
t
*
testing
.
T
)
{
...
...
@@ -530,12 +529,12 @@ func TestListProposalComment(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
:=
au
.
listProposalComment
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
len
(
testcase2
))
k
:=
2
for
_
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
k
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
k
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
k
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
k
]
.
Index
,
int32
(
tcase
.
index
))
k
--
}
...
...
@@ -547,11 +546,11 @@ func TestListProposalComment(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalComment
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
len
(
testcase2
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
i
]
.
Height
,
tcase
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
i
]
.
Index
,
int32
(
tcase
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
i
]
.
Height
,
tcase
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
i
]
.
Index
,
int32
(
tcase
.
index
))
}
// 翻页查找
...
...
@@ -562,12 +561,12 @@ func TestListProposalComment(t *testing.T) {
Index
:
-
1
,
}
rsp
,
err
=
au
.
listProposalComment
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Height
index
:=
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Index
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
assert
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
assert
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
req
=
&
auty
.
ReqQueryProposalComment
{
ProposalID
:
propID2
,
...
...
@@ -577,10 +576,10 @@ func TestListProposalComment(t *testing.T) {
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalComment
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
),
2
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
1
]
.
Height
,
testcase2
[
0
]
.
height
)
assert
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalComment
)
.
RltCmt
[
1
]
.
Index
,
int32
(
testcase2
[
0
]
.
index
))
}
plugin/dapp/autonomy/executor/ruleaction.go
View file @
6f4f7852
...
...
@@ -51,7 +51,8 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
alog
.
Error
(
"propRule RuleCfg invaild"
,
"ruleCfg"
,
prob
.
RuleCfg
)
return
nil
,
types
.
ErrInvalidParam
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
{
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
||
prob
.
StartBlockHeight
+
startEndBlockPeriod
>
prob
.
EndBlockHeight
{
alog
.
Error
(
"propRule height invaild"
,
"StartBlockHeight"
,
prob
.
StartBlockHeight
,
"EndBlockHeight"
,
prob
.
EndBlockHeight
,
"height"
,
a
.
height
)
return
nil
,
types
.
ErrInvalidParam
...
...
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
6f4f7852
...
...
@@ -16,8 +16,8 @@ import (
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
const
(
...
...
@@ -28,6 +28,79 @@ const (
testPublicPeriod
=
minPublicPeriod
)
func
TestPropRule
(
t
*
testing
.
T
)
{
env
,
exec
,
_
,
_
:=
InitEnv
()
opts
:=
[]
*
auty
.
ProposalRule
{
{
// 全0测试
RuleCfg
:
&
auty
.
RuleConfig
{},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// 边界测试
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
maxBoardApproveRatio
,
PubOpposeRatio
:
maxPubOpposeRatio
,
ProposalAmount
:
maxProposalAmount
,
LargeProjectAmount
:
maxLargeProjectAmount
,
PublicPeriod
:
maxPublicPeriod
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
minBoardApproveRatio
,
PubOpposeRatio
:
minPubOpposeRatio
,
ProposalAmount
:
minProposalAmount
,
LargeProjectAmount
:
minLargeProjectAmount
,
PublicPeriod
:
minPublicPeriod
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
minBoardApproveRatio
-
1
,
PubOpposeRatio
:
minPubOpposeRatio
-
1
,
ProposalAmount
:
minProposalAmount
-
1
,
LargeProjectAmount
:
minLargeProjectAmount
-
1
,
PublicPeriod
:
minPublicPeriod
-
1
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// 边界测试
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
maxBoardApproveRatio
+
1
,
PubOpposeRatio
:
maxPubOpposeRatio
+
1
,
ProposalAmount
:
maxProposalAmount
+
1
,
LargeProjectAmount
:
maxLargeProjectAmount
+
1
,
PublicPeriod
:
maxPublicPeriod
+
1
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
}
result
:=
[]
error
{
types
.
ErrInvalidParam
,
nil
,
nil
,
types
.
ErrInvalidParam
,
types
.
ErrInvalidParam
,
}
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
for
i
,
tcase
:=
range
opts
{
pbtx
,
err
:=
propRuleTx
(
tcase
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
exec
.
Exec
(
pbtx
,
int
(
i
))
assert
.
Equal
(
t
,
err
,
result
[
i
])
}
}
func
TestRevokeProposalRule
(
t
*
testing
.
T
)
{
env
,
exec
,
stateDB
,
kvdb
:=
InitEnv
()
// PropRule
...
...
@@ -65,17 +138,17 @@ func testPropRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.K
PublicPeriod
:
testPublicPeriod
,
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
10
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
}
pbtx
,
err
:=
propRuleTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
...
...
@@ -85,8 +158,8 @@ func testPropRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.K
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -102,7 +175,7 @@ func testPropRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.K
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
assert
.
Equal
(
t
,
proposalAmount
,
account
.
Frozen
)
}
func
propRuleTx
(
parm
*
auty
.
ProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -122,13 +195,13 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
ProposalID
:
proposalID
,
}
rtx
,
err
:=
revokeProposalRuleTx
(
opt2
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
rtx
,
err
=
signTx
(
rtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -137,8 +210,8 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -146,13 +219,13 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
rtx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check rule
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
...
...
@@ -161,12 +234,12 @@ func revokeProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
require
.
Equal
(
t
,
rule
.
PublicPeriod
,
publicPeriod
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
assert
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
assert
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
assert
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
assert
.
Equal
(
t
,
rule
.
PublicPeriod
,
publicPeriod
)
}
func
revokeProposalRuleTx
(
parm
*
auty
.
RevokeProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -208,31 +281,32 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
proposalID
:=
env
.
txHash
// 4人参与投票,3人赞成票,1人反对票
type
record
struct
{
priv
string
appr
bool
priv
string
appr
bool
origin
[]
string
}
records
:=
[]
record
{
{
PrivKeyA
,
false
},
{
PrivKeyB
,
true
},
{
PrivKeyC
,
true
},
{
PrivKeyD
,
true
},
{
priv
:
PrivKeyA
,
appr
:
false
},
{
priv
:
PrivKey1
,
appr
:
true
,
origin
:
[]
string
{
AddrB
,
AddrC
,
AddrD
}},
}
InitMinerAddr
(
stateDB
,
[]
string
{
AddrB
,
AddrC
,
AddrD
},
Addr1
)
for
_
,
record
:=
range
records
{
for
i
,
record
:=
range
records
{
opt
:=
&
auty
.
VoteProposalRule
{
ProposalID
:
proposalID
,
Approve
:
record
.
appr
,
OriginAddr
:
record
.
origin
,
}
tx
,
err
:=
voteProposalRuleTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
record
.
priv
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -240,8 +314,8 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
}
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -249,36 +323,40 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// 每次需要重新设置,对于下一个是多个授权地址的需要设置多次
if
i
+
1
<
len
(
records
)
{
for
j
:=
0
;
j
<
len
(
records
[
i
+
1
]
.
origin
);
j
++
{
acc
:=
&
types
.
Account
{
Currency
:
0
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
values
},
nil
)
.
Once
()
exec
.
SetAPI
(
api
)
}
}
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
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
assert
.
Equal
(
t
,
int64
(
proposalAmount
),
account
.
Balance
)
// status
value
,
err
:=
stateDB
.
Get
(
propRuleID
(
proposalID
))
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
cur
:=
&
auty
.
AutonomyProposalRule
{}
err
=
types
.
Decode
(
value
,
cur
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropRule
),
cur
.
Status
)
require
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
require
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
auty
.
AutonomyStatusTmintPropRule
),
cur
.
Status
)
assert
.
Equal
(
t
,
AddrA
,
cur
.
Address
)
assert
.
Equal
(
t
,
true
,
cur
.
VoteResult
.
Pass
)
// check rule
au
:=
&
Autonomy
{
drivers
.
DriverBase
{},
...
...
@@ -287,12 +365,12 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
testBoardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
testPubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
testProposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
testLargeProjectAmount
)
require
.
Equal
(
t
,
rule
.
PublicPeriod
,
testPublicPeriod
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
testBoardApproveRatio
)
assert
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
testPubOpposeRatio
)
assert
.
Equal
(
t
,
rule
.
ProposalAmount
,
testProposalAmount
)
assert
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
testLargeProjectAmount
)
assert
.
Equal
(
t
,
rule
.
PublicPeriod
,
testPublicPeriod
)
}
func
voteProposalRuleTx
(
parm
*
auty
.
VoteProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -328,13 +406,13 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
ProposalID
:
proposalID
,
}
tx
,
err
:=
terminateProposalRuleTx
(
opt
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
tx
,
err
=
signTx
(
tx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
if
save
{
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -343,8 +421,8 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
if
save
{
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -352,13 +430,13 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
}
// del
set
,
err
=
exec
.
ExecDelLocal
(
tx
,
receiptData
,
int
(
1
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
set
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
// check
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
assert
.
Equal
(
t
,
int64
(
0
),
account
.
Frozen
)
// check rule
au
:=
&
Autonomy
{
...
...
@@ -368,12 +446,12 @@ func terminateProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stat
au
.
SetLocalDB
(
kvdb
)
action
:=
newAction
(
au
,
&
types
.
Transaction
{},
0
)
rule
,
err
:=
action
.
getActiveRule
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
require
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
require
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
require
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
require
.
Equal
(
t
,
rule
.
PublicPeriod
,
publicPeriod
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
rule
.
BoardApproveRatio
,
boardApproveRatio
)
assert
.
Equal
(
t
,
rule
.
PubOpposeRatio
,
pubOpposeRatio
)
assert
.
Equal
(
t
,
rule
.
ProposalAmount
,
proposalAmount
)
assert
.
Equal
(
t
,
rule
.
LargeProjectAmount
,
largeProjectAmount
)
assert
.
Equal
(
t
,
rule
.
PublicPeriod
,
publicPeriod
)
}
func
terminateProposalRuleTx
(
parm
*
auty
.
TerminateProposalRule
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -401,16 +479,16 @@ func TestGetRuleReceiptLog(t *testing.T) {
Address
:
"123"
,
}
log
:=
getRuleReceiptLog
(
pre
,
cur
,
2
)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
assert
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
recpt
:=
&
auty
.
ReceiptProposalRule
{}
err
:=
types
.
Decode
(
log
.
Log
,
recpt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropRule
.
Year
)
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropRule
.
Year
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropRule
.
Year
)
assert
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropRule
.
Year
)
}
func
TestCopyAutonomyProposalRule
(
t
*
testing
.
T
)
{
require
.
Nil
(
t
,
copyAutonomyProposalRule
(
nil
))
assert
.
Nil
(
t
,
copyAutonomyProposalRule
(
nil
))
cur
:=
&
auty
.
AutonomyProposalRule
{
PropRule
:
&
auty
.
ProposalRule
{
Year
:
1900
,
Month
:
1
,
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
80
}},
CurRule
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
100
},
...
...
@@ -427,18 +505,18 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
cur
.
Address
=
"234"
cur
.
Status
=
1
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
.
CurRule
.
BoardApproveRatio
))
assert
.
Equal
(
t
,
1900
,
int
(
pre
.
PropRule
.
Year
))
assert
.
Equal
(
t
,
1
,
int
(
pre
.
PropRule
.
Month
))
assert
.
Equal
(
t
,
100
,
int
(
pre
.
VoteResult
.
TotalVotes
))
assert
.
Equal
(
t
,
"123"
,
pre
.
Address
)
assert
.
Equal
(
t
,
2
,
int
(
pre
.
Status
))
assert
.
Equal
(
t
,
80
,
int
(
pre
.
PropRule
.
RuleCfg
.
BoardApproveRatio
))
assert
.
Equal
(
t
,
100
,
int
(
pre
.
CurRule
.
BoardApproveRatio
))
}
func
TestUpgradeRule
(
t
*
testing
.
T
)
{
new
:=
upgradeRule
(
nil
,
&
auty
.
RuleConfig
{})
require
.
Nil
(
t
,
new
)
assert
.
Nil
(
t
,
new
)
cur
:=
&
auty
.
RuleConfig
{
BoardApproveRatio
:
2
,
PubOpposeRatio
:
3
,
...
...
@@ -454,12 +532,12 @@ func TestUpgradeRule(t *testing.T) {
PublicPeriod
:
0
,
}
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
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
)
require
.
Equal
(
t
,
new
.
PublicPeriod
,
cur
.
PublicPeriod
)
assert
.
NotNil
(
t
,
new
)
assert
.
Equal
(
t
,
new
.
BoardApproveRatio
,
cur
.
BoardApproveRatio
)
assert
.
Equal
(
t
,
new
.
PubOpposeRatio
,
cur
.
PubOpposeRatio
)
assert
.
Equal
(
t
,
new
.
ProposalAmount
,
cur
.
ProposalAmount
)
assert
.
Equal
(
t
,
new
.
LargeProjectAmount
,
cur
.
LargeProjectAmount
)
assert
.
Equal
(
t
,
new
.
PublicPeriod
,
cur
.
PublicPeriod
)
modify
=
&
auty
.
RuleConfig
{
BoardApproveRatio
:
20
,
...
...
@@ -469,12 +547,12 @@ func TestUpgradeRule(t *testing.T) {
PublicPeriod
:
60
,
}
new
=
upgradeRule
(
cur
,
modify
)
require
.
NotNil
(
t
,
new
)
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
)
require
.
Equal
(
t
,
new
.
PublicPeriod
,
modify
.
PublicPeriod
)
assert
.
NotNil
(
t
,
new
)
assert
.
Equal
(
t
,
new
.
BoardApproveRatio
,
modify
.
BoardApproveRatio
)
assert
.
Equal
(
t
,
new
.
PubOpposeRatio
,
modify
.
PubOpposeRatio
)
assert
.
Equal
(
t
,
new
.
ProposalAmount
,
modify
.
ProposalAmount
)
assert
.
Equal
(
t
,
new
.
LargeProjectAmount
,
modify
.
LargeProjectAmount
)
assert
.
Equal
(
t
,
new
.
PublicPeriod
,
modify
.
PublicPeriod
)
}
func
TestTransfer
(
t
*
testing
.
T
)
{
...
...
@@ -484,14 +562,14 @@ func TestTransfer(t *testing.T) {
Amount
:
types
.
Coin
*
190
,
}
pbtx
,
err
:=
transferFundTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -500,9 +578,9 @@ func TestTransfer(t *testing.T) {
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
.
SetDB
(
stateDB
)
account
:=
accCoin
.
LoadExecAccount
(
AddrA
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
total
-
types
.
Coin
*
190
,
account
.
Balance
)
assert
.
Equal
(
t
,
total
-
types
.
Coin
*
190
,
account
.
Balance
)
account
=
accCoin
.
LoadExecAccount
(
autonomyFundAddr
,
address
.
ExecAddress
(
auty
.
AutonomyX
))
require
.
Equal
(
t
,
types
.
Coin
*
190
,
account
.
Balance
)
assert
.
Equal
(
t
,
types
.
Coin
*
190
,
account
.
Balance
)
}
func
transferFundTx
(
parm
*
auty
.
TransferFund
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -528,14 +606,14 @@ func TestComment(t *testing.T) {
Comment
:
comment
,
}
pbtx
,
err
:=
commentPropTx
(
opt1
)
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
require
.
NoError
(
t
,
err
)
assert
.
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
...
...
@@ -543,20 +621,20 @@ func TestComment(t *testing.T) {
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
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// check
value
,
err
:=
kvdb
.
Get
(
calcCommentHeight
(
propID
,
drivers
.
HeightIndexStr
(
env
.
blockHeight
,
1
)))
require
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
cmt
:=
&
auty
.
RelationCmt
{}
err
=
types
.
Decode
(
value
,
cmt
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
cmt
.
Comment
,
comment
)
require
.
Equal
(
t
,
cmt
.
RepHash
,
Repcmt
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
cmt
.
Comment
,
comment
)
assert
.
Equal
(
t
,
cmt
.
RepHash
,
Repcmt
)
}
func
commentPropTx
(
parm
*
auty
.
Comment
)
(
*
types
.
Transaction
,
error
)
{
...
...
plugin/dapp/cert/authority/tools/cryptogen/generator/utils/certutils.go
View file @
6f4f7852
...
...
@@ -73,9 +73,9 @@ func ParseX509CertificateToSm2(x509Cert *x509.Certificate) *sm2.Certificate {
UnknownExtKeyUsage
:
x509Cert
.
UnknownExtKeyUsage
,
BasicConstraintsValid
:
x509Cert
.
BasicConstraintsValid
,
IsCA
:
x509Cert
.
IsCA
,
MaxPathLen
:
x509Cert
.
MaxPathLen
,
MaxPathLenZero
:
x509Cert
.
MaxPathLenZero
,
IsCA
:
x509Cert
.
IsCA
,
MaxPathLen
:
x509Cert
.
MaxPathLen
,
MaxPathLenZero
:
x509Cert
.
MaxPathLenZero
,
SubjectKeyId
:
x509Cert
.
SubjectKeyId
,
AuthorityKeyId
:
x509Cert
.
AuthorityKeyId
,
...
...
@@ -136,9 +136,9 @@ func ParseSm2CertificateToX509(sm2Cert *sm2.Certificate) *x509.Certificate {
UnknownExtKeyUsage
:
sm2Cert
.
UnknownExtKeyUsage
,
BasicConstraintsValid
:
sm2Cert
.
BasicConstraintsValid
,
IsCA
:
sm2Cert
.
IsCA
,
MaxPathLen
:
sm2Cert
.
MaxPathLen
,
MaxPathLenZero
:
sm2Cert
.
MaxPathLenZero
,
IsCA
:
sm2Cert
.
IsCA
,
MaxPathLen
:
sm2Cert
.
MaxPathLen
,
MaxPathLenZero
:
sm2Cert
.
MaxPathLenZero
,
SubjectKeyId
:
sm2Cert
.
SubjectKeyId
,
AuthorityKeyId
:
sm2Cert
.
AuthorityKeyId
,
...
...
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