Skip to content

Commit

Permalink
MsgWeightedVote -> MsgVoteWeighted
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed Jan 25, 2021
1 parent 56ed27a commit b125fcc
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 163 deletions.
6 changes: 3 additions & 3 deletions docs/architecture/adr-037-gov-split-vote.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ type Vote struct {
}
```

And for backwards compatibility, we introduce `MsgWeightedVote` while keeping `MsgVote`.
And for backwards compatibility, we introduce `MsgVoteWeighted` while keeping `MsgVote`.
```
type MsgVote struct {
ProposalID int64
Voter sdk.Address
Option Option
}
type MsgWeightedVote struct {
type MsgVoteWeighted struct {
ProposalID int64
Voter sdk.Address
Options []WeightedVoteOption
}
```

The `ValidateBasic` of a `MsgWeightedVote` struct would require that
The `ValidateBasic` of a `MsgVoteWeighted` struct would require that
1. The sum of all the Rates is equal to 1.0
2. No Option is repeated

Expand Down
16 changes: 8 additions & 8 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@
- [MsgSubmitProposalResponse](#cosmos.gov.v1beta1.MsgSubmitProposalResponse)
- [MsgVote](#cosmos.gov.v1beta1.MsgVote)
- [MsgVoteResponse](#cosmos.gov.v1beta1.MsgVoteResponse)
- [MsgWeightedVote](#cosmos.gov.v1beta1.MsgWeightedVote)
- [MsgWeightedVoteResponse](#cosmos.gov.v1beta1.MsgWeightedVoteResponse)
- [MsgVoteWeighted](#cosmos.gov.v1beta1.MsgVoteWeighted)
- [MsgVoteWeightedResponse](#cosmos.gov.v1beta1.MsgVoteWeightedResponse)

- [Msg](#cosmos.gov.v1beta1.Msg)

Expand Down Expand Up @@ -4402,9 +4402,9 @@ MsgVoteResponse defines the Msg/Vote response type.



<a name="cosmos.gov.v1beta1.MsgWeightedVote"></a>
<a name="cosmos.gov.v1beta1.MsgVoteWeighted"></a>

### MsgWeightedVote
### MsgVoteWeighted
MsgVote defines a message to cast a vote.


Expand All @@ -4419,10 +4419,10 @@ MsgVote defines a message to cast a vote.



<a name="cosmos.gov.v1beta1.MsgWeightedVoteResponse"></a>
<a name="cosmos.gov.v1beta1.MsgVoteWeightedResponse"></a>

### MsgWeightedVoteResponse
MsgWeightedVoteResponse defines the MsgWeightedVote response type.
### MsgVoteWeightedResponse
MsgVoteWeightedResponse defines the MsgVoteWeighted response type.



Expand All @@ -4444,7 +4444,7 @@ Msg defines the bank Msg service.
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `SubmitProposal` | [MsgSubmitProposal](#cosmos.gov.v1beta1.MsgSubmitProposal) | [MsgSubmitProposalResponse](#cosmos.gov.v1beta1.MsgSubmitProposalResponse) | SubmitProposal defines a method to create new proposal given a content. | |
| `Vote` | [MsgVote](#cosmos.gov.v1beta1.MsgVote) | [MsgVoteResponse](#cosmos.gov.v1beta1.MsgVoteResponse) | Vote defines a method to add a vote on a specific proposal. | |
| `WeightedVote` | [MsgWeightedVote](#cosmos.gov.v1beta1.MsgWeightedVote) | [MsgWeightedVoteResponse](#cosmos.gov.v1beta1.MsgWeightedVoteResponse) | WeightedVote defines a method to add a weighted vote on a specific proposal. | |
| `VoteWeighted` | [MsgVoteWeighted](#cosmos.gov.v1beta1.MsgVoteWeighted) | [MsgVoteWeightedResponse](#cosmos.gov.v1beta1.MsgVoteWeightedResponse) | WeightedVote defines a method to add a weighted vote on a specific proposal. | |
| `Deposit` | [MsgDeposit](#cosmos.gov.v1beta1.MsgDeposit) | [MsgDepositResponse](#cosmos.gov.v1beta1.MsgDepositResponse) | Deposit defines a method to add deposit on a specific proposal. | |

<!-- end services -->
Expand Down
8 changes: 4 additions & 4 deletions proto/cosmos/gov/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ service Msg {
rpc Vote(MsgVote) returns (MsgVoteResponse);

// WeightedVote defines a method to add a weighted vote on a specific proposal.
rpc WeightedVote(MsgWeightedVote) returns (MsgWeightedVoteResponse);
rpc VoteWeighted(MsgVoteWeighted) returns (MsgVoteWeightedResponse);

// Deposit defines a method to add deposit on a specific proposal.
rpc Deposit(MsgDeposit) returns (MsgDepositResponse);
Expand Down Expand Up @@ -59,7 +59,7 @@ message MsgVote {
}

// MsgVote defines a message to cast a vote.
message MsgWeightedVote {
message MsgVoteWeighted {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.stringer) = false;
Expand All @@ -73,8 +73,8 @@ message MsgWeightedVote {
// MsgVoteResponse defines the Msg/Vote response type.
message MsgVoteResponse {}

// MsgWeightedVoteResponse defines the MsgWeightedVote response type.
message MsgWeightedVoteResponse {}
// MsgVoteWeightedResponse defines the MsgVoteWeighted response type.
message MsgVoteWeightedResponse {}

// MsgDeposit defines a message to submit a deposit to an existing proposal.
message MsgDeposit {
Expand Down
2 changes: 1 addition & 1 deletion simapp/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
DefaultWeightMsgFundCommunityPool int = 50
DefaultWeightMsgDeposit int = 100
DefaultWeightMsgVote int = 67
DefaultWeightMsgWeightedVote int = 33
DefaultWeightMsgVoteWeighted int = 33
DefaultWeightMsgUnjail int = 100
DefaultWeightMsgCreateValidator int = 100
DefaultWeightMsgEditValidator int = 5
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ $ %s tx gov vote 1 yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05 --from mykey
}

// Build vote message and run basic validation
msg := types.NewMsgWeightedVote(from, proposalID, options)
msg := types.NewMsgVoteWeighted(from, proposalID, options)
err = msg.ValidateBasic()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func newWeightedVoteHandlerFn(clientCtx client.Context) http.HandlerFunc {
}

// create the message
msg := types.NewMsgWeightedVote(req.Voter, proposalID, options)
msg := types.NewMsgVoteWeighted(req.Voter, proposalID, options)
if rest.CheckBadRequestError(w, msg.ValidateBasic()) {
return
}
Expand Down
10 changes: 5 additions & 5 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVot
var (
events = []string{
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVote),
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgWeightedVote),
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgVoteWeighted),
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalVote, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
}
votes []types.Vote
Expand All @@ -104,8 +104,8 @@ func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVot
ProposalId: params.ProposalID,
Options: types.NewNonSplitVoteOption(voteMsg.Option),
})
} else if msg.Type() == types.TypeMsgWeightedVote {
voteMsg := msg.(*types.MsgWeightedVote)
} else if msg.Type() == types.TypeMsgVoteWeighted {
voteMsg := msg.(*types.MsgVoteWeighted)

votes = append(votes, types.Vote{
Voter: voteMsg.Voter,
Expand Down Expand Up @@ -166,8 +166,8 @@ func QueryVoteByTxQuery(clientCtx client.Context, params types.QueryVoteParams)
}

return bz, nil
} else if msg.Type() == types.TypeMsgWeightedVote {
voteMsg := msg.(*types.MsgWeightedVote)
} else if msg.Type() == types.TypeMsgVoteWeighted {
voteMsg := msg.(*types.MsgVoteWeighted)

vote := types.Vote{
Voter: voteMsg.Voter,
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/utils/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestGetPaginatedVotes(t *testing.T) {
}
acc2Msgs := []sdk.Msg{
types.NewMsgVote(acc2, 0, types.OptionYes),
types.NewMsgWeightedVote(acc2, 0, types.NewNonSplitVoteOption(types.OptionYes)),
types.NewMsgVoteWeighted(acc2, 0, types.NewNonSplitVoteOption(types.OptionYes)),
}
for _, tc := range []testCase{
{
Expand Down
4 changes: 2 additions & 2 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := msgServer.Vote(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgWeightedVote:
res, err := msgServer.WeightedVote(sdk.WrapSDKContext(ctx), msg)
case *types.MsgVoteWeighted:
res, err := msgServer.VoteWeighted(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

default:
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (k msgServer) Vote(goCtx context.Context, msg *types.MsgVote) (*types.MsgVo
return &types.MsgVoteResponse{}, nil
}

func (k msgServer) WeightedVote(goCtx context.Context, msg *types.MsgWeightedVote) (*types.MsgWeightedVoteResponse, error) {
func (k msgServer) VoteWeighted(goCtx context.Context, msg *types.MsgVoteWeighted) (*types.MsgVoteWeightedResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter)
if accErr != nil {
Expand All @@ -116,7 +116,7 @@ func (k msgServer) WeightedVote(goCtx context.Context, msg *types.MsgWeightedVot
),
)

return &types.MsgWeightedVoteResponse{}, nil
return &types.MsgVoteWeightedResponse{}, nil
}

func (k msgServer) Deposit(goCtx context.Context, msg *types.MsgDeposit) (*types.MsgDepositResponse, error) {
Expand Down
24 changes: 12 additions & 12 deletions x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var initialProposalID = uint64(100000000000000)
const (
OpWeightMsgDeposit = "op_weight_msg_deposit"
OpWeightMsgVote = "op_weight_msg_vote"
OpWeightMsgWeightedVote = "op_weight_msg_weighted_vote"
OpWeightMsgVoteWeighted = "op_weight_msg_weighted_vote"
)

// WeightedOperations returns all the operations from the module with their respective weights
Expand All @@ -34,7 +34,7 @@ func WeightedOperations(
var (
weightMsgDeposit int
weightMsgVote int
weightMsgWeightedVote int
weightMsgVoteWeighted int
)

appParams.GetOrGenerate(cdc, OpWeightMsgDeposit, &weightMsgDeposit, nil,
Expand All @@ -49,9 +49,9 @@ func WeightedOperations(
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgWeightedVote, &weightMsgWeightedVote, nil,
appParams.GetOrGenerate(cdc, OpWeightMsgVoteWeighted, &weightMsgVoteWeighted, nil,
func(_ *rand.Rand) {
weightMsgWeightedVote = simappparams.DefaultWeightMsgWeightedVote
weightMsgVoteWeighted = simappparams.DefaultWeightMsgVoteWeighted
},
)

Expand Down Expand Up @@ -83,8 +83,8 @@ func WeightedOperations(
SimulateMsgVote(ak, bk, k),
),
simulation.NewWeightedOperation(
weightMsgWeightedVote,
SimulateMsgWeightedVote(ak, bk, k),
weightMsgVoteWeighted,
SimulateMsgVoteWeighted(ak, bk, k),
),
}

Expand Down Expand Up @@ -327,12 +327,12 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee
}
}

// SimulateMsgWeightedVote generates a MsgWeightedVote with random values.
func SimulateMsgWeightedVote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return operationSimulateMsgWeightedVote(ak, bk, k, simtypes.Account{}, -1)
// SimulateMsgVoteWeighted generates a MsgVoteWeighted with random values.
func SimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return operationSimulateMsgVoteWeighted(ak, bk, k, simtypes.Account{}, -1)
}

func operationSimulateMsgWeightedVote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper,
func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper,
simAccount simtypes.Account, proposalIDInt int64) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
Expand All @@ -349,14 +349,14 @@ func operationSimulateMsgWeightedVote(ak types.AccountKeeper, bk types.BankKeepe
var ok bool
proposalID, ok = randomProposalID(r, k, ctx, types.StatusVotingPeriod)
if !ok {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWeightedVote, "unable to generate proposalID"), nil, nil
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgVoteWeighted, "unable to generate proposalID"), nil, nil
}
default:
proposalID = uint64(proposalIDInt)
}

options := randomWeightedVotingOptions(r)
msg := types.NewMsgWeightedVote(simAccount.Address, proposalID, options)
msg := types.NewMsgVoteWeighted(simAccount.Address, proposalID, options)

account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())
Expand Down
12 changes: 6 additions & 6 deletions x/gov/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestWeightedOperations(t *testing.T) {
{2, types.ModuleName, "submit_proposal"},
{simappparams.DefaultWeightMsgDeposit, types.ModuleName, types.TypeMsgDeposit},
{simappparams.DefaultWeightMsgVote, types.ModuleName, types.TypeMsgVote},
{simappparams.DefaultWeightMsgWeightedVote, types.ModuleName, types.TypeMsgWeightedVote},
{simappparams.DefaultWeightMsgVoteWeighted, types.ModuleName, types.TypeMsgVoteWeighted},
}

for i, w := range weightesOps {
Expand Down Expand Up @@ -208,9 +208,9 @@ func TestSimulateMsgVote(t *testing.T) {
require.Equal(t, types.TypeMsgVote, msg.Type())
}

// TestSimulateMsgWeightedVote tests the normal scenario of a valid message of type TypeMsgWeightedVote.
// TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted.
// Abonormal scenarios, where the message is created by an errors are not tested here.
func TestSimulateMsgWeightedVote(t *testing.T) {
func TestSimulateMsgVoteWeighted(t *testing.T) {
app, ctx := createTestApp(false)
blockTime := time.Now().UTC()
ctx = ctx.WithBlockTime(blockTime)
Expand All @@ -235,19 +235,19 @@ func TestSimulateMsgWeightedVote(t *testing.T) {
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}})

// execute operation
op := simulation.SimulateMsgWeightedVote(app.AccountKeeper, app.BankKeeper, app.GovKeeper)
op := simulation.SimulateMsgVoteWeighted(app.AccountKeeper, app.BankKeeper, app.GovKeeper)
operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "")
require.NoError(t, err)

var msg types.MsgWeightedVote
var msg types.MsgVoteWeighted
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, uint64(1), msg.ProposalId)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter)
require.True(t, len(msg.Options) >= 1)
require.Equal(t, "gov", msg.Route())
require.Equal(t, types.TypeMsgWeightedVote, msg.Type())
require.Equal(t, types.TypeMsgVoteWeighted, msg.Type())
}

// returns context and an app with updated mint keeper
Expand Down
2 changes: 1 addition & 1 deletion x/gov/spec/04_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The governance module emits the following events:
| message | action | vote |
| message | sender | {senderAddress} |

### MsgWeightedVote
### MsgVoteWeighted

| Type | Attribute Key | Attribute Value |
| ------------- | ------------- | ------------------------ |
Expand Down
4 changes: 2 additions & 2 deletions x/gov/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/MsgVote", nil)
cdc.RegisterConcrete(&MsgWeightedVote{}, "cosmos-sdk/MsgWeightedVote", nil)
cdc.RegisterConcrete(&MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted", nil)
cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSubmitProposal{},
&MsgVote{},
&MsgWeightedVote{},
&MsgVoteWeighted{},
&MsgDeposit{},
)
registry.RegisterInterface(
Expand Down
Loading

0 comments on commit b125fcc

Please sign in to comment.