Commit 095c7c43 authored by jiangpeng's avatar jiangpeng Committed by vipwzw

vote:add group name to vote info

parent 15fc6a0d
......@@ -84,21 +84,21 @@ func (v *vote) ExecLocal_UpdateGroup(update *vty.UpdateGroup, tx *types.Transact
func (v *vote) ExecLocal_CreateVote(payload *vty.CreateVote, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
voteInfo := decodeVoteInfo(receiptData.Logs[0].Log)
table := newVoteTable(v.GetLocalDB())
kvs, err := v.updateAndSaveTable(table.Add, table.Save, voteInfo, tx, vty.NameCreateVoteAction, "vote")
if err != nil {
return nil, err
}
dbSet.KV = kvs
table = newGroupTable(v.GetLocalDB())
row, err := table.GetData([]byte(voteInfo.GroupID))
vTable := newVoteTable(v.GetLocalDB())
gTable := newGroupTable(v.GetLocalDB())
row, err := gTable.GetData([]byte(voteInfo.GroupID))
if err != nil {
elog.Error("execLocal createVote", "txHash", hex.EncodeToString(tx.Hash()), "voteTable get", err)
return nil, err
}
groupInfo, _ := row.Data.(*vty.GroupInfo)
groupInfo.VoteNum++
kvs, err = v.updateAndSaveTable(table.Replace, table.Save, groupInfo, tx, vty.NameCreateVoteAction, "group")
voteInfo.GroupName = groupInfo.GetName()
dbSet.KV, err = v.updateAndSaveTable(vTable.Add, vTable.Save, voteInfo, tx, vty.NameCreateVoteAction, "vote")
if err != nil {
return nil, err
}
kvs, err := v.updateAndSaveTable(gTable.Replace, gTable.Save, groupInfo, tx, vty.NameCreateVoteAction, "group")
if err != nil {
return nil, err
}
......
......@@ -149,18 +149,26 @@ func TestVote_ExecLocal_CreateVote(t *testing.T) {
options := []*vty.VoteOption{{Option: "A"}, {Option: "B"}}
tcArr := []*testcase{{
index: 0,
payload: &vty.CreateGroup{Name: "test"},
payload: &vty.CreateGroup{Name: "g1"},
}, {
index: 1,
payload: &vty.CreateVote{Name: "test", GroupID: groupID, VoteOptions: []string{"A", "B"},
payload: &vty.CreateVote{Name: "v1", GroupID: groupID, VoteOptions: []string{"A", "B"},
BeginTimestamp: testBlockTime, EndTimestamp: testBlockTime + 1},
}, {
index: 2,
payload: &vty.CreateVote{Name: "v2", GroupID: groupID, VoteOptions: []string{"A", "B"},
BeginTimestamp: testBlockTime, EndTimestamp: testBlockTime + 1},
}, {
index: 3,
payload: &vty.CreateVote{Name: "v3", GroupID: groupID, VoteOptions: []string{"A", "B"},
BeginTimestamp: testBlockTime, EndTimestamp: testBlockTime + 1},
}}
testExec(t, mock, testTypeExecLocal, tcArr, privKeys[0])
table := newVoteTable(mock.exec.GetLocalDB())
expectVoteInfo := &vty.VoteInfo{
Name: "test", VoteOptions: options, BeginTimestamp: testBlockTime, EndTimestamp: testBlockTime + 1,
GroupID: groupID, ID: voteID, Creator: testAddrs[0],
Name: "v1", VoteOptions: options, BeginTimestamp: testBlockTime, EndTimestamp: testBlockTime + 1,
GroupID: groupID, ID: voteID, Creator: testAddrs[0], GroupName: "g1",
}
testTableData(t, table, []*tableCase{{
index: 0,
......@@ -172,11 +180,10 @@ func TestVote_ExecLocal_CreateVote(t *testing.T) {
row, err := table.GetData([]byte(groupID))
require.Nil(t, err)
info, _ := row.Data.(*vty.GroupInfo)
require.Equal(t, uint32(1), info.VoteNum)
tx := util.CreateNoneTx(mock.cfg, privKeys[0])
group, err := newAction(mock.exec, tx, 0).getGroupInfo(groupID)
require.Nil(t, err)
group.VoteNum = info.VoteNum
group.VoteNum = 3
require.Equal(t, group.String(), info.String())
}
......@@ -208,6 +215,7 @@ func TestVote_ExecLocal_CloseVote(t *testing.T) {
tx := util.CreateNoneTx(mock.cfg, privKeys[0])
vote, err := newAction(mock.exec, tx, 0).getVoteInfo(voteID)
require.Nil(t, err)
vote.GroupName = "test"
require.Equal(t, vote.String(), info.String())
}
......@@ -243,6 +251,7 @@ func TestVote_ExecLocal_CommitVote(t *testing.T) {
require.Nil(t, err)
vote.CommitInfos[0].TxHash = info.CommitInfos[0].TxHash
vote.CommitInfos[0].VoteWeight = info.CommitInfos[0].VoteWeight
vote.GroupName = "test"
require.Equal(t, vote.String(), info.String())
}
......
......@@ -104,6 +104,7 @@ message VoteInfo {
repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息
uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
string groupName = 11; //所属投票组名称
}
message VoteInfos {
......
This diff is collapsed.
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