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
b626e711
Commit
b626e711
authored
Sep 14, 2021
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix autonomy unit test and rpc test
parent
f1252ce0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
4 deletions
+90
-4
test-rpc.sh
plugin/dapp/autonomy/cmd/test/test-rpc.sh
+0
-0
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+46
-2
changeaction.go
plugin/dapp/autonomy/executor/changeaction.go
+6
-2
changeaction_test.go
plugin/dapp/autonomy/executor/changeaction_test.go
+38
-0
No files found.
plugin/dapp/autonomy/cmd/test/test-rpc.sh
View file @
b626e711
This diff is collapsed.
Click to expand it.
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
b626e711
...
...
@@ -237,16 +237,55 @@ func TestPropBoard(t *testing.T) {
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// ErrNotFound
BoardUpdate
:
auty
.
BoardUpdate_DELBoard
,
Boards
:
[]
string
{
"18e1nfiux7aVSfN2zYUZhbidMRokbBSPA6"
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// ErrNotFound
BoardUpdate
:
auty
.
BoardUpdate_DELBoard
,
Boards
:
[]
string
{
Addr17
,
"18e1nfiux7aVSfN2zYUZhbidMRokbBSPA6"
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// ErrBoardNumber
BoardUpdate
:
auty
.
BoardUpdate_DELBoard
,
Boards
:
[]
string
{
Addr16
,
Addr17
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// ErrRepeatAddr
BoardUpdate
:
auty
.
BoardUpdate_DELBoard
,
Boards
:
[]
string
{
Addr17
,
Addr17
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
{
// 正常
BoardUpdate
:
auty
.
BoardUpdate_DELBoard
,
Boards
:
[]
string
{
Addr17
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
EndBlockHeight
:
env
.
blockHeight
+
startEndBlockPeriod
+
10
,
},
}
result
:=
[]
error
{
auty
.
ErrRepeatAddr
,
auty
.
ErrRepeatAddr
,
auty
.
ErrBoardNumber
,
nil
,
auty
.
ErrRepeatAddr
,
auty
.
ErrBoardNumber
,
nil
,
types
.
ErrNotFound
,
types
.
ErrNotFound
,
auty
.
ErrBoardNumber
,
auty
.
ErrRepeatAddr
,
nil
,
}
lenBoards
:=
[]
int
{
0
,
0
,
0
,
22
,
0
,
0
,
21
,
0
,
0
,
0
,
0
,
20
}
InitBoard
(
stateDB
)
exec
.
SetStateDB
(
stateDB
)
...
...
@@ -256,9 +295,14 @@ func TestPropBoard(t *testing.T) {
assert
.
NoError
(
t
,
err
)
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
exec
.
Exec
(
pbtx
,
i
)
receipt
,
err
:
=
exec
.
Exec
(
pbtx
,
i
)
assert
.
Equal
(
t
,
errors
.
Cause
(
err
),
result
[
i
])
if
receipt
!=
nil
{
var
stat
auty
.
AutonomyProposalBoard
err
:=
types
.
Decode
(
receipt
.
KV
[
1
]
.
Value
,
&
stat
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
stat
.
Board
.
Boards
),
lenBoards
[
i
])
}
}
}
...
...
plugin/dapp/autonomy/executor/changeaction.go
View file @
b626e711
...
...
@@ -7,11 +7,11 @@ package executor
import
(
"sort"
"github.com/pkg/errors"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/pkg/errors"
)
func
(
a
*
action
)
propChange
(
prob
*
auty
.
ProposalChange
)
(
*
types
.
Receipt
,
error
)
{
...
...
@@ -368,6 +368,10 @@ func (a *action) replaceBoard(act *auty.ActiveBoard, change []*auty.Change) (*au
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"cancel=false not allow to addr=%s"
,
change
[
0
]
.
Addr
)
}
if
err
:=
address
.
CheckAddress
(
change
[
0
]
.
Addr
);
err
!=
nil
{
return
nil
,
err
}
mpBd
:=
make
(
map
[
string
]
struct
{})
mpRbd
:=
make
(
map
[
string
]
struct
{})
for
_
,
b
:=
range
act
.
Boards
{
...
...
plugin/dapp/autonomy/executor/changeaction_test.go
View file @
b626e711
...
...
@@ -5,6 +5,7 @@
package
executor
import
(
"github.com/33cn/chain33/util"
"testing"
"github.com/33cn/chain33/account"
...
...
@@ -593,6 +594,43 @@ func TestCheckChangeable(t *testing.T) {
assert
.
Equal
(
t
,
err
,
auty
.
ErrChangeBoardAddr
)
}
func
TestReplaceBoard
(
t
*
testing
.
T
)
{
at
:=
newTestAutonomy
()
signer
:=
util
.
HexToPrivkey
(
PrivKeyA
)
tx
:=
&
types
.
Transaction
{}
tx
.
Sign
(
types
.
SECP256K1
,
signer
)
action
:=
newAction
(
at
,
tx
,
0
)
act
:=
&
auty
.
ActiveBoard
{
Boards
:
boards
,
}
// 一个成员只允许替换一个新的
changes
:=
[]
*
auty
.
Change
{
{
Cancel
:
true
,
Addr
:
Addr18
},
{
Cancel
:
true
,
Addr
:
Addr19
},
}
_
,
err
:=
action
.
replaceBoard
(
act
,
changes
)
assert
.
ErrorIs
(
t
,
err
,
types
.
ErrInvalidParam
)
// 只允许替换,不允许恢复操作
changes
=
[]
*
auty
.
Change
{{
Cancel
:
false
,
Addr
:
Addr18
}}
_
,
err
=
action
.
replaceBoard
(
act
,
changes
)
assert
.
ErrorIs
(
t
,
err
,
types
.
ErrInvalidParam
)
// 替换一个不存在地址
changes
=
[]
*
auty
.
Change
{{
Cancel
:
true
,
Addr
:
"0x1111111111"
}}
_
,
err
=
action
.
replaceBoard
(
act
,
changes
)
assert
.
NotNil
(
t
,
err
)
// 正常替换一个地址
changes
=
[]
*
auty
.
Change
{{
Cancel
:
true
,
Addr
:
Addr18
}}
cur
,
err
:=
action
.
replaceBoard
(
act
,
changes
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
cur
.
Boards
[
0
],
Addr18
)
assert
.
Equal
(
t
,
cur
.
Revboards
[
0
],
AddrA
)
}
func
TestCopyAutonomyProposalChange
(
t
*
testing
.
T
)
{
assert
.
Nil
(
t
,
copyAutonomyProposalChange
(
nil
))
cur
:=
&
auty
.
AutonomyProposalChange
{
...
...
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