Commit 9771febb authored by liuyuhang's avatar liuyuhang

add change test

parent 05b8ae47
...@@ -58,14 +58,14 @@ func proposalChange(cmd *cobra.Command, args []string) { ...@@ -58,14 +58,14 @@ func proposalChange(cmd *cobra.Command, args []string) {
if len(per) == 2 { if len(per) == 2 {
if per[1] == "true" { if per[1] == "true" {
change := &auty.Change{ change := &auty.Change{
Cancel:true, Cancel: true,
Addr:per[0], Addr: per[0],
} }
changes = append(changes, change) changes = append(changes, change)
} else if per[1] == "false" { } else if per[1] == "false" {
change := &auty.Change{ change := &auty.Change{
Cancel:false, Cancel: false,
Addr:per[0], Addr: per[0],
} }
changes = append(changes, change) changes = append(changes, change)
} }
......
...@@ -7,12 +7,13 @@ package commands ...@@ -7,12 +7,13 @@ package commands
import ( import (
"encoding/json" "encoding/json"
"strings"
jsonrpc "github.com/33cn/chain33/rpc/jsonclient" jsonrpc "github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types" rpctypes "github.com/33cn/chain33/rpc/types"
"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/spf13/cobra" "github.com/spf13/cobra"
"strings"
) )
// ProposalProjectCmd 创建提案命令 // ProposalProjectCmd 创建提案命令
......
...@@ -7,12 +7,13 @@ package commands ...@@ -7,12 +7,13 @@ package commands
import ( import (
"encoding/json" "encoding/json"
"strings"
jsonrpc "github.com/33cn/chain33/rpc/jsonclient" jsonrpc "github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types" rpctypes "github.com/33cn/chain33/rpc/types"
"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/spf13/cobra" "github.com/spf13/cobra"
"strings"
) )
// ProposalRuleCmd 创建提案命令 // ProposalRuleCmd 创建提案命令
......
...@@ -398,7 +398,7 @@ func (a *action) verifyMinerAddr(addrs []string, bindAddr string) (string, error ...@@ -398,7 +398,7 @@ func (a *action) verifyMinerAddr(addrs []string, bindAddr string) (string, error
} }
tkBind := &ticketTy.TicketBind{} tkBind := &ticketTy.TicketBind{}
err = types.Decode(value, tkBind) err = types.Decode(value, tkBind)
if err != nil ||tkBind.MinerAddress != bindAddr { if err != nil || tkBind.MinerAddress != bindAddr {
return addr, auty.ErrBindAddr return addr, auty.ErrBindAddr
} }
} }
......
...@@ -20,10 +20,10 @@ import ( ...@@ -20,10 +20,10 @@ import (
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
"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"
ticket "github.com/33cn/plugin/plugin/dapp/ticket/executor"
ticketTy "github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ticketTy "github.com/33cn/plugin/plugin/dapp/ticket/types"
ticket "github.com/33cn/plugin/plugin/dapp/ticket/executor"
) )
// ExecEnv exec environment // ExecEnv exec environment
...@@ -58,30 +58,57 @@ var ( ...@@ -58,30 +58,57 @@ var (
PrivKey9 = "0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1" PrivKey9 = "0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1"
PrivKey10 = "0x1c3e6cac2f887e1ab9180e2d5772dc4ba01accb8d4df434faba097003eb35482" PrivKey10 = "0x1c3e6cac2f887e1ab9180e2d5772dc4ba01accb8d4df434faba097003eb35482"
Addr1 = "12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
Addr2 = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
Addr3 = "12cjnN5D4DPdBQSwh6vjwJbtsW4EJALTMv"
Addr4 = "1Luh4AziYyaC5zP3hUXtXFZS873xAxm6rH"
Addr5 = "1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB"
Addr6 = "1L1puAUjfmtDECKo2C1qLWsAMZtDGTBWf6"
Addr7 = "1LNf9AVXzUMQkQM5hgGLhkdrVtD8UMBSUm"
Addr8 = "1PcGKYYoLn1PLLJJodc1UpgWGeFAQasAkx"
Addr9 = "1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu"
Addr10 = "1Q9sQwothzM1gKSzkVZ8Dt1tqKX1uzSagx"
PrivKey11 = "0xfd0c4a8a1efcd221ee0f36b7d4f57d8ff843cb8bc193b39c7863332d355acafa"
PrivKey12 = "0x4c9691bf6acc908ef5c07abcad23cf7f98e46e84101aa5059322aa53eb4dc471"
PrivKey13 = "0x50b9c6a4358ef8ffc96d5831a8dfd5e0fae504d49e20c5eafd12b6015423de33"
PrivKey14 = "0x96e3c766850a915fe4718b890d96208d5d1a3694b2597e08165480b5b48b84cb"
PrivKey15 = "0xeac5e45243c3920cf8a98f3d3a2e3a9b43f30a21769b57f734213913511e7575"
PrivKey16 = "0xd2aaa6f050a4db13fbd2c8bf87cbb96e217289172baca6c12e8a8b0680b9aa1a"
PrivKey17 = "0x33b3b977c657435a49773b5605a704ad5fdca0fa34fe36a02ea0f13a49099832"
Addr11 = "15VUiygdxMSZ3rykwe742yomp2cPJ9Tfve"
Addr12 = "1DyR84CU5AHbGXLEnhHMwMvWNMeunLZsuJ"
Addr13 = "132pBvrgSYgHASxzoeL3bqnsqUpaBbUktm"
Addr14 = "1DEV4XwdBUWRkMuy4ARRiEAoxQ2LoDByNG"
Addr15 = "18Y87cw2hiYC71bvpD872oYMYXtw66Qp6o"
Addr16 = "1Fghq6cgdJEDr6gQBmvba3t6aXAkyZyjr2"
Addr17 = "142KsfJLvEA5FJxAgKm9ZDtFVjkRaPdu82"
boards = []string{ boards = []string{
AddrA, AddrA,
AddrB, AddrB,
AddrC, AddrC,
AddrD, AddrD,
"12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d", Addr1,
"1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj", Addr2,
"12cjnN5D4DPdBQSwh6vjwJbtsW4EJALTMv", Addr3,
"1Luh4AziYyaC5zP3hUXtXFZS873xAxm6rH", Addr4,
"1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB", Addr5,
"1L1puAUjfmtDECKo2C1qLWsAMZtDGTBWf6", Addr6,
"1LNf9AVXzUMQkQM5hgGLhkdrVtD8UMBSUm", Addr7,
"1PcGKYYoLn1PLLJJodc1UpgWGeFAQasAkx", Addr8,
"1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu", Addr9,
"1Q9sQwothzM1gKSzkVZ8Dt1tqKX1uzSagx", Addr10,
"15VUiygdxMSZ3rykwe742yomp2cPJ9Tfve", Addr11,
"1DyR84CU5AHbGXLEnhHMwMvWNMeunLZsuJ", Addr12,
"132pBvrgSYgHASxzoeL3bqnsqUpaBbUktm", Addr13,
"1DEV4XwdBUWRkMuy4ARRiEAoxQ2LoDByNG", Addr14,
"18Y87cw2hiYC71bvpD872oYMYXtw66Qp6o", Addr15,
"1Fghq6cgdJEDr6gQBmvba3t6aXAkyZyjr2", Addr16,
"142KsfJLvEA5FJxAgKm9ZDtFVjkRaPdu82", Addr17,
} }
total = types.Coin * 30000 total = types.Coin * 30000
) )
......
This diff is collapsed.
...@@ -8,10 +8,8 @@ import ( ...@@ -8,10 +8,8 @@ import (
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"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"
) )
func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) { func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) {
//如果全小于等于0,则说明该提案规则参数不正确 //如果全小于等于0,则说明该提案规则参数不正确
if prob == nil || len(prob.Changes) == 0 { if prob == nil || len(prob.Changes) == 0 {
...@@ -59,7 +57,7 @@ func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) { ...@@ -59,7 +57,7 @@ func (a *action) propChange(prob *auty.ProposalChange) (*types.Receipt, error) {
PropChange: prob, PropChange: prob,
CurRule: rule, CurRule: rule,
Board: new, Board: new,
VoteResult: &auty.VoteResult{TotalVotes:int32(len(act.Boards))}, VoteResult: &auty.VoteResult{TotalVotes: int32(len(act.Boards))},
Status: auty.AutonomyStatusProposalChange, Status: auty.AutonomyStatusProposalChange,
Address: a.fromaddr, Address: a.fromaddr,
Height: a.height, Height: a.height,
...@@ -168,15 +166,10 @@ func (a *action) votePropChange(voteProb *auty.VoteProposalChange) (*types.Recei ...@@ -168,15 +166,10 @@ func (a *action) votePropChange(voteProb *auty.VoteProposalChange) (*types.Recei
// 更新投票记录 // 更新投票记录
votes.Address = append(votes.Address, a.fromaddr) votes.Address = append(votes.Address, a.fromaddr)
// 获取可投票数
vtCouts, err := a.getAddressVotes(a.fromaddr, start)
if err != nil {
return nil, err
}
if voteProb.Approve { if voteProb.Approve {
cur.VoteResult.ApproveVotes += vtCouts cur.VoteResult.ApproveVotes++
} else { } else {
cur.VoteResult.OpposeVotes += vtCouts cur.VoteResult.OpposeVotes++
} }
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
...@@ -359,13 +352,14 @@ func copyAutonomyProposalChange(cur *auty.AutonomyProposalChange) *auty.Autonomy ...@@ -359,13 +352,14 @@ func copyAutonomyProposalChange(cur *auty.AutonomyProposalChange) *auty.Autonomy
} }
newAut := *cur newAut := *cur
if cur.PropChange != nil { if cur.PropChange != nil {
newPropChange := *cur.GetPropChange() newPropChange := *cur.PropChange
newAut.PropChange = &newPropChange newAut.PropChange = &newPropChange
if cur.PropChange.Changes != nil { if cur.PropChange.Changes != nil {
chs := cur.GetPropChange().GetChanges() newAut.PropChange.Changes = make([]*auty.Change, len(cur.PropChange.Changes))
for _, ch := range chs { chs := cur.PropChange.Changes
for i, ch := range chs {
newch := *ch newch := *ch
newAut.PropChange.Changes = append(newAut.PropChange.Changes, &newch) newAut.PropChange.Changes[i] = &newch
} }
} }
} }
...@@ -375,6 +369,10 @@ func copyAutonomyProposalChange(cur *auty.AutonomyProposalChange) *auty.Autonomy ...@@ -375,6 +369,10 @@ func copyAutonomyProposalChange(cur *auty.AutonomyProposalChange) *auty.Autonomy
} }
if cur.Board != nil { if cur.Board != nil {
newBoard := *cur.GetBoard() newBoard := *cur.GetBoard()
newBoard.Boards = make([]string, len(cur.Board.Boards))
copy(newBoard.Boards, cur.Board.Boards)
newBoard.Revboards = make([]string, len(cur.Board.Revboards))
copy(newBoard.Revboards, cur.Board.Revboards)
newAut.Board = &newBoard newAut.Board = &newBoard
} }
if cur.VoteResult != nil { if cur.VoteResult != nil {
......
This diff is collapsed.
...@@ -105,7 +105,6 @@ func (a *Autonomy) Exec_CommentProp(payload *auty.Comment, tx *types.Transaction ...@@ -105,7 +105,6 @@ func (a *Autonomy) Exec_CommentProp(payload *auty.Comment, tx *types.Transaction
return action.commentProp(payload) return action.commentProp(payload)
} }
// 提案修改董事会成员相关 // 提案修改董事会成员相关
// Exec_PropChange 创建提案规则 // Exec_PropChange 创建提案规则
......
...@@ -85,7 +85,6 @@ func (a *Autonomy) ExecLocal_CommentProp(payload *auty.Comment, tx *types.Transa ...@@ -85,7 +85,6 @@ func (a *Autonomy) ExecLocal_CommentProp(payload *auty.Comment, tx *types.Transa
return a.execAutoLocalCommentProp(tx, receiptData) return a.execAutoLocalCommentProp(tx, receiptData)
} }
// 提案修改董事会成员相关 // 提案修改董事会成员相关
// ExecLocal_PropChange 创建提案规则 // ExecLocal_PropChange 创建提案规则
......
...@@ -37,10 +37,10 @@ func (a *action) propProject(prob *auty.ProposalProject) (*types.Receipt, error) ...@@ -37,10 +37,10 @@ func (a *action) propProject(prob *auty.ProposalProject) (*types.Receipt, error)
} }
// 检查是否可以对已审批额度归0,如果可以则设置kv // 检查是否可以对已审批额度归0,如果可以则设置kv
var kva *types.KeyValue var kva *types.KeyValue
if a.height > pboard.StartHeight + boardPeriod { if a.height > pboard.StartHeight+boardPeriod {
pboard.StartHeight = a.height pboard.StartHeight = a.height
pboard.Amount = 0 pboard.Amount = 0
kva = &types.KeyValue{Key:activeBoardID(), Value:types.Encode(pboard)} kva = &types.KeyValue{Key: activeBoardID(), Value: types.Encode(pboard)}
} }
// 检查额度 // 检查额度
pass := a.checkPeriodAmount(pboard, prob.Amount) pass := a.checkPeriodAmount(pboard, prob.Amount)
...@@ -593,7 +593,7 @@ func (a *action) checkPeriodAmount(act *auty.ActiveBoard, amount int64) bool { ...@@ -593,7 +593,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
...@@ -604,10 +604,10 @@ func (a *action) updatePeriodAmount(amount int64) (*types.KeyValue, error) { ...@@ -604,10 +604,10 @@ func (a *action) updatePeriodAmount(amount int64) (*types.KeyValue, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if a.height > act.StartHeight + boardPeriod { if a.height > act.StartHeight+boardPeriod {
act.StartHeight = a.height act.StartHeight = a.height
act.Amount = 0 act.Amount = 0
} }
act.Amount += amount act.Amount += amount
return &types.KeyValue{Key:activeBoardID(), Value:types.Encode(act)}, nil return &types.KeyValue{Key: activeBoardID(), Value: types.Encode(act)}, nil
} }
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
"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/33cn/chain33/system/dapp"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/system/dapp"
) )
const ( const (
...@@ -34,13 +34,12 @@ const ( ...@@ -34,13 +34,12 @@ const (
minProposalAmount = types.Coin * 20 minProposalAmount = types.Coin * 20
// 最大提案金 // 最大提案金
maxProposalAmount = types.Coin * 2000 maxProposalAmount = types.Coin * 2000
) )
func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) { func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
//如果全小于等于0,则说明该提案规则参数不正确 //如果全小于等于0,则说明该提案规则参数不正确
if prob.RuleCfg == nil || prob.RuleCfg.BoardApproveRatio <= 0 && prob.RuleCfg.PubOpposeRatio <= 0 && if prob.RuleCfg == nil || prob.RuleCfg.BoardApproveRatio <= 0 && prob.RuleCfg.PubOpposeRatio <= 0 &&
prob.RuleCfg.ProposalAmount <= 0 && prob.RuleCfg.LargeProjectAmount <= 0 && prob.RuleCfg.PublicPeriod <= 0{ prob.RuleCfg.ProposalAmount <= 0 && prob.RuleCfg.LargeProjectAmount <= 0 && prob.RuleCfg.PublicPeriod <= 0 {
alog.Error("propRule ", "ProposalRule RuleCfg invaild or have no modify param", prob.RuleCfg) alog.Error("propRule ", "ProposalRule RuleCfg invaild or have no modify param", prob.RuleCfg)
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
...@@ -48,7 +47,7 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) { ...@@ -48,7 +47,7 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
prob.RuleCfg.PubOpposeRatio > maxPubOpposeRatio || prob.RuleCfg.PubOpposeRatio < minPubOpposeRatio || prob.RuleCfg.PubOpposeRatio > maxPubOpposeRatio || prob.RuleCfg.PubOpposeRatio < minPubOpposeRatio ||
prob.RuleCfg.PublicPeriod > maxPublicPeriod || prob.RuleCfg.PublicPeriod < minPublicPeriod || prob.RuleCfg.PublicPeriod > maxPublicPeriod || prob.RuleCfg.PublicPeriod < minPublicPeriod ||
prob.RuleCfg.LargeProjectAmount > maxLargeProjectAmount || prob.RuleCfg.LargeProjectAmount < minLargeProjectAmount || prob.RuleCfg.LargeProjectAmount > maxLargeProjectAmount || prob.RuleCfg.LargeProjectAmount < minLargeProjectAmount ||
prob.RuleCfg.ProposalAmount > maxProposalAmount || prob.RuleCfg.ProposalAmount < minProposalAmount{ prob.RuleCfg.ProposalAmount > maxProposalAmount || prob.RuleCfg.ProposalAmount < minProposalAmount {
alog.Error("propRule RuleCfg invaild", "ruleCfg", prob.RuleCfg) alog.Error("propRule RuleCfg invaild", "ruleCfg", prob.RuleCfg)
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
......
...@@ -88,8 +88,6 @@ const ( ...@@ -88,8 +88,6 @@ const (
AutonomyStatusTmintPropChange AutonomyStatusTmintPropChange
) )
const ( const (
// GetProposalBoard 用于在cmd里面的区分不同的查询 // GetProposalBoard 用于在cmd里面的区分不同的查询
GetProposalBoard = "GetProposalBoard" GetProposalBoard = "GetProposalBoard"
......
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