Commit 5b29261b authored by liuyuhang's avatar liuyuhang Committed by 33cn

add test

parent e720e6de
...@@ -403,10 +403,18 @@ func copyAutonomyProposalBoard(cur *auty.AutonomyProposalBoard) *auty.AutonomyPr ...@@ -403,10 +403,18 @@ func copyAutonomyProposalBoard(cur *auty.AutonomyProposalBoard) *auty.AutonomyPr
return nil return nil
} }
newAut := *cur newAut := *cur
newBoard := *cur.GetPropBoard() if cur.PropBoard != nil {
newRes := *cur.GetVoteResult() newBoard := *cur.GetPropBoard()
newAut.PropBoard = &newBoard newAut.PropBoard = &newBoard
newAut.VoteResult = &newRes }
if cur.CurRule != nil {
newRule := *cur.GetCurRule()
newAut.CurRule = &newRule
}
if cur.VoteResult != nil {
newRes := *cur.GetVoteResult()
newAut.VoteResult = &newRes
}
return &newAut return &newAut
} }
...@@ -460,22 +460,25 @@ func TestCopyAutonomyProposalBoard(t *testing.T) { ...@@ -460,22 +460,25 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
require.Nil(t, copyAutonomyProposalBoard(nil)) require.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{BoardAttendRatio: 100},
VoteResult: &auty.VoteResult{TotalVotes: 100}, VoteResult: &auty.VoteResult{TotalVotes: 100},
Status: 2, Status: 2,
Address:"123", Address:"123",
} }
new := copyAutonomyProposalBoard(cur) pre := copyAutonomyProposalBoard(cur)
cur.PropBoard.Year = 1800 cur.PropBoard.Year = 1800
cur.PropBoard.Month = 2 cur.PropBoard.Month = 2
cur.CurRule.BoardAttendRatio = 90
cur.VoteResult.TotalVotes = 50 cur.VoteResult.TotalVotes = 50
cur.Address = "234" cur.Address = "234"
cur.Status = 1 cur.Status = 1
require.Equal(t, 1900, int(new.PropBoard.Year)) require.Equal(t, 1900, int(pre.PropBoard.Year))
require.Equal(t, 1, int(new.PropBoard.Month)) require.Equal(t, 1, int(pre.PropBoard.Month))
require.Equal(t, 100, int(new.VoteResult.TotalVotes)) require.Equal(t, 100, int(pre.CurRule.BoardAttendRatio))
require.Equal(t, "123", new.Address) require.Equal(t, 100, int(pre.VoteResult.TotalVotes))
require.Equal(t, 2, int(new.Status)) require.Equal(t, "123", pre.Address)
require.Equal(t, 2, int(pre.Status))
} }
func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) { func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) {
......
...@@ -15,8 +15,8 @@ import ( ...@@ -15,8 +15,8 @@ import (
func (a *action) propProject(prob *auty.ProposalProject) (*types.Receipt, error) { func (a *action) propProject(prob *auty.ProposalProject) (*types.Receipt, error) {
if err := address.CheckAddress(prob.ToAddr); err != nil { if err := address.CheckAddress(prob.ToAddr); err != nil {
alog.Error("propProject ", "check toAddr error", err) alog.Error("propProject ", "addr", prob.ToAddr, "check toAddr error", err)
return nil, types.ErrInvalidParam 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 {
...@@ -465,12 +465,22 @@ func copyAutonomyProposalProject(cur *auty.AutonomyProposalProject) *auty.Autono ...@@ -465,12 +465,22 @@ func copyAutonomyProposalProject(cur *auty.AutonomyProposalProject) *auty.Autono
return nil return nil
} }
newAut := *cur newAut := *cur
newProject := *cur.GetPropProject() if cur.PropProject != nil{
newRes := *cur.GetBoardVoteRes() newProject := *cur.GetPropProject()
newPub := *cur.GetPubVote() newAut.PropProject = &newProject
newAut.PropProject = &newProject }
newAut.BoardVoteRes = &newRes if cur.CurRule != nil {
newAut.PubVote = &newPub newRule := *cur.GetCurRule()
newAut.CurRule = &newRule
}
if cur.BoardVoteRes != nil {
newRes := *cur.GetBoardVoteRes()
newAut.BoardVoteRes = &newRes
}
if cur.PubVote != nil {
newPub := *cur.GetPubVote()
newAut.PubVote = &newPub
}
return &newAut return &newAut
} }
This diff is collapsed.
...@@ -314,18 +314,22 @@ func copyAutonomyProposalRule(cur *auty.AutonomyProposalRule) *auty.AutonomyProp ...@@ -314,18 +314,22 @@ func copyAutonomyProposalRule(cur *auty.AutonomyProposalRule) *auty.AutonomyProp
return nil return nil
} }
newAut := *cur newAut := *cur
newPropRule := *cur.GetPropRule() if cur.PropRule != nil {
var newCfg *auty.RuleConfig newPropRule := *cur.GetPropRule()
if newPropRule.RuleCfg != nil { newAut.PropRule = &newPropRule
cfg := *cur.GetPropRule().GetRuleCfg() if cur.PropRule.RuleCfg != nil {
newCfg = &cfg cfg := *cur.GetPropRule().GetRuleCfg()
} newAut.PropRule.RuleCfg = &cfg
newRule := *cur.GetRule() }
newRes := *cur.GetVoteResult() }
newAut.PropRule = &newPropRule if cur.Rule != nil {
newAut.PropRule.RuleCfg = newCfg newRule := *cur.GetRule()
newAut.Rule = &newRule newAut.Rule = &newRule
newAut.VoteResult = &newRes }
if cur.VoteResult != nil {
newRes := *cur.GetVoteResult()
newAut.VoteResult = &newRes
}
return &newAut return &newAut
} }
......
...@@ -406,7 +406,7 @@ func TestCopyAutonomyProposalRule(t *testing.T) { ...@@ -406,7 +406,7 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
Status: 2, Status: 2,
Address:"123", Address:"123",
} }
new := copyAutonomyProposalRule(cur) pre := copyAutonomyProposalRule(cur)
cur.PropRule.Year = 1800 cur.PropRule.Year = 1800
cur.PropRule.Month = 2 cur.PropRule.Month = 2
cur.PropRule.RuleCfg.BoardApproveRatio = 90 cur.PropRule.RuleCfg.BoardApproveRatio = 90
...@@ -415,13 +415,13 @@ func TestCopyAutonomyProposalRule(t *testing.T) { ...@@ -415,13 +415,13 @@ func TestCopyAutonomyProposalRule(t *testing.T) {
cur.Address = "234" cur.Address = "234"
cur.Status = 1 cur.Status = 1
require.Equal(t, 1900, int(new.PropRule.Year)) require.Equal(t, 1900, int(pre.PropRule.Year))
require.Equal(t, 1, int(new.PropRule.Month)) require.Equal(t, 1, int(pre.PropRule.Month))
require.Equal(t, 100, int(new.VoteResult.TotalVotes)) require.Equal(t, 100, int(pre.VoteResult.TotalVotes))
require.Equal(t, "123", new.Address) require.Equal(t, "123", pre.Address)
require.Equal(t, 2, int(new.Status)) require.Equal(t, 2, int(pre.Status))
require.Equal(t, 80, int(new.PropRule.RuleCfg.BoardApproveRatio)) require.Equal(t, 80, int(pre.PropRule.RuleCfg.BoardApproveRatio))
require.Equal(t, 100, int(new.Rule.BoardApproveRatio)) require.Equal(t, 100, int(pre.Rule.BoardApproveRatio))
} }
func TestUpgradeRule(t *testing.T) { func TestUpgradeRule(t *testing.T) {
......
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