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