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