Commit b626e711 authored by QM's avatar QM

fix autonomy unit test and rpc test

parent f1252ce0
This diff is collapsed.
......@@ -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])
}
}
}
......
......@@ -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 {
......
......@@ -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{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment