fix comments and add CHANGELOG

This commit is contained in:
antstalepresh 2021-02-06 00:57:12 +10:00
parent b125fccfd2
commit b55913ddad
6 changed files with 71 additions and 6 deletions

View File

@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements
* (x/gov) [\#7733](https://github.com/cosmos/cosmos-sdk/pull/7733) ADR 037 Implementation: Governance Split Votes
* (x/bank) [\#8302](https://github.com/cosmos/cosmos-sdk/issues/8302) Add gRPC and CLI queries for client denomination metadata.
* (tendermint) [\#8316](https://github.com/cosmos/cosmos-sdk/pull/8316) Bump Tendermint version to [v0.34.2](https://github.com/tendermint/tendermint/releases/tag/v0.34.2)

View File

@ -6,7 +6,7 @@
## Status
Proposed
Accepted
## Abstract

View File

@ -0,0 +1,56 @@
package utils
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNormalizeWeightedVoteOptions(t *testing.T) {
cases := map[string]struct {
options string
normalized string
}{
"simple Yes": {
options: "Yes",
normalized: "VOTE_OPTION_YES=1",
},
"simple yes": {
options: "yes",
normalized: "VOTE_OPTION_YES=1",
},
"formal yes": {
options: "yes=1",
normalized: "VOTE_OPTION_YES=1",
},
"half yes half no": {
options: "yes=0.5,no=0.5",
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5",
},
"3 options": {
options: "Yes=0.5,No=0.4,NoWithVeto=0.1",
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.4,VOTE_OPTION_NO_WITH_VETO=0.1",
},
"zero weight option": {
options: "Yes=0.5,No=0.5,NoWithVeto=0",
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5,VOTE_OPTION_NO_WITH_VETO=0",
},
"minus weight option": {
options: "Yes=0.5,No=0.6,NoWithVeto=-0.1",
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.6,VOTE_OPTION_NO_WITH_VETO=-0.1",
},
"empty options": {
options: "",
normalized: "=1",
},
"not available option": {
options: "Yessss=1",
normalized: "Yessss=1",
},
}
for _, tc := range cases {
normalized := NormalizeWeightedVoteOptions(tc.options)
require.Equal(t, normalized, tc.normalized)
}
}

View File

@ -423,6 +423,7 @@ func TestTallyJailedValidator(t *testing.T) {
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], types.NewNonSplitVoteOption(types.OptionYes)))
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], types.NewNonSplitVoteOption(types.OptionNo)))
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], types.NewNonSplitVoteOption(types.OptionNo)))
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
require.True(t, ok)

View File

@ -258,6 +258,10 @@ func (msg MsgVoteWeighted) ValidateBasic() error {
return sdkerrors.Wrap(ErrInvalidVote, "Total weight overflow 1.00")
}
if totalWeight.LT(sdk.NewDec(1)) {
return sdkerrors.Wrap(ErrInvalidVote, "Total weight lower than 1.00")
}
return nil
}

View File

@ -1,13 +1,13 @@
package types
import (
"encoding/json"
"fmt"
"strings"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
)
// NewVote creates a new Vote instance
@ -62,16 +62,19 @@ func NewNonSplitVoteOption(option VoteOption) WeightedVoteOptions {
}
func (v WeightedVoteOption) String() string {
out, _ := json.Marshal(v)
out, _ := proto.Marshal(&v)
return string(out)
}
// WeightedVoteOptions describes array of WeightedVoteOptions
type WeightedVoteOptions []WeightedVoteOption
func (v WeightedVoteOptions) String() string {
out, _ := json.Marshal(v)
return string(out)
func (v WeightedVoteOptions) String() (out string) {
for _, opt := range v {
out += opt.String() + "\n"
}
return strings.TrimSpace(out)
}
// ValidWeightedVoteOption returns true if the sub vote is valid and false otherwise.