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