feat: implement new gov msg & query servers (#10868)
## Description Ref: #9438 This PR performs the major work of swapping out the v1beta1 msg server and query server for the new one which can process a proposal as an array of messages. This PR still retains the legacy servers which simply wrap around the new ones, providing the same interface as before. In order to keep backwards compatibility, a new msg, `MsgExecLegacyContent` has been created which allows `Content` to become a `Msg` type and still be used as part of the new implementation. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
f52d87003c
commit
eb5b11be8a
|
@ -114,6 +114,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
* [\#10748](https://github.com/cosmos/cosmos-sdk/pull/10748) Move legacy `x/gov` api to `v1beta1` directory.
|
* [\#10748](https://github.com/cosmos/cosmos-sdk/pull/10748) Move legacy `x/gov` api to `v1beta1` directory.
|
||||||
* [\#10816](https://github.com/cosmos/cosmos-sdk/pull/10816) Reuse blocked addresses from the bank module. No need to pass them to distribution.
|
* [\#10816](https://github.com/cosmos/cosmos-sdk/pull/10816) Reuse blocked addresses from the bank module. No need to pass them to distribution.
|
||||||
* [\#10852](https://github.com/cosmos/cosmos-sdk/pull/10852) Move `x/gov/types` to `x/gov/types/v1beta2`.
|
* [\#10852](https://github.com/cosmos/cosmos-sdk/pull/10852) Move `x/gov/types` to `x/gov/types/v1beta2`.
|
||||||
|
* [\#10868](https://github.com/cosmos/cosmos-sdk/pull/10868) The Gov keeper accepts now a mandatory last argument, the ServiceMsgRouter.
|
||||||
|
|
||||||
### Client Breaking Changes
|
### Client Breaking Changes
|
||||||
|
|
||||||
|
@ -185,6 +186,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
* [\#10422](https://github.com/cosmos/cosmos-sdk/pull/10422) and [\#10529](https://github.com/cosmos/cosmos-sdk/pull/10529) Add `MinCommissionRate` param to `x/staking` module.
|
* [\#10422](https://github.com/cosmos/cosmos-sdk/pull/10422) and [\#10529](https://github.com/cosmos/cosmos-sdk/pull/10529) Add `MinCommissionRate` param to `x/staking` module.
|
||||||
* [#10763](https://github.com/cosmos/cosmos-sdk/pull/10763) modify the fields in `TallyParams` to use `string` instead of `bytes`
|
* [#10763](https://github.com/cosmos/cosmos-sdk/pull/10763) modify the fields in `TallyParams` to use `string` instead of `bytes`
|
||||||
* [#10770](https://github.com/cosmos/cosmos-sdk/pull/10770) revert tx when block gas limit exceeded
|
* [#10770](https://github.com/cosmos/cosmos-sdk/pull/10770) revert tx when block gas limit exceeded
|
||||||
|
* [\#10868](https://github.com/cosmos/cosmos-sdk/pull/10868) Bump gov to v1beta2. Both v1beta1 and v1beta2 queries and Msgs are accepted.
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,6 +24,9 @@ const _ = grpc.SupportPackageIsVersion7
|
||||||
type MsgClient interface {
|
type MsgClient interface {
|
||||||
// SubmitProposal defines a method to create new proposal given a content.
|
// SubmitProposal defines a method to create new proposal given a content.
|
||||||
SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error)
|
SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error)
|
||||||
|
// ExecLegacyContent defines a Msg to be in included in a MsgSubmitProposal
|
||||||
|
// to execute a legacy content-based proposal.
|
||||||
|
ExecLegacyContent(ctx context.Context, in *MsgExecLegacyContent, opts ...grpc.CallOption) (*MsgExecLegacyContentResponse, error)
|
||||||
// Vote defines a method to add a vote on a specific proposal.
|
// Vote defines a method to add a vote on a specific proposal.
|
||||||
Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error)
|
Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error)
|
||||||
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
||||||
|
@ -51,6 +54,15 @@ func (c *msgClient) SubmitProposal(ctx context.Context, in *MsgSubmitProposal, o
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *msgClient) ExecLegacyContent(ctx context.Context, in *MsgExecLegacyContent, opts ...grpc.CallOption) (*MsgExecLegacyContentResponse, error) {
|
||||||
|
out := new(MsgExecLegacyContentResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/ExecLegacyContent", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *msgClient) Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) {
|
func (c *msgClient) Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) {
|
||||||
out := new(MsgVoteResponse)
|
out := new(MsgVoteResponse)
|
||||||
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/Vote", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/Vote", in, out, opts...)
|
||||||
|
@ -84,6 +96,9 @@ func (c *msgClient) Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.Ca
|
||||||
type MsgServer interface {
|
type MsgServer interface {
|
||||||
// SubmitProposal defines a method to create new proposal given a content.
|
// SubmitProposal defines a method to create new proposal given a content.
|
||||||
SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error)
|
SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error)
|
||||||
|
// ExecLegacyContent defines a Msg to be in included in a MsgSubmitProposal
|
||||||
|
// to execute a legacy content-based proposal.
|
||||||
|
ExecLegacyContent(context.Context, *MsgExecLegacyContent) (*MsgExecLegacyContentResponse, error)
|
||||||
// Vote defines a method to add a vote on a specific proposal.
|
// Vote defines a method to add a vote on a specific proposal.
|
||||||
Vote(context.Context, *MsgVote) (*MsgVoteResponse, error)
|
Vote(context.Context, *MsgVote) (*MsgVoteResponse, error)
|
||||||
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
||||||
|
@ -102,6 +117,9 @@ type UnimplementedMsgServer struct {
|
||||||
func (UnimplementedMsgServer) SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) {
|
func (UnimplementedMsgServer) SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method SubmitProposal not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method SubmitProposal not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedMsgServer) ExecLegacyContent(context.Context, *MsgExecLegacyContent) (*MsgExecLegacyContentResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ExecLegacyContent not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedMsgServer) Vote(context.Context, *MsgVote) (*MsgVoteResponse, error) {
|
func (UnimplementedMsgServer) Vote(context.Context, *MsgVote) (*MsgVoteResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Vote not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Vote not implemented")
|
||||||
}
|
}
|
||||||
|
@ -142,6 +160,24 @@ func _Msg_SubmitProposal_Handler(srv interface{}, ctx context.Context, dec func(
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Msg_ExecLegacyContent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(MsgExecLegacyContent)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(MsgServer).ExecLegacyContent(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/cosmos.gov.v1beta2.Msg/ExecLegacyContent",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(MsgServer).ExecLegacyContent(ctx, req.(*MsgExecLegacyContent))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _Msg_Vote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _Msg_Vote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(MsgVote)
|
in := new(MsgVote)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
|
@ -207,6 +243,10 @@ var Msg_ServiceDesc = grpc.ServiceDesc{
|
||||||
MethodName: "SubmitProposal",
|
MethodName: "SubmitProposal",
|
||||||
Handler: _Msg_SubmitProposal_Handler,
|
Handler: _Msg_SubmitProposal_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ExecLegacyContent",
|
||||||
|
Handler: _Msg_ExecLegacyContent_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "Vote",
|
MethodName: "Vote",
|
||||||
Handler: _Msg_Vote_Handler,
|
Handler: _Msg_Vote_Handler,
|
||||||
|
|
|
@ -14,6 +14,10 @@ service Msg {
|
||||||
// SubmitProposal defines a method to create new proposal given a content.
|
// SubmitProposal defines a method to create new proposal given a content.
|
||||||
rpc SubmitProposal(MsgSubmitProposal) returns (MsgSubmitProposalResponse);
|
rpc SubmitProposal(MsgSubmitProposal) returns (MsgSubmitProposalResponse);
|
||||||
|
|
||||||
|
// ExecLegacyContent defines a Msg to be in included in a MsgSubmitProposal
|
||||||
|
// to execute a legacy content-based proposal.
|
||||||
|
rpc ExecLegacyContent(MsgExecLegacyContent) returns (MsgExecLegacyContentResponse);
|
||||||
|
|
||||||
// Vote defines a method to add a vote on a specific proposal.
|
// Vote defines a method to add a vote on a specific proposal.
|
||||||
rpc Vote(MsgVote) returns (MsgVoteResponse);
|
rpc Vote(MsgVote) returns (MsgVoteResponse);
|
||||||
|
|
||||||
|
@ -39,6 +43,18 @@ message MsgSubmitProposalResponse {
|
||||||
uint64 proposal_id = 1;
|
uint64 proposal_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MsgExecLegacyContent is used to wrap the legacy content field into a message.
|
||||||
|
// This ensures backwards compatibility with v1beta1.MsgSubmitProposal.
|
||||||
|
message MsgExecLegacyContent {
|
||||||
|
// content is the proposal's content.
|
||||||
|
google.protobuf.Any content = 1 [(cosmos_proto.accepts_interface) = "Content"];
|
||||||
|
// authority must be the gov module address.
|
||||||
|
string authority = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgExecLegacyContentResponse defines the Msg/ExecLegacyContent response type.
|
||||||
|
message MsgExecLegacyContentResponse {}
|
||||||
|
|
||||||
// MsgVote defines a message to cast a vote.
|
// MsgVote defines a message to cast a vote.
|
||||||
message MsgVote {
|
message MsgVote {
|
||||||
uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id"];
|
uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id"];
|
||||||
|
|
|
@ -66,7 +66,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
oldgovtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/group"
|
"github.com/cosmos/cosmos-sdk/x/group"
|
||||||
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
|
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
|
||||||
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
|
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
|
||||||
|
@ -296,14 +297,14 @@ func NewSimApp(
|
||||||
app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.msgSvcRouter, app.AccountKeeper)
|
app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.msgSvcRouter, app.AccountKeeper)
|
||||||
|
|
||||||
// register the proposal types
|
// register the proposal types
|
||||||
govRouter := oldgovtypes.NewRouter()
|
govRouter := govv1beta1.NewRouter()
|
||||||
govRouter.AddRoute(govtypes.RouterKey, oldgovtypes.ProposalHandler).
|
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
|
||||||
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
|
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
|
||||||
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
|
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
|
||||||
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
|
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
|
||||||
govKeeper := govkeeper.NewKeeper(
|
govKeeper := govkeeper.NewKeeper(
|
||||||
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
|
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
|
||||||
&stakingKeeper, govRouter,
|
&stakingKeeper, govRouter, app.msgSvcRouter,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.GovKeeper = *govKeeper.SetHooks(
|
app.GovKeeper = *govKeeper.SetHooks(
|
||||||
|
@ -616,7 +617,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
|
||||||
paramsKeeper.Subspace(minttypes.ModuleName)
|
paramsKeeper.Subspace(minttypes.ModuleName)
|
||||||
paramsKeeper.Subspace(distrtypes.ModuleName)
|
paramsKeeper.Subspace(distrtypes.ModuleName)
|
||||||
paramsKeeper.Subspace(slashingtypes.ModuleName)
|
paramsKeeper.Subspace(slashingtypes.ModuleName)
|
||||||
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(oldgovtypes.ParamKeyTable())
|
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1beta2.ParamKeyTable())
|
||||||
paramsKeeper.Subspace(crisistypes.ModuleName)
|
paramsKeeper.Subspace(crisistypes.ModuleName)
|
||||||
|
|
||||||
return paramsKeeper
|
return paramsKeeper
|
||||||
|
|
|
@ -13,7 +13,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ func (s *MWTestSuite) setupAcctsForTips(ctx sdk.Context) (sdk.Context, []testAcc
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Create dummy proposal for tipper to vote on.
|
// Create dummy proposal for tipper to vote on.
|
||||||
prop, err := govtypes.NewProposal(govtypes.NewTextProposal("foo", "bar"), 1, time.Now(), time.Now().Add(time.Hour))
|
prop, err := govtypes.NewProposal([]sdk.Msg{banktypes.NewMsgSend(accts[0].acc.GetAddress(), accts[0].acc.GetAddress(), initialRegens)}, 1, time.Now(), time.Now().Add(time.Hour))
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.app.GovKeeper.SetProposal(ctx, prop)
|
s.app.GovKeeper.SetProposal(ctx, prop)
|
||||||
s.app.GovKeeper.ActivateVotingPeriod(ctx, prop)
|
s.app.GovKeeper.ActivateVotingPeriod(ctx, prop)
|
||||||
|
|
|
@ -60,7 +60,7 @@ func NewCmdGrantAuthorization() *cobra.Command {
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
$ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl..
|
$ %s tx %s grant cosmos1skjw.. send %s --spend-limit=1000stake --from=cosmos1skl..
|
||||||
$ %s tx %s grant cosmos1skjw.. generic --msg-type=/cosmos.gov.v1beta1.MsgVote --from=cosmos1sk..
|
$ %s tx %s grant cosmos1skjw.. generic --msg-type=/cosmos.gov.v1beta2.MsgVote --from=cosmos1sk..
|
||||||
`, version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, authz.ModuleName),
|
`, version.AppName, authz.ModuleName, bank.SendAuthorization{}.MsgTypeURL(), version.AppName, authz.ModuleName),
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
|
|
|
@ -19,7 +19,8 @@ import (
|
||||||
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,8 +55,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
|
|
||||||
// create a proposal with deposit
|
// create a proposal with deposit
|
||||||
_, err = govtestutil.MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
_, err = govtestutil.MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
||||||
"Text Proposal 1", "Where is the title!?", govtypes.ProposalTypeText,
|
"Text Proposal 1", "Where is the title!?", govv1beta1.ProposalTypeText,
|
||||||
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens).String()))
|
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govv1beta2.DefaultMinDepositTokens).String()))
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Create new account in the keyring.
|
// Create new account in the keyring.
|
||||||
|
@ -139,8 +140,8 @@ func (s *IntegrationTestSuite) TearDownSuite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var typeMsgSend = bank.SendAuthorization{}.MsgTypeURL()
|
var typeMsgSend = bank.SendAuthorization{}.MsgTypeURL()
|
||||||
var typeMsgVote = sdk.MsgTypeURL(&govtypes.MsgVote{})
|
var typeMsgVote = sdk.MsgTypeURL(&govv1beta2.MsgVote{})
|
||||||
var typeMsgSubmitProposal = sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{})
|
var typeMsgSubmitProposal = sdk.MsgTypeURL(&govv1beta2.MsgSubmitProposal{})
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() {
|
func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
@ -531,7 +532,7 @@ func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
// msg vote
|
// msg vote
|
||||||
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1beta1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
|
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1beta2.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
|
||||||
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
|
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
|
||||||
|
|
||||||
// waiting for authorization to expires
|
// waiting for authorization to expires
|
||||||
|
@ -572,7 +573,7 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// msg vote
|
// msg vote
|
||||||
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1beta1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
|
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1beta2.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
|
||||||
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
|
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
|
|
@ -21,7 +21,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/feegrant/client/cli"
|
||||||
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
govtestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -82,7 +83,7 @@ func (s *IntegrationTestSuite) createGrant(granter, grantee sdk.Address) {
|
||||||
commonFlags := []string{
|
commonFlags := []string{
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(100))).String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
fee := sdk.NewCoin("stake", sdk.NewInt(100))
|
fee := sdk.NewCoin("stake", sdk.NewInt(100))
|
||||||
|
@ -696,7 +697,7 @@ func (s *IntegrationTestSuite) TestTxWithFeeGrant() {
|
||||||
// granted fee allowance for an account which is not in state and creating
|
// granted fee allowance for an account which is not in state and creating
|
||||||
// any tx with it by using --fee-account shouldn't fail
|
// any tx with it by using --fee-account shouldn't fail
|
||||||
out, err := govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
|
out, err := govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
|
||||||
"Text Proposal", "No desc", govtypes.ProposalTypeText,
|
"Text Proposal", "No desc", govv1beta1.ProposalTypeText,
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -721,11 +722,11 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
|
||||||
commonFlags := []string{
|
commonFlags := []string{
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(100))).String()),
|
||||||
}
|
}
|
||||||
spendLimit := sdk.NewCoin("stake", sdk.NewInt(1000))
|
spendLimit := sdk.NewCoin("stake", sdk.NewInt(1000))
|
||||||
|
|
||||||
allowMsgs := strings.Join([]string{sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{}), sdk.MsgTypeURL(&govtypes.MsgVoteWeighted{})}, ",")
|
allowMsgs := strings.Join([]string{sdk.MsgTypeURL(&govv1beta1.MsgSubmitProposal{}), sdk.MsgTypeURL(&govv1beta2.MsgVoteWeighted{})}, ",")
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -836,8 +837,9 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
|
||||||
"valid proposal tx",
|
"valid proposal tx",
|
||||||
func() (testutil.BufferWriter, error) {
|
func() (testutil.BufferWriter, error) {
|
||||||
return govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
|
return govtestutil.MsgSubmitProposal(val.ClientCtx, grantee.String(),
|
||||||
"Text Proposal", "No desc", govtypes.ProposalTypeText,
|
"Text Proposal", "No desc", govv1beta1.ProposalTypeText,
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(100))).String()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
&sdk.TxResponse{},
|
&sdk.TxResponse{},
|
||||||
|
@ -848,6 +850,7 @@ func (s *IntegrationTestSuite) TestFilteredFeeAllowance() {
|
||||||
func() (testutil.BufferWriter, error) {
|
func() (testutil.BufferWriter, error) {
|
||||||
return govtestutil.MsgVote(val.ClientCtx, grantee.String(), "0", "yes",
|
return govtestutil.MsgVote(val.ClientCtx, grantee.String(), "0", "yes",
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
fmt.Sprintf("--%s=%s", flags.FlagFeeGranter, granter.String()),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(100))).String()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
&sdk.TxResponse{},
|
&sdk.TxResponse{},
|
||||||
|
|
|
@ -4,15 +4,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
|
||||||
ocproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
ocproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilteredFeeValidAllow(t *testing.T) {
|
func TestFilteredFeeValidAllow(t *testing.T) {
|
||||||
|
@ -47,7 +46,7 @@ func TestFilteredFeeValidAllow(t *testing.T) {
|
||||||
},
|
},
|
||||||
"msg not contained": {
|
"msg not contained": {
|
||||||
allowance: &feegrant.BasicAllowance{},
|
allowance: &feegrant.BasicAllowance{},
|
||||||
msgs: []string{"/cosmos.gov.v1beta1.MsgVote"},
|
msgs: []string{"/cosmos.gov.v1beta2.MsgVote"},
|
||||||
accept: false,
|
accept: false,
|
||||||
},
|
},
|
||||||
"small fee without expire": {
|
"small fee without expire": {
|
||||||
|
|
|
@ -48,7 +48,7 @@ func generateRandomAllowances(granter, grantee sdk.AccAddress, r *rand.Rand) fee
|
||||||
|
|
||||||
filteredAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.AllowedMsgAllowance{
|
filteredAllowance, err := feegrant.NewGrant(granter, grantee, &feegrant.AllowedMsgAllowance{
|
||||||
Allowance: basicAllowance.GetAllowance(),
|
Allowance: basicAllowance.GetAllowance(),
|
||||||
AllowedMessages: []string{"/cosmos.gov.v1beta1.MsgSubmitProposal"},
|
AllowedMessages: []string{"/cosmos.gov.v1beta2.MsgSubmitProposal"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -8,17 +8,17 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EndBlocker called every block, process inflation, update validator set.
|
// EndBlocker called every block, process inflation, update validator set.
|
||||||
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
||||||
defer telemetry.ModuleMeasureSince(v1beta1.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
|
||||||
|
|
||||||
logger := keeper.Logger(ctx)
|
logger := keeper.Logger(ctx)
|
||||||
|
|
||||||
// delete dead proposals from store and burn theirs deposits. A proposal is dead when it's inactive and didn't get enough deposit on time to get into voting phase.
|
// delete dead proposals from store and burn theirs deposits. A proposal is dead when it's inactive and didn't get enough deposit on time to get into voting phase.
|
||||||
keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal v1beta1.Proposal) bool {
|
keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal v1beta2.Proposal) bool {
|
||||||
keeper.DeleteProposal(ctx, proposal.ProposalId)
|
keeper.DeleteProposal(ctx, proposal.ProposalId)
|
||||||
keeper.DeleteAndBurnDeposits(ctx, proposal.ProposalId)
|
keeper.DeleteAndBurnDeposits(ctx, proposal.ProposalId)
|
||||||
|
|
||||||
|
@ -36,16 +36,15 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
||||||
logger.Info(
|
logger.Info(
|
||||||
"proposal did not meet minimum deposit; deleted",
|
"proposal did not meet minimum deposit; deleted",
|
||||||
"proposal", proposal.ProposalId,
|
"proposal", proposal.ProposalId,
|
||||||
"title", proposal.GetTitle(),
|
"min_deposit", sdk.NewCoins(keeper.GetDepositParams(ctx).MinDeposit...).String(),
|
||||||
"min_deposit", keeper.GetDepositParams(ctx).MinDeposit.String(),
|
"total_deposit", sdk.NewCoins(proposal.TotalDeposit...).String(),
|
||||||
"total_deposit", proposal.TotalDeposit.String(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
// fetch active proposals whose voting periods have ended (are passed the block time)
|
// fetch active proposals whose voting periods have ended (are passed the block time)
|
||||||
keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal v1beta1.Proposal) bool {
|
keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal v1beta2.Proposal) bool {
|
||||||
var tagValue, logMsg string
|
var tagValue, logMsg string
|
||||||
|
|
||||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||||
|
@ -57,15 +56,31 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if passes {
|
if passes {
|
||||||
handler := keeper.Router().GetRoute(proposal.ProposalRoute())
|
var (
|
||||||
cacheCtx, writeCache := ctx.CacheContext()
|
idx int
|
||||||
|
msg sdk.Msg
|
||||||
|
)
|
||||||
|
|
||||||
// The proposal handler may execute state mutating logic depending
|
// attempt to execute all messages within the passed proposal
|
||||||
// on the proposal content. If the handler fails, no state mutation
|
// Messages may mutate state thus we use a cached context. If one of
|
||||||
// is written and the error message is logged.
|
// the handlers fails, no state mutation is written and the error
|
||||||
err := handler(cacheCtx, proposal.GetContent())
|
// message is logged.
|
||||||
|
cacheCtx, writeCache := ctx.CacheContext()
|
||||||
|
messages, err := proposal.GetMsgs()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
proposal.Status = v1beta1.StatusPassed
|
for idx, msg = range messages {
|
||||||
|
handler := keeper.Router().Handler(msg)
|
||||||
|
_, err = handler(cacheCtx, msg)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `err == nil` when all handlers passed.
|
||||||
|
// Or else, `idx` and `err` are populated with the msg index and error.
|
||||||
|
if err == nil {
|
||||||
|
proposal.Status = v1beta2.StatusPassed
|
||||||
tagValue = types.AttributeValueProposalPassed
|
tagValue = types.AttributeValueProposalPassed
|
||||||
logMsg = "passed"
|
logMsg = "passed"
|
||||||
|
|
||||||
|
@ -78,20 +93,20 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
||||||
// write state to the underlying multi-store
|
// write state to the underlying multi-store
|
||||||
writeCache()
|
writeCache()
|
||||||
} else {
|
} else {
|
||||||
proposal.Status = v1beta1.StatusFailed
|
proposal.Status = v1beta2.StatusFailed
|
||||||
tagValue = types.AttributeValueProposalFailed
|
tagValue = types.AttributeValueProposalFailed
|
||||||
logMsg = fmt.Sprintf("passed, but failed on execution: %s", err)
|
logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
proposal.Status = v1beta1.StatusRejected
|
proposal.Status = v1beta2.StatusRejected
|
||||||
tagValue = types.AttributeValueProposalRejected
|
tagValue = types.AttributeValueProposalRejected
|
||||||
logMsg = "rejected"
|
logMsg = "rejected"
|
||||||
}
|
}
|
||||||
|
|
||||||
proposal.FinalTallyResult = tallyResults
|
proposal.FinalTallyResult = &tallyResults
|
||||||
|
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
keeper.RemoveFromActiveProposalQueue(ctx, proposal.ProposalId, proposal.VotingEndTime)
|
keeper.RemoveFromActiveProposalQueue(ctx, proposal.ProposalId, *proposal.VotingEndTime)
|
||||||
|
|
||||||
// when proposal become active
|
// when proposal become active
|
||||||
keeper.AfterProposalVotingPeriodEnded(ctx, proposal.ProposalId)
|
keeper.AfterProposalVotingPeriodEnded(ctx, proposal.ProposalId)
|
||||||
|
@ -99,8 +114,7 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
|
||||||
logger.Info(
|
logger.Info(
|
||||||
"proposal tallied",
|
"proposal tallied",
|
||||||
"proposal", proposal.ProposalId,
|
"proposal", proposal.ProposalId,
|
||||||
"title", proposal.GetTitle(),
|
"results", logMsg,
|
||||||
"result", logMsg,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
@ -33,10 +33,10 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg, err := v1beta1.NewMsgSubmitProposal(
|
newProposalMsg, err := v1beta2.NewMsgSubmitProposal(
|
||||||
v1beta1.ContentFromProposalType("test", "test", v1beta1.ProposalTypeText),
|
[]sdk.Msg{mkTestLegacyContent(t)},
|
||||||
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
||||||
addrs[0],
|
addrs[0].String(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
newHeader = ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
||||||
|
@ -85,10 +85,10 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg, err := v1beta1.NewMsgSubmitProposal(
|
newProposalMsg, err := v1beta2.NewMsgSubmitProposal(
|
||||||
v1beta1.ContentFromProposalType("test", "test", v1beta1.ProposalTypeText),
|
[]sdk.Msg{mkTestLegacyContent(t)},
|
||||||
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
||||||
addrs[0],
|
addrs[0].String(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg2, err := v1beta1.NewMsgSubmitProposal(
|
newProposalMsg2, err := v1beta2.NewMsgSubmitProposal(
|
||||||
v1beta1.ContentFromProposalType("test2", "test2", v1beta1.ProposalTypeText),
|
[]sdk.Msg{mkTestLegacyContent(t)},
|
||||||
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
||||||
addrs[0],
|
addrs[0].String(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
newHeader = ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
||||||
|
@ -165,10 +165,10 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
||||||
require.False(t, activeQueue.Valid())
|
require.False(t, activeQueue.Valid())
|
||||||
activeQueue.Close()
|
activeQueue.Close()
|
||||||
|
|
||||||
newProposalMsg, err := v1beta1.NewMsgSubmitProposal(
|
newProposalMsg, err := v1beta2.NewMsgSubmitProposal(
|
||||||
v1beta1.ContentFromProposalType("test2", "test2", v1beta1.ProposalTypeText),
|
[]sdk.Msg{mkTestLegacyContent(t)},
|
||||||
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
||||||
addrs[0],
|
addrs[0].String(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newDepositMsg := v1beta1.NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)})
|
newDepositMsg := v1beta2.NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)})
|
||||||
|
|
||||||
res1, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
res1, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -221,7 +221,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
activeQueue.Close()
|
activeQueue.Close()
|
||||||
|
|
||||||
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 5))}
|
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 5))}
|
||||||
newProposalMsg, err := v1beta1.NewMsgSubmitProposal(TestProposal, proposalCoins, addrs[0])
|
newProposalMsg, err := v1beta2.NewMsgSubmitProposal([]sdk.Msg{mkTestLegacyContent(t)}, proposalCoins, addrs[0].String())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
wrapCtx := sdk.WrapSDKContext(ctx)
|
wrapCtx := sdk.WrapSDKContext(ctx)
|
||||||
|
@ -236,14 +236,14 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
newDepositMsg := v1beta1.NewMsgDeposit(addrs[1], proposalID, proposalCoins)
|
newDepositMsg := v1beta2.NewMsgDeposit(addrs[1], proposalID, proposalCoins)
|
||||||
|
|
||||||
res1, err := govMsgSvr.Deposit(wrapCtx, newDepositMsg)
|
res1, err := govMsgSvr.Deposit(wrapCtx, newDepositMsg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res1)
|
require.NotNil(t, res1)
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
newHeader = ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
||||||
|
@ -256,7 +256,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
activeProposalID := types.GetProposalIDFromBytes(activeQueue.Value())
|
activeProposalID := types.GetProposalIDFromBytes(activeQueue.Value())
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, activeProposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, activeProposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, v1beta1.StatusVotingPeriod, proposal.Status)
|
require.Equal(t, v1beta2.StatusVotingPeriod, proposal.Status)
|
||||||
|
|
||||||
activeQueue.Close()
|
activeQueue.Close()
|
||||||
|
|
||||||
|
@ -289,11 +289,11 @@ func TestProposalPassedEndblocker(t *testing.T) {
|
||||||
require.NotNil(t, macc)
|
require.NotNil(t, macc)
|
||||||
initialModuleAccCoins := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
initialModuleAccCoins := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
||||||
|
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10))}
|
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10))}
|
||||||
newDepositMsg := v1beta1.NewMsgDeposit(addrs[0], proposal.ProposalId, proposalCoins)
|
newDepositMsg := v1beta2.NewMsgDeposit(addrs[0], proposal.ProposalId, proposalCoins)
|
||||||
|
|
||||||
res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -306,11 +306,11 @@ func TestProposalPassedEndblocker(t *testing.T) {
|
||||||
deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...)
|
deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...)
|
||||||
require.True(t, moduleAccCoins.IsEqual(deposits))
|
require.True(t, moduleAccCoins.IsEqual(deposits))
|
||||||
|
|
||||||
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
newHeader := ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
gov.EndBlocker(ctx, app.GovKeeper)
|
gov.EndBlocker(ctx, app.GovKeeper)
|
||||||
|
@ -339,22 +339,22 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
|
||||||
// Create a proposal where the handler will pass for the test proposal
|
// Create a proposal where the handler will pass for the test proposal
|
||||||
// because the value of contextKeyBadProposal is true.
|
// because the value of contextKeyBadProposal is true.
|
||||||
ctx = ctx.WithValue(contextKeyBadProposal, true)
|
ctx = ctx.WithValue(contextKeyBadProposal, true)
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10)))
|
proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10)))
|
||||||
newDepositMsg := v1beta1.NewMsgDeposit(addrs[0], proposal.ProposalId, proposalCoins)
|
newDepositMsg := v1beta2.NewMsgDeposit(addrs[0], proposal.ProposalId, proposalCoins)
|
||||||
|
|
||||||
govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper)
|
govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper)
|
||||||
res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
newHeader := ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetVotingParams(ctx).VotingPeriod)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
// Set the contextKeyBadProposal value to false so that the handler will fail
|
// Set the contextKeyBadProposal value to false so that the handler will fail
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetQueryCmd returns the cli query commands for this module
|
// GetQueryCmd returns the cli query commands for this module
|
||||||
|
@ -64,7 +64,7 @@ $ %s query gov proposal 1
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -75,13 +75,13 @@ $ %s query gov proposal 1
|
||||||
// Query the proposal
|
// Query the proposal
|
||||||
res, err := queryClient.Proposal(
|
res, err := queryClient.Proposal(
|
||||||
cmd.Context(),
|
cmd.Context(),
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientCtx.PrintProto(&res.Proposal)
|
return clientCtx.PrintProto(res.Proposal)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ $ %s query gov proposals --page=2 --limit=100
|
||||||
bechVoterAddr, _ := cmd.Flags().GetString(flagVoter)
|
bechVoterAddr, _ := cmd.Flags().GetString(flagVoter)
|
||||||
strProposalStatus, _ := cmd.Flags().GetString(flagStatus)
|
strProposalStatus, _ := cmd.Flags().GetString(flagStatus)
|
||||||
|
|
||||||
var proposalStatus v1beta1.ProposalStatus
|
var proposalStatus v1beta2.ProposalStatus
|
||||||
|
|
||||||
if len(bechDepositorAddr) != 0 {
|
if len(bechDepositorAddr) != 0 {
|
||||||
_, err := sdk.AccAddressFromBech32(bechDepositorAddr)
|
_, err := sdk.AccAddressFromBech32(bechDepositorAddr)
|
||||||
|
@ -130,7 +130,7 @@ $ %s query gov proposals --page=2 --limit=100
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(strProposalStatus) != 0 {
|
if len(strProposalStatus) != 0 {
|
||||||
proposalStatus1, err := v1beta1.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus))
|
proposalStatus1, err := v1beta2.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus))
|
||||||
proposalStatus = proposalStatus1
|
proposalStatus = proposalStatus1
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -141,7 +141,7 @@ $ %s query gov proposals --page=2 --limit=100
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -150,7 +150,7 @@ $ %s query gov proposals --page=2 --limit=100
|
||||||
|
|
||||||
res, err := queryClient.Proposals(
|
res, err := queryClient.Proposals(
|
||||||
cmd.Context(),
|
cmd.Context(),
|
||||||
&v1beta1.QueryProposalsRequest{
|
&v1beta2.QueryProposalsRequest{
|
||||||
ProposalStatus: proposalStatus,
|
ProposalStatus: proposalStatus,
|
||||||
Voter: bechVoterAddr,
|
Voter: bechVoterAddr,
|
||||||
Depositor: bechDepositorAddr,
|
Depositor: bechDepositorAddr,
|
||||||
|
@ -199,7 +199,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -211,7 +211,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
_, err = queryClient.Proposal(
|
_, err = queryClient.Proposal(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
||||||
|
@ -224,7 +224,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
|
|
||||||
res, err := queryClient.Vote(
|
res, err := queryClient.Vote(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryVoteRequest{ProposalId: proposalID, Voter: args[1]},
|
&v1beta2.QueryVoteRequest{ProposalId: proposalID, Voter: args[1]},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -232,19 +232,19 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
|
|
||||||
vote := res.GetVote()
|
vote := res.GetVote()
|
||||||
if vote.Empty() {
|
if vote.Empty() {
|
||||||
params := v1beta1.NewQueryVoteParams(proposalID, voterAddr)
|
params := v1beta2.NewQueryVoteParams(proposalID, voterAddr)
|
||||||
resByTxQuery, err := gcutils.QueryVoteByTxQuery(clientCtx, params)
|
resByTxQuery, err := gcutils.QueryVoteByTxQuery(clientCtx, params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := clientCtx.Codec.UnmarshalJSON(resByTxQuery, &vote); err != nil {
|
if err := clientCtx.Codec.UnmarshalJSON(resByTxQuery, vote); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientCtx.PrintProto(&res.Vote)
|
return clientCtx.PrintProto(res.Vote)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -286,24 +286,24 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
proposalRes, err := queryClient.Proposal(
|
proposalRes, err := queryClient.Proposal(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
propStatus := proposalRes.GetProposal().Status
|
propStatus := proposalRes.GetProposal().Status
|
||||||
if !(propStatus == v1beta1.StatusVotingPeriod || propStatus == v1beta1.StatusDepositPeriod) {
|
if !(propStatus == v1beta2.StatusVotingPeriod || propStatus == v1beta2.StatusDepositPeriod) {
|
||||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||||
|
|
||||||
params := v1beta1.NewQueryProposalVotesParams(proposalID, page, limit)
|
params := v1beta2.NewQueryProposalVotesParams(proposalID, page, limit)
|
||||||
resByTxQuery, err := gcutils.QueryVotesByTxQuery(clientCtx, params)
|
resByTxQuery, err := gcutils.QueryVotesByTxQuery(clientCtx, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var votes v1beta1.Votes
|
var votes v1beta2.Votes
|
||||||
// TODO migrate to use JSONCodec (implement MarshalJSONArray
|
// TODO migrate to use JSONCodec (implement MarshalJSONArray
|
||||||
// or wrap lists of proto.Message in some other message)
|
// or wrap lists of proto.Message in some other message)
|
||||||
clientCtx.LegacyAmino.MustUnmarshalJSON(resByTxQuery, &votes)
|
clientCtx.LegacyAmino.MustUnmarshalJSON(resByTxQuery, &votes)
|
||||||
|
@ -318,7 +318,7 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
|
||||||
|
|
||||||
res, err := queryClient.Votes(
|
res, err := queryClient.Votes(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryVotesRequest{ProposalId: proposalID, Pagination: pageReq},
|
&v1beta2.QueryVotesRequest{ProposalId: proposalID, Pagination: pageReq},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -357,7 +357,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -369,7 +369,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
_, err = queryClient.Proposal(
|
_, err = queryClient.Proposal(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
||||||
|
@ -377,13 +377,13 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
|
||||||
|
|
||||||
res, err := queryClient.Deposit(
|
res, err := queryClient.Deposit(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryDepositRequest{ProposalId: proposalID, Depositor: args[1]},
|
&v1beta2.QueryDepositRequest{ProposalId: proposalID, Depositor: args[1]},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientCtx.PrintProto(&res.Deposit)
|
return clientCtx.PrintProto(res.Deposit)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ $ %s query gov deposits 1
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -425,7 +425,7 @@ $ %s query gov deposits 1
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
_, err = queryClient.Proposal(
|
_, err = queryClient.Proposal(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
||||||
|
@ -438,7 +438,7 @@ $ %s query gov deposits 1
|
||||||
|
|
||||||
res, err := queryClient.Deposits(
|
res, err := queryClient.Deposits(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryDepositsRequest{ProposalId: proposalID, Pagination: pageReq},
|
&v1beta2.QueryDepositsRequest{ProposalId: proposalID, Pagination: pageReq},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -476,7 +476,7 @@ $ %s query gov tally 1
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// validate that the proposal id is a uint
|
// validate that the proposal id is a uint
|
||||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||||
|
@ -488,7 +488,7 @@ $ %s query gov tally 1
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
_, err = queryClient.Proposal(
|
_, err = queryClient.Proposal(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryProposalRequest{ProposalId: proposalID},
|
&v1beta2.QueryProposalRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
|
||||||
|
@ -497,13 +497,13 @@ $ %s query gov tally 1
|
||||||
// Query store
|
// Query store
|
||||||
res, err := queryClient.TallyResult(
|
res, err := queryClient.TallyResult(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryTallyResultRequest{ProposalId: proposalID},
|
&v1beta2.QueryTallyResultRequest{ProposalId: proposalID},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientCtx.PrintProto(&res.Tally)
|
return clientCtx.PrintProto(res.Tally)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,13 +532,13 @@ $ %s query gov params
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// Query store for all 3 params
|
// Query store for all 3 params
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
votingRes, err := queryClient.Params(
|
votingRes, err := queryClient.Params(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryParamsRequest{ParamsType: "voting"},
|
&v1beta2.QueryParamsRequest{ParamsType: "voting"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -546,7 +546,7 @@ $ %s query gov params
|
||||||
|
|
||||||
tallyRes, err := queryClient.Params(
|
tallyRes, err := queryClient.Params(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryParamsRequest{ParamsType: "tallying"},
|
&v1beta2.QueryParamsRequest{ParamsType: "tallying"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -554,16 +554,16 @@ $ %s query gov params
|
||||||
|
|
||||||
depositRes, err := queryClient.Params(
|
depositRes, err := queryClient.Params(
|
||||||
ctx,
|
ctx,
|
||||||
&v1beta1.QueryParamsRequest{ParamsType: "deposit"},
|
&v1beta2.QueryParamsRequest{ParamsType: "deposit"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
params := v1beta1.NewParams(
|
params := v1beta2.NewParams(
|
||||||
votingRes.GetVotingParams(),
|
*votingRes.GetVotingParams(),
|
||||||
tallyRes.GetTallyParams(),
|
*tallyRes.GetTallyParams(),
|
||||||
depositRes.GetDepositParams(),
|
*depositRes.GetDepositParams(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return clientCtx.PrintObjectLegacy(params)
|
return clientCtx.PrintObjectLegacy(params)
|
||||||
|
@ -597,12 +597,12 @@ $ %s query gov param deposit
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
queryClient := v1beta1.NewQueryClient(clientCtx)
|
queryClient := v1beta2.NewQueryClient(clientCtx)
|
||||||
|
|
||||||
// Query store
|
// Query store
|
||||||
res, err := queryClient.Params(
|
res, err := queryClient.Params(
|
||||||
cmd.Context(),
|
cmd.Context(),
|
||||||
&v1beta1.QueryParamsRequest{ParamsType: args[0]},
|
&v1beta2.QueryParamsRequest{ParamsType: args[0]},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,7 +13,9 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Proposal flags
|
// Proposal flags
|
||||||
|
@ -52,13 +54,15 @@ var ProposalFlags = []string{
|
||||||
// under the governance CLI (eg. parameter change proposals).
|
// under the governance CLI (eg. parameter change proposals).
|
||||||
func NewTxCmd(propCmds []*cobra.Command) *cobra.Command {
|
func NewTxCmd(propCmds []*cobra.Command) *cobra.Command {
|
||||||
govTxCmd := &cobra.Command{
|
govTxCmd := &cobra.Command{
|
||||||
Use: v1beta1.ModuleName,
|
Use: types.ModuleName,
|
||||||
Short: "Governance transactions subcommands",
|
Short: "Governance transactions subcommands",
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
SuggestionsMinimumDistance: 2,
|
SuggestionsMinimumDistance: 2,
|
||||||
RunE: client.ValidateCmd,
|
RunE: client.ValidateCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Add CLI for new submit proposal
|
||||||
|
// https://github.com/cosmos/cosmos-sdk/issues/10952
|
||||||
cmdSubmitProp := NewCmdSubmitProposal()
|
cmdSubmitProp := NewCmdSubmitProposal()
|
||||||
for _, propCmd := range propCmds {
|
for _, propCmd := range propCmds {
|
||||||
flags.AddTxFlagsToCmd(propCmd)
|
flags.AddTxFlagsToCmd(propCmd)
|
||||||
|
@ -120,7 +124,6 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
|
||||||
}
|
}
|
||||||
|
|
||||||
content := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
content := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
||||||
|
|
||||||
msg, err := v1beta1.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress())
|
msg, err := v1beta1.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid message: %w", err)
|
return fmt.Errorf("invalid message: %w", err)
|
||||||
|
@ -177,7 +180,7 @@ $ %s tx gov deposit 1 10stake --from mykey
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := v1beta1.NewMsgDeposit(from, proposalID, amount)
|
msg := v1beta2.NewMsgDeposit(from, proposalID, amount)
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
|
@ -219,13 +222,13 @@ $ %s tx gov vote 1 yes --from mykey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out which vote option user chose
|
// Find out which vote option user chose
|
||||||
byteVoteOption, err := v1beta1.VoteOptionFromString(govutils.NormalizeVoteOption(args[1]))
|
byteVoteOption, err := v1beta2.VoteOptionFromString(govutils.NormalizeVoteOption(args[1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build vote message and run basic validation
|
// Build vote message and run basic validation
|
||||||
msg := v1beta1.NewMsgVote(from, proposalID, byteVoteOption)
|
msg := v1beta2.NewMsgVote(from, proposalID, byteVoteOption)
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
|
@ -268,13 +271,13 @@ $ %s tx gov weighted-vote 1 yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05 --from
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out which vote options user chose
|
// Figure out which vote options user chose
|
||||||
options, err := v1beta1.WeightedVoteOptionsFromString(govutils.NormalizeWeightedVoteOptions(args[1]))
|
options, err := v1beta2.WeightedVoteOptionsFromString(govutils.NormalizeWeightedVoteOptions(args[1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build vote message and run basic validation
|
// Build vote message and run basic validation
|
||||||
msg := v1beta1.NewMsgVoteWeighted(from, proposalID, options)
|
msg := v1beta2.NewMsgVoteWeighted(from, proposalID, options)
|
||||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DepositTestSuite struct {
|
type DepositTestSuite struct {
|
||||||
|
@ -41,7 +42,7 @@ func (s *DepositTestSuite) SetupSuite() {
|
||||||
|
|
||||||
deposits := sdk.Coins{
|
deposits := sdk.Coins{
|
||||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)),
|
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)),
|
||||||
sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens.Sub(sdk.NewInt(50))),
|
sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens.Sub(sdk.NewInt(50))),
|
||||||
}
|
}
|
||||||
s.deposits = deposits
|
s.deposits = deposits
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
|
||||||
proposalID := s.proposalIDs[0]
|
proposalID := s.proposalIDs[0]
|
||||||
|
|
||||||
// deposit amount
|
// deposit amount
|
||||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()
|
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens.Add(sdk.NewInt(50))).String()
|
||||||
_, err := MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
|
_, err := MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
@ -109,14 +110,14 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
|
||||||
// query deposit
|
// query deposit
|
||||||
deposit := s.queryDeposit(val, proposalID, false, "")
|
deposit := s.queryDeposit(val, proposalID, false, "")
|
||||||
s.Require().NotNil(deposit)
|
s.Require().NotNil(deposit)
|
||||||
s.Require().Equal(deposit.Amount.String(), depositAmount)
|
s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount)
|
||||||
|
|
||||||
// query deposits
|
// query deposits
|
||||||
deposits := s.queryDeposits(val, proposalID, false, "")
|
deposits := s.queryDeposits(val, proposalID, false, "")
|
||||||
s.Require().NotNil(deposits)
|
s.Require().NotNil(deposits)
|
||||||
s.Require().Len(deposits.Deposits, 1)
|
s.Require().Len(deposits.Deposits, 1)
|
||||||
// verify initial deposit
|
// verify initial deposit
|
||||||
s.Require().Equal(deposits.Deposits[0].Amount.String(), depositAmount)
|
s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), depositAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DepositTestSuite) TestQueryProposalNotEnoughDeposits() {
|
func (s *DepositTestSuite) TestQueryProposalNotEnoughDeposits() {
|
||||||
|
@ -146,14 +147,14 @@ func (s *DepositTestSuite) TestRejectedProposalDeposits() {
|
||||||
|
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
clientCtx := val.ClientCtx
|
clientCtx := val.ClientCtx
|
||||||
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens)
|
initialDeposit := sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens)
|
||||||
id := 1
|
id := 1
|
||||||
proposalID := fmt.Sprintf("%d", id)
|
proposalID := fmt.Sprintf("%d", id)
|
||||||
|
|
||||||
s.createProposal(val, initialDeposit, id)
|
s.createProposal(val, initialDeposit, id)
|
||||||
|
|
||||||
// query deposits
|
// query deposits
|
||||||
var deposits v1beta1.QueryDepositsResponse
|
var deposits v1beta2.QueryDepositsResponse
|
||||||
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||||
cmd := cli.GetCmdQueryDeposits()
|
cmd := cli.GetCmdQueryDeposits()
|
||||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||||
|
@ -161,7 +162,7 @@ func (s *DepositTestSuite) TestRejectedProposalDeposits() {
|
||||||
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &deposits))
|
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &deposits))
|
||||||
s.Require().Equal(len(deposits.Deposits), 1)
|
s.Require().Equal(len(deposits.Deposits), 1)
|
||||||
// verify initial deposit
|
// verify initial deposit
|
||||||
s.Require().Equal(deposits.Deposits[0].Amount.String(), initialDeposit.String())
|
s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), initialDeposit.String())
|
||||||
|
|
||||||
// vote
|
// vote
|
||||||
_, err = MsgVote(clientCtx, val.Address.String(), proposalID, "no")
|
_, err = MsgVote(clientCtx, val.Address.String(), proposalID, "no")
|
||||||
|
@ -180,12 +181,12 @@ func (s *DepositTestSuite) TestRejectedProposalDeposits() {
|
||||||
s.Require().NotNil(depositsRes)
|
s.Require().NotNil(depositsRes)
|
||||||
s.Require().Len(depositsRes.Deposits, 1)
|
s.Require().Len(depositsRes.Deposits, 1)
|
||||||
// verify initial deposit
|
// verify initial deposit
|
||||||
s.Require().Equal(depositsRes.Deposits[0].Amount.String(), initialDeposit.String())
|
s.Require().Equal(sdk.Coins(depositsRes.Deposits[0].Amount).String(), initialDeposit.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1beta1.QueryDepositsResponse {
|
func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1beta2.QueryDepositsResponse {
|
||||||
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
args := []string{proposalID, fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||||
var depositsRes *v1beta1.QueryDepositsResponse
|
var depositsRes *v1beta2.QueryDepositsResponse
|
||||||
cmd := cli.GetCmdQueryDeposits()
|
cmd := cli.GetCmdQueryDeposits()
|
||||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||||
|
|
||||||
|
@ -200,9 +201,9 @@ func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID stri
|
||||||
return depositsRes
|
return depositsRes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1beta1.Deposit {
|
func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1beta2.Deposit {
|
||||||
args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", tmcli.OutputFlag)}
|
||||||
var depositRes *v1beta1.Deposit
|
var depositRes *v1beta2.Deposit
|
||||||
cmd := cli.GetCmdQueryDeposit()
|
cmd := cli.GetCmdQueryDeposit()
|
||||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||||
if exceptErr {
|
if exceptErr {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/rest"
|
"github.com/cosmos/cosmos-sdk/testutil/rest"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestGetProposalGRPC() {
|
func (s *IntegrationTestSuite) TestGetProposalGRPC() {
|
||||||
|
@ -22,17 +22,17 @@ func (s *IntegrationTestSuite) TestGetProposalGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty proposal",
|
"empty proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s", val.APIAddress, ""),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s", val.APIAddress, ""),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get non existing proposal",
|
"get non existing proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s", val.APIAddress, "10"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s", val.APIAddress, "10"),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get proposal with id",
|
"get proposal with id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s", val.APIAddress, "1"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s", val.APIAddress, "1"),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func (s *IntegrationTestSuite) TestGetProposalGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var proposal v1beta1.QueryProposalResponse
|
var proposal v1beta2.QueryProposalResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposal)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposal)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -68,7 +68,7 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"get proposals with height 1",
|
"get proposals with height 1",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals", val.APIAddress),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals", val.APIAddress),
|
||||||
map[string]string{
|
map[string]string{
|
||||||
grpctypes.GRPCBlockHeightHeader: "1",
|
grpctypes.GRPCBlockHeightHeader: "1",
|
||||||
},
|
},
|
||||||
|
@ -77,14 +77,14 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request",
|
"valid request",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals", val.APIAddress),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals", val.APIAddress),
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
3,
|
3,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request with filter by status",
|
"valid request with filter by status",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals?proposal_status=1", val.APIAddress),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals?proposal_status=1", val.APIAddress),
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
1,
|
1,
|
||||||
false,
|
false,
|
||||||
|
@ -97,7 +97,7 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var proposals v1beta1.QueryProposalsResponse
|
var proposals v1beta2.QueryProposalsResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposals)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposals)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -119,41 +119,41 @@ func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() {
|
||||||
name string
|
name string
|
||||||
url string
|
url string
|
||||||
expErr bool
|
expErr bool
|
||||||
expVoteOptions v1beta1.WeightedVoteOptions
|
expVoteOptions v1beta2.WeightedVoteOptions
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty proposal",
|
"empty proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes/%s", val.APIAddress, "", voterAddressBech32),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes/%s", val.APIAddress, "", voterAddressBech32),
|
||||||
true,
|
true,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get non existing proposal",
|
"get non existing proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes/%s", val.APIAddress, "10", voterAddressBech32),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes/%s", val.APIAddress, "10", voterAddressBech32),
|
||||||
true,
|
true,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get proposal with wrong voter address",
|
"get proposal with wrong voter address",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes/%s", val.APIAddress, "1", "wrongVoterAddress"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes/%s", val.APIAddress, "1", "wrongVoterAddress"),
|
||||||
true,
|
true,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get proposal with id",
|
"get proposal with id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes/%s", val.APIAddress, "1", voterAddressBech32),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes/%s", val.APIAddress, "1", voterAddressBech32),
|
||||||
false,
|
false,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get proposal with id for split vote",
|
"get proposal with id for split vote",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes/%s", val.APIAddress, "3", voterAddressBech32),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes/%s", val.APIAddress, "3", voterAddressBech32),
|
||||||
false,
|
false,
|
||||||
v1beta1.WeightedVoteOptions{
|
v1beta2.WeightedVoteOptions{
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionYes, Weight: sdk.NewDecWithPrec(60, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionNo, Weight: sdk.NewDecWithPrec(30, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var vote v1beta1.QueryVoteResponse
|
var vote v1beta2.QueryVoteResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &vote)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &vote)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -175,7 +175,7 @@ func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() {
|
||||||
s.Require().Equal(len(vote.Vote.Options), len(tc.expVoteOptions))
|
s.Require().Equal(len(vote.Vote.Options), len(tc.expVoteOptions))
|
||||||
for i, option := range tc.expVoteOptions {
|
for i, option := range tc.expVoteOptions {
|
||||||
s.Require().Equal(option.Option, vote.Vote.Options[i].Option)
|
s.Require().Equal(option.Option, vote.Vote.Options[i].Option)
|
||||||
s.Require().True(option.Weight.Equal(vote.Vote.Options[i].Weight))
|
s.Require().Equal(option.Weight, vote.Vote.Options[i].Weight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -192,12 +192,12 @@ func (s *IntegrationTestSuite) TestGetProposalVotesGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"votes with empty proposal id",
|
"votes with empty proposal id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes", val.APIAddress, ""),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes", val.APIAddress, ""),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get votes with valid id",
|
"get votes with valid id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/votes", val.APIAddress, "1"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/votes", val.APIAddress, "1"),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ func (s *IntegrationTestSuite) TestGetProposalVotesGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var votes v1beta1.QueryVotesResponse
|
var votes v1beta2.QueryVotesResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &votes)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &votes)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -231,22 +231,22 @@ func (s *IntegrationTestSuite) TestGetProposalDepositGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"get deposit with empty proposal id",
|
"get deposit with empty proposal id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits/%s", val.APIAddress, "", val.Address.String()),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits/%s", val.APIAddress, "", val.Address.String()),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get deposit of non existing proposal",
|
"get deposit of non existing proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits/%s", val.APIAddress, "10", val.Address.String()),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits/%s", val.APIAddress, "10", val.Address.String()),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get deposit with wrong depositer address",
|
"get deposit with wrong depositer address",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits/%s", val.APIAddress, "1", "wrongDepositerAddress"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits/%s", val.APIAddress, "1", "wrongDepositerAddress"),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get deposit valid request",
|
"get deposit valid request",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits/%s", val.APIAddress, "1", val.Address.String()),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits/%s", val.APIAddress, "1", val.Address.String()),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ func (s *IntegrationTestSuite) TestGetProposalDepositGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var deposit v1beta1.QueryDepositResponse
|
var deposit v1beta2.QueryDepositResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposit)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposit)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -280,12 +280,12 @@ func (s *IntegrationTestSuite) TestGetProposalDepositsGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"get deposits with empty proposal id",
|
"get deposits with empty proposal id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits", val.APIAddress, ""),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits", val.APIAddress, ""),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request",
|
"valid request",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/deposits", val.APIAddress, "1"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/deposits", val.APIAddress, "1"),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ func (s *IntegrationTestSuite) TestGetProposalDepositsGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var deposits v1beta1.QueryDepositsResponse
|
var deposits v1beta2.QueryDepositsResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposits)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposits)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -320,17 +320,17 @@ func (s *IntegrationTestSuite) TestGetTallyGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"get tally with no proposal id",
|
"get tally with no proposal id",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/tally", val.APIAddress, ""),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/tally", val.APIAddress, ""),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get tally with non existing proposal",
|
"get tally with non existing proposal",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/tally", val.APIAddress, "10"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/tally", val.APIAddress, "10"),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get tally valid request",
|
"get tally valid request",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%s/tally", val.APIAddress, "1"),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/proposals/%s/tally", val.APIAddress, "1"),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ func (s *IntegrationTestSuite) TestGetTallyGRPC() {
|
||||||
resp, err := rest.GetRequest(tc.url)
|
resp, err := rest.GetRequest(tc.url)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var tally v1beta1.QueryTallyResultResponse
|
var tally v1beta2.QueryTallyResultResponse
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &tally)
|
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &tally)
|
||||||
|
|
||||||
if tc.expErr {
|
if tc.expErr {
|
||||||
|
@ -357,6 +357,10 @@ func (s *IntegrationTestSuite) TestGetTallyGRPC() {
|
||||||
func (s *IntegrationTestSuite) TestGetParamsGRPC() {
|
func (s *IntegrationTestSuite) TestGetParamsGRPC() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
|
dp := v1beta2.DefaultDepositParams()
|
||||||
|
vp := v1beta2.DefaultVotingParams()
|
||||||
|
tp := v1beta2.DefaultTallyParams()
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
url string
|
url string
|
||||||
|
@ -366,35 +370,29 @@ func (s *IntegrationTestSuite) TestGetParamsGRPC() {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"request params with empty params type",
|
"request params with empty params type",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/params/%s", val.APIAddress, ""),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/params/%s", val.APIAddress, ""),
|
||||||
true, nil, nil,
|
true, nil, nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get deposit params",
|
"get deposit params",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/params/%s", val.APIAddress, v1beta1.ParamDeposit),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/params/%s", val.APIAddress, v1beta2.ParamDeposit),
|
||||||
false,
|
false,
|
||||||
&v1beta1.QueryParamsResponse{},
|
&v1beta2.QueryParamsResponse{},
|
||||||
&v1beta1.QueryParamsResponse{
|
&v1beta2.QueryParamsResponse{DepositParams: &dp},
|
||||||
DepositParams: v1beta1.DefaultDepositParams(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get vote params",
|
"get vote params",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/params/%s", val.APIAddress, v1beta1.ParamVoting),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/params/%s", val.APIAddress, v1beta2.ParamVoting),
|
||||||
false,
|
false,
|
||||||
&v1beta1.QueryParamsResponse{},
|
&v1beta2.QueryParamsResponse{},
|
||||||
&v1beta1.QueryParamsResponse{
|
&v1beta2.QueryParamsResponse{VotingParams: &vp},
|
||||||
VotingParams: v1beta1.DefaultVotingParams(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get tally params",
|
"get tally params",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/params/%s", val.APIAddress, v1beta1.ParamTallying),
|
fmt.Sprintf("%s/cosmos/gov/v1beta2/params/%s", val.APIAddress, v1beta2.ParamTallying),
|
||||||
false,
|
false,
|
||||||
&v1beta1.QueryParamsResponse{},
|
&v1beta2.QueryParamsResponse{},
|
||||||
&v1beta1.QueryParamsResponse{
|
&v1beta2.QueryParamsResponse{TallyParams: &tp},
|
||||||
TallyParams: v1beta1.DefaultTallyParams(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IntegrationTestSuite struct {
|
type IntegrationTestSuite struct {
|
||||||
|
@ -45,7 +46,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
// create a proposal with deposit
|
// create a proposal with deposit
|
||||||
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
||||||
"Text Proposal 1", "Where is the title!?", v1beta1.ProposalTypeText,
|
"Text Proposal 1", "Where is the title!?", v1beta1.ProposalTypeText,
|
||||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens).String()))
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens).String()))
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
_, err = s.network.WaitForHeight(1)
|
_, err = s.network.WaitForHeight(1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -64,7 +65,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
// create a proposal3 with deposit
|
// create a proposal3 with deposit
|
||||||
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
_, err = MsgSubmitProposal(val.ClientCtx, val.Address.String(),
|
||||||
"Text Proposal 3", "Where is the title!?", v1beta1.ProposalTypeText,
|
"Text Proposal 3", "Where is the title!?", v1beta1.ProposalTypeText,
|
||||||
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens).String()))
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens).String()))
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
_, err = s.network.WaitForHeight(1)
|
_, err = s.network.WaitForHeight(1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -226,7 +227,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expectedOutput v1beta1.TallyResult
|
expectedOutput v1beta2.TallyResult
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"without proposal id",
|
"without proposal id",
|
||||||
|
@ -234,7 +235,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
v1beta1.TallyResult{},
|
v1beta2.TallyResult{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"json output",
|
"json output",
|
||||||
|
@ -243,7 +244,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
v1beta1.NewTallyResult(sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
v1beta2.NewTallyResult(sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"json output",
|
"json output",
|
||||||
|
@ -252,7 +253,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
v1beta1.NewTallyResult(s.cfg.BondedTokens, sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
v1beta2.NewTallyResult(s.cfg.BondedTokens, sdk.NewInt(0), sdk.NewInt(0), sdk.NewInt(0)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +268,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
|
||||||
if tc.expectErr {
|
if tc.expectErr {
|
||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
} else {
|
} else {
|
||||||
var tally v1beta1.TallyResult
|
var tally v1beta2.TallyResult
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &tally), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &tally), out.String())
|
||||||
s.Require().Equal(tally, tc.expectedOutput)
|
s.Require().Equal(tally, tc.expectedOutput)
|
||||||
}
|
}
|
||||||
|
@ -407,9 +408,9 @@ func (s *IntegrationTestSuite) TestCmdGetProposal() {
|
||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
var proposal v1beta1.Proposal
|
var proposal v1beta2.Proposal
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposal), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposal), out.String())
|
||||||
s.Require().Equal(title, proposal.GetTitle())
|
s.Require().Equal(title, proposal.Messages[0].GetCachedValue().(*v1beta2.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -452,7 +453,7 @@ func (s *IntegrationTestSuite) TestCmdGetProposals() {
|
||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
var proposals v1beta1.QueryProposalsResponse
|
var proposals v1beta2.QueryProposalsResponse
|
||||||
|
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposals), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposals), out.String())
|
||||||
s.Require().Len(proposals.Proposals, 3)
|
s.Require().Len(proposals.Proposals, 3)
|
||||||
|
@ -499,7 +500,7 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposits() {
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var deposits v1beta1.QueryDepositsResponse
|
var deposits v1beta2.QueryDepositsResponse
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposits), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposits), out.String())
|
||||||
s.Require().Len(deposits.Deposits, 1)
|
s.Require().Len(deposits.Deposits, 1)
|
||||||
}
|
}
|
||||||
|
@ -509,7 +510,7 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposits() {
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestCmdQueryDeposit() {
|
func (s *IntegrationTestSuite) TestCmdQueryDeposit() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1beta1.DefaultMinDepositTokens)
|
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1beta2.DefaultMinDepositTokens)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -555,9 +556,9 @@ func (s *IntegrationTestSuite) TestCmdQueryDeposit() {
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var deposit v1beta1.Deposit
|
var deposit v1beta2.Deposit
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposit), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposit), out.String())
|
||||||
s.Require().Equal(depositAmount.String(), deposit.Amount.String())
|
s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Amount).String())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -684,7 +685,7 @@ func (s *IntegrationTestSuite) TestCmdQueryVotes() {
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var votes v1beta1.QueryVotesResponse
|
var votes v1beta2.QueryVotesResponse
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &votes), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &votes), out.String())
|
||||||
s.Require().Len(votes.Votes, 1)
|
s.Require().Len(votes.Votes, 1)
|
||||||
}
|
}
|
||||||
|
@ -699,7 +700,7 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
expectErr bool
|
expectErr bool
|
||||||
expVoteOptions v1beta1.WeightedVoteOptions
|
expVoteOptions v1beta2.WeightedVoteOptions
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"get vote of non existing proposal",
|
"get vote of non existing proposal",
|
||||||
|
@ -708,7 +709,7 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
val.Address.String(),
|
val.Address.String(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"get vote by wrong voter",
|
"get vote by wrong voter",
|
||||||
|
@ -717,7 +718,7 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
"wrong address",
|
"wrong address",
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"vote for valid proposal",
|
"vote for valid proposal",
|
||||||
|
@ -727,7 +728,7 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"split vote for valid proposal",
|
"split vote for valid proposal",
|
||||||
|
@ -737,11 +738,11 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
v1beta1.WeightedVoteOptions{
|
v1beta2.WeightedVoteOptions{
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionYes, Weight: sdk.NewDecWithPrec(60, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionNo, Weight: sdk.NewDecWithPrec(30, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2)},
|
&v1beta2.WeightedVoteOption{Option: v1beta2.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2).String()},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -759,12 +760,12 @@ func (s *IntegrationTestSuite) TestCmdQueryVote() {
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var vote v1beta1.Vote
|
var vote v1beta2.Vote
|
||||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &vote), out.String())
|
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &vote), out.String())
|
||||||
s.Require().Equal(len(vote.Options), len(tc.expVoteOptions))
|
s.Require().Equal(len(vote.Options), len(tc.expVoteOptions))
|
||||||
for i, option := range tc.expVoteOptions {
|
for i, option := range tc.expVoteOptions {
|
||||||
s.Require().Equal(option.Option, vote.Options[i].Option)
|
s.Require().Equal(option.Option, vote.Options[i].Option)
|
||||||
s.Require().True(option.Weight.Equal(vote.Options[i].Weight))
|
s.Require().Equal(option.Weight, vote.Options[i].Weight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -38,8 +39,8 @@ func (p Proposer) String() string {
|
||||||
//
|
//
|
||||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||||
// support configurable pagination.
|
// support configurable pagination.
|
||||||
func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalParams) ([]byte, error) {
|
func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta2.QueryProposalParams) ([]byte, error) {
|
||||||
var deposits []v1beta1.Deposit
|
var deposits []v1beta2.Deposit
|
||||||
|
|
||||||
// initial deposit was submitted with proposal, so must be queried separately
|
// initial deposit was submitted with proposal, so must be queried separately
|
||||||
initialDeposit, err := queryInitialDepositByTxQuery(clientCtx, params.ProposalID)
|
initialDeposit, err := queryInitialDepositByTxQuery(clientCtx, params.ProposalID)
|
||||||
|
@ -47,7 +48,7 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta1.QueryPropos
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initialDeposit.Amount.IsZero() {
|
if !sdk.Coins(initialDeposit.Amount).IsZero() {
|
||||||
deposits = append(deposits, initialDeposit)
|
deposits = append(deposits, initialDeposit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,14 +56,19 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta1.QueryPropos
|
||||||
clientCtx, defaultPage,
|
clientCtx, defaultPage,
|
||||||
// Query legacy Msgs event action
|
// Query legacy Msgs event action
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgDeposit),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgDeposit),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
// Query proto Msgs event action
|
// Query proto Msgs event action v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgDeposit{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgDeposit{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
|
// Query proto Msgs event action v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgDeposit{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -71,7 +77,15 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta1.QueryPropos
|
||||||
for _, info := range searchResult.Txs {
|
for _, info := range searchResult.Txs {
|
||||||
for _, msg := range info.GetTx().GetMsgs() {
|
for _, msg := range info.GetTx().GetMsgs() {
|
||||||
if depMsg, ok := msg.(*v1beta1.MsgDeposit); ok {
|
if depMsg, ok := msg.(*v1beta1.MsgDeposit); ok {
|
||||||
deposits = append(deposits, v1beta1.Deposit{
|
deposits = append(deposits, v1beta2.Deposit{
|
||||||
|
Depositor: depMsg.Depositor,
|
||||||
|
ProposalId: params.ProposalID,
|
||||||
|
Amount: depMsg.Amount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if depMsg, ok := msg.(*v1beta2.MsgDeposit); ok {
|
||||||
|
deposits = append(deposits, v1beta2.Deposit{
|
||||||
Depositor: depMsg.Depositor,
|
Depositor: depMsg.Depositor,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Amount: depMsg.Amount,
|
Amount: depMsg.Amount,
|
||||||
|
@ -91,9 +105,9 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params v1beta1.QueryPropos
|
||||||
// QueryVotesByTxQuery will query for votes via a direct txs tags query. It
|
// QueryVotesByTxQuery will query for votes via a direct txs tags query. It
|
||||||
// will fetch and build votes directly from the returned txs and return a JSON
|
// will fetch and build votes directly from the returned txs and return a JSON
|
||||||
// marshalled result or any error that occurred.
|
// marshalled result or any error that occurred.
|
||||||
func QueryVotesByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalVotesParams) ([]byte, error) {
|
func QueryVotesByTxQuery(clientCtx client.Context, params v1beta2.QueryProposalVotesParams) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
votes []v1beta1.Vote
|
votes []*v1beta2.Vote
|
||||||
nextTxPage = defaultPage
|
nextTxPage = defaultPage
|
||||||
totalLimit = params.Limit * params.Page
|
totalLimit = params.Limit * params.Page
|
||||||
)
|
)
|
||||||
|
@ -105,24 +119,34 @@ func QueryVotesByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalV
|
||||||
clientCtx, nextTxPage,
|
clientCtx, nextTxPage,
|
||||||
// Query legacy Vote Msgs
|
// Query legacy Vote Msgs
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgVote),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgVote),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
// Query Vote proto Msgs
|
// Query Vote proto Msgs v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVote{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVote{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
// Query legacy VoteWeighted Msgs
|
// Query Vote proto Msgs v1beta2
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgVoteWeighted),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgVote{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
// Query VoteWeighted proto Msgs
|
// Query legacy VoteWeighted Msgs
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgVoteWeighted),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
},
|
||||||
|
// Query VoteWeighted proto Msgs v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVoteWeighted{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVoteWeighted{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
},
|
},
|
||||||
|
// Query VoteWeighted proto Msgs v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgVoteWeighted{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -131,15 +155,27 @@ func QueryVotesByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalV
|
||||||
for _, info := range searchResult.Txs {
|
for _, info := range searchResult.Txs {
|
||||||
for _, msg := range info.GetTx().GetMsgs() {
|
for _, msg := range info.GetTx().GetMsgs() {
|
||||||
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
||||||
votes = append(votes, v1beta1.Vote{
|
votes = append(votes, &v1beta2.Vote{
|
||||||
Voter: voteMsg.Voter,
|
Voter: voteMsg.Voter,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Options: v1beta1.NewNonSplitVoteOption(voteMsg.Option),
|
Options: v1beta2.NewNonSplitVoteOption(v1beta2.VoteOption(voteMsg.Option)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if voteMsg, ok := msg.(*v1beta2.MsgVote); ok {
|
||||||
|
votes = append(votes, &v1beta2.Vote{
|
||||||
|
Voter: voteMsg.Voter,
|
||||||
|
ProposalId: params.ProposalID,
|
||||||
|
Options: v1beta2.NewNonSplitVoteOption(voteMsg.Option),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
||||||
votes = append(votes, v1beta1.Vote{
|
votes = append(votes, convertVote(voteWeightedMsg))
|
||||||
|
}
|
||||||
|
|
||||||
|
if voteWeightedMsg, ok := msg.(*v1beta2.MsgVoteWeighted); ok {
|
||||||
|
votes = append(votes, &v1beta2.Vote{
|
||||||
Voter: voteWeightedMsg.Voter,
|
Voter: voteWeightedMsg.Voter,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Options: voteWeightedMsg.Options,
|
Options: voteWeightedMsg.Options,
|
||||||
|
@ -155,7 +191,7 @@ func QueryVotesByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalV
|
||||||
}
|
}
|
||||||
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
|
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
|
||||||
if start < 0 || end < 0 {
|
if start < 0 || end < 0 {
|
||||||
votes = []v1beta1.Vote{}
|
votes = []*v1beta2.Vote{}
|
||||||
} else {
|
} else {
|
||||||
votes = votes[start:end]
|
votes = votes[start:end]
|
||||||
}
|
}
|
||||||
|
@ -169,33 +205,45 @@ func QueryVotesByTxQuery(clientCtx client.Context, params v1beta1.QueryProposalV
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryVoteByTxQuery will query for a single vote via a direct txs tags query.
|
// QueryVoteByTxQuery will query for a single vote via a direct txs tags query.
|
||||||
func QueryVoteByTxQuery(clientCtx client.Context, params v1beta1.QueryVoteParams) ([]byte, error) {
|
func QueryVoteByTxQuery(clientCtx client.Context, params v1beta2.QueryVoteParams) ([]byte, error) {
|
||||||
searchResult, err := combineEvents(
|
searchResult, err := combineEvents(
|
||||||
clientCtx, defaultPage,
|
clientCtx, defaultPage,
|
||||||
// Query legacy Vote Msgs
|
// Query legacy Vote Msgs
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgVote),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgVote),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter),
|
||||||
},
|
},
|
||||||
// Query Vote proto Msgs
|
// Query Vote proto Msgs v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVote{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVote{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter.String()),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter.String()),
|
||||||
},
|
},
|
||||||
// Query legacy VoteWeighted Msgs
|
// Query Vote proto Msgs v1beta2
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgVoteWeighted),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgVote{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter.String()),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter.String()),
|
||||||
},
|
},
|
||||||
// Query VoteWeighted proto Msgs
|
// Query legacy VoteWeighted Msgs
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgVoteWeighted),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter.String()),
|
||||||
|
},
|
||||||
|
// Query VoteWeighted proto Msgs v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVoteWeighted{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgVoteWeighted{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter),
|
||||||
},
|
},
|
||||||
|
// Query VoteWeighted proto Msgs v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgVoteWeighted{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalVote, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Voter),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -204,17 +252,29 @@ func QueryVoteByTxQuery(clientCtx client.Context, params v1beta1.QueryVoteParams
|
||||||
for _, info := range searchResult.Txs {
|
for _, info := range searchResult.Txs {
|
||||||
for _, msg := range info.GetTx().GetMsgs() {
|
for _, msg := range info.GetTx().GetMsgs() {
|
||||||
// there should only be a single vote under the given conditions
|
// there should only be a single vote under the given conditions
|
||||||
var vote *v1beta1.Vote
|
var vote *v1beta2.Vote
|
||||||
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
||||||
vote = &v1beta1.Vote{
|
vote = &v1beta2.Vote{
|
||||||
Voter: voteMsg.Voter,
|
Voter: voteMsg.Voter,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Options: v1beta1.NewNonSplitVoteOption(voteMsg.Option),
|
Options: v1beta2.NewNonSplitVoteOption(v1beta2.VoteOption(voteMsg.Option)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if voteMsg, ok := msg.(*v1beta2.MsgVote); ok {
|
||||||
|
vote = &v1beta2.Vote{
|
||||||
|
Voter: voteMsg.Voter,
|
||||||
|
ProposalId: params.ProposalID,
|
||||||
|
Options: v1beta2.NewNonSplitVoteOption(voteMsg.Option),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
||||||
vote = &v1beta1.Vote{
|
vote = convertVote(voteWeightedMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if voteWeightedMsg, ok := msg.(*v1beta2.MsgVoteWeighted); ok {
|
||||||
|
vote = &v1beta2.Vote{
|
||||||
Voter: voteWeightedMsg.Voter,
|
Voter: voteWeightedMsg.Voter,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Options: voteWeightedMsg.Options,
|
Options: voteWeightedMsg.Options,
|
||||||
|
@ -237,7 +297,7 @@ func QueryVoteByTxQuery(clientCtx client.Context, params v1beta1.QueryVoteParams
|
||||||
|
|
||||||
// QueryDepositByTxQuery will query for a single deposit via a direct txs tags
|
// QueryDepositByTxQuery will query for a single deposit via a direct txs tags
|
||||||
// query.
|
// query.
|
||||||
func QueryDepositByTxQuery(clientCtx client.Context, params v1beta1.QueryDepositParams) ([]byte, error) {
|
func QueryDepositByTxQuery(clientCtx client.Context, params v1beta2.QueryDepositParams) ([]byte, error) {
|
||||||
|
|
||||||
// initial deposit was submitted with proposal, so must be queried separately
|
// initial deposit was submitted with proposal, so must be queried separately
|
||||||
initialDeposit, err := queryInitialDepositByTxQuery(clientCtx, params.ProposalID)
|
initialDeposit, err := queryInitialDepositByTxQuery(clientCtx, params.ProposalID)
|
||||||
|
@ -245,7 +305,7 @@ func QueryDepositByTxQuery(clientCtx client.Context, params v1beta1.QueryDeposit
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initialDeposit.Amount.IsZero() {
|
if !sdk.Coins(initialDeposit.Amount).IsZero() {
|
||||||
bz, err := clientCtx.Codec.MarshalJSON(&initialDeposit)
|
bz, err := clientCtx.Codec.MarshalJSON(&initialDeposit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -258,16 +318,22 @@ func QueryDepositByTxQuery(clientCtx client.Context, params v1beta1.QueryDeposit
|
||||||
clientCtx, defaultPage,
|
clientCtx, defaultPage,
|
||||||
// Query legacy Msgs event action
|
// Query legacy Msgs event action
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgDeposit),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgDeposit),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Depositor.String()),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Depositor.String()),
|
||||||
},
|
},
|
||||||
// Query proto Msgs event action
|
// Query proto Msgs event action v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgDeposit{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgDeposit{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Depositor.String()),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Depositor.String()),
|
||||||
},
|
},
|
||||||
|
// Query proto Msgs event action v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgDeposit{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeProposalDeposit, types.AttributeKeyProposalID, params.ProposalID),
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeySender, params.Depositor.String()),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -277,7 +343,22 @@ func QueryDepositByTxQuery(clientCtx client.Context, params v1beta1.QueryDeposit
|
||||||
for _, msg := range info.GetTx().GetMsgs() {
|
for _, msg := range info.GetTx().GetMsgs() {
|
||||||
// there should only be a single deposit under the given conditions
|
// there should only be a single deposit under the given conditions
|
||||||
if depMsg, ok := msg.(*v1beta1.MsgDeposit); ok {
|
if depMsg, ok := msg.(*v1beta1.MsgDeposit); ok {
|
||||||
deposit := v1beta1.Deposit{
|
deposit := v1beta2.Deposit{
|
||||||
|
Depositor: depMsg.Depositor,
|
||||||
|
ProposalId: params.ProposalID,
|
||||||
|
Amount: depMsg.Amount,
|
||||||
|
}
|
||||||
|
|
||||||
|
bz, err := clientCtx.Codec.MarshalJSON(&deposit)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bz, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if depMsg, ok := msg.(*v1beta2.MsgDeposit); ok {
|
||||||
|
deposit := v1beta2.Deposit{
|
||||||
Depositor: depMsg.Depositor,
|
Depositor: depMsg.Depositor,
|
||||||
ProposalId: params.ProposalID,
|
ProposalId: params.ProposalID,
|
||||||
Amount: depMsg.Amount,
|
Amount: depMsg.Amount,
|
||||||
|
@ -304,14 +385,19 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos
|
||||||
defaultPage,
|
defaultPage,
|
||||||
// Query legacy Msgs event action
|
// Query legacy Msgs event action
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgSubmitProposal),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgSubmitProposal),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
},
|
},
|
||||||
// Query proto Msgs event action
|
// Query proto Msgs event action v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgSubmitProposal{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgSubmitProposal{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
},
|
},
|
||||||
|
// Query proto Msgs event action v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgSubmitProposal{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proposer{}, err
|
return Proposer{}, err
|
||||||
|
@ -323,6 +409,9 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos
|
||||||
if subMsg, ok := msg.(*v1beta1.MsgSubmitProposal); ok {
|
if subMsg, ok := msg.(*v1beta1.MsgSubmitProposal); ok {
|
||||||
return NewProposer(proposalID, subMsg.Proposer), nil
|
return NewProposer(proposalID, subMsg.Proposer), nil
|
||||||
}
|
}
|
||||||
|
if subMsg, ok := msg.(*v1beta2.MsgSubmitProposal); ok {
|
||||||
|
return NewProposer(proposalID, subMsg.Proposer), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +420,7 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos
|
||||||
|
|
||||||
// QueryProposalByID takes a proposalID and returns a proposal
|
// QueryProposalByID takes a proposalID and returns a proposal
|
||||||
func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute string) ([]byte, error) {
|
func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute string) ([]byte, error) {
|
||||||
params := v1beta1.NewQueryProposalParams(proposalID)
|
params := v1beta2.NewQueryProposalParams(proposalID)
|
||||||
bz, err := clientCtx.LegacyAmino.MarshalJSON(params)
|
bz, err := clientCtx.LegacyAmino.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -369,30 +458,43 @@ func combineEvents(clientCtx client.Context, page int, eventGroups ...[]string)
|
||||||
|
|
||||||
// queryInitialDepositByTxQuery will query for a initial deposit of a governance proposal by
|
// queryInitialDepositByTxQuery will query for a initial deposit of a governance proposal by
|
||||||
// ID.
|
// ID.
|
||||||
func queryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) (v1beta1.Deposit, error) {
|
func queryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) (v1beta2.Deposit, error) {
|
||||||
searchResult, err := combineEvents(
|
searchResult, err := combineEvents(
|
||||||
clientCtx, defaultPage,
|
clientCtx, defaultPage,
|
||||||
// Query legacy Msgs event action
|
// Query legacy Msgs event action
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta1.TypeMsgSubmitProposal),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, v1beta2.TypeMsgSubmitProposal),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
},
|
},
|
||||||
// Query proto Msgs event action
|
// Query proto Msgs event action v1beta1
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgSubmitProposal{})),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta1.MsgSubmitProposal{})),
|
||||||
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
},
|
},
|
||||||
|
// Query proto Msgs event action v1beta2
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, sdk.MsgTypeURL(&v1beta2.MsgSubmitProposal{})),
|
||||||
|
fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v1beta1.Deposit{}, err
|
return v1beta2.Deposit{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, info := range searchResult.Txs {
|
for _, info := range searchResult.Txs {
|
||||||
for _, msg := range info.GetTx().GetMsgs() {
|
for _, msg := range info.GetTx().GetMsgs() {
|
||||||
// there should only be a single proposal under the given conditions
|
// there should only be a single proposal under the given conditions
|
||||||
if subMsg, ok := msg.(*v1beta1.MsgSubmitProposal); ok {
|
if subMsg, ok := msg.(*v1beta1.MsgSubmitProposal); ok {
|
||||||
return v1beta1.Deposit{
|
return v1beta2.Deposit{
|
||||||
|
ProposalId: proposalID,
|
||||||
|
Depositor: subMsg.Proposer,
|
||||||
|
Amount: subMsg.InitialDeposit,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if subMsg, ok := msg.(*v1beta2.MsgSubmitProposal); ok {
|
||||||
|
return v1beta2.Deposit{
|
||||||
ProposalId: proposalID,
|
ProposalId: proposalID,
|
||||||
Depositor: subMsg.Proposer,
|
Depositor: subMsg.Proposer,
|
||||||
Amount: subMsg.InitialDeposit,
|
Amount: subMsg.InitialDeposit,
|
||||||
|
@ -401,5 +503,21 @@ func queryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return v1beta1.Deposit{}, sdkerrors.ErrNotFound.Wrapf("failed to find the initial deposit for proposalID %d", proposalID)
|
return v1beta2.Deposit{}, sdkerrors.ErrNotFound.Wrapf("failed to find the initial deposit for proposalID %d", proposalID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertVote converts a MsgVoteWeighted into a *v1beta2.Vote.
|
||||||
|
func convertVote(v *v1beta1.MsgVoteWeighted) *v1beta2.Vote {
|
||||||
|
opts := make([]*v1beta2.WeightedVoteOption, len(v.Options))
|
||||||
|
for i, o := range v.Options {
|
||||||
|
opts[i] = &v1beta2.WeightedVoteOption{
|
||||||
|
Option: v1beta2.VoteOption(o.Option),
|
||||||
|
Weight: o.Weight.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &v1beta2.Vote{
|
||||||
|
Voter: v.Voter,
|
||||||
|
ProposalId: v.ProposalId,
|
||||||
|
Options: opts,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
"github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TxSearchMock struct {
|
type TxSearchMock struct {
|
||||||
|
@ -81,19 +81,19 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
description string
|
description string
|
||||||
page, limit int
|
page, limit int
|
||||||
msgs [][]sdk.Msg
|
msgs [][]sdk.Msg
|
||||||
votes []v1beta1.Vote
|
votes []v1beta2.Vote
|
||||||
}
|
}
|
||||||
acc1 := make(sdk.AccAddress, 20)
|
acc1 := make(sdk.AccAddress, 20)
|
||||||
acc1[0] = 1
|
acc1[0] = 1
|
||||||
acc2 := make(sdk.AccAddress, 20)
|
acc2 := make(sdk.AccAddress, 20)
|
||||||
acc2[0] = 2
|
acc2[0] = 2
|
||||||
acc1Msgs := []sdk.Msg{
|
acc1Msgs := []sdk.Msg{
|
||||||
v1beta1.NewMsgVote(acc1, 0, v1beta1.OptionYes),
|
v1beta2.NewMsgVote(acc1, 0, v1beta2.OptionYes),
|
||||||
v1beta1.NewMsgVote(acc1, 0, v1beta1.OptionYes),
|
v1beta2.NewMsgVote(acc1, 0, v1beta2.OptionYes),
|
||||||
}
|
}
|
||||||
acc2Msgs := []sdk.Msg{
|
acc2Msgs := []sdk.Msg{
|
||||||
v1beta1.NewMsgVote(acc2, 0, v1beta1.OptionYes),
|
v1beta2.NewMsgVote(acc2, 0, v1beta2.OptionYes),
|
||||||
v1beta1.NewMsgVoteWeighted(acc2, 0, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewMsgVoteWeighted(acc2, 0, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
}
|
}
|
||||||
for _, tc := range []testCase{
|
for _, tc := range []testCase{
|
||||||
{
|
{
|
||||||
|
@ -104,9 +104,9 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
acc1Msgs[:1],
|
acc1Msgs[:1],
|
||||||
acc2Msgs[:1],
|
acc2Msgs[:1],
|
||||||
},
|
},
|
||||||
votes: []v1beta1.Vote{
|
votes: []v1beta2.Vote{
|
||||||
v1beta1.NewVote(0, acc1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewVote(0, acc1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
v1beta1.NewVote(0, acc2, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))},
|
v1beta2.NewVote(0, acc2, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "2MsgPerTx1Chunk",
|
description: "2MsgPerTx1Chunk",
|
||||||
|
@ -116,9 +116,9 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
acc1Msgs,
|
acc1Msgs,
|
||||||
acc2Msgs,
|
acc2Msgs,
|
||||||
},
|
},
|
||||||
votes: []v1beta1.Vote{
|
votes: []v1beta2.Vote{
|
||||||
v1beta1.NewVote(0, acc1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewVote(0, acc1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
v1beta1.NewVote(0, acc1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewVote(0, acc1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -129,9 +129,9 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
acc1Msgs,
|
acc1Msgs,
|
||||||
acc2Msgs,
|
acc2Msgs,
|
||||||
},
|
},
|
||||||
votes: []v1beta1.Vote{
|
votes: []v1beta2.Vote{
|
||||||
v1beta1.NewVote(0, acc2, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewVote(0, acc2, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
v1beta1.NewVote(0, acc2, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)),
|
v1beta2.NewVote(0, acc2, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -141,7 +141,7 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
msgs: [][]sdk.Msg{
|
msgs: [][]sdk.Msg{
|
||||||
acc1Msgs[:1],
|
acc1Msgs[:1],
|
||||||
},
|
},
|
||||||
votes: []v1beta1.Vote{v1beta1.NewVote(0, acc1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))},
|
votes: []v1beta2.Vote{v1beta2.NewVote(0, acc1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "InvalidPage",
|
description: "InvalidPage",
|
||||||
|
@ -179,10 +179,10 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||||
marshalled[i] = tx
|
marshalled[i] = tx
|
||||||
}
|
}
|
||||||
|
|
||||||
params := v1beta1.NewQueryProposalVotesParams(0, tc.page, tc.limit)
|
params := v1beta2.NewQueryProposalVotesParams(0, tc.page, tc.limit)
|
||||||
votesData, err := utils.QueryVotesByTxQuery(clientCtx, params)
|
votesData, err := utils.QueryVotesByTxQuery(clientCtx, params)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
votes := []v1beta1.Vote{}
|
votes := []v1beta2.Vote{}
|
||||||
require.NoError(t, clientCtx.LegacyAmino.UnmarshalJSON(votesData, &votes))
|
require.NoError(t, clientCtx.LegacyAmino.UnmarshalJSON(votesData, &votes))
|
||||||
require.Equal(t, len(tc.votes), len(votes))
|
require.Equal(t, len(tc.votes), len(votes))
|
||||||
for i := range votes {
|
for i := range votes {
|
||||||
|
|
|
@ -4,12 +4,17 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -19,6 +24,14 @@ var (
|
||||||
TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes.
|
||||||
|
func mkTestLegacyContent(t *testing.T) *v1beta2.MsgExecLegacyContent {
|
||||||
|
msgContent, err := v1beta2.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return msgContent
|
||||||
|
}
|
||||||
|
|
||||||
// SortAddresses - Sorts Addresses
|
// SortAddresses - Sorts Addresses
|
||||||
func SortAddresses(addrs []sdk.AccAddress) {
|
func SortAddresses(addrs []sdk.AccAddress) {
|
||||||
byteAddrs := make([][]byte, len(addrs))
|
byteAddrs := make([][]byte, len(addrs))
|
||||||
|
|
|
@ -6,15 +6,15 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitGenesis - store genesis parameters
|
// InitGenesis - store genesis parameters
|
||||||
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, data *v1beta1.GenesisState) {
|
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, data *v1beta2.GenesisState) {
|
||||||
k.SetProposalID(ctx, data.StartingProposalId)
|
k.SetProposalID(ctx, data.StartingProposalId)
|
||||||
k.SetDepositParams(ctx, data.DepositParams)
|
k.SetDepositParams(ctx, *data.DepositParams)
|
||||||
k.SetVotingParams(ctx, data.VotingParams)
|
k.SetVotingParams(ctx, *data.VotingParams)
|
||||||
k.SetTallyParams(ctx, data.TallyParams)
|
k.SetTallyParams(ctx, *data.TallyParams)
|
||||||
|
|
||||||
// check if the deposits pool account exists
|
// check if the deposits pool account exists
|
||||||
moduleAcc := k.GetGovernanceAccount(ctx)
|
moduleAcc := k.GetGovernanceAccount(ctx)
|
||||||
|
@ -24,22 +24,22 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
|
||||||
|
|
||||||
var totalDeposits sdk.Coins
|
var totalDeposits sdk.Coins
|
||||||
for _, deposit := range data.Deposits {
|
for _, deposit := range data.Deposits {
|
||||||
k.SetDeposit(ctx, deposit)
|
k.SetDeposit(ctx, *deposit)
|
||||||
totalDeposits = totalDeposits.Add(deposit.Amount...)
|
totalDeposits = totalDeposits.Add(deposit.Amount...)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, vote := range data.Votes {
|
for _, vote := range data.Votes {
|
||||||
k.SetVote(ctx, vote)
|
k.SetVote(ctx, *vote)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, proposal := range data.Proposals {
|
for _, proposal := range data.Proposals {
|
||||||
switch proposal.Status {
|
switch proposal.Status {
|
||||||
case v1beta1.StatusDepositPeriod:
|
case v1beta2.StatusDepositPeriod:
|
||||||
k.InsertInactiveProposalQueue(ctx, proposal.ProposalId, proposal.DepositEndTime)
|
k.InsertInactiveProposalQueue(ctx, proposal.ProposalId, *proposal.DepositEndTime)
|
||||||
case v1beta1.StatusVotingPeriod:
|
case v1beta2.StatusVotingPeriod:
|
||||||
k.InsertActiveProposalQueue(ctx, proposal.ProposalId, proposal.VotingEndTime)
|
k.InsertActiveProposalQueue(ctx, proposal.ProposalId, *proposal.VotingEndTime)
|
||||||
}
|
}
|
||||||
k.SetProposal(ctx, proposal)
|
k.SetProposal(ctx, *proposal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if account has zero balance it probably means it's not set, so we set it
|
// if account has zero balance it probably means it's not set, so we set it
|
||||||
|
@ -55,15 +55,15 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportGenesis - output genesis parameters
|
// ExportGenesis - output genesis parameters
|
||||||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *v1beta1.GenesisState {
|
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *v1beta2.GenesisState {
|
||||||
startingProposalID, _ := k.GetProposalID(ctx)
|
startingProposalID, _ := k.GetProposalID(ctx)
|
||||||
depositParams := k.GetDepositParams(ctx)
|
depositParams := k.GetDepositParams(ctx)
|
||||||
votingParams := k.GetVotingParams(ctx)
|
votingParams := k.GetVotingParams(ctx)
|
||||||
tallyParams := k.GetTallyParams(ctx)
|
tallyParams := k.GetTallyParams(ctx)
|
||||||
proposals := k.GetProposals(ctx)
|
proposals := k.GetProposals(ctx)
|
||||||
|
|
||||||
var proposalsDeposits v1beta1.Deposits
|
var proposalsDeposits v1beta2.Deposits
|
||||||
var proposalsVotes v1beta1.Votes
|
var proposalsVotes v1beta2.Votes
|
||||||
for _, proposal := range proposals {
|
for _, proposal := range proposals {
|
||||||
deposits := k.GetDeposits(ctx, proposal.ProposalId)
|
deposits := k.GetDeposits(ctx, proposal.ProposalId)
|
||||||
proposalsDeposits = append(proposalsDeposits, deposits...)
|
proposalsDeposits = append(proposalsDeposits, deposits...)
|
||||||
|
@ -72,13 +72,13 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *v1beta1.GenesisState {
|
||||||
proposalsVotes = append(proposalsVotes, votes...)
|
proposalsVotes = append(proposalsVotes, votes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.GenesisState{
|
return &v1beta2.GenesisState{
|
||||||
StartingProposalId: startingProposalID,
|
StartingProposalId: startingProposalID,
|
||||||
Deposits: proposalsDeposits,
|
Deposits: proposalsDeposits,
|
||||||
Votes: proposalsVotes,
|
Votes: proposalsVotes,
|
||||||
Proposals: proposals,
|
Proposals: proposals,
|
||||||
DepositParams: depositParams,
|
DepositParams: &depositParams,
|
||||||
VotingParams: votingParams,
|
VotingParams: &votingParams,
|
||||||
TallyParams: tallyParams,
|
TallyParams: &tallyParams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
@ -34,14 +34,12 @@ func TestImportExportQueues(t *testing.T) {
|
||||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
||||||
|
|
||||||
ctx = app.BaseApp.NewContext(false, tmproto.Header{})
|
ctx = app.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
|
|
||||||
// Create two proposals, put the second into the voting period
|
// Create two proposals, put the second into the voting period
|
||||||
proposal := TestProposal
|
proposal1, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)})
|
||||||
proposal1, err := app.GovKeeper.SubmitProposal(ctx, proposal)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID1 := proposal1.ProposalId
|
proposalID1 := proposal1.ProposalId
|
||||||
|
|
||||||
proposal2, err := app.GovKeeper.SubmitProposal(ctx, proposal)
|
proposal2, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID2 := proposal2.ProposalId
|
proposalID2 := proposal2.ProposalId
|
||||||
|
|
||||||
|
@ -53,8 +51,8 @@ func TestImportExportQueues(t *testing.T) {
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
proposal2, ok = app.GovKeeper.GetProposal(ctx, proposalID2)
|
proposal2, ok = app.GovKeeper.GetProposal(ctx, proposalID2)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.True(t, proposal1.Status == v1beta1.StatusDepositPeriod)
|
require.True(t, proposal1.Status == v1beta2.StatusDepositPeriod)
|
||||||
require.True(t, proposal2.Status == v1beta1.StatusVotingPeriod)
|
require.True(t, proposal2.Status == v1beta2.StatusVotingPeriod)
|
||||||
|
|
||||||
authGenState := auth.ExportGenesis(ctx, app.AccountKeeper)
|
authGenState := auth.ExportGenesis(ctx, app.AccountKeeper)
|
||||||
bankGenState := app.BankKeeper.ExportGenesis(ctx)
|
bankGenState := app.BankKeeper.ExportGenesis(ctx)
|
||||||
|
@ -96,18 +94,18 @@ func TestImportExportQueues(t *testing.T) {
|
||||||
ctx2 := app2.BaseApp.NewContext(false, tmproto.Header{})
|
ctx2 := app2.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
|
|
||||||
// Jump the time forward past the DepositPeriod and VotingPeriod
|
// Jump the time forward past the DepositPeriod and VotingPeriod
|
||||||
ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(app2.GovKeeper.GetDepositParams(ctx2).MaxDepositPeriod).Add(app2.GovKeeper.GetVotingParams(ctx2).VotingPeriod))
|
ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(*app2.GovKeeper.GetDepositParams(ctx2).MaxDepositPeriod).Add(*app2.GovKeeper.GetVotingParams(ctx2).VotingPeriod))
|
||||||
|
|
||||||
// Make sure that they are still in the DepositPeriod and VotingPeriod respectively
|
// Make sure that they are still in the DepositPeriod and VotingPeriod respectively
|
||||||
proposal1, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1)
|
proposal1, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2)
|
proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.True(t, proposal1.Status == v1beta1.StatusDepositPeriod)
|
require.True(t, proposal1.Status == v1beta2.StatusDepositPeriod)
|
||||||
require.True(t, proposal2.Status == v1beta1.StatusVotingPeriod)
|
require.True(t, proposal2.Status == v1beta2.StatusVotingPeriod)
|
||||||
|
|
||||||
macc := app2.GovKeeper.GetGovernanceAccount(ctx2)
|
macc := app2.GovKeeper.GetGovernanceAccount(ctx2)
|
||||||
require.Equal(t, app2.GovKeeper.GetDepositParams(ctx2).MinDeposit, app2.BankKeeper.GetAllBalances(ctx2, macc.GetAddress()))
|
require.Equal(t, sdk.Coins(app2.GovKeeper.GetDepositParams(ctx2).MinDeposit), app2.BankKeeper.GetAllBalances(ctx2, macc.GetAddress()))
|
||||||
|
|
||||||
// Run the endblocker. Check to make sure that proposal1 is removed from state, and proposal2 is finished VotingPeriod.
|
// Run the endblocker. Check to make sure that proposal1 is removed from state, and proposal2 is finished VotingPeriod.
|
||||||
gov.EndBlocker(ctx2, app2.GovKeeper)
|
gov.EndBlocker(ctx2, app2.GovKeeper)
|
||||||
|
@ -117,15 +115,15 @@ func TestImportExportQueues(t *testing.T) {
|
||||||
|
|
||||||
proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2)
|
proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.True(t, proposal2.Status == v1beta1.StatusRejected)
|
require.True(t, proposal2.Status == v1beta2.StatusRejected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) {
|
func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) {
|
||||||
app := simapp.Setup(t, false)
|
app := simapp.Setup(t, false)
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
require.Panics(t, func() {
|
require.Panics(t, func() {
|
||||||
gov.InitGenesis(ctx, app.AccountKeeper, app.BankKeeper, app.GovKeeper, &v1beta1.GenesisState{
|
gov.InitGenesis(ctx, app.AccountKeeper, app.BankKeeper, app.GovKeeper, &v1beta2.GenesisState{
|
||||||
Deposits: v1beta1.Deposits{
|
Deposits: v1beta2.Deposits{
|
||||||
{
|
{
|
||||||
ProposalId: 1234,
|
ProposalId: 1234,
|
||||||
Depositor: "me",
|
Depositor: "me",
|
||||||
|
@ -140,46 +138,3 @@ func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqualProposals(t *testing.T) {
|
|
||||||
app := simapp.Setup(t, false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
||||||
addrs := simapp.AddTestAddrs(app, ctx, 2, valTokens)
|
|
||||||
|
|
||||||
SortAddresses(addrs)
|
|
||||||
|
|
||||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
|
||||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
|
||||||
|
|
||||||
// Submit two proposals
|
|
||||||
proposal := TestProposal
|
|
||||||
proposal1, err := app.GovKeeper.SubmitProposal(ctx, proposal)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
proposal2, err := app.GovKeeper.SubmitProposal(ctx, proposal)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// They are similar but their IDs should be different
|
|
||||||
require.NotEqual(t, proposal1, proposal2)
|
|
||||||
require.NotEqual(t, proposal1, proposal2)
|
|
||||||
|
|
||||||
// Now create two genesis blocks
|
|
||||||
state1 := v1beta1.GenesisState{Proposals: []v1beta1.Proposal{proposal1}}
|
|
||||||
state2 := v1beta1.GenesisState{Proposals: []v1beta1.Proposal{proposal2}}
|
|
||||||
require.NotEqual(t, state1, state2)
|
|
||||||
require.False(t, state1.Equal(state2))
|
|
||||||
|
|
||||||
// Now make proposals identical by setting both IDs to 55
|
|
||||||
proposal1.ProposalId = 55
|
|
||||||
proposal2.ProposalId = 55
|
|
||||||
require.Equal(t, proposal1, proposal1)
|
|
||||||
require.Equal(t, proposal1, proposal2)
|
|
||||||
|
|
||||||
// Reassign proposals into state
|
|
||||||
state1.Proposals[0] = proposal1
|
|
||||||
state2.Proposals[0] = proposal2
|
|
||||||
|
|
||||||
// State should be identical now..
|
|
||||||
require.Equal(t, state1, state2)
|
|
||||||
require.True(t, state1.Equal(state2))
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,17 +6,36 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TestProposal = v1beta1.NewTextProposal("Test", "description")
|
_, _, addr = testdata.KeyTestPubAddr()
|
||||||
|
govAcct = authtypes.NewModuleAddress(types.ModuleName)
|
||||||
|
TestProposal = getTestProposal()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getTestProposal() []sdk.Msg {
|
||||||
|
legacyProposalMsg, err := v1beta2.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []sdk.Msg{
|
||||||
|
banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000)))),
|
||||||
|
legacyProposalMsg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
||||||
addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000))
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000))
|
||||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetDeposit gets the deposit of a specific depositor on a specific proposal
|
// GetDeposit gets the deposit of a specific depositor on a specific proposal
|
||||||
func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) (deposit v1beta1.Deposit, found bool) {
|
func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) (deposit v1beta2.Deposit, found bool) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
bz := store.Get(types.DepositKey(proposalID, depositorAddr))
|
bz := store.Get(types.DepositKey(proposalID, depositorAddr))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
|
@ -23,7 +23,7 @@ func (keeper Keeper) GetDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeposit sets a Deposit to the gov store
|
// SetDeposit sets a Deposit to the gov store
|
||||||
func (keeper Keeper) SetDeposit(ctx sdk.Context, deposit v1beta1.Deposit) {
|
func (keeper Keeper) SetDeposit(ctx sdk.Context, deposit v1beta2.Deposit) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
bz := keeper.cdc.MustMarshal(&deposit)
|
bz := keeper.cdc.MustMarshal(&deposit)
|
||||||
depositor, err := sdk.AccAddressFromBech32(deposit.Depositor)
|
depositor, err := sdk.AccAddressFromBech32(deposit.Depositor)
|
||||||
|
@ -35,9 +35,9 @@ func (keeper Keeper) SetDeposit(ctx sdk.Context, deposit v1beta1.Deposit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllDeposits returns all the deposits from the store
|
// GetAllDeposits returns all the deposits from the store
|
||||||
func (keeper Keeper) GetAllDeposits(ctx sdk.Context) (deposits v1beta1.Deposits) {
|
func (keeper Keeper) GetAllDeposits(ctx sdk.Context) (deposits v1beta2.Deposits) {
|
||||||
keeper.IterateAllDeposits(ctx, func(deposit v1beta1.Deposit) bool {
|
keeper.IterateAllDeposits(ctx, func(deposit v1beta2.Deposit) bool {
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, &deposit)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ func (keeper Keeper) GetAllDeposits(ctx sdk.Context) (deposits v1beta1.Deposits)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeposits returns all the deposits from a proposal
|
// GetDeposits returns all the deposits from a proposal
|
||||||
func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID uint64) (deposits v1beta1.Deposits) {
|
func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID uint64) (deposits v1beta2.Deposits) {
|
||||||
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta1.Deposit) bool {
|
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta2.Deposit) bool {
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, &deposit)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID uint64) (deposits v
|
||||||
func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) {
|
func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
|
|
||||||
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta1.Deposit) bool {
|
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta2.Deposit) bool {
|
||||||
err := keeper.bankKeeper.BurnCoins(ctx, v1beta1.ModuleName, deposit.Amount)
|
err := keeper.bankKeeper.BurnCoins(ctx, types.ModuleName, deposit.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateAllDeposits iterates over the all the stored deposits and performs a callback function
|
// IterateAllDeposits iterates over the all the stored deposits and performs a callback function
|
||||||
func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1beta1.Deposit) (stop bool)) {
|
func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1beta2.Deposit) (stop bool)) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKeyPrefix)
|
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKeyPrefix)
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var deposit v1beta1.Deposit
|
var deposit v1beta2.Deposit
|
||||||
|
|
||||||
keeper.cdc.MustUnmarshal(iterator.Value(), &deposit)
|
keeper.cdc.MustUnmarshal(iterator.Value(), &deposit)
|
||||||
|
|
||||||
|
@ -92,14 +92,14 @@ func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1beta1
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateDeposits iterates over the all the proposals deposits and performs a callback function
|
// IterateDeposits iterates over the all the proposals deposits and performs a callback function
|
||||||
func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func(deposit v1beta1.Deposit) (stop bool)) {
|
func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func(deposit v1beta2.Deposit) (stop bool)) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKey(proposalID))
|
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKey(proposalID))
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var deposit v1beta1.Deposit
|
var deposit v1beta2.Deposit
|
||||||
|
|
||||||
keeper.cdc.MustUnmarshal(iterator.Value(), &deposit)
|
keeper.cdc.MustUnmarshal(iterator.Value(), &deposit)
|
||||||
|
|
||||||
|
@ -119,24 +119,24 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if proposal is still depositable
|
// Check if proposal is still depositable
|
||||||
if (proposal.Status != v1beta1.StatusDepositPeriod) && (proposal.Status != v1beta1.StatusVotingPeriod) {
|
if (proposal.Status != v1beta2.StatusDepositPeriod) && (proposal.Status != v1beta2.StatusVotingPeriod) {
|
||||||
return false, sdkerrors.Wrapf(types.ErrInactiveProposal, "%d", proposalID)
|
return false, sdkerrors.Wrapf(types.ErrInactiveProposal, "%d", proposalID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the governance module's account coins pool
|
// update the governance module's account coins pool
|
||||||
err := keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, v1beta1.ModuleName, depositAmount)
|
err := keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, types.ModuleName, depositAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update proposal
|
// Update proposal
|
||||||
proposal.TotalDeposit = proposal.TotalDeposit.Add(depositAmount...)
|
proposal.TotalDeposit = sdk.NewCoins(proposal.TotalDeposit...).Add(depositAmount...)
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
// Check if deposit has provided sufficient total funds to transition the proposal into the voting period
|
// Check if deposit has provided sufficient total funds to transition the proposal into the voting period
|
||||||
activatedVotingPeriod := false
|
activatedVotingPeriod := false
|
||||||
|
|
||||||
if proposal.Status == v1beta1.StatusDepositPeriod && proposal.TotalDeposit.IsAllGTE(keeper.GetDepositParams(ctx).MinDeposit) {
|
if proposal.Status == v1beta2.StatusDepositPeriod && sdk.NewCoins(proposal.TotalDeposit...).IsAllGTE(keeper.GetDepositParams(ctx).MinDeposit) {
|
||||||
keeper.ActivateVotingPeriod(ctx, proposal)
|
keeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
|
|
||||||
activatedVotingPeriod = true
|
activatedVotingPeriod = true
|
||||||
|
@ -146,9 +146,9 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
|
||||||
deposit, found := keeper.GetDeposit(ctx, proposalID, depositorAddr)
|
deposit, found := keeper.GetDeposit(ctx, proposalID, depositorAddr)
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
deposit.Amount = deposit.Amount.Add(depositAmount...)
|
deposit.Amount = sdk.NewCoins(deposit.Amount...).Add(depositAmount...)
|
||||||
} else {
|
} else {
|
||||||
deposit = v1beta1.NewDeposit(proposalID, depositorAddr, depositAmount)
|
deposit = v1beta2.NewDeposit(proposalID, depositorAddr, depositAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when deposit has been added to a proposal, however the proposal may not be active
|
// called when deposit has been added to a proposal, however the proposal may not be active
|
||||||
|
@ -171,13 +171,13 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
|
||||||
func (keeper Keeper) RefundAndDeleteDeposits(ctx sdk.Context, proposalID uint64) {
|
func (keeper Keeper) RefundAndDeleteDeposits(ctx sdk.Context, proposalID uint64) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
|
|
||||||
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta1.Deposit) bool {
|
keeper.IterateDeposits(ctx, proposalID, func(deposit v1beta2.Deposit) bool {
|
||||||
depositor, err := sdk.AccAddressFromBech32(deposit.Depositor)
|
depositor, err := sdk.AccAddressFromBech32(deposit.Depositor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = keeper.bankKeeper.SendCoinsFromModuleToAccount(ctx, v1beta1.ModuleName, depositor, deposit.Amount)
|
err = keeper.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, depositor, deposit.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
|
@ -28,14 +27,14 @@ func TestDeposits(t *testing.T) {
|
||||||
addr0Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])
|
addr0Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])
|
||||||
addr1Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])
|
addr1Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])
|
||||||
|
|
||||||
require.True(t, proposal.TotalDeposit.IsEqual(sdk.NewCoins()))
|
require.True(t, sdk.NewCoins(proposal.TotalDeposit...).IsEqual(sdk.NewCoins()))
|
||||||
|
|
||||||
// Check no deposits at beginning
|
// Check no deposits at beginning
|
||||||
deposit, found := app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
deposit, found := app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
||||||
require.False(t, found)
|
require.False(t, found)
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.True(t, proposal.VotingStartTime.Equal(time.Time{}))
|
require.Nil(t, proposal.VotingStartTime)
|
||||||
|
|
||||||
// Check first deposit
|
// Check first deposit
|
||||||
votingStarted, err := app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake)
|
votingStarted, err := app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake)
|
||||||
|
@ -43,11 +42,11 @@ func TestDeposits(t *testing.T) {
|
||||||
require.False(t, votingStarted)
|
require.False(t, votingStarted)
|
||||||
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0])
|
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, fourStake, deposit.Amount)
|
require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...))
|
||||||
require.Equal(t, TestAddrs[0].String(), deposit.Depositor)
|
require.Equal(t, TestAddrs[0].String(), deposit.Depositor)
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake, proposal.TotalDeposit)
|
require.Equal(t, fourStake, sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
||||||
|
|
||||||
// Check a second deposit from same address
|
// Check a second deposit from same address
|
||||||
|
@ -56,11 +55,11 @@ func TestDeposits(t *testing.T) {
|
||||||
require.False(t, votingStarted)
|
require.False(t, votingStarted)
|
||||||
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0])
|
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...), deposit.Amount)
|
require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(deposit.Amount...))
|
||||||
require.Equal(t, TestAddrs[0].String(), deposit.Depositor)
|
require.Equal(t, TestAddrs[0].String(), deposit.Depositor)
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...), proposal.TotalDeposit)
|
require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr0Initial.Sub(fourStake).Sub(fiveStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
require.Equal(t, addr0Initial.Sub(fourStake).Sub(fiveStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
||||||
|
|
||||||
// Check third deposit from a new address
|
// Check third deposit from a new address
|
||||||
|
@ -70,10 +69,10 @@ func TestDeposits(t *testing.T) {
|
||||||
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, TestAddrs[1].String(), deposit.Depositor)
|
require.Equal(t, TestAddrs[1].String(), deposit.Depositor)
|
||||||
require.Equal(t, fourStake, deposit.Amount)
|
require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...))
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), proposal.TotalDeposit)
|
require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr1Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]))
|
require.Equal(t, addr1Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]))
|
||||||
|
|
||||||
// Check that proposal moved to voting period
|
// Check that proposal moved to voting period
|
||||||
|
@ -87,14 +86,14 @@ func TestDeposits(t *testing.T) {
|
||||||
require.Len(t, deposits, 2)
|
require.Len(t, deposits, 2)
|
||||||
require.Equal(t, deposits, app.GovKeeper.GetDeposits(ctx, proposalID))
|
require.Equal(t, deposits, app.GovKeeper.GetDeposits(ctx, proposalID))
|
||||||
require.Equal(t, TestAddrs[0].String(), deposits[0].Depositor)
|
require.Equal(t, TestAddrs[0].String(), deposits[0].Depositor)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...), deposits[0].Amount)
|
require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(deposits[0].Amount...))
|
||||||
require.Equal(t, TestAddrs[1].String(), deposits[1].Depositor)
|
require.Equal(t, TestAddrs[1].String(), deposits[1].Depositor)
|
||||||
require.Equal(t, fourStake, deposits[1].Amount)
|
require.Equal(t, fourStake, sdk.NewCoins(deposits[1].Amount...))
|
||||||
|
|
||||||
// Test Refund Deposits
|
// Test Refund Deposits
|
||||||
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, fourStake, deposit.Amount)
|
require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...))
|
||||||
app.GovKeeper.RefundAndDeleteDeposits(ctx, proposalID)
|
app.GovKeeper.RefundAndDeleteDeposits(ctx, proposalID)
|
||||||
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
|
||||||
require.False(t, found)
|
require.False(t, found)
|
||||||
|
|
|
@ -10,13 +10,13 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ v1beta1.QueryServer = Keeper{}
|
var _ v1beta2.QueryServer = Keeper{}
|
||||||
|
|
||||||
// Proposal returns proposal details based on ProposalID
|
// Proposal returns proposal details based on ProposalID
|
||||||
func (q Keeper) Proposal(c context.Context, req *v1beta1.QueryProposalRequest) (*v1beta1.QueryProposalResponse, error) {
|
func (q Keeper) Proposal(c context.Context, req *v1beta2.QueryProposalRequest) (*v1beta2.QueryProposalResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,19 @@ func (q Keeper) Proposal(c context.Context, req *v1beta1.QueryProposalRequest) (
|
||||||
return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", req.ProposalId)
|
return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", req.ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryProposalResponse{Proposal: proposal}, nil
|
return &v1beta2.QueryProposalResponse{Proposal: &proposal}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proposals implements the Query/Proposals gRPC method
|
// Proposals implements the Query/Proposals gRPC method
|
||||||
func (q Keeper) Proposals(c context.Context, req *v1beta1.QueryProposalsRequest) (*v1beta1.QueryProposalsResponse, error) {
|
func (q Keeper) Proposals(c context.Context, req *v1beta2.QueryProposalsRequest) (*v1beta2.QueryProposalsResponse, error) {
|
||||||
var filteredProposals v1beta1.Proposals
|
var filteredProposals []*v1beta2.Proposal
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
store := ctx.KVStore(q.storeKey)
|
store := ctx.KVStore(q.storeKey)
|
||||||
proposalStore := prefix.NewStore(store, types.ProposalsKeyPrefix)
|
proposalStore := prefix.NewStore(store, types.ProposalsKeyPrefix)
|
||||||
|
|
||||||
pageRes, err := query.FilteredPaginate(proposalStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
|
pageRes, err := query.FilteredPaginate(proposalStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
|
||||||
var p v1beta1.Proposal
|
var p v1beta2.Proposal
|
||||||
if err := q.cdc.Unmarshal(value, &p); err != nil {
|
if err := q.cdc.Unmarshal(value, &p); err != nil {
|
||||||
return false, status.Error(codes.Internal, err.Error())
|
return false, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func (q Keeper) Proposals(c context.Context, req *v1beta1.QueryProposalsRequest)
|
||||||
matchVoter, matchDepositor, matchStatus := true, true, true
|
matchVoter, matchDepositor, matchStatus := true, true, true
|
||||||
|
|
||||||
// match status (if supplied/valid)
|
// match status (if supplied/valid)
|
||||||
if v1beta1.ValidProposalStatus(req.ProposalStatus) {
|
if v1beta2.ValidProposalStatus(req.ProposalStatus) {
|
||||||
matchStatus = p.Status == req.ProposalStatus
|
matchStatus = p.Status == req.ProposalStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (q Keeper) Proposals(c context.Context, req *v1beta1.QueryProposalsRequest)
|
||||||
|
|
||||||
if matchVoter && matchDepositor && matchStatus {
|
if matchVoter && matchDepositor && matchStatus {
|
||||||
if accumulate {
|
if accumulate {
|
||||||
filteredProposals = append(filteredProposals, p)
|
filteredProposals = append(filteredProposals, &p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -90,11 +90,11 @@ func (q Keeper) Proposals(c context.Context, req *v1beta1.QueryProposalsRequest)
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryProposalsResponse{Proposals: filteredProposals, Pagination: pageRes}, nil
|
return &v1beta2.QueryProposalsResponse{Proposals: filteredProposals, Pagination: pageRes}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vote returns Voted information based on proposalID, voterAddr
|
// Vote returns Voted information based on proposalID, voterAddr
|
||||||
func (q Keeper) Vote(c context.Context, req *v1beta1.QueryVoteRequest) (*v1beta1.QueryVoteResponse, error) {
|
func (q Keeper) Vote(c context.Context, req *v1beta2.QueryVoteRequest) (*v1beta2.QueryVoteResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,11 @@ func (q Keeper) Vote(c context.Context, req *v1beta1.QueryVoteRequest) (*v1beta1
|
||||||
"voter: %v not found for proposal: %v", req.Voter, req.ProposalId)
|
"voter: %v not found for proposal: %v", req.Voter, req.ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryVoteResponse{Vote: vote}, nil
|
return &v1beta2.QueryVoteResponse{Vote: &vote}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Votes returns single proposal's votes
|
// Votes returns single proposal's votes
|
||||||
func (q Keeper) Votes(c context.Context, req *v1beta1.QueryVotesRequest) (*v1beta1.QueryVotesResponse, error) {
|
func (q Keeper) Votes(c context.Context, req *v1beta2.QueryVotesRequest) (*v1beta2.QueryVotesResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -132,20 +132,20 @@ func (q Keeper) Votes(c context.Context, req *v1beta1.QueryVotesRequest) (*v1bet
|
||||||
return nil, status.Error(codes.InvalidArgument, "proposal id can not be 0")
|
return nil, status.Error(codes.InvalidArgument, "proposal id can not be 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
var votes v1beta1.Votes
|
var votes v1beta2.Votes
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
store := ctx.KVStore(q.storeKey)
|
store := ctx.KVStore(q.storeKey)
|
||||||
votesStore := prefix.NewStore(store, types.VotesKey(req.ProposalId))
|
votesStore := prefix.NewStore(store, types.VotesKey(req.ProposalId))
|
||||||
|
|
||||||
pageRes, err := query.Paginate(votesStore, req.Pagination, func(key []byte, value []byte) error {
|
pageRes, err := query.Paginate(votesStore, req.Pagination, func(key []byte, value []byte) error {
|
||||||
var vote v1beta1.Vote
|
var vote v1beta2.Vote
|
||||||
if err := q.cdc.Unmarshal(value, &vote); err != nil {
|
if err := q.cdc.Unmarshal(value, &vote); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
populateLegacyOption(&vote)
|
populateLegacyOption(&vote)
|
||||||
|
|
||||||
votes = append(votes, vote)
|
votes = append(votes, &vote)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -153,11 +153,11 @@ func (q Keeper) Votes(c context.Context, req *v1beta1.QueryVotesRequest) (*v1bet
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryVotesResponse{Votes: votes, Pagination: pageRes}, nil
|
return &v1beta2.QueryVotesResponse{Votes: votes, Pagination: pageRes}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params queries all params
|
// Params queries all params
|
||||||
func (q Keeper) Params(c context.Context, req *v1beta1.QueryParamsRequest) (*v1beta1.QueryParamsResponse, error) {
|
func (q Keeper) Params(c context.Context, req *v1beta2.QueryParamsRequest) (*v1beta2.QueryParamsResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -165,17 +165,17 @@ func (q Keeper) Params(c context.Context, req *v1beta1.QueryParamsRequest) (*v1b
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
switch req.ParamsType {
|
switch req.ParamsType {
|
||||||
case v1beta1.ParamDeposit:
|
case v1beta2.ParamDeposit:
|
||||||
depositParmas := q.GetDepositParams(ctx)
|
depositParmas := q.GetDepositParams(ctx)
|
||||||
return &v1beta1.QueryParamsResponse{DepositParams: depositParmas}, nil
|
return &v1beta2.QueryParamsResponse{DepositParams: &depositParmas}, nil
|
||||||
|
|
||||||
case v1beta1.ParamVoting:
|
case v1beta2.ParamVoting:
|
||||||
votingParmas := q.GetVotingParams(ctx)
|
votingParmas := q.GetVotingParams(ctx)
|
||||||
return &v1beta1.QueryParamsResponse{VotingParams: votingParmas}, nil
|
return &v1beta2.QueryParamsResponse{VotingParams: &votingParmas}, nil
|
||||||
|
|
||||||
case v1beta1.ParamTallying:
|
case v1beta2.ParamTallying:
|
||||||
tallyParams := q.GetTallyParams(ctx)
|
tallyParams := q.GetTallyParams(ctx)
|
||||||
return &v1beta1.QueryParamsResponse{TallyParams: tallyParams}, nil
|
return &v1beta2.QueryParamsResponse{TallyParams: &tallyParams}, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, status.Errorf(codes.InvalidArgument,
|
return nil, status.Errorf(codes.InvalidArgument,
|
||||||
|
@ -184,7 +184,7 @@ func (q Keeper) Params(c context.Context, req *v1beta1.QueryParamsRequest) (*v1b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposit queries single deposit information based proposalID, depositAddr
|
// Deposit queries single deposit information based proposalID, depositAddr
|
||||||
func (q Keeper) Deposit(c context.Context, req *v1beta1.QueryDepositRequest) (*v1beta1.QueryDepositResponse, error) {
|
func (q Keeper) Deposit(c context.Context, req *v1beta2.QueryDepositRequest) (*v1beta2.QueryDepositResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -209,11 +209,11 @@ func (q Keeper) Deposit(c context.Context, req *v1beta1.QueryDepositRequest) (*v
|
||||||
"depositer: %v not found for proposal: %v", req.Depositor, req.ProposalId)
|
"depositer: %v not found for proposal: %v", req.Depositor, req.ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryDepositResponse{Deposit: deposit}, nil
|
return &v1beta2.QueryDepositResponse{Deposit: &deposit}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposits returns single proposal's all deposits
|
// Deposits returns single proposal's all deposits
|
||||||
func (q Keeper) Deposits(c context.Context, req *v1beta1.QueryDepositsRequest) (*v1beta1.QueryDepositsResponse, error) {
|
func (q Keeper) Deposits(c context.Context, req *v1beta2.QueryDepositsRequest) (*v1beta2.QueryDepositsResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -222,19 +222,19 @@ func (q Keeper) Deposits(c context.Context, req *v1beta1.QueryDepositsRequest) (
|
||||||
return nil, status.Error(codes.InvalidArgument, "proposal id can not be 0")
|
return nil, status.Error(codes.InvalidArgument, "proposal id can not be 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
var deposits v1beta1.Deposits
|
var deposits []*v1beta2.Deposit
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
store := ctx.KVStore(q.storeKey)
|
store := ctx.KVStore(q.storeKey)
|
||||||
depositStore := prefix.NewStore(store, types.DepositsKey(req.ProposalId))
|
depositStore := prefix.NewStore(store, types.DepositsKey(req.ProposalId))
|
||||||
|
|
||||||
pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error {
|
pageRes, err := query.Paginate(depositStore, req.Pagination, func(key []byte, value []byte) error {
|
||||||
var deposit v1beta1.Deposit
|
var deposit v1beta2.Deposit
|
||||||
if err := q.cdc.Unmarshal(value, &deposit); err != nil {
|
if err := q.cdc.Unmarshal(value, &deposit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, &deposit)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -242,11 +242,11 @@ func (q Keeper) Deposits(c context.Context, req *v1beta1.QueryDepositsRequest) (
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil
|
return &v1beta2.QueryDepositsResponse{Deposits: deposits, Pagination: pageRes}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TallyResult queries the tally of a proposal vote
|
// TallyResult queries the tally of a proposal vote
|
||||||
func (q Keeper) TallyResult(c context.Context, req *v1beta1.QueryTallyResultRequest) (*v1beta1.QueryTallyResultResponse, error) {
|
func (q Keeper) TallyResult(c context.Context, req *v1beta2.QueryTallyResultRequest) (*v1beta2.QueryTallyResultResponse, error) {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||||
}
|
}
|
||||||
|
@ -262,19 +262,19 @@ func (q Keeper) TallyResult(c context.Context, req *v1beta1.QueryTallyResultRequ
|
||||||
return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", req.ProposalId)
|
return nil, status.Errorf(codes.NotFound, "proposal %d doesn't exist", req.ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tallyResult v1beta1.TallyResult
|
var tallyResult v1beta2.TallyResult
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case proposal.Status == v1beta1.StatusDepositPeriod:
|
case proposal.Status == v1beta2.StatusDepositPeriod:
|
||||||
tallyResult = v1beta1.EmptyTallyResult()
|
tallyResult = v1beta2.EmptyTallyResult()
|
||||||
|
|
||||||
case proposal.Status == v1beta1.StatusPassed || proposal.Status == v1beta1.StatusRejected:
|
case proposal.Status == v1beta2.StatusPassed || proposal.Status == v1beta2.StatusRejected:
|
||||||
tallyResult = proposal.FinalTallyResult
|
tallyResult = *proposal.FinalTallyResult
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// proposal is in voting period
|
// proposal is in voting period
|
||||||
_, _, tallyResult = q.Tally(ctx, proposal)
|
_, _, tallyResult = q.Tally(ctx, proposal)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1beta1.QueryTallyResultResponse{Tally: tallyResult}, nil
|
return &v1beta2.QueryTallyResultResponse{Tally: &tallyResult}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package keeper_test
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
|
func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
|
||||||
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
|
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryProposalRequest
|
req *v1beta2.QueryProposalRequest
|
||||||
expProposal v1beta1.Proposal
|
expProposal v1beta2.Proposal
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -27,30 +27,32 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalRequest{}
|
req = &v1beta2.QueryProposalRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non existing proposal request",
|
"non existing proposal request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalRequest{ProposalId: 3}
|
req = &v1beta2.QueryProposalRequest{ProposalId: 3}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalRequest{ProposalId: 0}
|
req = &v1beta2.QueryProposalRequest{ProposalId: 0}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request",
|
"valid request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalRequest{ProposalId: 1}
|
req = &v1beta2.QueryProposalRequest{ProposalId: 1}
|
||||||
testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal")
|
testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal")
|
||||||
submittedProposal, err := app.GovKeeper.SubmitProposal(ctx, testProposal)
|
msgContent, err := v1beta2.NewLegacyContent(testProposal, govAcct.String())
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
submittedProposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().NotEmpty(submittedProposal)
|
suite.Require().NotEmpty(submittedProposal)
|
||||||
|
|
||||||
|
@ -68,7 +70,13 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
|
||||||
|
|
||||||
if testCase.expPass {
|
if testCase.expPass {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(expProposal.String(), proposalRes.Proposal.String())
|
// Instead of using MashalJSON, we could compare .String() output too.
|
||||||
|
// https://github.com/cosmos/cosmos-sdk/issues/10965
|
||||||
|
expJSON, err := suite.app.AppCodec().MarshalJSON(&expProposal)
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
actualJSON, err := suite.app.AppCodec().MarshalJSON(proposalRes.Proposal)
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
suite.Require().Equal(expJSON, actualJSON)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
suite.Require().Nil(proposalRes)
|
suite.Require().Nil(proposalRes)
|
||||||
|
@ -80,11 +88,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
|
||||||
func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
||||||
|
|
||||||
testProposals := []v1beta1.Proposal{}
|
testProposals := []*v1beta2.Proposal{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryProposalsRequest
|
req *v1beta2.QueryProposalsRequest
|
||||||
expRes *v1beta1.QueryProposalsResponse
|
expRes *v1beta2.QueryProposalsResponse
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -95,7 +103,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
{
|
{
|
||||||
"empty state request",
|
"empty state request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalsRequest{}
|
req = &v1beta2.QueryProposalsRequest{}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
@ -104,19 +112,21 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
func() {
|
func() {
|
||||||
// create 5 test proposals
|
// create 5 test proposals
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
num := strconv.Itoa(i + 1)
|
govAddress := app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||||
testProposal := v1beta1.NewTextProposal("Proposal"+num, "testing proposal "+num)
|
testProposal := []sdk.Msg{
|
||||||
|
v1beta2.NewMsgVote(govAddress, uint64(i), v1beta2.OptionYes),
|
||||||
|
}
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, testProposal)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, testProposal)
|
||||||
suite.Require().NotEmpty(proposal)
|
suite.Require().NotEmpty(proposal)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
testProposals = append(testProposals, proposal)
|
testProposals = append(testProposals, &proposal)
|
||||||
}
|
}
|
||||||
|
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
Pagination: &query.PageRequest{Limit: 3},
|
Pagination: &query.PageRequest{Limit: 3},
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals[:3],
|
Proposals: testProposals[:3],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -125,11 +135,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
{
|
{
|
||||||
"request 2nd page with limit 4",
|
"request 2nd page with limit 4",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
Pagination: &query.PageRequest{Offset: 3, Limit: 3},
|
Pagination: &query.PageRequest{Offset: 3, Limit: 3},
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals[3:],
|
Proposals: testProposals[3:],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -138,11 +148,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
{
|
{
|
||||||
"request with limit 2 and count true",
|
"request with limit 2 and count true",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
Pagination: &query.PageRequest{Limit: 2, CountTotal: true},
|
Pagination: &query.PageRequest{Limit: 2, CountTotal: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals[:2],
|
Proposals: testProposals[:2],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -151,11 +161,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
{
|
{
|
||||||
"request with filter of status deposit period",
|
"request with filter of status deposit period",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
ProposalStatus: v1beta1.StatusDepositPeriod,
|
ProposalStatus: v1beta2.StatusDepositPeriod,
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals,
|
Proposals: testProposals,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -165,14 +175,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
"request with filter of deposit address",
|
"request with filter of deposit address",
|
||||||
func() {
|
func() {
|
||||||
depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
||||||
deposit := v1beta1.NewDeposit(testProposals[0].ProposalId, addrs[0], depositCoins)
|
deposit := v1beta2.NewDeposit(testProposals[0].ProposalId, addrs[0], depositCoins)
|
||||||
app.GovKeeper.SetDeposit(ctx, deposit)
|
app.GovKeeper.SetDeposit(ctx, deposit)
|
||||||
|
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
Depositor: addrs[0].String(),
|
Depositor: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals[:1],
|
Proposals: testProposals[:1],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -181,15 +191,15 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
{
|
{
|
||||||
"request with filter of deposit address",
|
"request with filter of deposit address",
|
||||||
func() {
|
func() {
|
||||||
testProposals[1].Status = v1beta1.StatusVotingPeriod
|
testProposals[1].Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, testProposals[1])
|
app.GovKeeper.SetProposal(ctx, *testProposals[1])
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, testProposals[1].ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, testProposals[1].ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)))
|
||||||
|
|
||||||
req = &v1beta1.QueryProposalsRequest{
|
req = &v1beta2.QueryProposalsRequest{
|
||||||
Voter: addrs[0].String(),
|
Voter: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryProposalsResponse{
|
expRes = &v1beta2.QueryProposalsResponse{
|
||||||
Proposals: testProposals[1:2],
|
Proposals: testProposals[1:2],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -208,7 +218,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() {
|
||||||
|
|
||||||
suite.Require().Len(proposals.GetProposals(), len(expRes.GetProposals()))
|
suite.Require().Len(proposals.GetProposals(), len(expRes.GetProposals()))
|
||||||
for i := 0; i < len(proposals.GetProposals()); i++ {
|
for i := 0; i < len(proposals.GetProposals()); i++ {
|
||||||
suite.Require().Equal(proposals.GetProposals()[i].String(), expRes.GetProposals()[i].String())
|
// Instead of using MashalJSON, we could compare .String() output too.
|
||||||
|
// https://github.com/cosmos/cosmos-sdk/issues/10965
|
||||||
|
expJSON, err := suite.app.AppCodec().MarshalJSON(expRes.GetProposals()[i])
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
actualJSON, err := suite.app.AppCodec().MarshalJSON(proposals.GetProposals()[i])
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
|
suite.Require().Equal(expJSON, actualJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,9 +240,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
|
||||||
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryVoteRequest
|
req *v1beta2.QueryVoteRequest
|
||||||
expRes *v1beta1.QueryVoteResponse
|
expRes *v1beta2.QueryVoteResponse
|
||||||
proposal v1beta1.Proposal
|
proposal v1beta2.Proposal
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -236,14 +253,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVoteRequest{}
|
req = &v1beta2.QueryVoteRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: 0,
|
ProposalId: 0,
|
||||||
Voter: addrs[0].String(),
|
Voter: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
@ -253,7 +270,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
|
||||||
{
|
{
|
||||||
"empty voter request",
|
"empty voter request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: 1,
|
ProposalId: 1,
|
||||||
Voter: "",
|
Voter: "",
|
||||||
}
|
}
|
||||||
|
@ -263,7 +280,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
|
||||||
{
|
{
|
||||||
"non existed proposal",
|
"non existed proposal",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: 3,
|
ProposalId: 3,
|
||||||
Voter: addrs[0].String(),
|
Voter: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
@ -277,40 +294,40 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
|
||||||
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Voter: addrs[0].String(),
|
Voter: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryVoteResponse{}
|
expRes = &v1beta2.QueryVoteResponse{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request",
|
"valid request",
|
||||||
func() {
|
func() {
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)))
|
||||||
|
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Voter: addrs[0].String(),
|
Voter: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryVoteResponse{Vote: v1beta1.Vote{ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Option: v1beta1.OptionAbstain, Options: []v1beta1.WeightedVoteOption{{Option: v1beta1.OptionAbstain, Weight: sdk.MustNewDecFromStr("1.0")}}}}
|
expRes = &v1beta2.QueryVoteResponse{Vote: &v1beta2.Vote{ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Option: v1beta2.OptionAbstain, Options: []*v1beta2.WeightedVoteOption{{Option: v1beta2.OptionAbstain, Weight: sdk.MustNewDecFromStr("1.0").String()}}}}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wrong voter id request",
|
"wrong voter id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVoteRequest{
|
req = &v1beta2.QueryVoteRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Voter: addrs[1].String(),
|
Voter: addrs[1].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryVoteResponse{}
|
expRes = &v1beta2.QueryVoteResponse{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -339,10 +356,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
addrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000))
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000))
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryVotesRequest
|
req *v1beta2.QueryVotesRequest
|
||||||
expRes *v1beta1.QueryVotesResponse
|
expRes *v1beta2.QueryVotesResponse
|
||||||
proposal v1beta1.Proposal
|
proposal v1beta2.Proposal
|
||||||
votes v1beta1.Votes
|
votes v1beta2.Votes
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -353,14 +370,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVotesRequest{}
|
req = &v1beta2.QueryVotesRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVotesRequest{
|
req = &v1beta2.QueryVotesRequest{
|
||||||
ProposalId: 0,
|
ProposalId: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -369,7 +386,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
{
|
{
|
||||||
"non existed proposals",
|
"non existed proposals",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryVotesRequest{
|
req = &v1beta2.QueryVotesRequest{
|
||||||
ProposalId: 2,
|
ProposalId: 2,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -382,7 +399,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
req = &v1beta1.QueryVotesRequest{
|
req = &v1beta2.QueryVotesRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -391,12 +408,12 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
{
|
{
|
||||||
"request after adding 2 votes",
|
"request after adding 2 votes",
|
||||||
func() {
|
func() {
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
votes = []v1beta1.Vote{
|
votes = []*v1beta2.Vote{
|
||||||
{ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Option: v1beta1.OptionAbstain, Options: v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)},
|
{ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Option: v1beta2.OptionAbstain, Options: v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)},
|
||||||
{ProposalId: proposal.ProposalId, Voter: addrs[1].String(), Option: v1beta1.OptionYes, Options: v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)},
|
{ProposalId: proposal.ProposalId, Voter: addrs[1].String(), Option: v1beta2.OptionYes, Options: v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)},
|
||||||
}
|
}
|
||||||
accAddr1, err1 := sdk.AccAddressFromBech32(votes[0].Voter)
|
accAddr1, err1 := sdk.AccAddressFromBech32(votes[0].Voter)
|
||||||
accAddr2, err2 := sdk.AccAddressFromBech32(votes[1].Voter)
|
accAddr2, err2 := sdk.AccAddressFromBech32(votes[1].Voter)
|
||||||
|
@ -405,11 +422,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, accAddr1, votes[0].Options))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, accAddr1, votes[0].Options))
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, accAddr2, votes[1].Options))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, accAddr2, votes[1].Options))
|
||||||
|
|
||||||
req = &v1beta1.QueryVotesRequest{
|
req = &v1beta2.QueryVotesRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryVotesResponse{
|
expRes = &v1beta2.QueryVotesResponse{
|
||||||
Votes: votes,
|
Votes: votes,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -438,8 +455,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
|
||||||
queryClient := suite.queryClient
|
queryClient := suite.queryClient
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryParamsRequest
|
req *v1beta2.QueryParamsRequest
|
||||||
expRes *v1beta1.QueryParamsResponse
|
expRes *v1beta2.QueryParamsResponse
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -450,17 +467,17 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryParamsRequest{}
|
req = &v1beta2.QueryParamsRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"deposit params request",
|
"deposit params request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryParamsRequest{ParamsType: v1beta1.ParamDeposit}
|
req = &v1beta2.QueryParamsRequest{ParamsType: v1beta2.ParamDeposit}
|
||||||
expRes = &v1beta1.QueryParamsResponse{
|
depositParams := v1beta2.DefaultDepositParams()
|
||||||
DepositParams: v1beta1.DefaultDepositParams(),
|
expRes = &v1beta2.QueryParamsResponse{
|
||||||
TallyParams: v1beta1.NewTallyParams(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)),
|
DepositParams: &depositParams,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
@ -468,10 +485,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
|
||||||
{
|
{
|
||||||
"voting params request",
|
"voting params request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryParamsRequest{ParamsType: v1beta1.ParamVoting}
|
req = &v1beta2.QueryParamsRequest{ParamsType: v1beta2.ParamVoting}
|
||||||
expRes = &v1beta1.QueryParamsResponse{
|
votingParams := v1beta2.DefaultVotingParams()
|
||||||
VotingParams: v1beta1.DefaultVotingParams(),
|
expRes = &v1beta2.QueryParamsResponse{
|
||||||
TallyParams: v1beta1.NewTallyParams(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)),
|
VotingParams: &votingParams,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
@ -479,9 +496,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
|
||||||
{
|
{
|
||||||
"tally params request",
|
"tally params request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryParamsRequest{ParamsType: v1beta1.ParamTallying}
|
req = &v1beta2.QueryParamsRequest{ParamsType: v1beta2.ParamTallying}
|
||||||
expRes = &v1beta1.QueryParamsResponse{
|
tallyParams := v1beta2.DefaultTallyParams()
|
||||||
TallyParams: v1beta1.DefaultTallyParams(),
|
expRes = &v1beta2.QueryParamsResponse{
|
||||||
|
TallyParams: &tallyParams,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
@ -489,8 +507,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() {
|
||||||
{
|
{
|
||||||
"invalid request",
|
"invalid request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryParamsRequest{ParamsType: "wrongPath"}
|
req = &v1beta2.QueryParamsRequest{ParamsType: "wrongPath"}
|
||||||
expRes = &v1beta1.QueryParamsResponse{}
|
expRes = &v1beta2.QueryParamsResponse{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -519,9 +537,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryDepositRequest
|
req *v1beta2.QueryDepositRequest
|
||||||
expRes *v1beta1.QueryDepositResponse
|
expRes *v1beta2.QueryDepositResponse
|
||||||
proposal v1beta1.Proposal
|
proposal v1beta2.Proposal
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -532,14 +550,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositRequest{}
|
req = &v1beta2.QueryDepositRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositRequest{
|
req = &v1beta2.QueryDepositRequest{
|
||||||
ProposalId: 0,
|
ProposalId: 0,
|
||||||
Depositor: addrs[0].String(),
|
Depositor: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
@ -549,7 +567,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
{
|
{
|
||||||
"empty deposit address request",
|
"empty deposit address request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositRequest{
|
req = &v1beta2.QueryDepositRequest{
|
||||||
ProposalId: 1,
|
ProposalId: 1,
|
||||||
Depositor: "",
|
Depositor: "",
|
||||||
}
|
}
|
||||||
|
@ -559,7 +577,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
{
|
{
|
||||||
"non existed proposal",
|
"non existed proposal",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositRequest{
|
req = &v1beta2.QueryDepositRequest{
|
||||||
ProposalId: 2,
|
ProposalId: 2,
|
||||||
Depositor: addrs[0].String(),
|
Depositor: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
@ -574,7 +592,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().NotNil(proposal)
|
suite.Require().NotNil(proposal)
|
||||||
|
|
||||||
req = &v1beta1.QueryDepositRequest{
|
req = &v1beta2.QueryDepositRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Depositor: addrs[0].String(),
|
Depositor: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
@ -585,15 +603,15 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
|
||||||
"valid request",
|
"valid request",
|
||||||
func() {
|
func() {
|
||||||
depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
||||||
deposit := v1beta1.NewDeposit(proposal.ProposalId, addrs[0], depositCoins)
|
deposit := v1beta2.NewDeposit(proposal.ProposalId, addrs[0], depositCoins)
|
||||||
app.GovKeeper.SetDeposit(ctx, deposit)
|
app.GovKeeper.SetDeposit(ctx, deposit)
|
||||||
|
|
||||||
req = &v1beta1.QueryDepositRequest{
|
req = &v1beta2.QueryDepositRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Depositor: addrs[0].String(),
|
Depositor: addrs[0].String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryDepositResponse{Deposit: deposit}
|
expRes = &v1beta2.QueryDepositResponse{Deposit: &deposit}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
@ -620,9 +638,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
|
||||||
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryDepositsRequest
|
req *v1beta2.QueryDepositsRequest
|
||||||
expRes *v1beta1.QueryDepositsResponse
|
expRes *v1beta2.QueryDepositsResponse
|
||||||
proposal v1beta1.Proposal
|
proposal v1beta2.Proposal
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -633,14 +651,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositsRequest{}
|
req = &v1beta2.QueryDepositsRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositsRequest{
|
req = &v1beta2.QueryDepositsRequest{
|
||||||
ProposalId: 0,
|
ProposalId: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -649,7 +667,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
|
||||||
{
|
{
|
||||||
"non existed proposal",
|
"non existed proposal",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryDepositsRequest{
|
req = &v1beta2.QueryDepositsRequest{
|
||||||
ProposalId: 2,
|
ProposalId: 2,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -662,7 +680,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
|
||||||
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
req = &v1beta1.QueryDepositsRequest{
|
req = &v1beta2.QueryDepositsRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -672,20 +690,20 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
|
||||||
"get deposits with default limit",
|
"get deposits with default limit",
|
||||||
func() {
|
func() {
|
||||||
depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20)))
|
||||||
deposit1 := v1beta1.NewDeposit(proposal.ProposalId, addrs[0], depositAmount1)
|
deposit1 := v1beta2.NewDeposit(proposal.ProposalId, addrs[0], depositAmount1)
|
||||||
app.GovKeeper.SetDeposit(ctx, deposit1)
|
app.GovKeeper.SetDeposit(ctx, deposit1)
|
||||||
|
|
||||||
depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 30)))
|
depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 30)))
|
||||||
deposit2 := v1beta1.NewDeposit(proposal.ProposalId, addrs[1], depositAmount2)
|
deposit2 := v1beta2.NewDeposit(proposal.ProposalId, addrs[1], depositAmount2)
|
||||||
app.GovKeeper.SetDeposit(ctx, deposit2)
|
app.GovKeeper.SetDeposit(ctx, deposit2)
|
||||||
|
|
||||||
deposits := v1beta1.Deposits{deposit1, deposit2}
|
deposits := v1beta2.Deposits{&deposit1, &deposit2}
|
||||||
|
|
||||||
req = &v1beta1.QueryDepositsRequest{
|
req = &v1beta2.QueryDepositsRequest{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
}
|
}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryDepositsResponse{
|
expRes = &v1beta2.QueryDepositsResponse{
|
||||||
Deposits: deposits,
|
Deposits: deposits,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -716,9 +734,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryTally() {
|
||||||
addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})
|
addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
req *v1beta1.QueryTallyResultRequest
|
req *v1beta2.QueryTallyResultRequest
|
||||||
expRes *v1beta1.QueryTallyResultResponse
|
expRes *v1beta2.QueryTallyResultResponse
|
||||||
proposal v1beta1.Proposal
|
proposal v1beta2.Proposal
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -729,21 +747,21 @@ func (suite *KeeperTestSuite) TestGRPCQueryTally() {
|
||||||
{
|
{
|
||||||
"empty request",
|
"empty request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryTallyResultRequest{}
|
req = &v1beta2.QueryTallyResultRequest{}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero proposal id request",
|
"zero proposal id request",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryTallyResultRequest{ProposalId: 0}
|
req = &v1beta2.QueryTallyResultRequest{ProposalId: 0}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"query non existed proposal",
|
"query non existed proposal",
|
||||||
func() {
|
func() {
|
||||||
req = &v1beta1.QueryTallyResultRequest{ProposalId: 1}
|
req = &v1beta2.QueryTallyResultRequest{ProposalId: 1}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -755,10 +773,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryTally() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().NotNil(proposal)
|
suite.Require().NotNil(proposal)
|
||||||
|
|
||||||
req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
req = &v1beta2.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryTallyResultResponse{
|
tallyResult := v1beta2.EmptyTallyResult()
|
||||||
Tally: v1beta1.EmptyTallyResult(),
|
expRes = &v1beta2.QueryTallyResultResponse{
|
||||||
|
Tally: &tallyResult,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
|
@ -766,18 +785,21 @@ func (suite *KeeperTestSuite) TestGRPCQueryTally() {
|
||||||
{
|
{
|
||||||
"request tally after few votes",
|
"request tally after few votes",
|
||||||
func() {
|
func() {
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
req = &v1beta2.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryTallyResultResponse{
|
expRes = &v1beta2.QueryTallyResultResponse{
|
||||||
Tally: v1beta1.TallyResult{
|
Tally: &v1beta2.TallyResult{
|
||||||
Yes: sdk.NewInt(3 * 5 * 1000000),
|
Yes: sdk.NewInt(3 * 5 * 1000000).String(),
|
||||||
|
No: "0",
|
||||||
|
Abstain: "0",
|
||||||
|
NoWithVeto: "0",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -786,13 +808,13 @@ func (suite *KeeperTestSuite) TestGRPCQueryTally() {
|
||||||
{
|
{
|
||||||
"request final tally after status changed",
|
"request final tally after status changed",
|
||||||
func() {
|
func() {
|
||||||
proposal.Status = v1beta1.StatusPassed
|
proposal.Status = v1beta2.StatusPassed
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
|
proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
|
||||||
|
|
||||||
req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
req = &v1beta2.QueryTallyResultRequest{ProposalId: proposal.ProposalId}
|
||||||
|
|
||||||
expRes = &v1beta1.QueryTallyResultResponse{
|
expRes = &v1beta2.QueryTallyResultResponse{
|
||||||
Tally: proposal.FinalTallyResult,
|
Tally: proposal.FinalTallyResult,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ types.GovHooks = &MockGovHooksReceiver{}
|
var _ types.GovHooks = &MockGovHooksReceiver{}
|
||||||
|
@ -69,7 +69,7 @@ func TestHooks(t *testing.T) {
|
||||||
require.True(t, govHooksReceiver.AfterProposalSubmissionValid)
|
require.True(t, govHooksReceiver.AfterProposalSubmissionValid)
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
newHeader := ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(time.Duration(1) * time.Second)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod).Add(time.Duration(1) * time.Second)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
gov.EndBlocker(ctx, app.GovKeeper)
|
gov.EndBlocker(ctx, app.GovKeeper)
|
||||||
|
|
||||||
|
@ -83,12 +83,12 @@ func TestHooks(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, govHooksReceiver.AfterProposalDepositValid)
|
require.True(t, govHooksReceiver.AfterProposalDepositValid)
|
||||||
|
|
||||||
err = app.GovKeeper.AddVote(ctx, p2.ProposalId, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
err = app.GovKeeper.AddVote(ctx, p2.ProposalId, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, govHooksReceiver.AfterProposalVoteValid)
|
require.True(t, govHooksReceiver.AfterProposalVoteValid)
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
newHeader = ctx.BlockHeader()
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(app.GovKeeper.GetVotingParams(ctx).VotingPeriod).Add(time.Duration(1) * time.Second)
|
newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetVotingParams(ctx).VotingPeriod).Add(time.Duration(1) * time.Second)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
gov.EndBlocker(ctx, app.GovKeeper)
|
gov.EndBlocker(ctx, app.GovKeeper)
|
||||||
require.True(t, govHooksReceiver.AfterProposalVotingPeriodEndedValid)
|
require.True(t, govHooksReceiver.AfterProposalVotingPeriodEndedValid)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterInvariants registers all governance invariants
|
// RegisterInvariants registers all governance invariants
|
||||||
|
@ -28,7 +28,7 @@ func ModuleAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant {
|
||||||
return func(ctx sdk.Context) (string, bool) {
|
return func(ctx sdk.Context) (string, bool) {
|
||||||
var expectedDeposits sdk.Coins
|
var expectedDeposits sdk.Coins
|
||||||
|
|
||||||
keeper.IterateAllDeposits(ctx, func(deposit v1beta1.Deposit) bool {
|
keeper.IterateAllDeposits(ctx, func(deposit v1beta2.Deposit) bool {
|
||||||
expectedDeposits = expectedDeposits.Add(deposit.Amount...)
|
expectedDeposits = expectedDeposits.Add(deposit.Amount...)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,9 +9,11 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth/middleware"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Keeper defines the governance module Keeper
|
// Keeper defines the governance module Keeper
|
||||||
|
@ -34,8 +36,11 @@ type Keeper struct {
|
||||||
// The codec codec for binary encoding/decoding.
|
// The codec codec for binary encoding/decoding.
|
||||||
cdc codec.BinaryCodec
|
cdc codec.BinaryCodec
|
||||||
|
|
||||||
// Proposal router
|
// Legacy Proposal router
|
||||||
router v1beta1.Router
|
legacyRouter v1beta1.Router
|
||||||
|
|
||||||
|
// Msg server router
|
||||||
|
router *middleware.MsgServiceRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper returns a governance keeper. It handles:
|
// NewKeeper returns a governance keeper. It handles:
|
||||||
|
@ -47,7 +52,8 @@ type Keeper struct {
|
||||||
// CONTRACT: the parameter Subspace must have the param key table already initialized
|
// CONTRACT: the parameter Subspace must have the param key table already initialized
|
||||||
func NewKeeper(
|
func NewKeeper(
|
||||||
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace,
|
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace,
|
||||||
authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr v1beta1.Router,
|
authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper,
|
||||||
|
legacyRouter v1beta1.Router, router *middleware.MsgServiceRouter,
|
||||||
) Keeper {
|
) Keeper {
|
||||||
|
|
||||||
// ensure governance module account is set
|
// ensure governance module account is set
|
||||||
|
@ -58,7 +64,7 @@ func NewKeeper(
|
||||||
// It is vital to seal the governance proposal router here as to not allow
|
// It is vital to seal the governance proposal router here as to not allow
|
||||||
// further handlers to be registered after the keeper is created since this
|
// further handlers to be registered after the keeper is created since this
|
||||||
// could create invalid or non-deterministic behavior.
|
// could create invalid or non-deterministic behavior.
|
||||||
rtr.Seal()
|
legacyRouter.Seal()
|
||||||
|
|
||||||
return Keeper{
|
return Keeper{
|
||||||
storeKey: key,
|
storeKey: key,
|
||||||
|
@ -67,7 +73,8 @@ func NewKeeper(
|
||||||
bankKeeper: bankKeeper,
|
bankKeeper: bankKeeper,
|
||||||
sk: sk,
|
sk: sk,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
router: rtr,
|
legacyRouter: legacyRouter,
|
||||||
|
router: router,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +94,16 @@ func (keeper Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||||
return ctx.Logger().With("module", "x/"+types.ModuleName)
|
return ctx.Logger().With("module", "x/"+types.ModuleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Router returns the gov Keeper's Router
|
// Router returns the gov keeper's router
|
||||||
func (keeper Keeper) Router() v1beta1.Router {
|
func (keeper Keeper) Router() *middleware.MsgServiceRouter {
|
||||||
return keeper.router
|
return keeper.router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LegacyRouter returns the gov keeper's legacy router
|
||||||
|
func (keeper Keeper) LegacyRouter() v1beta1.Router {
|
||||||
|
return keeper.legacyRouter
|
||||||
|
}
|
||||||
|
|
||||||
// GetGovernanceAccount returns the governance ModuleAccount
|
// GetGovernanceAccount returns the governance ModuleAccount
|
||||||
func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) authtypes.ModuleAccountI {
|
func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) authtypes.ModuleAccountI {
|
||||||
return keeper.authKeeper.GetModuleAccount(ctx, types.ModuleName)
|
return keeper.authKeeper.GetModuleAccount(ctx, types.ModuleName)
|
||||||
|
@ -129,7 +141,7 @@ func (keeper Keeper) RemoveFromInactiveProposalQueue(ctx sdk.Context, proposalID
|
||||||
|
|
||||||
// IterateActiveProposalsQueue iterates over the proposals in the active proposal queue
|
// IterateActiveProposalsQueue iterates over the proposals in the active proposal queue
|
||||||
// and performs a callback function
|
// and performs a callback function
|
||||||
func (keeper Keeper) IterateActiveProposalsQueue(ctx sdk.Context, endTime time.Time, cb func(proposal v1beta1.Proposal) (stop bool)) {
|
func (keeper Keeper) IterateActiveProposalsQueue(ctx sdk.Context, endTime time.Time, cb func(proposal v1beta2.Proposal) (stop bool)) {
|
||||||
iterator := keeper.ActiveProposalQueueIterator(ctx, endTime)
|
iterator := keeper.ActiveProposalQueueIterator(ctx, endTime)
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
@ -148,7 +160,7 @@ func (keeper Keeper) IterateActiveProposalsQueue(ctx sdk.Context, endTime time.T
|
||||||
|
|
||||||
// IterateInactiveProposalsQueue iterates over the proposals in the inactive proposal queue
|
// IterateInactiveProposalsQueue iterates over the proposals in the inactive proposal queue
|
||||||
// and performs a callback function
|
// and performs a callback function
|
||||||
func (keeper Keeper) IterateInactiveProposalsQueue(ctx sdk.Context, endTime time.Time, cb func(proposal v1beta1.Proposal) (stop bool)) {
|
func (keeper Keeper) IterateInactiveProposalsQueue(ctx sdk.Context, endTime time.Time, cb func(proposal v1beta2.Proposal) (stop bool)) {
|
||||||
iterator := keeper.InactiveProposalQueueIterator(ctx, endTime)
|
iterator := keeper.InactiveProposalQueueIterator(ctx, endTime)
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
|
|
@ -11,7 +11,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeeperTestSuite struct {
|
type KeeperTestSuite struct {
|
||||||
|
@ -19,7 +20,7 @@ type KeeperTestSuite struct {
|
||||||
|
|
||||||
app *simapp.SimApp
|
app *simapp.SimApp
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
queryClient v1beta1.QueryClient
|
queryClient v1beta2.QueryClient
|
||||||
addrs []sdk.AccAddress
|
addrs []sdk.AccAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +28,17 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||||
app := simapp.Setup(suite.T(), false)
|
app := simapp.Setup(suite.T(), false)
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
|
|
||||||
|
// Populate the gov account with some coins, as the TestProposal we have
|
||||||
|
// is a MsgSend from the gov account.
|
||||||
|
coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100000)))
|
||||||
|
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)
|
||||||
|
suite.NoError(err)
|
||||||
|
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, coins)
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
||||||
v1beta1.RegisterQueryServer(queryHelper, app.GovKeeper)
|
v1beta2.RegisterQueryServer(queryHelper, app.GovKeeper)
|
||||||
queryClient := v1beta1.NewQueryClient(queryHelper)
|
queryClient := v1beta2.NewQueryClient(queryHelper)
|
||||||
|
|
||||||
suite.app = app
|
suite.app = app
|
||||||
suite.ctx = ctx
|
suite.ctx = ctx
|
||||||
|
@ -67,7 +76,7 @@ func TestProposalQueues(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
inactiveIterator := app.GovKeeper.InactiveProposalQueueIterator(ctx, proposal.DepositEndTime)
|
inactiveIterator := app.GovKeeper.InactiveProposalQueueIterator(ctx, *proposal.DepositEndTime)
|
||||||
require.True(t, inactiveIterator.Valid())
|
require.True(t, inactiveIterator.Valid())
|
||||||
|
|
||||||
proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value())
|
proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value())
|
||||||
|
@ -79,7 +88,7 @@ func TestProposalQueues(t *testing.T) {
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, proposal.VotingEndTime)
|
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, *proposal.VotingEndTime)
|
||||||
require.True(t, activeIterator.Valid())
|
require.True(t, activeIterator.Valid())
|
||||||
|
|
||||||
proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key())
|
proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key())
|
||||||
|
|
|
@ -10,8 +10,10 @@ import (
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type msgServer struct {
|
type msgServer struct {
|
||||||
|
@ -20,15 +22,21 @@ type msgServer struct {
|
||||||
|
|
||||||
// NewMsgServerImpl returns an implementation of the gov MsgServer interface
|
// NewMsgServerImpl returns an implementation of the gov MsgServer interface
|
||||||
// for the provided Keeper.
|
// for the provided Keeper.
|
||||||
func NewMsgServerImpl(keeper Keeper) v1beta1.MsgServer {
|
func NewMsgServerImpl(keeper Keeper) v1beta2.MsgServer {
|
||||||
return &msgServer{Keeper: keeper}
|
return &msgServer{Keeper: keeper}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ v1beta1.MsgServer = msgServer{}
|
var _ v1beta2.MsgServer = msgServer{}
|
||||||
|
|
||||||
func (k msgServer) SubmitProposal(goCtx context.Context, msg *v1beta1.MsgSubmitProposal) (*v1beta1.MsgSubmitProposalResponse, error) {
|
func (k msgServer) SubmitProposal(goCtx context.Context, msg *v1beta2.MsgSubmitProposal) (*v1beta2.MsgSubmitProposalResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
proposal, err := k.Keeper.SubmitProposal(ctx, msg.GetContent())
|
|
||||||
|
proposalMsgs, err := msg.GetMsgs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
proposal, err := k.Keeper.SubmitProposal(ctx, proposalMsgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -44,9 +52,10 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *v1beta1.MsgSubmitP
|
||||||
"submit proposal",
|
"submit proposal",
|
||||||
)
|
)
|
||||||
|
|
||||||
defer telemetry.IncrCounter(1, v1beta1.ModuleName, "proposal")
|
defer telemetry.IncrCounter(1, types.ModuleName, "proposal")
|
||||||
|
|
||||||
votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), msg.GetInitialDeposit())
|
proposer, _ := sdk.AccAddressFromBech32(msg.GetProposer())
|
||||||
|
votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, proposer, msg.GetInitialDeposit())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -55,36 +64,63 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *v1beta1.MsgSubmitP
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
sdk.EventTypeMessage,
|
sdk.EventTypeMessage,
|
||||||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
||||||
sdk.NewAttribute(sdk.AttributeKeySender, msg.GetProposer().String()),
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.GetProposer()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
submitEvent := sdk.NewEvent(types.EventTypeSubmitProposal, sdk.NewAttribute(types.AttributeKeyProposalType, msg.GetContent().ProposalType()))
|
|
||||||
if votingStarted {
|
if votingStarted {
|
||||||
submitEvent = submitEvent.AppendAttributes(
|
submitEvent := sdk.NewEvent(types.EventTypeSubmitProposal,
|
||||||
sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", proposal.ProposalId)),
|
sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", proposal.ProposalId)),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(submitEvent)
|
ctx.EventManager().EmitEvent(submitEvent)
|
||||||
return &v1beta1.MsgSubmitProposalResponse{
|
}
|
||||||
|
|
||||||
|
return &v1beta2.MsgSubmitProposalResponse{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) Vote(goCtx context.Context, msg *v1beta1.MsgVote) (*v1beta1.MsgVoteResponse, error) {
|
func (k msgServer) ExecLegacyContent(goCtx context.Context, msg *v1beta2.MsgExecLegacyContent) (*v1beta2.MsgExecLegacyContentResponse, error) {
|
||||||
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
|
govAcct := k.GetGovernanceAccount(ctx).GetAddress().String()
|
||||||
|
if govAcct != msg.Authority {
|
||||||
|
return nil, sdkerrors.Wrapf(types.ErrInvalidSigner, "expected %s got %s", govAcct, msg.Authority)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := v1beta2.LegacyContentFromMessage(msg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, sdkerrors.Wrapf(types.ErrInvalidProposalContent, "%+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the content has a respective handler
|
||||||
|
if !k.Keeper.legacyRouter.HasRoute(content.ProposalRoute()) {
|
||||||
|
return nil, sdkerrors.Wrap(types.ErrNoProposalHandlerExists, content.ProposalRoute())
|
||||||
|
}
|
||||||
|
|
||||||
|
handler := k.Keeper.legacyRouter.GetRoute(content.ProposalRoute())
|
||||||
|
if err := handler(ctx, content); err != nil {
|
||||||
|
return nil, sdkerrors.Wrapf(types.ErrInvalidProposalContent, "failed to run legacy handler %s, %+v", content.ProposalRoute(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &v1beta2.MsgExecLegacyContentResponse{}, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k msgServer) Vote(goCtx context.Context, msg *v1beta2.MsgVote) (*v1beta2.MsgVoteResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter)
|
accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter)
|
||||||
if accErr != nil {
|
if accErr != nil {
|
||||||
return nil, accErr
|
return nil, accErr
|
||||||
}
|
}
|
||||||
err := k.Keeper.AddVote(ctx, msg.ProposalId, accAddr, v1beta1.NewNonSplitVoteOption(msg.Option))
|
err := k.Keeper.AddVote(ctx, msg.ProposalId, accAddr, v1beta2.NewNonSplitVoteOption(msg.Option))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer telemetry.IncrCounterWithLabels(
|
defer telemetry.IncrCounterWithLabels(
|
||||||
[]string{v1beta1.ModuleName, "vote"},
|
[]string{types.ModuleName, "vote"},
|
||||||
1,
|
1,
|
||||||
[]metrics.Label{
|
[]metrics.Label{
|
||||||
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
||||||
|
@ -99,10 +135,10 @@ func (k msgServer) Vote(goCtx context.Context, msg *v1beta1.MsgVote) (*v1beta1.M
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return &v1beta1.MsgVoteResponse{}, nil
|
return &v1beta2.MsgVoteResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) VoteWeighted(goCtx context.Context, msg *v1beta1.MsgVoteWeighted) (*v1beta1.MsgVoteWeightedResponse, error) {
|
func (k msgServer) VoteWeighted(goCtx context.Context, msg *v1beta2.MsgVoteWeighted) (*v1beta2.MsgVoteWeightedResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter)
|
accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter)
|
||||||
if accErr != nil {
|
if accErr != nil {
|
||||||
|
@ -114,7 +150,7 @@ func (k msgServer) VoteWeighted(goCtx context.Context, msg *v1beta1.MsgVoteWeigh
|
||||||
}
|
}
|
||||||
|
|
||||||
defer telemetry.IncrCounterWithLabels(
|
defer telemetry.IncrCounterWithLabels(
|
||||||
[]string{v1beta1.ModuleName, "vote"},
|
[]string{types.ModuleName, "vote"},
|
||||||
1,
|
1,
|
||||||
[]metrics.Label{
|
[]metrics.Label{
|
||||||
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
||||||
|
@ -129,10 +165,10 @@ func (k msgServer) VoteWeighted(goCtx context.Context, msg *v1beta1.MsgVoteWeigh
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return &v1beta1.MsgVoteWeightedResponse{}, nil
|
return &v1beta2.MsgVoteWeightedResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) Deposit(goCtx context.Context, msg *v1beta1.MsgDeposit) (*v1beta1.MsgDepositResponse, error) {
|
func (k msgServer) Deposit(goCtx context.Context, msg *v1beta2.MsgDeposit) (*v1beta2.MsgDepositResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
accAddr, err := sdk.AccAddressFromBech32(msg.Depositor)
|
accAddr, err := sdk.AccAddressFromBech32(msg.Depositor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,7 +180,7 @@ func (k msgServer) Deposit(goCtx context.Context, msg *v1beta1.MsgDeposit) (*v1b
|
||||||
}
|
}
|
||||||
|
|
||||||
defer telemetry.IncrCounterWithLabels(
|
defer telemetry.IncrCounterWithLabels(
|
||||||
[]string{v1beta1.ModuleName, "deposit"},
|
[]string{types.ModuleName, "deposit"},
|
||||||
1,
|
1,
|
||||||
[]metrics.Label{
|
[]metrics.Label{
|
||||||
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))),
|
||||||
|
@ -168,5 +204,85 @@ func (k msgServer) Deposit(goCtx context.Context, msg *v1beta1.MsgDeposit) (*v1b
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &v1beta2.MsgDepositResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type legacyMsgServer struct {
|
||||||
|
govAcct string
|
||||||
|
server v1beta2.MsgServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewLegacyMsgServerImpl returns an implementation of the v1beta1 legacy MsgServer interface. It wraps around
|
||||||
|
// the current MsgServer
|
||||||
|
func NewLegacyMsgServerImpl(govAcct string, v1beta2Server v1beta2.MsgServer) v1beta1.MsgServer {
|
||||||
|
return &legacyMsgServer{govAcct: govAcct, server: v1beta2Server}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ v1beta1.MsgServer = legacyMsgServer{}
|
||||||
|
|
||||||
|
func (k legacyMsgServer) SubmitProposal(goCtx context.Context, msg *v1beta1.MsgSubmitProposal) (*v1beta1.MsgSubmitProposalResponse, error) {
|
||||||
|
contentMsg, err := v1beta2.NewLegacyContent(msg.GetContent(), k.govAcct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting legacy content into proposal message: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
proposal, err := v1beta2.NewMsgSubmitProposal(
|
||||||
|
[]sdk.Msg{contentMsg},
|
||||||
|
msg.InitialDeposit,
|
||||||
|
msg.Proposer,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := k.server.SubmitProposal(goCtx, proposal)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &v1beta1.MsgSubmitProposalResponse{ProposalId: resp.ProposalId}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k legacyMsgServer) Vote(goCtx context.Context, msg *v1beta1.MsgVote) (*v1beta1.MsgVoteResponse, error) {
|
||||||
|
_, err := k.server.Vote(goCtx, &v1beta2.MsgVote{
|
||||||
|
ProposalId: msg.ProposalId,
|
||||||
|
Voter: msg.Voter,
|
||||||
|
Option: v1beta2.VoteOption(msg.Option),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &v1beta1.MsgVoteResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k legacyMsgServer) VoteWeighted(goCtx context.Context, msg *v1beta1.MsgVoteWeighted) (*v1beta1.MsgVoteWeightedResponse, error) {
|
||||||
|
opts := make([]*v1beta2.WeightedVoteOption, len(msg.Options))
|
||||||
|
for idx, opt := range msg.Options {
|
||||||
|
opts[idx] = &v1beta2.WeightedVoteOption{
|
||||||
|
Option: v1beta2.VoteOption(opt.Option),
|
||||||
|
Weight: opt.Weight.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := k.server.VoteWeighted(goCtx, &v1beta2.MsgVoteWeighted{
|
||||||
|
ProposalId: msg.ProposalId,
|
||||||
|
Voter: msg.Voter,
|
||||||
|
Options: opts,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &v1beta1.MsgVoteWeightedResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k legacyMsgServer) Deposit(goCtx context.Context, msg *v1beta1.MsgDeposit) (*v1beta1.MsgDepositResponse, error) {
|
||||||
|
_, err := k.server.Deposit(goCtx, &v1beta2.MsgDeposit{
|
||||||
|
ProposalId: msg.ProposalId,
|
||||||
|
Depositor: msg.Depositor,
|
||||||
|
Amount: msg.Amount,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &v1beta1.MsgDepositResponse{}, nil
|
return &v1beta1.MsgDepositResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,42 +2,41 @@ package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetDepositParams returns the current DepositParams from the global param store
|
// GetDepositParams returns the current DepositParams from the global param store
|
||||||
func (keeper Keeper) GetDepositParams(ctx sdk.Context) v1beta1.DepositParams {
|
func (keeper Keeper) GetDepositParams(ctx sdk.Context) v1beta2.DepositParams {
|
||||||
var depositParams v1beta1.DepositParams
|
var depositParams v1beta2.DepositParams
|
||||||
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyDepositParams, &depositParams)
|
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyDepositParams, &depositParams)
|
||||||
return depositParams
|
return depositParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVotingParams returns the current VotingParams from the global param store
|
// GetVotingParams returns the current VotingParams from the global param store
|
||||||
func (keeper Keeper) GetVotingParams(ctx sdk.Context) v1beta1.VotingParams {
|
func (keeper Keeper) GetVotingParams(ctx sdk.Context) v1beta2.VotingParams {
|
||||||
var votingParams v1beta1.VotingParams
|
var votingParams v1beta2.VotingParams
|
||||||
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyVotingParams, &votingParams)
|
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyVotingParams, &votingParams)
|
||||||
return votingParams
|
return votingParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTallyParams returns the current TallyParam from the global param store
|
// GetTallyParams returns the current TallyParam from the global param store
|
||||||
func (keeper Keeper) GetTallyParams(ctx sdk.Context) v1beta1.TallyParams {
|
func (keeper Keeper) GetTallyParams(ctx sdk.Context) v1beta2.TallyParams {
|
||||||
var tallyParams v1beta1.TallyParams
|
var tallyParams v1beta2.TallyParams
|
||||||
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyTallyParams, &tallyParams)
|
keeper.paramSpace.Get(ctx, v1beta2.ParamStoreKeyTallyParams, &tallyParams)
|
||||||
return tallyParams
|
return tallyParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDepositParams sets DepositParams to the global param store
|
// SetDepositParams sets DepositParams to the global param store
|
||||||
func (keeper Keeper) SetDepositParams(ctx sdk.Context, depositParams v1beta1.DepositParams) {
|
func (keeper Keeper) SetDepositParams(ctx sdk.Context, depositParams v1beta2.DepositParams) {
|
||||||
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyDepositParams, &depositParams)
|
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyDepositParams, &depositParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVotingParams sets VotingParams to the global param store
|
// SetVotingParams sets VotingParams to the global param store
|
||||||
func (keeper Keeper) SetVotingParams(ctx sdk.Context, votingParams v1beta1.VotingParams) {
|
func (keeper Keeper) SetVotingParams(ctx sdk.Context, votingParams v1beta2.VotingParams) {
|
||||||
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyVotingParams, &votingParams)
|
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyVotingParams, &votingParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTallyParams sets TallyParams to the global param store
|
// SetTallyParams sets TallyParams to the global param store
|
||||||
func (keeper Keeper) SetTallyParams(ctx sdk.Context, tallyParams v1beta1.TallyParams) {
|
func (keeper Keeper) SetTallyParams(ctx sdk.Context, tallyParams v1beta2.TallyParams) {
|
||||||
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyTallyParams, &tallyParams)
|
keeper.paramSpace.Set(ctx, v1beta2.ParamStoreKeyTallyParams, &tallyParams)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,39 +7,69 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubmitProposal create new proposal given a content
|
// SubmitProposal create new proposal given an array of messages
|
||||||
func (keeper Keeper) SubmitProposal(ctx sdk.Context, content v1beta1.Content) (v1beta1.Proposal, error) {
|
func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg) (v1beta2.Proposal, error) {
|
||||||
if !keeper.router.HasRoute(content.ProposalRoute()) {
|
// Will hold a comma-separated string of all Msg type URLs.
|
||||||
return v1beta1.Proposal{}, sdkerrors.Wrap(types.ErrNoProposalHandlerExists, content.ProposalRoute())
|
msgsStr := ""
|
||||||
|
|
||||||
|
// Loop through all messages and confirm that each has a handler and the gov module account
|
||||||
|
// as the only signer
|
||||||
|
for _, msg := range messages {
|
||||||
|
msgsStr += fmt.Sprintf(",%s", sdk.MsgTypeURL(msg))
|
||||||
|
|
||||||
|
// perform a basic validation of the message
|
||||||
|
if err := msg.ValidateBasic(); err != nil {
|
||||||
|
return v1beta2.Proposal{}, sdkerrors.Wrap(types.ErrInvalidProposalMsg, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the proposal content in a new context branch (with branched store)
|
signers := msg.GetSigners()
|
||||||
// to validate the actual parameter changes before the proposal proceeds
|
if len(signers) != 1 {
|
||||||
// through the governance process. State is not persisted.
|
return v1beta2.Proposal{}, types.ErrInvalidSigner
|
||||||
|
}
|
||||||
|
|
||||||
|
// assert that the governance module account is the only signer of the messages
|
||||||
|
if !signers[0].Equals(keeper.GetGovernanceAccount(ctx).GetAddress()) {
|
||||||
|
return v1beta2.Proposal{}, sdkerrors.Wrapf(types.ErrInvalidSigner, signers[0].String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// use the msg service router to see that there is a valid route for that message.
|
||||||
|
handler := keeper.router.Handler(msg)
|
||||||
|
if handler == nil {
|
||||||
|
return v1beta2.Proposal{}, sdkerrors.Wrap(types.ErrUnroutableProposalMsg, sdk.MsgTypeURL(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only if it's a MsgExecLegacyContent do we try to execute the
|
||||||
|
// proposal in a cached context.
|
||||||
|
// For other Msgs, we do not verify the proposal messages any further.
|
||||||
|
// They may fail upon execution.
|
||||||
|
// ref: https://github.com/cosmos/cosmos-sdk/pull/10868#discussion_r784872842
|
||||||
|
if msg, ok := msg.(*v1beta2.MsgExecLegacyContent); ok {
|
||||||
cacheCtx, _ := ctx.CacheContext()
|
cacheCtx, _ := ctx.CacheContext()
|
||||||
handler := keeper.router.GetRoute(content.ProposalRoute())
|
if _, err := handler(cacheCtx, msg); err != nil {
|
||||||
if err := handler(cacheCtx, content); err != nil {
|
return v1beta2.Proposal{}, sdkerrors.Wrap(types.ErrNoProposalHandlerExists, err.Error())
|
||||||
return v1beta1.Proposal{}, sdkerrors.Wrap(v1beta1.ErrInvalidProposalContent, err.Error())
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proposalID, err := keeper.GetProposalID(ctx)
|
proposalID, err := keeper.GetProposalID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v1beta1.Proposal{}, err
|
return v1beta2.Proposal{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
submitTime := ctx.BlockHeader().Time
|
submitTime := ctx.BlockHeader().Time
|
||||||
depositPeriod := keeper.GetDepositParams(ctx).MaxDepositPeriod
|
depositPeriod := keeper.GetDepositParams(ctx).MaxDepositPeriod
|
||||||
|
|
||||||
proposal, err := v1beta1.NewProposal(content, proposalID, submitTime, submitTime.Add(depositPeriod))
|
proposal, err := v1beta2.NewProposal(messages, proposalID, submitTime, submitTime.Add(*depositPeriod))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v1beta1.Proposal{}, err
|
return v1beta2.Proposal{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
keeper.InsertInactiveProposalQueue(ctx, proposalID, proposal.DepositEndTime)
|
keeper.InsertInactiveProposalQueue(ctx, proposalID, *proposal.DepositEndTime)
|
||||||
keeper.SetProposalID(ctx, proposalID+1)
|
keeper.SetProposalID(ctx, proposalID+1)
|
||||||
|
|
||||||
// called right after a proposal is submitted
|
// called right after a proposal is submitted
|
||||||
|
@ -49,6 +79,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, content v1beta1.Content) (v
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeSubmitProposal,
|
types.EventTypeSubmitProposal,
|
||||||
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)),
|
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyProposalMessages, msgsStr),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,15 +88,15 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, content v1beta1.Content) (v
|
||||||
|
|
||||||
// GetProposal get proposal from store by ProposalID.
|
// GetProposal get proposal from store by ProposalID.
|
||||||
// Panics if can't unmarshal the proposal.
|
// Panics if can't unmarshal the proposal.
|
||||||
func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (v1beta1.Proposal, bool) {
|
func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (v1beta2.Proposal, bool) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
|
|
||||||
bz := store.Get(types.ProposalKey(proposalID))
|
bz := store.Get(types.ProposalKey(proposalID))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return v1beta1.Proposal{}, false
|
return v1beta2.Proposal{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
var proposal v1beta1.Proposal
|
var proposal v1beta2.Proposal
|
||||||
if err := keeper.UnmarshalProposal(bz, &proposal); err != nil {
|
if err := keeper.UnmarshalProposal(bz, &proposal); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +106,7 @@ func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (v1beta1.Pr
|
||||||
|
|
||||||
// SetProposal set a proposal to store.
|
// SetProposal set a proposal to store.
|
||||||
// Panics if can't marshal the proposal.
|
// Panics if can't marshal the proposal.
|
||||||
func (keeper Keeper) SetProposal(ctx sdk.Context, proposal v1beta1.Proposal) {
|
func (keeper Keeper) SetProposal(ctx sdk.Context, proposal v1beta2.Proposal) {
|
||||||
bz, err := keeper.MarshalProposal(proposal)
|
bz, err := keeper.MarshalProposal(proposal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -93,21 +124,27 @@ func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64) {
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("couldn't find proposal with id#%d", proposalID))
|
panic(fmt.Sprintf("couldn't find proposal with id#%d", proposalID))
|
||||||
}
|
}
|
||||||
keeper.RemoveFromInactiveProposalQueue(ctx, proposalID, proposal.DepositEndTime)
|
|
||||||
keeper.RemoveFromActiveProposalQueue(ctx, proposalID, proposal.VotingEndTime)
|
if proposal.DepositEndTime != nil {
|
||||||
|
keeper.RemoveFromInactiveProposalQueue(ctx, proposalID, *proposal.DepositEndTime)
|
||||||
|
}
|
||||||
|
if proposal.VotingEndTime != nil {
|
||||||
|
keeper.RemoveFromActiveProposalQueue(ctx, proposalID, *proposal.VotingEndTime)
|
||||||
|
}
|
||||||
|
|
||||||
store.Delete(types.ProposalKey(proposalID))
|
store.Delete(types.ProposalKey(proposalID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateProposals iterates over the all the proposals and performs a callback function.
|
// IterateProposals iterates over the all the proposals and performs a callback function.
|
||||||
// Panics when the iterator encounters a proposal which can't be unmarshaled.
|
// Panics when the iterator encounters a proposal which can't be unmarshaled.
|
||||||
func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal v1beta1.Proposal) (stop bool)) {
|
func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal v1beta2.Proposal) (stop bool)) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
|
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.ProposalsKeyPrefix)
|
iterator := sdk.KVStorePrefixIterator(store, types.ProposalsKeyPrefix)
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
|
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var proposal v1beta1.Proposal
|
var proposal v1beta2.Proposal
|
||||||
err := keeper.UnmarshalProposal(iterator.Value(), &proposal)
|
err := keeper.UnmarshalProposal(iterator.Value(), &proposal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -120,9 +157,9 @@ func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal v1beta1.
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProposals returns all the proposals from store
|
// GetProposals returns all the proposals from store
|
||||||
func (keeper Keeper) GetProposals(ctx sdk.Context) (proposals v1beta1.Proposals) {
|
func (keeper Keeper) GetProposals(ctx sdk.Context) (proposals v1beta2.Proposals) {
|
||||||
keeper.IterateProposals(ctx, func(proposal v1beta1.Proposal) bool {
|
keeper.IterateProposals(ctx, func(proposal v1beta2.Proposal) bool {
|
||||||
proposals = append(proposals, proposal)
|
proposals = append(proposals, &proposal)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -137,15 +174,15 @@ func (keeper Keeper) GetProposals(ctx sdk.Context) (proposals v1beta1.Proposals)
|
||||||
//
|
//
|
||||||
// NOTE: If no filters are provided, all proposals will be returned in paginated
|
// NOTE: If no filters are provided, all proposals will be returned in paginated
|
||||||
// form.
|
// form.
|
||||||
func (keeper Keeper) GetProposalsFiltered(ctx sdk.Context, params v1beta1.QueryProposalsParams) v1beta1.Proposals {
|
func (keeper Keeper) GetProposalsFiltered(ctx sdk.Context, params v1beta2.QueryProposalsParams) v1beta2.Proposals {
|
||||||
proposals := keeper.GetProposals(ctx)
|
proposals := keeper.GetProposals(ctx)
|
||||||
filteredProposals := make([]v1beta1.Proposal, 0, len(proposals))
|
filteredProposals := make([]*v1beta2.Proposal, 0, len(proposals))
|
||||||
|
|
||||||
for _, p := range proposals {
|
for _, p := range proposals {
|
||||||
matchVoter, matchDepositor, matchStatus := true, true, true
|
matchVoter, matchDepositor, matchStatus := true, true, true
|
||||||
|
|
||||||
// match status (if supplied/valid)
|
// match status (if supplied/valid)
|
||||||
if v1beta1.ValidProposalStatus(params.ProposalStatus) {
|
if v1beta2.ValidProposalStatus(params.ProposalStatus) {
|
||||||
matchStatus = p.Status == params.ProposalStatus
|
matchStatus = p.Status == params.ProposalStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +203,7 @@ func (keeper Keeper) GetProposalsFiltered(ctx sdk.Context, params v1beta1.QueryP
|
||||||
|
|
||||||
start, end := client.Paginate(len(filteredProposals), params.Page, params.Limit, 100)
|
start, end := client.Paginate(len(filteredProposals), params.Page, params.Limit, 100)
|
||||||
if start < 0 || end < 0 {
|
if start < 0 || end < 0 {
|
||||||
filteredProposals = []v1beta1.Proposal{}
|
filteredProposals = []*v1beta2.Proposal{}
|
||||||
} else {
|
} else {
|
||||||
filteredProposals = filteredProposals[start:end]
|
filteredProposals = filteredProposals[start:end]
|
||||||
}
|
}
|
||||||
|
@ -192,18 +229,20 @@ func (keeper Keeper) SetProposalID(ctx sdk.Context, proposalID uint64) {
|
||||||
store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID))
|
store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (keeper Keeper) ActivateVotingPeriod(ctx sdk.Context, proposal v1beta1.Proposal) {
|
func (keeper Keeper) ActivateVotingPeriod(ctx sdk.Context, proposal v1beta2.Proposal) {
|
||||||
proposal.VotingStartTime = ctx.BlockHeader().Time
|
startTime := ctx.BlockHeader().Time
|
||||||
|
proposal.VotingStartTime = &startTime
|
||||||
votingPeriod := keeper.GetVotingParams(ctx).VotingPeriod
|
votingPeriod := keeper.GetVotingParams(ctx).VotingPeriod
|
||||||
proposal.VotingEndTime = proposal.VotingStartTime.Add(votingPeriod)
|
endTime := proposal.VotingStartTime.Add(*votingPeriod)
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.VotingEndTime = &endTime
|
||||||
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
keeper.RemoveFromInactiveProposalQueue(ctx, proposal.ProposalId, proposal.DepositEndTime)
|
keeper.RemoveFromInactiveProposalQueue(ctx, proposal.ProposalId, *proposal.DepositEndTime)
|
||||||
keeper.InsertActiveProposalQueue(ctx, proposal.ProposalId, proposal.VotingEndTime)
|
keeper.InsertActiveProposalQueue(ctx, proposal.ProposalId, *proposal.VotingEndTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (keeper Keeper) MarshalProposal(proposal v1beta1.Proposal) ([]byte, error) {
|
func (keeper Keeper) MarshalProposal(proposal v1beta2.Proposal) ([]byte, error) {
|
||||||
bz, err := keeper.cdc.Marshal(&proposal)
|
bz, err := keeper.cdc.Marshal(&proposal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -211,7 +250,7 @@ func (keeper Keeper) MarshalProposal(proposal v1beta1.Proposal) ([]byte, error)
|
||||||
return bz, nil
|
return bz, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (keeper Keeper) UnmarshalProposal(bz []byte, proposal *v1beta1.Proposal) error {
|
func (keeper Keeper) UnmarshalProposal(bz []byte, proposal *v1beta2.Proposal) error {
|
||||||
err := keeper.cdc.Unmarshal(bz, proposal)
|
err := keeper.cdc.Unmarshal(bz, proposal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,11 +4,16 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetSetProposal() {
|
func (suite *KeeperTestSuite) TestGetSetProposal() {
|
||||||
|
@ -20,7 +25,7 @@ func (suite *KeeperTestSuite) TestGetSetProposal() {
|
||||||
|
|
||||||
gotProposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposalID)
|
gotProposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposalID)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
suite.Require().True(proposal.Equal(gotProposal))
|
suite.Require().Equal(proposal, gotProposal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
|
func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
|
||||||
|
@ -28,16 +33,15 @@ func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
|
||||||
proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, tp)
|
proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, tp)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
suite.Require().True(proposal.VotingStartTime.Equal(time.Time{}))
|
suite.Require().Nil(proposal.VotingStartTime)
|
||||||
|
|
||||||
suite.app.GovKeeper.ActivateVotingPeriod(suite.ctx, proposal)
|
suite.app.GovKeeper.ActivateVotingPeriod(suite.ctx, proposal)
|
||||||
|
|
||||||
suite.Require().True(proposal.VotingStartTime.Equal(suite.ctx.BlockHeader().Time))
|
|
||||||
|
|
||||||
proposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposal.ProposalId)
|
proposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposal.ProposalId)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
|
suite.Require().True(proposal.VotingStartTime.Equal(suite.ctx.BlockHeader().Time))
|
||||||
|
|
||||||
activeIterator := suite.app.GovKeeper.ActiveProposalQueueIterator(suite.ctx, proposal.VotingEndTime)
|
activeIterator := suite.app.GovKeeper.ActiveProposalQueueIterator(suite.ctx, *proposal.VotingEndTime)
|
||||||
suite.Require().True(activeIterator.Valid())
|
suite.Require().True(activeIterator.Valid())
|
||||||
|
|
||||||
proposalID := types.GetProposalIDFromBytes(activeIterator.Value())
|
proposalID := types.GetProposalIDFromBytes(activeIterator.Value())
|
||||||
|
@ -50,42 +54,50 @@ type invalidProposalRoute struct{ v1beta1.TextProposal }
|
||||||
func (invalidProposalRoute) ProposalRoute() string { return "nonexistingroute" }
|
func (invalidProposalRoute) ProposalRoute() string { return "nonexistingroute" }
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestSubmitProposal() {
|
func (suite *KeeperTestSuite) TestSubmitProposal() {
|
||||||
|
govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress().String()
|
||||||
|
_, _, randomAddr := testdata.KeyTestPubAddr()
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
content v1beta1.Content
|
content v1beta1.Content
|
||||||
|
authority string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
{&v1beta1.TextProposal{Title: "title", Description: "description"}, nil},
|
{&v1beta1.TextProposal{Title: "title", Description: "description"}, govAcct, nil},
|
||||||
// Keeper does not check the validity of title and description, no error
|
// Keeper does not check the validity of title and description, no error
|
||||||
{&v1beta1.TextProposal{Title: "", Description: "description"}, nil},
|
{&v1beta1.TextProposal{Title: "", Description: "description"}, govAcct, nil},
|
||||||
{&v1beta1.TextProposal{Title: strings.Repeat("1234567890", 100), Description: "description"}, nil},
|
{&v1beta1.TextProposal{Title: strings.Repeat("1234567890", 100), Description: "description"}, govAcct, nil},
|
||||||
{&v1beta1.TextProposal{Title: "title", Description: ""}, nil},
|
{&v1beta1.TextProposal{Title: "title", Description: ""}, govAcct, nil},
|
||||||
{&v1beta1.TextProposal{Title: "title", Description: strings.Repeat("1234567890", 1000)}, nil},
|
{&v1beta1.TextProposal{Title: "title", Description: strings.Repeat("1234567890", 1000)}, govAcct, nil},
|
||||||
|
// error when signer is not gov acct
|
||||||
|
{&v1beta1.TextProposal{Title: "title", Description: "description"}, randomAddr.String(), types.ErrInvalidSigner},
|
||||||
// error only when invalid route
|
// error only when invalid route
|
||||||
{&invalidProposalRoute{}, types.ErrNoProposalHandlerExists},
|
{&invalidProposalRoute{}, govAcct, types.ErrNoProposalHandlerExists},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
_, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, tc.content)
|
prop, err := v1beta2.NewLegacyContent(tc.content, tc.authority)
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
_, err = suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{prop})
|
||||||
suite.Require().True(errors.Is(tc.expectedErr, err), "tc #%d; got: %v, expected: %v", i, err, tc.expectedErr)
|
suite.Require().True(errors.Is(tc.expectedErr, err), "tc #%d; got: %v, expected: %v", i, err, tc.expectedErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetProposalsFiltered() {
|
func (suite *KeeperTestSuite) TestGetProposalsFiltered() {
|
||||||
proposalID := uint64(1)
|
proposalID := uint64(1)
|
||||||
status := []v1beta1.ProposalStatus{v1beta1.StatusDepositPeriod, v1beta1.StatusVotingPeriod}
|
status := []v1beta2.ProposalStatus{v1beta2.StatusDepositPeriod, v1beta2.StatusVotingPeriod}
|
||||||
|
|
||||||
addr1 := sdk.AccAddress("foo_________________")
|
addr1 := sdk.AccAddress("foo_________________")
|
||||||
|
|
||||||
for _, s := range status {
|
for _, s := range status {
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
p, err := v1beta1.NewProposal(TestProposal, proposalID, time.Now(), time.Now())
|
p, err := v1beta2.NewProposal(TestProposal, proposalID, time.Now(), time.Now())
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
p.Status = s
|
p.Status = s
|
||||||
|
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
d := v1beta1.NewDeposit(proposalID, addr1, nil)
|
d := v1beta2.NewDeposit(proposalID, addr1, nil)
|
||||||
v := v1beta1.NewVote(proposalID, addr1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
v := v1beta2.NewVote(proposalID, addr1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
suite.app.GovKeeper.SetDeposit(suite.ctx, d)
|
suite.app.GovKeeper.SetDeposit(suite.ctx, d)
|
||||||
suite.app.GovKeeper.SetVote(suite.ctx, v)
|
suite.app.GovKeeper.SetVote(suite.ctx, v)
|
||||||
}
|
}
|
||||||
|
@ -96,21 +108,21 @@ func (suite *KeeperTestSuite) TestGetProposalsFiltered() {
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
params v1beta1.QueryProposalsParams
|
params v1beta2.QueryProposalsParams
|
||||||
expectedNumResults int
|
expectedNumResults int
|
||||||
}{
|
}{
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusNil, nil, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusNil, nil, nil), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusDepositPeriod, nil, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusDepositPeriod, nil, nil), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusVotingPeriod, nil, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusVotingPeriod, nil, nil), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 25, v1beta1.StatusNil, nil, nil), 25},
|
{v1beta2.NewQueryProposalsParams(1, 25, v1beta2.StatusNil, nil, nil), 25},
|
||||||
{v1beta1.NewQueryProposalsParams(2, 25, v1beta1.StatusNil, nil, nil), 25},
|
{v1beta2.NewQueryProposalsParams(2, 25, v1beta2.StatusNil, nil, nil), 25},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusRejected, nil, nil), 0},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusRejected, nil, nil), 0},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusNil, addr1, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusNil, addr1, nil), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusNil, nil, addr1), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusNil, nil, addr1), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusNil, addr1, addr1), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusNil, addr1, addr1), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusDepositPeriod, addr1, addr1), 25},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusDepositPeriod, addr1, addr1), 25},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusDepositPeriod, nil, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusDepositPeriod, nil, nil), 50},
|
||||||
{v1beta1.NewQueryProposalsParams(1, 50, v1beta1.StatusVotingPeriod, nil, nil), 50},
|
{v1beta2.NewQueryProposalsParams(1, 50, v1beta2.StatusVotingPeriod, nil, nil), 50},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
|
@ -119,10 +131,20 @@ func (suite *KeeperTestSuite) TestGetProposalsFiltered() {
|
||||||
suite.Require().Len(proposals, tc.expectedNumResults)
|
suite.Require().Len(proposals, tc.expectedNumResults)
|
||||||
|
|
||||||
for _, p := range proposals {
|
for _, p := range proposals {
|
||||||
if v1beta1.ValidProposalStatus(tc.params.ProposalStatus) {
|
if v1beta2.ValidProposalStatus(tc.params.ProposalStatus) {
|
||||||
suite.Require().Equal(tc.params.ProposalStatus, p.Status)
|
suite.Require().Equal(tc.params.ProposalStatus, p.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMigrateProposalMessages(t *testing.T) {
|
||||||
|
content := v1beta1.NewTextProposal("Test", "description")
|
||||||
|
contentMsg, err := v1beta2.NewLegacyContent(content, sdk.AccAddress("test1").String())
|
||||||
|
require.NoError(t, err)
|
||||||
|
content, err = v1beta2.LegacyContentFromMessage(contentMsg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "Test", content.GetTitle())
|
||||||
|
require.Equal(t, "description", content.GetDescription())
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -139,7 +138,7 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
||||||
|
|
||||||
deposits := keeper.GetDeposits(ctx, params.ProposalID)
|
deposits := keeper.GetDeposits(ctx, params.ProposalID)
|
||||||
if deposits == nil {
|
if deposits == nil {
|
||||||
deposits = v1beta1.Deposits{}
|
deposits = v1beta2.Deposits{}
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, deposits)
|
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, deposits)
|
||||||
|
@ -165,14 +164,14 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||||
return nil, sdkerrors.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
return nil, sdkerrors.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tallyResult v1beta1.TallyResult
|
var tallyResult v1beta2.TallyResult
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case proposal.Status == v1beta1.StatusDepositPeriod:
|
case proposal.Status == v1beta2.StatusDepositPeriod:
|
||||||
tallyResult = v1beta1.EmptyTallyResult()
|
tallyResult = v1beta2.EmptyTallyResult()
|
||||||
|
|
||||||
case proposal.Status == v1beta1.StatusPassed || proposal.Status == v1beta1.StatusRejected:
|
case proposal.Status == v1beta2.StatusPassed || proposal.Status == v1beta2.StatusRejected:
|
||||||
tallyResult = proposal.FinalTallyResult
|
tallyResult = *proposal.FinalTallyResult
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// proposal is in voting period
|
// proposal is in voting period
|
||||||
|
@ -189,7 +188,7 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||||
|
|
||||||
// nolint: unparam
|
// nolint: unparam
|
||||||
func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
||||||
var params v1beta1.QueryProposalVotesParams
|
var params v1beta2.QueryProposalVotesParams
|
||||||
err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms)
|
err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
||||||
|
@ -197,11 +196,11 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||||
|
|
||||||
votes := keeper.GetVotes(ctx, params.ProposalID)
|
votes := keeper.GetVotes(ctx, params.ProposalID)
|
||||||
if votes == nil {
|
if votes == nil {
|
||||||
votes = v1beta1.Votes{}
|
votes = v1beta2.Votes{}
|
||||||
} else {
|
} else {
|
||||||
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
|
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
|
||||||
if start < 0 || end < 0 {
|
if start < 0 || end < 0 {
|
||||||
votes = v1beta1.Votes{}
|
votes = v1beta2.Votes{}
|
||||||
} else {
|
} else {
|
||||||
votes = votes[start:end]
|
votes = votes[start:end]
|
||||||
}
|
}
|
||||||
|
@ -216,7 +215,7 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
||||||
var params v1beta1.QueryProposalsParams
|
var params v1beta2.QueryProposalsParams
|
||||||
err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms)
|
err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
||||||
|
@ -224,7 +223,7 @@ func queryProposals(ctx sdk.Context, _ []string, req abci.RequestQuery, keeper K
|
||||||
|
|
||||||
proposals := keeper.GetProposalsFiltered(ctx, params)
|
proposals := keeper.GetProposalsFiltered(ctx, params)
|
||||||
if proposals == nil {
|
if proposals == nil {
|
||||||
proposals = v1beta1.Proposals{}
|
proposals = v1beta2.Proposals{}
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, proposals)
|
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, proposals)
|
||||||
|
|
|
@ -15,47 +15,46 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const custom = "custom"
|
const custom = "custom"
|
||||||
|
|
||||||
func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier) (v1beta1.DepositParams, v1beta1.VotingParams, v1beta1.TallyParams) {
|
func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier) (v1beta2.DepositParams, v1beta2.VotingParams, v1beta2.TallyParams) {
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryParams, v1beta1.ParamDeposit}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryParams, v1beta2.ParamDeposit}, "/"),
|
||||||
Data: []byte{},
|
Data: []byte{},
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryParams, v1beta1.ParamDeposit}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryParams, v1beta2.ParamDeposit}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var depositParams v1beta1.DepositParams
|
var depositParams v1beta2.DepositParams
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &depositParams))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &depositParams))
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
query = abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryParams, v1beta1.ParamVoting}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryParams, v1beta2.ParamVoting}, "/"),
|
||||||
Data: []byte{},
|
Data: []byte{},
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err = querier(ctx, []string{v1beta1.QueryParams, v1beta1.ParamVoting}, query)
|
bz, err = querier(ctx, []string{v1beta2.QueryParams, v1beta2.ParamVoting}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var votingParams v1beta1.VotingParams
|
var votingParams v1beta2.VotingParams
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &votingParams))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &votingParams))
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
query = abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryParams, v1beta1.ParamTallying}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryParams, v1beta2.ParamTallying}, "/"),
|
||||||
Data: []byte{},
|
Data: []byte{},
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err = querier(ctx, []string{v1beta1.QueryParams, v1beta1.ParamTallying}, query)
|
bz, err = querier(ctx, []string{v1beta2.QueryParams, v1beta2.ParamTallying}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var tallyParams v1beta1.TallyParams
|
var tallyParams v1beta2.TallyParams
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &tallyParams))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &tallyParams))
|
||||||
|
|
||||||
return depositParams, votingParams, tallyParams
|
return depositParams, votingParams, tallyParams
|
||||||
|
@ -63,84 +62,84 @@ func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, que
|
||||||
|
|
||||||
func getQueriedProposals(
|
func getQueriedProposals(
|
||||||
t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier,
|
t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier,
|
||||||
depositor, voter sdk.AccAddress, status v1beta1.ProposalStatus, page, limit int,
|
depositor, voter sdk.AccAddress, status v1beta2.ProposalStatus, page, limit int,
|
||||||
) []v1beta1.Proposal {
|
) []*v1beta2.Proposal {
|
||||||
|
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryProposals}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryProposals}, "/"),
|
||||||
Data: cdc.MustMarshalJSON(v1beta1.NewQueryProposalsParams(page, limit, status, voter, depositor)),
|
Data: cdc.MustMarshalJSON(v1beta2.NewQueryProposalsParams(page, limit, status, voter, depositor)),
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryProposals}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryProposals}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var proposals v1beta1.Proposals
|
var proposals v1beta2.Proposals
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &proposals))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &proposals))
|
||||||
|
|
||||||
return proposals
|
return proposals
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQueriedDeposit(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64, depositor sdk.AccAddress) v1beta1.Deposit {
|
func getQueriedDeposit(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64, depositor sdk.AccAddress) v1beta2.Deposit {
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryDeposit}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryDeposit}, "/"),
|
||||||
Data: cdc.MustMarshalJSON(v1beta1.NewQueryDepositParams(proposalID, depositor)),
|
Data: cdc.MustMarshalJSON(v1beta2.NewQueryDepositParams(proposalID, depositor)),
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryDeposit}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryDeposit}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var deposit v1beta1.Deposit
|
var deposit v1beta2.Deposit
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &deposit))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &deposit))
|
||||||
|
|
||||||
return deposit
|
return deposit
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQueriedDeposits(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64) []v1beta1.Deposit {
|
func getQueriedDeposits(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64) []v1beta2.Deposit {
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryDeposits}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryDeposits}, "/"),
|
||||||
Data: cdc.MustMarshalJSON(v1beta1.NewQueryProposalParams(proposalID)),
|
Data: cdc.MustMarshalJSON(v1beta2.NewQueryProposalParams(proposalID)),
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryDeposits}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryDeposits}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var deposits []v1beta1.Deposit
|
var deposits []v1beta2.Deposit
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &deposits))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &deposits))
|
||||||
|
|
||||||
return deposits
|
return deposits
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQueriedVote(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64, voter sdk.AccAddress) v1beta1.Vote {
|
func getQueriedVote(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier, proposalID uint64, voter sdk.AccAddress) v1beta2.Vote {
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryVote}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryVote}, "/"),
|
||||||
Data: cdc.MustMarshalJSON(v1beta1.NewQueryVoteParams(proposalID, voter)),
|
Data: cdc.MustMarshalJSON(v1beta2.NewQueryVoteParams(proposalID, voter)),
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryVote}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryVote}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var vote v1beta1.Vote
|
var vote v1beta2.Vote
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &vote))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &vote))
|
||||||
|
|
||||||
return vote
|
return vote
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQueriedVotes(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier,
|
func getQueriedVotes(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, querier sdk.Querier,
|
||||||
proposalID uint64, page, limit int) []v1beta1.Vote {
|
proposalID uint64, page, limit int) []v1beta2.Vote {
|
||||||
query := abci.RequestQuery{
|
query := abci.RequestQuery{
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta1.QueryVote}, "/"),
|
Path: strings.Join([]string{custom, types.QuerierRoute, v1beta2.QueryVote}, "/"),
|
||||||
Data: cdc.MustMarshalJSON(v1beta1.NewQueryProposalVotesParams(proposalID, page, limit)),
|
Data: cdc.MustMarshalJSON(v1beta2.NewQueryProposalVotesParams(proposalID, page, limit)),
|
||||||
}
|
}
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{v1beta1.QueryVotes}, query)
|
bz, err := querier(ctx, []string{v1beta2.QueryVotes}, query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, bz)
|
require.NotNil(t, bz)
|
||||||
|
|
||||||
var votes []v1beta1.Vote
|
var votes []v1beta2.Vote
|
||||||
require.NoError(t, cdc.UnmarshalJSON(bz, &votes))
|
require.NoError(t, cdc.UnmarshalJSON(bz, &votes))
|
||||||
|
|
||||||
return votes
|
return votes
|
||||||
|
@ -164,58 +163,60 @@ func TestQueries(t *testing.T) {
|
||||||
// TestAddrs[0] proposes (and deposits) proposals #1 and #2
|
// TestAddrs[0] proposes (and deposits) proposals #1 and #2
|
||||||
proposal1, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal1, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
deposit1 := v1beta1.NewDeposit(proposal1.ProposalId, TestAddrs[0], oneCoins)
|
deposit1 := v1beta2.NewDeposit(proposal1.ProposalId, TestAddrs[0], oneCoins)
|
||||||
depositer1, err := sdk.AccAddressFromBech32(deposit1.Depositor)
|
depositer1, err := sdk.AccAddressFromBech32(deposit1.Depositor)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = app.GovKeeper.AddDeposit(ctx, deposit1.ProposalId, depositer1, deposit1.Amount)
|
_, err = app.GovKeeper.AddDeposit(ctx, deposit1.ProposalId, depositer1, deposit1.Amount)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposal1.TotalDeposit = proposal1.TotalDeposit.Add(deposit1.Amount...)
|
proposal1.TotalDeposit = sdk.NewCoins(proposal1.TotalDeposit...).Add(deposit1.Amount...)
|
||||||
|
|
||||||
proposal2, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal2, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
deposit2 := v1beta1.NewDeposit(proposal2.ProposalId, TestAddrs[0], consCoins)
|
deposit2 := v1beta2.NewDeposit(proposal2.ProposalId, TestAddrs[0], consCoins)
|
||||||
depositer2, err := sdk.AccAddressFromBech32(deposit2.Depositor)
|
depositer2, err := sdk.AccAddressFromBech32(deposit2.Depositor)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = app.GovKeeper.AddDeposit(ctx, deposit2.ProposalId, depositer2, deposit2.Amount)
|
_, err = app.GovKeeper.AddDeposit(ctx, deposit2.ProposalId, depositer2, deposit2.Amount)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit2.Amount...)
|
proposal2.TotalDeposit = sdk.NewCoins(proposal2.TotalDeposit...).Add(deposit2.Amount...)
|
||||||
|
|
||||||
// TestAddrs[1] proposes (and deposits) on proposal #3
|
// TestAddrs[1] proposes (and deposits) on proposal #3
|
||||||
proposal3, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal3, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
deposit3 := v1beta1.NewDeposit(proposal3.ProposalId, TestAddrs[1], oneCoins)
|
deposit3 := v1beta2.NewDeposit(proposal3.ProposalId, TestAddrs[1], oneCoins)
|
||||||
depositer3, err := sdk.AccAddressFromBech32(deposit3.Depositor)
|
depositer3, err := sdk.AccAddressFromBech32(deposit3.Depositor)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = app.GovKeeper.AddDeposit(ctx, deposit3.ProposalId, depositer3, deposit3.Amount)
|
_, err = app.GovKeeper.AddDeposit(ctx, deposit3.ProposalId, depositer3, deposit3.Amount)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit3.Amount...)
|
proposal3.TotalDeposit = sdk.NewCoins(proposal3.TotalDeposit...).Add(deposit3.Amount...)
|
||||||
|
|
||||||
// TestAddrs[1] deposits on proposals #2 & #3
|
// TestAddrs[1] deposits on proposals #2 & #3
|
||||||
deposit4 := v1beta1.NewDeposit(proposal2.ProposalId, TestAddrs[1], depositParams.MinDeposit)
|
deposit4 := v1beta2.NewDeposit(proposal2.ProposalId, TestAddrs[1], depositParams.MinDeposit)
|
||||||
depositer4, err := sdk.AccAddressFromBech32(deposit4.Depositor)
|
depositer4, err := sdk.AccAddressFromBech32(deposit4.Depositor)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = app.GovKeeper.AddDeposit(ctx, deposit4.ProposalId, depositer4, deposit4.Amount)
|
_, err = app.GovKeeper.AddDeposit(ctx, deposit4.ProposalId, depositer4, deposit4.Amount)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit4.Amount...)
|
proposal2.TotalDeposit = sdk.NewCoins(proposal2.TotalDeposit...).Add(deposit4.Amount...)
|
||||||
proposal2.Status = v1beta1.StatusVotingPeriod
|
proposal2.Status = v1beta2.StatusVotingPeriod
|
||||||
proposal2.VotingEndTime = proposal2.VotingEndTime.Add(v1beta2.DefaultPeriod)
|
votingEndTime := ctx.BlockTime().Add(v1beta2.DefaultPeriod)
|
||||||
|
proposal2.VotingEndTime = &votingEndTime
|
||||||
|
|
||||||
deposit5 := v1beta1.NewDeposit(proposal3.ProposalId, TestAddrs[1], depositParams.MinDeposit)
|
deposit5 := v1beta2.NewDeposit(proposal3.ProposalId, TestAddrs[1], depositParams.MinDeposit)
|
||||||
depositer5, err := sdk.AccAddressFromBech32(deposit5.Depositor)
|
depositer5, err := sdk.AccAddressFromBech32(deposit5.Depositor)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = app.GovKeeper.AddDeposit(ctx, deposit5.ProposalId, depositer5, deposit5.Amount)
|
_, err = app.GovKeeper.AddDeposit(ctx, deposit5.ProposalId, depositer5, deposit5.Amount)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit5.Amount...)
|
proposal3.TotalDeposit = sdk.NewCoins(proposal3.TotalDeposit...).Add(deposit5.Amount...)
|
||||||
proposal3.Status = v1beta1.StatusVotingPeriod
|
proposal3.Status = v1beta2.StatusVotingPeriod
|
||||||
proposal3.VotingEndTime = proposal3.VotingEndTime.Add(v1beta2.DefaultPeriod)
|
votingEndTime = ctx.BlockTime().Add(v1beta2.DefaultPeriod)
|
||||||
|
proposal3.VotingEndTime = &votingEndTime
|
||||||
// total deposit of TestAddrs[1] on proposal #3 is worth the proposal deposit + individual deposit
|
// total deposit of TestAddrs[1] on proposal #3 is worth the proposal deposit + individual deposit
|
||||||
deposit5.Amount = deposit5.Amount.Add(deposit3.Amount...)
|
deposit5.Amount = sdk.NewCoins(deposit5.Amount...).Add(deposit3.Amount...)
|
||||||
|
|
||||||
// check deposits on proposal1 match individual deposits
|
// check deposits on proposal1 match individual deposits
|
||||||
|
|
||||||
|
@ -241,33 +242,33 @@ func TestQueries(t *testing.T) {
|
||||||
deposit = getQueriedDeposit(t, ctx, legacyQuerierCdc, querier, proposal3.ProposalId, TestAddrs[1])
|
deposit = getQueriedDeposit(t, ctx, legacyQuerierCdc, querier, proposal3.ProposalId, TestAddrs[1])
|
||||||
require.Equal(t, deposit5, deposit)
|
require.Equal(t, deposit5, deposit)
|
||||||
|
|
||||||
// Only proposal #1 should be in v1beta1.Deposit Period
|
// Only proposal #1 should be in v1beta2.Deposit Period
|
||||||
proposals := getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta1.StatusDepositPeriod, 1, 0)
|
proposals := getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta2.StatusDepositPeriod, 1, 0)
|
||||||
require.Len(t, proposals, 1)
|
require.Len(t, proposals, 1)
|
||||||
require.Equal(t, proposal1, proposals[0])
|
require.Equal(t, proposal1, *proposals[0])
|
||||||
|
|
||||||
// Only proposals #2 and #3 should be in Voting Period
|
// Only proposals #2 and #3 should be in Voting Period
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta1.StatusVotingPeriod, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta2.StatusVotingPeriod, 1, 0)
|
||||||
require.Len(t, proposals, 2)
|
require.Len(t, proposals, 2)
|
||||||
require.Equal(t, proposal2, proposals[0])
|
checkEqualProposal(t, proposal2, *proposals[0])
|
||||||
require.Equal(t, proposal3, proposals[1])
|
checkEqualProposal(t, proposal3, *proposals[1])
|
||||||
|
|
||||||
// Addrs[0] votes on proposals #2 & #3
|
// Addrs[0] votes on proposals #2 & #3
|
||||||
vote1 := v1beta1.NewVote(proposal2.ProposalId, TestAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
vote1 := v1beta2.NewVote(proposal2.ProposalId, TestAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
vote2 := v1beta1.NewVote(proposal3.ProposalId, TestAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
vote2 := v1beta2.NewVote(proposal3.ProposalId, TestAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
app.GovKeeper.SetVote(ctx, vote1)
|
app.GovKeeper.SetVote(ctx, vote1)
|
||||||
app.GovKeeper.SetVote(ctx, vote2)
|
app.GovKeeper.SetVote(ctx, vote2)
|
||||||
|
|
||||||
// Addrs[1] votes on proposal #3
|
// Addrs[1] votes on proposal #3
|
||||||
vote3 := v1beta1.NewVote(proposal3.ProposalId, TestAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
vote3 := v1beta2.NewVote(proposal3.ProposalId, TestAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
app.GovKeeper.SetVote(ctx, vote3)
|
app.GovKeeper.SetVote(ctx, vote3)
|
||||||
|
|
||||||
// Test query voted by TestAddrs[0]
|
// Test query voted by TestAddrs[0]
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, TestAddrs[0], v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, TestAddrs[0], v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal2, proposals[0])
|
checkEqualProposal(t, proposal2, *proposals[0])
|
||||||
require.Equal(t, proposal3, proposals[1])
|
checkEqualProposal(t, proposal3, *proposals[1])
|
||||||
|
|
||||||
// Test query votes on v1beta1.Proposal 2
|
// Test query votes on v1beta2.Proposal 2
|
||||||
votes := getQueriedVotes(t, ctx, legacyQuerierCdc, querier, proposal2.ProposalId, 1, 0)
|
votes := getQueriedVotes(t, ctx, legacyQuerierCdc, querier, proposal2.ProposalId, 1, 0)
|
||||||
require.Len(t, votes, 1)
|
require.Len(t, votes, 1)
|
||||||
checkEqualVotes(t, vote1, votes[0])
|
checkEqualVotes(t, vote1, votes[0])
|
||||||
|
@ -275,33 +276,33 @@ func TestQueries(t *testing.T) {
|
||||||
vote := getQueriedVote(t, ctx, legacyQuerierCdc, querier, proposal2.ProposalId, TestAddrs[0])
|
vote := getQueriedVote(t, ctx, legacyQuerierCdc, querier, proposal2.ProposalId, TestAddrs[0])
|
||||||
checkEqualVotes(t, vote1, vote)
|
checkEqualVotes(t, vote1, vote)
|
||||||
|
|
||||||
// Test query votes on v1beta1.Proposal 3
|
// Test query votes on v1beta2.Proposal 3
|
||||||
votes = getQueriedVotes(t, ctx, legacyQuerierCdc, querier, proposal3.ProposalId, 1, 0)
|
votes = getQueriedVotes(t, ctx, legacyQuerierCdc, querier, proposal3.ProposalId, 1, 0)
|
||||||
require.Len(t, votes, 2)
|
require.Len(t, votes, 2)
|
||||||
checkEqualVotes(t, vote2, votes[0])
|
checkEqualVotes(t, vote2, votes[0])
|
||||||
checkEqualVotes(t, vote3, votes[1])
|
checkEqualVotes(t, vote3, votes[1])
|
||||||
|
|
||||||
// Test query all proposals
|
// Test query all proposals
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, nil, v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal1, proposals[0])
|
checkEqualProposal(t, proposal1, *proposals[0])
|
||||||
require.Equal(t, proposal2, proposals[1])
|
checkEqualProposal(t, proposal2, *proposals[1])
|
||||||
require.Equal(t, proposal3, proposals[2])
|
checkEqualProposal(t, proposal3, *proposals[2])
|
||||||
|
|
||||||
// Test query voted by TestAddrs[1]
|
// Test query voted by TestAddrs[1]
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, TestAddrs[1], v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, nil, TestAddrs[1], v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal3.ProposalId, proposals[0].ProposalId)
|
require.Equal(t, proposal3.ProposalId, proposals[0].ProposalId)
|
||||||
|
|
||||||
// Test query deposited by TestAddrs[0]
|
// Test query deposited by TestAddrs[0]
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[0], nil, v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[0], nil, v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal1.ProposalId, proposals[0].ProposalId)
|
require.Equal(t, proposal1.ProposalId, proposals[0].ProposalId)
|
||||||
|
|
||||||
// Test query deposited by addr2
|
// Test query deposited by addr2
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[1], nil, v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[1], nil, v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal2.ProposalId, proposals[0].ProposalId)
|
require.Equal(t, proposal2.ProposalId, proposals[0].ProposalId)
|
||||||
require.Equal(t, proposal3.ProposalId, proposals[1].ProposalId)
|
require.Equal(t, proposal3.ProposalId, proposals[1].ProposalId)
|
||||||
|
|
||||||
// Test query voted AND deposited by addr1
|
// Test query voted AND deposited by addr1
|
||||||
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[0], TestAddrs[0], v1beta1.StatusNil, 1, 0)
|
proposals = getQueriedProposals(t, ctx, legacyQuerierCdc, querier, TestAddrs[0], TestAddrs[0], v1beta2.StatusNil, 1, 0)
|
||||||
require.Equal(t, proposal2.ProposalId, proposals[0].ProposalId)
|
require.Equal(t, proposal2.ProposalId, proposals[0].ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,14 +311,14 @@ func TestPaginatedVotesQuery(t *testing.T) {
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||||
legacyQuerierCdc := app.LegacyAmino()
|
legacyQuerierCdc := app.LegacyAmino()
|
||||||
|
|
||||||
proposal := v1beta1.Proposal{
|
proposal := v1beta2.Proposal{
|
||||||
ProposalId: 100,
|
ProposalId: 100,
|
||||||
Status: v1beta1.StatusVotingPeriod,
|
Status: v1beta2.StatusVotingPeriod,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
votes := make([]v1beta1.Vote, 20)
|
votes := make([]v1beta2.Vote, 20)
|
||||||
random := rand.New(rand.NewSource(time.Now().UnixNano()))
|
random := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
addrMap := make(map[string]struct{})
|
addrMap := make(map[string]struct{})
|
||||||
genAddr := func() string {
|
genAddr := func() string {
|
||||||
|
@ -332,10 +333,10 @@ func TestPaginatedVotesQuery(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range votes {
|
for i := range votes {
|
||||||
vote := v1beta1.Vote{
|
vote := v1beta2.Vote{
|
||||||
ProposalId: proposal.ProposalId,
|
ProposalId: proposal.ProposalId,
|
||||||
Voter: genAddr(),
|
Voter: genAddr(),
|
||||||
Options: v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes),
|
Options: v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes),
|
||||||
}
|
}
|
||||||
votes[i] = vote
|
votes[i] = vote
|
||||||
app.GovKeeper.SetVote(ctx, vote)
|
app.GovKeeper.SetVote(ctx, vote)
|
||||||
|
@ -351,7 +352,7 @@ func TestPaginatedVotesQuery(t *testing.T) {
|
||||||
description string
|
description string
|
||||||
page int
|
page int
|
||||||
limit int
|
limit int
|
||||||
votes []v1beta1.Vote
|
votes []v1beta2.Vote
|
||||||
}
|
}
|
||||||
for _, tc := range []testCase{
|
for _, tc := range []testCase{
|
||||||
{
|
{
|
||||||
|
@ -392,8 +393,49 @@ func TestPaginatedVotesQuery(t *testing.T) {
|
||||||
// When querying, the keeper populates the `vote.Option` field when there's
|
// When querying, the keeper populates the `vote.Option` field when there's
|
||||||
// only 1 vote, this function checks equality of structs while skipping that
|
// only 1 vote, this function checks equality of structs while skipping that
|
||||||
// field.
|
// field.
|
||||||
func checkEqualVotes(t *testing.T, vote1, vote2 v1beta1.Vote) {
|
func checkEqualVotes(t *testing.T, vote1, vote2 v1beta2.Vote) {
|
||||||
require.Equal(t, vote1.Options, vote2.Options)
|
require.Equal(t, vote1.Options, vote2.Options)
|
||||||
require.Equal(t, vote1.Voter, vote2.Voter)
|
require.Equal(t, vote1.Voter, vote2.Voter)
|
||||||
require.Equal(t, vote1.ProposalId, vote2.ProposalId)
|
require.Equal(t, vote1.ProposalId, vote2.ProposalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkEqualProposal checks that 2 proposals are equal.
|
||||||
|
// When decoding with Amino, there are weird cases where the voting times
|
||||||
|
// are actually equal, but `require.Equal()` says they are not:
|
||||||
|
//
|
||||||
|
// Diff:
|
||||||
|
// --- Expected
|
||||||
|
// +++ Actual
|
||||||
|
// @@ -68,3 +68,7 @@
|
||||||
|
// },
|
||||||
|
// - VotingStartTime: (*time.Time)(<nil>),
|
||||||
|
// + VotingStartTime: (*time.Time)({
|
||||||
|
// + wall: (uint64) 0,
|
||||||
|
// + ext: (int64) 0,
|
||||||
|
// + loc: (*time.Location)(<nil>)
|
||||||
|
// + }),
|
||||||
|
func checkEqualProposal(t *testing.T, p1, p2 v1beta2.Proposal) {
|
||||||
|
require.Equal(t, p1.ProposalId, p2.ProposalId)
|
||||||
|
require.Equal(t, p1.Messages, p2.Messages)
|
||||||
|
require.Equal(t, p1.Status, p2.Status)
|
||||||
|
require.Equal(t, p1.FinalTallyResult, p2.FinalTallyResult)
|
||||||
|
require.Equal(t, p1.SubmitTime, p2.SubmitTime)
|
||||||
|
require.Equal(t, p1.DepositEndTime, p2.DepositEndTime)
|
||||||
|
require.Equal(t, p1.TotalDeposit, p2.TotalDeposit)
|
||||||
|
require.Equal(t, convertNilToDefault(p1.VotingStartTime), convertNilToDefault(p2.VotingStartTime))
|
||||||
|
require.Equal(t, convertNilToDefault(p1.VotingEndTime), convertNilToDefault(p2.VotingEndTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertNilToDefault converts a (*time.Time)(<nil>) into a (*time.Time)(<default>)).
|
||||||
|
// In proto structs dealing with time, we use *time.Time, which can be nil.
|
||||||
|
// However, when using Amino, a nil time is unmarshalled into
|
||||||
|
// (*time.Time)(<default>)), which is Jan 1st 1970.
|
||||||
|
// This function converts a nil time to a default time, to check that they are
|
||||||
|
// actually equal.
|
||||||
|
func convertNilToDefault(t *time.Time) *time.Time {
|
||||||
|
if t == nil {
|
||||||
|
return &time.Time{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,30 +10,30 @@ import (
|
||||||
|
|
||||||
// Tally iterates over the votes and updates the tally of a proposal based on the voting power of the
|
// Tally iterates over the votes and updates the tally of a proposal based on the voting power of the
|
||||||
// voters
|
// voters
|
||||||
func (keeper Keeper) Tally(ctx sdk.Context, proposal v1beta1.Proposal) (passes bool, burnDeposits bool, tallyResults v1beta1.TallyResult) {
|
func (keeper Keeper) Tally(ctx sdk.Context, proposal v1beta2.Proposal) (passes bool, burnDeposits bool, tallyResults v1beta2.TallyResult) {
|
||||||
results := make(map[v1beta1.VoteOption]sdk.Dec)
|
results := make(map[v1beta2.VoteOption]sdk.Dec)
|
||||||
results[v1beta1.OptionYes] = sdk.ZeroDec()
|
results[v1beta2.OptionYes] = sdk.ZeroDec()
|
||||||
results[v1beta1.OptionAbstain] = sdk.ZeroDec()
|
results[v1beta2.OptionAbstain] = sdk.ZeroDec()
|
||||||
results[v1beta1.OptionNo] = sdk.ZeroDec()
|
results[v1beta2.OptionNo] = sdk.ZeroDec()
|
||||||
results[v1beta1.OptionNoWithVeto] = sdk.ZeroDec()
|
results[v1beta2.OptionNoWithVeto] = sdk.ZeroDec()
|
||||||
|
|
||||||
totalVotingPower := sdk.ZeroDec()
|
totalVotingPower := sdk.ZeroDec()
|
||||||
currValidators := make(map[string]v1beta1.ValidatorGovInfo)
|
currValidators := make(map[string]v1beta2.ValidatorGovInfo)
|
||||||
|
|
||||||
// fetch all the bonded validators, insert them into currValidators
|
// fetch all the bonded validators, insert them into currValidators
|
||||||
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
|
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
|
||||||
currValidators[validator.GetOperator().String()] = v1beta1.NewValidatorGovInfo(
|
currValidators[validator.GetOperator().String()] = v1beta2.NewValidatorGovInfo(
|
||||||
validator.GetOperator(),
|
validator.GetOperator(),
|
||||||
validator.GetBondedTokens(),
|
validator.GetBondedTokens(),
|
||||||
validator.GetDelegatorShares(),
|
validator.GetDelegatorShares(),
|
||||||
sdk.ZeroDec(),
|
sdk.ZeroDec(),
|
||||||
v1beta1.WeightedVoteOptions{},
|
v1beta2.WeightedVoteOptions{},
|
||||||
)
|
)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
keeper.IterateVotes(ctx, proposal.ProposalId, func(vote v1beta1.Vote) bool {
|
keeper.IterateVotes(ctx, proposal.ProposalId, func(vote v1beta2.Vote) bool {
|
||||||
// if validator, just record it in the map
|
// if validator, just record it in the map
|
||||||
voter, err := sdk.AccAddressFromBech32(vote.Voter)
|
voter, err := sdk.AccAddressFromBech32(vote.Voter)
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1beta1.Proposal) (passes b
|
||||||
votingPower := delegation.GetShares().MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
votingPower := delegation.GetShares().MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
||||||
|
|
||||||
for _, option := range vote.Options {
|
for _, option := range vote.Options {
|
||||||
subPower := votingPower.Mul(option.Weight)
|
weight, _ := sdk.NewDecFromStr(option.Weight)
|
||||||
|
subPower := votingPower.Mul(weight)
|
||||||
results[option.Option] = results[option.Option].Add(subPower)
|
results[option.Option] = results[option.Option].Add(subPower)
|
||||||
}
|
}
|
||||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||||
|
@ -84,14 +85,15 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1beta1.Proposal) (passes b
|
||||||
votingPower := sharesAfterDeductions.MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
votingPower := sharesAfterDeductions.MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
||||||
|
|
||||||
for _, option := range val.Vote {
|
for _, option := range val.Vote {
|
||||||
subPower := votingPower.Mul(option.Weight)
|
weight, _ := sdk.NewDecFromStr(option.Weight)
|
||||||
|
subPower := votingPower.Mul(weight)
|
||||||
results[option.Option] = results[option.Option].Add(subPower)
|
results[option.Option] = results[option.Option].Add(subPower)
|
||||||
}
|
}
|
||||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||||
}
|
}
|
||||||
|
|
||||||
tallyParams := keeper.GetTallyParams(ctx)
|
tallyParams := keeper.GetTallyParams(ctx)
|
||||||
tallyResults = v1beta1.NewTallyResultFromMap(results)
|
tallyResults = v1beta2.NewTallyResultFromMap(results)
|
||||||
|
|
||||||
// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
|
// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
|
||||||
// If there is no staked coins, the proposal fails
|
// If there is no staked coins, the proposal fails
|
||||||
|
@ -101,22 +103,25 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1beta1.Proposal) (passes b
|
||||||
|
|
||||||
// If there is not enough quorum of votes, the proposal fails
|
// If there is not enough quorum of votes, the proposal fails
|
||||||
percentVoting := totalVotingPower.Quo(keeper.sk.TotalBondedTokens(ctx).ToDec())
|
percentVoting := totalVotingPower.Quo(keeper.sk.TotalBondedTokens(ctx).ToDec())
|
||||||
if percentVoting.LT(tallyParams.Quorum) {
|
quorum, _ := sdk.NewDecFromStr(tallyParams.Quorum)
|
||||||
|
if percentVoting.LT(quorum) {
|
||||||
return false, true, tallyResults
|
return false, true, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no one votes (everyone abstains), proposal fails
|
// If no one votes (everyone abstains), proposal fails
|
||||||
if totalVotingPower.Sub(results[v1beta1.OptionAbstain]).Equal(sdk.ZeroDec()) {
|
if totalVotingPower.Sub(results[v1beta2.OptionAbstain]).Equal(sdk.ZeroDec()) {
|
||||||
return false, false, tallyResults
|
return false, false, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1/3 of voters veto, proposal fails
|
// If more than 1/3 of voters veto, proposal fails
|
||||||
if results[v1beta1.OptionNoWithVeto].Quo(totalVotingPower).GT(tallyParams.VetoThreshold) {
|
vetoThreshold, _ := sdk.NewDecFromStr(tallyParams.VetoThreshold)
|
||||||
|
if results[v1beta2.OptionNoWithVeto].Quo(totalVotingPower).GT(vetoThreshold) {
|
||||||
return false, true, tallyResults
|
return false, true, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
|
// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
|
||||||
if results[v1beta1.OptionYes].Quo(totalVotingPower.Sub(results[v1beta1.OptionAbstain])).GT(tallyParams.Threshold) {
|
threshold, _ := sdk.NewDecFromStr(tallyParams.Threshold)
|
||||||
|
if results[v1beta2.OptionYes].Quo(totalVotingPower.Sub(results[v1beta2.OptionAbstain])).GT(threshold) {
|
||||||
return true, false, tallyResults
|
return true, false, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ func TestTallyNoOneVotes(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
|
@ -32,7 +32,7 @@ func TestTallyNoOneVotes(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.True(t, burnDeposits)
|
require.True(t, burnDeposits)
|
||||||
require.True(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.True(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyNoQuorum(t *testing.T) {
|
func TestTallyNoQuorum(t *testing.T) {
|
||||||
|
@ -47,10 +47,10 @@ func TestTallyNoQuorum(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
err = app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
err = app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
|
@ -70,12 +70,12 @@ func TestTallyOnlyValidatorsAllYes(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -83,7 +83,7 @@ func TestTallyOnlyValidatorsAllYes(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, passes)
|
require.True(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyOnlyValidators51No(t *testing.T) {
|
func TestTallyOnlyValidators51No(t *testing.T) {
|
||||||
|
@ -96,11 +96,11 @@ func TestTallyOnlyValidators51No(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -120,11 +120,11 @@ func TestTallyOnlyValidators51Yes(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -132,7 +132,7 @@ func TestTallyOnlyValidators51Yes(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, passes)
|
require.True(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
||||||
|
@ -145,12 +145,12 @@ func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNoWithVeto)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNoWithVeto)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -158,7 +158,7 @@ func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.True(t, burnDeposits)
|
require.True(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
||||||
|
@ -171,12 +171,12 @@ func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -184,7 +184,7 @@ func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, passes)
|
require.True(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
||||||
|
@ -197,12 +197,12 @@ func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -210,7 +210,7 @@ func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
||||||
|
@ -224,11 +224,11 @@ func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr1, v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr2, v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr2, v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -236,7 +236,7 @@ func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyDelgatorOverride(t *testing.T) {
|
func TestTallyDelgatorOverride(t *testing.T) {
|
||||||
|
@ -258,13 +258,13 @@ func TestTallyDelgatorOverride(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[4], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[4], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -272,7 +272,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyDelgatorInherit(t *testing.T) {
|
func TestTallyDelgatorInherit(t *testing.T) {
|
||||||
|
@ -294,12 +294,12 @@ func TestTallyDelgatorInherit(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -307,7 +307,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, passes)
|
require.True(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||||
|
@ -333,13 +333,13 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -347,7 +347,7 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||||
|
@ -375,12 +375,12 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -388,7 +388,7 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||||
|
|
||||||
require.False(t, passes)
|
require.False(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyJailedValidator(t *testing.T) {
|
func TestTallyJailedValidator(t *testing.T) {
|
||||||
|
@ -418,12 +418,12 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -431,7 +431,7 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, passes)
|
require.True(t, passes)
|
||||||
require.False(t, burnDeposits)
|
require.False(t, burnDeposits)
|
||||||
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
require.False(t, tallyResults.Equals(v1beta2.EmptyTallyResult()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
||||||
|
@ -451,12 +451,12 @@ func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
||||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.NewNonSplitVoteOption(v1beta2.OptionNo)))
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
|
|
||||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
@ -469,7 +469,7 @@ func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
||||||
expectedAbstain := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
expectedAbstain := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
||||||
expectedNo := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
expectedNo := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
||||||
expectedNoWithVeto := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
expectedNoWithVeto := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
||||||
expectedTallyResult := v1beta1.NewTallyResult(expectedYes, expectedAbstain, expectedNo, expectedNoWithVeto)
|
expectedTallyResult := v1beta2.NewTallyResult(expectedYes, expectedAbstain, expectedNo, expectedNoWithVeto)
|
||||||
|
|
||||||
require.True(t, tallyResults.Equals(expectedTallyResult))
|
require.True(t, tallyResults.Equals(expectedTallyResult))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,26 +6,26 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddVote adds a vote on a specific proposal
|
// AddVote adds a vote on a specific proposal
|
||||||
func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress, options v1beta1.WeightedVoteOptions) error {
|
func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress, options v1beta2.WeightedVoteOptions) error {
|
||||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return sdkerrors.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
return sdkerrors.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
||||||
}
|
}
|
||||||
if proposal.Status != v1beta1.StatusVotingPeriod {
|
if proposal.Status != v1beta2.StatusVotingPeriod {
|
||||||
return sdkerrors.Wrapf(types.ErrInactiveProposal, "%d", proposalID)
|
return sdkerrors.Wrapf(types.ErrInactiveProposal, "%d", proposalID)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if !v1beta1.ValidWeightedVoteOption(option) {
|
if !v1beta2.ValidWeightedVoteOption(*option) {
|
||||||
return sdkerrors.Wrap(v1beta1.ErrInvalidVote, option.String())
|
return sdkerrors.Wrap(types.ErrInvalidVote, option.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vote := v1beta1.NewVote(proposalID, voterAddr, options)
|
vote := v1beta2.NewVote(proposalID, voterAddr, options)
|
||||||
keeper.SetVote(ctx, vote)
|
keeper.SetVote(ctx, vote)
|
||||||
|
|
||||||
// called after a vote on a proposal is cast
|
// called after a vote on a proposal is cast
|
||||||
|
@ -43,27 +43,27 @@ func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllVotes returns all the votes from the store
|
// GetAllVotes returns all the votes from the store
|
||||||
func (keeper Keeper) GetAllVotes(ctx sdk.Context) (votes v1beta1.Votes) {
|
func (keeper Keeper) GetAllVotes(ctx sdk.Context) (votes v1beta2.Votes) {
|
||||||
keeper.IterateAllVotes(ctx, func(vote v1beta1.Vote) bool {
|
keeper.IterateAllVotes(ctx, func(vote v1beta2.Vote) bool {
|
||||||
populateLegacyOption(&vote)
|
populateLegacyOption(&vote)
|
||||||
votes = append(votes, vote)
|
votes = append(votes, &vote)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVotes returns all the votes from a proposal
|
// GetVotes returns all the votes from a proposal
|
||||||
func (keeper Keeper) GetVotes(ctx sdk.Context, proposalID uint64) (votes v1beta1.Votes) {
|
func (keeper Keeper) GetVotes(ctx sdk.Context, proposalID uint64) (votes v1beta2.Votes) {
|
||||||
keeper.IterateVotes(ctx, proposalID, func(vote v1beta1.Vote) bool {
|
keeper.IterateVotes(ctx, proposalID, func(vote v1beta2.Vote) bool {
|
||||||
populateLegacyOption(&vote)
|
populateLegacyOption(&vote)
|
||||||
votes = append(votes, vote)
|
votes = append(votes, &vote)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVote gets the vote from an address on a specific proposal
|
// GetVote gets the vote from an address on a specific proposal
|
||||||
func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) (vote v1beta1.Vote, found bool) {
|
func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) (vote v1beta2.Vote, found bool) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
bz := store.Get(types.VoteKey(proposalID, voterAddr))
|
bz := store.Get(types.VoteKey(proposalID, voterAddr))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
|
@ -77,10 +77,10 @@ func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVote sets a Vote to the gov store
|
// SetVote sets a Vote to the gov store
|
||||||
func (keeper Keeper) SetVote(ctx sdk.Context, vote v1beta1.Vote) {
|
func (keeper Keeper) SetVote(ctx sdk.Context, vote v1beta2.Vote) {
|
||||||
// vote.Option is a deprecated field, we don't set it in state
|
// vote.Option is a deprecated field, we don't set it in state
|
||||||
if vote.Option != v1beta1.OptionEmpty { // nolint
|
if vote.Option != v1beta2.OptionEmpty { // nolint
|
||||||
vote.Option = v1beta1.OptionEmpty // nolint
|
vote.Option = v1beta2.OptionEmpty // nolint
|
||||||
}
|
}
|
||||||
|
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
|
@ -93,13 +93,13 @@ func (keeper Keeper) SetVote(ctx sdk.Context, vote v1beta1.Vote) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateAllVotes iterates over the all the stored votes and performs a callback function
|
// IterateAllVotes iterates over the all the stored votes and performs a callback function
|
||||||
func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1beta1.Vote) (stop bool)) {
|
func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1beta2.Vote) (stop bool)) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.VotesKeyPrefix)
|
iterator := sdk.KVStorePrefixIterator(store, types.VotesKeyPrefix)
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var vote v1beta1.Vote
|
var vote v1beta2.Vote
|
||||||
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
|
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
|
||||||
populateLegacyOption(&vote)
|
populateLegacyOption(&vote)
|
||||||
|
|
||||||
|
@ -110,13 +110,13 @@ func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1beta1.Vote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateVotes iterates over the all the proposals votes and performs a callback function
|
// IterateVotes iterates over the all the proposals votes and performs a callback function
|
||||||
func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vote v1beta1.Vote) (stop bool)) {
|
func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vote v1beta2.Vote) (stop bool)) {
|
||||||
store := ctx.KVStore(keeper.storeKey)
|
store := ctx.KVStore(keeper.storeKey)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.VotesKey(proposalID))
|
iterator := sdk.KVStorePrefixIterator(store, types.VotesKey(proposalID))
|
||||||
|
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var vote v1beta1.Vote
|
var vote v1beta2.Vote
|
||||||
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
|
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
|
||||||
populateLegacyOption(&vote)
|
populateLegacyOption(&vote)
|
||||||
|
|
||||||
|
@ -134,8 +134,8 @@ func (keeper Keeper) deleteVote(ctx sdk.Context, proposalID uint64, voterAddr sd
|
||||||
|
|
||||||
// populateLegacyOption adds graceful fallback of deprecated `Option` field, in case
|
// populateLegacyOption adds graceful fallback of deprecated `Option` field, in case
|
||||||
// there's only 1 VoteOption.
|
// there's only 1 VoteOption.
|
||||||
func populateLegacyOption(vote *v1beta1.Vote) {
|
func populateLegacyOption(vote *v1beta2.Vote) {
|
||||||
if len(vote.Options) == 1 && vote.Options[0].Weight.Equal(sdk.MustNewDecFromStr("1.0")) {
|
if len(vote.Options) == 1 && sdk.MustNewDecFromStr(vote.Options[0].Weight).Equal(sdk.MustNewDecFromStr("1.0")) {
|
||||||
vote.Option = vote.Options[0].Option // nolint
|
vote.Option = vote.Options[0].Option // nolint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVotes(t *testing.T) {
|
func TestVotes(t *testing.T) {
|
||||||
|
@ -22,57 +22,57 @@ func TestVotes(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
proposalID := proposal.ProposalId
|
proposalID := proposal.ProposalId
|
||||||
|
|
||||||
var invalidOption v1beta1.VoteOption = 0x10
|
var invalidOption v1beta2.VoteOption = 0x10
|
||||||
|
|
||||||
require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)), "proposal not on voting period")
|
require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)), "proposal not on voting period")
|
||||||
require.Error(t, app.GovKeeper.AddVote(ctx, 10, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)), "invalid proposal ID")
|
require.Error(t, app.GovKeeper.AddVote(ctx, 10, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)), "invalid proposal ID")
|
||||||
|
|
||||||
proposal.Status = v1beta1.StatusVotingPeriod
|
proposal.Status = v1beta2.StatusVotingPeriod
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
|
||||||
require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(invalidOption)), "invalid option")
|
require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(invalidOption)), "invalid option")
|
||||||
|
|
||||||
// Test first vote
|
// Test first vote
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionAbstain)))
|
||||||
vote, found := app.GovKeeper.GetVote(ctx, proposalID, addrs[0])
|
vote, found := app.GovKeeper.GetVote(ctx, proposalID, addrs[0])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, addrs[0].String(), vote.Voter)
|
require.Equal(t, addrs[0].String(), vote.Voter)
|
||||||
require.Equal(t, proposalID, vote.ProposalId)
|
require.Equal(t, proposalID, vote.ProposalId)
|
||||||
require.True(t, len(vote.Options) == 1)
|
require.True(t, len(vote.Options) == 1)
|
||||||
require.Equal(t, v1beta1.OptionAbstain, vote.Options[0].Option)
|
require.Equal(t, v1beta2.OptionAbstain, vote.Options[0].Option)
|
||||||
require.Equal(t, v1beta1.OptionAbstain, vote.Option)
|
require.Equal(t, v1beta2.OptionAbstain, vote.Option)
|
||||||
|
|
||||||
// Test change of vote
|
// Test change of vote
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta2.NewNonSplitVoteOption(v1beta2.OptionYes)))
|
||||||
vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[0])
|
vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[0])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, addrs[0].String(), vote.Voter)
|
require.Equal(t, addrs[0].String(), vote.Voter)
|
||||||
require.Equal(t, proposalID, vote.ProposalId)
|
require.Equal(t, proposalID, vote.ProposalId)
|
||||||
require.True(t, len(vote.Options) == 1)
|
require.True(t, len(vote.Options) == 1)
|
||||||
require.Equal(t, v1beta1.OptionYes, vote.Options[0].Option)
|
require.Equal(t, v1beta2.OptionYes, vote.Options[0].Option)
|
||||||
require.Equal(t, v1beta1.OptionYes, vote.Option)
|
require.Equal(t, v1beta2.OptionYes, vote.Option)
|
||||||
|
|
||||||
// Test second vote
|
// Test second vote
|
||||||
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.WeightedVoteOptions{
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta2.WeightedVoteOptions{
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionYes, Weight: sdk.NewDecWithPrec(60, 2)},
|
v1beta2.NewWeightedVoteOption(v1beta2.OptionYes, sdk.NewDecWithPrec(60, 2)),
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNo, Weight: sdk.NewDecWithPrec(30, 2)},
|
v1beta2.NewWeightedVoteOption(v1beta2.OptionNo, sdk.NewDecWithPrec(30, 2)),
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionAbstain, Weight: sdk.NewDecWithPrec(5, 2)},
|
v1beta2.NewWeightedVoteOption(v1beta2.OptionAbstain, sdk.NewDecWithPrec(5, 2)),
|
||||||
v1beta1.WeightedVoteOption{Option: v1beta1.OptionNoWithVeto, Weight: sdk.NewDecWithPrec(5, 2)},
|
v1beta2.NewWeightedVoteOption(v1beta2.OptionNoWithVeto, sdk.NewDecWithPrec(5, 2)),
|
||||||
}))
|
}))
|
||||||
vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[1])
|
vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[1])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, addrs[1].String(), vote.Voter)
|
require.Equal(t, addrs[1].String(), vote.Voter)
|
||||||
require.Equal(t, proposalID, vote.ProposalId)
|
require.Equal(t, proposalID, vote.ProposalId)
|
||||||
require.True(t, len(vote.Options) == 4)
|
require.True(t, len(vote.Options) == 4)
|
||||||
require.Equal(t, v1beta1.OptionYes, vote.Options[0].Option)
|
require.Equal(t, v1beta2.OptionYes, vote.Options[0].Option)
|
||||||
require.Equal(t, v1beta1.OptionNo, vote.Options[1].Option)
|
require.Equal(t, v1beta2.OptionNo, vote.Options[1].Option)
|
||||||
require.Equal(t, v1beta1.OptionAbstain, vote.Options[2].Option)
|
require.Equal(t, v1beta2.OptionAbstain, vote.Options[2].Option)
|
||||||
require.Equal(t, v1beta1.OptionNoWithVeto, vote.Options[3].Option)
|
require.Equal(t, v1beta2.OptionNoWithVeto, vote.Options[3].Option)
|
||||||
require.True(t, vote.Options[0].Weight.Equal(sdk.NewDecWithPrec(60, 2)))
|
require.Equal(t, vote.Options[0].Weight, sdk.NewDecWithPrec(60, 2).String())
|
||||||
require.True(t, vote.Options[1].Weight.Equal(sdk.NewDecWithPrec(30, 2)))
|
require.Equal(t, vote.Options[1].Weight, sdk.NewDecWithPrec(30, 2).String())
|
||||||
require.True(t, vote.Options[2].Weight.Equal(sdk.NewDecWithPrec(5, 2)))
|
require.Equal(t, vote.Options[2].Weight, sdk.NewDecWithPrec(5, 2).String())
|
||||||
require.True(t, vote.Options[3].Weight.Equal(sdk.NewDecWithPrec(5, 2)))
|
require.Equal(t, vote.Options[3].Weight, sdk.NewDecWithPrec(5, 2).String())
|
||||||
require.Equal(t, v1beta1.OptionEmpty, vote.Option)
|
require.Equal(t, v1beta2.OptionEmpty, vote.Option)
|
||||||
|
|
||||||
// Test vote iterator
|
// Test vote iterator
|
||||||
// NOTE order of deposits is determined by the addresses
|
// NOTE order of deposits is determined by the addresses
|
||||||
|
@ -82,13 +82,13 @@ func TestVotes(t *testing.T) {
|
||||||
require.Equal(t, addrs[0].String(), votes[0].Voter)
|
require.Equal(t, addrs[0].String(), votes[0].Voter)
|
||||||
require.Equal(t, proposalID, votes[0].ProposalId)
|
require.Equal(t, proposalID, votes[0].ProposalId)
|
||||||
require.True(t, len(votes[0].Options) == 1)
|
require.True(t, len(votes[0].Options) == 1)
|
||||||
require.Equal(t, v1beta1.OptionYes, votes[0].Options[0].Option)
|
require.Equal(t, v1beta2.OptionYes, votes[0].Options[0].Option)
|
||||||
require.Equal(t, addrs[1].String(), votes[1].Voter)
|
require.Equal(t, addrs[1].String(), votes[1].Voter)
|
||||||
require.Equal(t, proposalID, votes[1].ProposalId)
|
require.Equal(t, proposalID, votes[1].ProposalId)
|
||||||
require.True(t, len(votes[1].Options) == 4)
|
require.True(t, len(votes[1].Options) == 4)
|
||||||
require.True(t, votes[1].Options[0].Weight.Equal(sdk.NewDecWithPrec(60, 2)))
|
require.Equal(t, votes[1].Options[0].Weight, sdk.NewDecWithPrec(60, 2).String())
|
||||||
require.True(t, votes[1].Options[1].Weight.Equal(sdk.NewDecWithPrec(30, 2)))
|
require.Equal(t, votes[1].Options[1].Weight, sdk.NewDecWithPrec(30, 2).String())
|
||||||
require.True(t, votes[1].Options[2].Weight.Equal(sdk.NewDecWithPrec(5, 2)))
|
require.Equal(t, votes[1].Options[2].Weight, sdk.NewDecWithPrec(5, 2).String())
|
||||||
require.True(t, votes[1].Options[3].Weight.Equal(sdk.NewDecWithPrec(5, 2)))
|
require.Equal(t, votes[1].Options[3].Weight, sdk.NewDecWithPrec(5, 2).String())
|
||||||
require.Equal(t, v1beta1.OptionEmpty, vote.Option)
|
require.Equal(t, v1beta2.OptionEmpty, vote.Option)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,6 +55,7 @@ func (AppModuleBasic) Name() string {
|
||||||
// RegisterLegacyAminoCodec registers the gov module's types for the given codec.
|
// RegisterLegacyAminoCodec registers the gov module's types for the given codec.
|
||||||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
v1beta1.RegisterLegacyAminoCodec(cdc)
|
v1beta1.RegisterLegacyAminoCodec(cdc)
|
||||||
|
v1beta2.RegisterLegacyAminoCodec(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultGenesis returns default genesis state as raw bytes for the gov
|
// DefaultGenesis returns default genesis state as raw bytes for the gov
|
||||||
|
@ -64,12 +66,12 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
||||||
|
|
||||||
// ValidateGenesis performs genesis state validation for the gov module.
|
// ValidateGenesis performs genesis state validation for the gov module.
|
||||||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
||||||
var data v1beta1.GenesisState
|
var data v1beta2.GenesisState
|
||||||
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return v1beta1.ValidateGenesis(&data)
|
return v1beta2.ValidateGenesis(&data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterRESTRoutes registers the REST routes for the gov module.
|
// RegisterRESTRoutes registers the REST routes for the gov module.
|
||||||
|
@ -79,6 +81,9 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro
|
||||||
|
|
||||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module.
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module.
|
||||||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||||
|
if err := v1beta2.RegisterQueryHandlerClient(context.Background(), mux, v1beta2.NewQueryClient(clientCtx)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
if err := v1beta1.RegisterQueryHandlerClient(context.Background(), mux, v1beta1.NewQueryClient(clientCtx)); err != nil {
|
if err := v1beta1.RegisterQueryHandlerClient(context.Background(), mux, v1beta1.NewQueryClient(clientCtx)); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -101,6 +106,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||||
|
|
||||||
// RegisterInterfaces implements InterfaceModule.RegisterInterfaces
|
// RegisterInterfaces implements InterfaceModule.RegisterInterfaces
|
||||||
func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||||
|
v1beta2.RegisterInterfaces(registry)
|
||||||
v1beta1.RegisterInterfaces(registry)
|
v1beta1.RegisterInterfaces(registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,8 +156,13 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
|
||||||
|
|
||||||
// RegisterServices registers module services.
|
// RegisterServices registers module services.
|
||||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||||
v1beta1.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
msgServer := keeper.NewMsgServerImpl(am.keeper)
|
||||||
v1beta1.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
v1beta1.RegisterMsgServer(cfg.MsgServer(), keeper.NewLegacyMsgServerImpl(am.accountKeeper.GetModuleAddress(types.ModuleName).String(), msgServer))
|
||||||
|
v1beta2.RegisterMsgServer(cfg.MsgServer(), msgServer)
|
||||||
|
|
||||||
|
// TODO Register v1beta1 query server.
|
||||||
|
// https://github.com/cosmos/cosmos-sdk/issues/10951
|
||||||
|
v1beta2.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||||
|
|
||||||
m := keeper.NewMigrator(am.keeper)
|
m := keeper.NewMigrator(am.keeper)
|
||||||
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
|
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
|
||||||
|
@ -163,7 +174,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||||
// InitGenesis performs genesis initialization for the gov module. It returns
|
// InitGenesis performs genesis initialization for the gov module. It returns
|
||||||
// no validator updates.
|
// no validator updates.
|
||||||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
||||||
var genesisState v1beta1.GenesisState
|
var genesisState v1beta2.GenesisState
|
||||||
cdc.MustUnmarshalJSON(data, &genesisState)
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
||||||
InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState)
|
InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState)
|
||||||
return []abci.ValidatorUpdate{}
|
return []abci.ValidatorUpdate{}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
"github.com/cosmos/cosmos-sdk/types/simulation"
|
"github.com/cosmos/cosmos-sdk/types/simulation"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,5 +107,5 @@ func RandomizedGenState(simState *module.SimulationState) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz)
|
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz)
|
||||||
simState.GenState[v1beta2.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis)
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||||
simulation.RandomizedGenState(&simState)
|
simulation.RandomizedGenState(&simState)
|
||||||
|
|
||||||
var govGenesis v1beta2.GenesisState
|
var govGenesis v1beta2.GenesisState
|
||||||
simState.Cdc.MustUnmarshalJSON(simState.GenState[v1beta2.ModuleName], &govGenesis)
|
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &govGenesis)
|
||||||
|
|
||||||
dec1, _ := sdk.NewDecFromStr("0.361000000000000000")
|
dec1, _ := sdk.NewDecFromStr("0.361000000000000000")
|
||||||
dec2, _ := sdk.NewDecFromStr("0.512000000000000000")
|
dec2, _ := sdk.NewDecFromStr("0.512000000000000000")
|
||||||
|
|
|
@ -126,21 +126,21 @@ func SimulateMsgSubmitProposal(
|
||||||
// 1) submit proposal now
|
// 1) submit proposal now
|
||||||
content := contentSim(r, ctx, accs)
|
content := contentSim(r, ctx, accs)
|
||||||
if content == nil {
|
if content == nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgSubmitProposal, "content is nil"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgSubmitProposal, "content is nil"), nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
simAccount, _ := simtypes.RandomAcc(r, accs)
|
simAccount, _ := simtypes.RandomAcc(r, accs)
|
||||||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address)
|
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address)
|
||||||
switch {
|
switch {
|
||||||
case skip:
|
case skip:
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgSubmitProposal, "skip deposit"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgSubmitProposal, "skip deposit"), nil, nil
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgSubmitProposal, "unable to generate deposit"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgSubmitProposal, "unable to generate deposit"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, simAccount.Address)
|
msg, err := v1beta1.NewMsgSubmitProposal(content, deposit, simAccount.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to generate a submit proposal msg"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate a submit proposal msg"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
account := ak.GetAccount(ctx, simAccount.Address)
|
account := ak.GetAccount(ctx, simAccount.Address)
|
||||||
|
@ -151,7 +151,7 @@ func SimulateMsgSubmitProposal(
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to generate fees"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,12 +167,12 @@ func SimulateMsgSubmitProposal(
|
||||||
simAccount.PrivKey,
|
simAccount.PrivKey,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
opMsg := simtypes.NewOperationMsg(msg, true, "", nil)
|
opMsg := simtypes.NewOperationMsg(msg, true, "", nil)
|
||||||
|
@ -180,7 +180,7 @@ func SimulateMsgSubmitProposal(
|
||||||
// get the submitted proposal ID
|
// get the submitted proposal ID
|
||||||
proposalID, err := k.GetProposalID(ctx)
|
proposalID, err := k.GetProposalID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to generate proposalID"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate proposalID"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Schedule operations for votes
|
// 2) Schedule operations for votes
|
||||||
|
@ -217,15 +217,15 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
|
||||||
simAccount, _ := simtypes.RandomAcc(r, accs)
|
simAccount, _ := simtypes.RandomAcc(r, accs)
|
||||||
proposalID, ok := randomProposalID(r, k, ctx, v1beta1.StatusDepositPeriod)
|
proposalID, ok := randomProposalID(r, k, ctx, v1beta1.StatusDepositPeriod)
|
||||||
if !ok {
|
if !ok {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgDeposit, "unable to generate proposalID"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgDeposit, "unable to generate proposalID"), nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address)
|
deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address)
|
||||||
switch {
|
switch {
|
||||||
case skip:
|
case skip:
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgDeposit, "skip deposit"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgDeposit, "skip deposit"), nil, nil
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgDeposit, "unable to generate deposit"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgDeposit, "unable to generate deposit"), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := v1beta1.NewMsgDeposit(simAccount.Address, proposalID, deposit)
|
msg := v1beta1.NewMsgDeposit(simAccount.Address, proposalID, deposit)
|
||||||
|
@ -238,7 +238,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, msg.Type(), "unable to generate fees"), nil, err
|
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
SimAccount: simAccount,
|
SimAccount: simAccount,
|
||||||
AccountKeeper: ak,
|
AccountKeeper: ak,
|
||||||
ModuleName: v1beta1.ModuleName,
|
ModuleName: types.ModuleName,
|
||||||
}
|
}
|
||||||
|
|
||||||
return simulation.GenAndDeliverTx(txCtx, fees)
|
return simulation.GenAndDeliverTx(txCtx, fees)
|
||||||
|
@ -280,7 +280,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee
|
||||||
var ok bool
|
var ok bool
|
||||||
proposalID, ok = randomProposalID(r, k, ctx, v1beta1.StatusVotingPeriod)
|
proposalID, ok = randomProposalID(r, k, ctx, v1beta1.StatusVotingPeriod)
|
||||||
if !ok {
|
if !ok {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgVote, "unable to generate proposalID"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgVote, "unable to generate proposalID"), nil, nil
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
proposalID = uint64(proposalIDInt)
|
proposalID = uint64(proposalIDInt)
|
||||||
|
@ -303,7 +303,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee
|
||||||
SimAccount: simAccount,
|
SimAccount: simAccount,
|
||||||
AccountKeeper: ak,
|
AccountKeeper: ak,
|
||||||
Bankkeeper: bk,
|
Bankkeeper: bk,
|
||||||
ModuleName: v1beta1.ModuleName,
|
ModuleName: types.ModuleName,
|
||||||
CoinsSpentInMsg: spendable,
|
CoinsSpentInMsg: spendable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe
|
||||||
var ok bool
|
var ok bool
|
||||||
proposalID, ok = randomProposalID(r, k, ctx, v1beta1.StatusVotingPeriod)
|
proposalID, ok = randomProposalID(r, k, ctx, v1beta1.StatusVotingPeriod)
|
||||||
if !ok {
|
if !ok {
|
||||||
return simtypes.NoOpMsg(v1beta1.ModuleName, v1beta1.TypeMsgVoteWeighted, "unable to generate proposalID"), nil, nil
|
return simtypes.NoOpMsg(types.ModuleName, v1beta1.TypeMsgVoteWeighted, "unable to generate proposalID"), nil, nil
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
proposalID = uint64(proposalIDInt)
|
proposalID = uint64(proposalIDInt)
|
||||||
|
@ -356,7 +356,7 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe
|
||||||
SimAccount: simAccount,
|
SimAccount: simAccount,
|
||||||
AccountKeeper: ak,
|
AccountKeeper: ak,
|
||||||
Bankkeeper: bk,
|
Bankkeeper: bk,
|
||||||
ModuleName: v1beta1.ModuleName,
|
ModuleName: types.ModuleName,
|
||||||
CoinsSpentInMsg: spendable,
|
CoinsSpentInMsg: spendable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ func randomProposalID(r *rand.Rand, k keeper.Keeper,
|
||||||
}
|
}
|
||||||
|
|
||||||
proposal, ok := k.GetProposal(ctx, proposalID)
|
proposal, ok := k.GetProposal(ctx, proposalID)
|
||||||
if !ok || proposal.Status != status {
|
if !ok || v1beta1.ProposalStatus(proposal.Status) != status {
|
||||||
return proposalID, false
|
return proposalID, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@ import (
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,12 +78,12 @@ func TestWeightedOperations(t *testing.T) {
|
||||||
opMsgRoute string
|
opMsgRoute string
|
||||||
opMsgName string
|
opMsgName string
|
||||||
}{
|
}{
|
||||||
{0, v1beta1.ModuleName, "submit_proposal"},
|
{0, types.ModuleName, "submit_proposal"},
|
||||||
{1, v1beta1.ModuleName, "submit_proposal"},
|
{1, types.ModuleName, "submit_proposal"},
|
||||||
{2, v1beta1.ModuleName, "submit_proposal"},
|
{2, types.ModuleName, "submit_proposal"},
|
||||||
{simappparams.DefaultWeightMsgDeposit, v1beta1.ModuleName, v1beta1.TypeMsgDeposit},
|
{simappparams.DefaultWeightMsgDeposit, types.ModuleName, v1beta1.TypeMsgDeposit},
|
||||||
{simappparams.DefaultWeightMsgVote, v1beta1.ModuleName, v1beta1.TypeMsgVote},
|
{simappparams.DefaultWeightMsgVote, types.ModuleName, v1beta1.TypeMsgVote},
|
||||||
{simappparams.DefaultWeightMsgVoteWeighted, v1beta1.ModuleName, v1beta1.TypeMsgVoteWeighted},
|
{simappparams.DefaultWeightMsgVoteWeighted, types.ModuleName, v1beta1.TypeMsgVoteWeighted},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, w := range weightesOps {
|
for i, w := range weightesOps {
|
||||||
|
@ -114,7 +116,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var msg v1beta1.MsgSubmitProposal
|
var msg v1beta1.MsgSubmitProposal
|
||||||
v1beta1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(t, operationMsg.OK)
|
require.True(t, operationMsg.OK)
|
||||||
require.Equal(t, "cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.Proposer)
|
require.Equal(t, "cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.Proposer)
|
||||||
|
@ -139,11 +141,13 @@ func TestSimulateMsgDeposit(t *testing.T) {
|
||||||
|
|
||||||
// setup a proposal
|
// setup a proposal
|
||||||
content := v1beta1.NewTextProposal("Test", "description")
|
content := v1beta1.NewTextProposal("Test", "description")
|
||||||
|
contentMsg, err := v1beta2.NewLegacyContent(content, app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
submitTime := ctx.BlockHeader().Time
|
submitTime := ctx.BlockHeader().Time
|
||||||
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
||||||
|
|
||||||
proposal, err := v1beta1.NewProposal(content, 1, submitTime, submitTime.Add(depositPeriod))
|
proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
app.GovKeeper.SetProposal(ctx, proposal)
|
app.GovKeeper.SetProposal(ctx, proposal)
|
||||||
|
@ -157,7 +161,7 @@ func TestSimulateMsgDeposit(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var msg v1beta1.MsgDeposit
|
var msg v1beta1.MsgDeposit
|
||||||
v1beta1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(t, operationMsg.OK)
|
require.True(t, operationMsg.OK)
|
||||||
require.Equal(t, uint64(1), msg.ProposalId)
|
require.Equal(t, uint64(1), msg.ProposalId)
|
||||||
|
@ -180,12 +184,14 @@ func TestSimulateMsgVote(t *testing.T) {
|
||||||
accounts := getTestingAccounts(t, r, app, ctx, 3)
|
accounts := getTestingAccounts(t, r, app, ctx, 3)
|
||||||
|
|
||||||
// setup a proposal
|
// setup a proposal
|
||||||
content := v1beta1.NewTextProposal("Test", "description")
|
govAcc := app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String()
|
||||||
|
contentMsg, err := v1beta2.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), govAcc)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
submitTime := ctx.BlockHeader().Time
|
submitTime := ctx.BlockHeader().Time
|
||||||
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
||||||
|
|
||||||
proposal, err := v1beta1.NewProposal(content, 1, submitTime, submitTime.Add(depositPeriod))
|
proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
|
@ -199,7 +205,7 @@ func TestSimulateMsgVote(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var msg v1beta1.MsgVote
|
var msg v1beta1.MsgVote
|
||||||
v1beta1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(t, operationMsg.OK)
|
require.True(t, operationMsg.OK)
|
||||||
require.Equal(t, uint64(1), msg.ProposalId)
|
require.Equal(t, uint64(1), msg.ProposalId)
|
||||||
|
@ -222,12 +228,13 @@ func TestSimulateMsgVoteWeighted(t *testing.T) {
|
||||||
accounts := getTestingAccounts(t, r, app, ctx, 3)
|
accounts := getTestingAccounts(t, r, app, ctx, 3)
|
||||||
|
|
||||||
// setup a proposal
|
// setup a proposal
|
||||||
content := v1beta1.NewTextProposal("Test", "description")
|
govAcc := app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String()
|
||||||
|
contentMsg, err := v1beta2.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), govAcc)
|
||||||
|
require.NoError(t, err)
|
||||||
submitTime := ctx.BlockHeader().Time
|
submitTime := ctx.BlockHeader().Time
|
||||||
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod
|
||||||
|
|
||||||
proposal, err := v1beta1.NewProposal(content, 1, submitTime, submitTime.Add(depositPeriod))
|
proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
|
@ -241,7 +248,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var msg v1beta1.MsgVoteWeighted
|
var msg v1beta1.MsgVoteWeighted
|
||||||
v1beta1.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
||||||
|
|
||||||
require.True(t, operationMsg.OK)
|
require.True(t, operationMsg.OK)
|
||||||
require.Equal(t, uint64(1), msg.ProposalId)
|
require.Equal(t, uint64(1), msg.ProposalId)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
amino = codec.NewLegacyAmino()
|
||||||
|
|
||||||
|
// ModuleCdc references the global x/gov module codec. Note, the codec should
|
||||||
|
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
||||||
|
// still used for that purpose.
|
||||||
|
//
|
||||||
|
// The actual codec used for serialization should be provided to x/gov and
|
||||||
|
// defined at the application level.
|
||||||
|
ModuleCdc = codec.NewAminoCodec(amino)
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cryptocodec.RegisterCrypto(amino)
|
||||||
|
|
||||||
|
// v1beta1 and v1beta2 will each add their own Amino registrations inside
|
||||||
|
// their init() functions.
|
||||||
|
}
|
|
@ -9,8 +9,10 @@ var (
|
||||||
ErrUnknownProposal = sdkerrors.Register(ModuleName, 2, "unknown proposal")
|
ErrUnknownProposal = sdkerrors.Register(ModuleName, 2, "unknown proposal")
|
||||||
ErrInactiveProposal = sdkerrors.Register(ModuleName, 3, "inactive proposal")
|
ErrInactiveProposal = sdkerrors.Register(ModuleName, 3, "inactive proposal")
|
||||||
ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 4, "proposal already active")
|
ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 4, "proposal already active")
|
||||||
// Errors 5 & 6 are reserved as legacy errors
|
// Errors 5 & 6 are legacy errors related to v1beta1.Proposal.
|
||||||
// See x/gov/types/v1beta1/errors.go
|
ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 5, "invalid proposal content")
|
||||||
|
ErrInvalidProposalType = sdkerrors.Register(ModuleName, 6, "invalid proposal type")
|
||||||
|
ErrInvalidVote = sdkerrors.Register(ModuleName, 7, "invalid vote option")
|
||||||
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 8, "invalid genesis state")
|
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 8, "invalid genesis state")
|
||||||
ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 9, "no handler exists for proposal type")
|
ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 9, "no handler exists for proposal type")
|
||||||
ErrUnroutableProposalMsg = sdkerrors.Register(ModuleName, 10, "proposal message not recognized by router")
|
ErrUnroutableProposalMsg = sdkerrors.Register(ModuleName, 10, "proposal message not recognized by router")
|
||||||
|
@ -18,5 +20,4 @@ var (
|
||||||
ErrInvalidProposalMsg = sdkerrors.Register(ModuleName, 12, "invalid proposal message")
|
ErrInvalidProposalMsg = sdkerrors.Register(ModuleName, 12, "invalid proposal message")
|
||||||
ErrInvalidSigner = sdkerrors.Register(ModuleName, 13, "expected gov account as only signer for proposal message")
|
ErrInvalidSigner = sdkerrors.Register(ModuleName, 13, "expected gov account as only signer for proposal message")
|
||||||
ErrInvalidSignalMsg = sdkerrors.Register(ModuleName, 14, "signal message is invalid")
|
ErrInvalidSignalMsg = sdkerrors.Register(ModuleName, 14, "signal message is invalid")
|
||||||
ErrInvalidVote = sdkerrors.Register(ModuleName, 15, "invalid vote option")
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,7 @@ const (
|
||||||
AttributeKeyProposalResult = "proposal_result"
|
AttributeKeyProposalResult = "proposal_result"
|
||||||
AttributeKeyOption = "option"
|
AttributeKeyOption = "option"
|
||||||
AttributeKeyProposalID = "proposal_id"
|
AttributeKeyProposalID = "proposal_id"
|
||||||
|
AttributeKeyProposalMessages = "proposal_messages" // Msg type_urls in the proposal
|
||||||
AttributeKeyVotingPeriodStart = "voting_period_start"
|
AttributeKeyVotingPeriodStart = "voting_period_start"
|
||||||
AttributeValueCategory = "governance"
|
AttributeValueCategory = "governance"
|
||||||
AttributeValueProposalDropped = "proposal_dropped" // didn't meet min deposit
|
AttributeValueProposalDropped = "proposal_dropped" // didn't meet min deposit
|
||||||
|
|
|
@ -2,10 +2,10 @@ package v1beta1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
|
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
|
||||||
|
@ -19,7 +19,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil)
|
cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||||
registry.RegisterImplementations((*sdk.Msg)(nil),
|
registry.RegisterImplementations((*sdk.Msg)(nil),
|
||||||
&MsgSubmitProposal{},
|
&MsgSubmitProposal{},
|
||||||
&MsgVote{},
|
&MsgVote{},
|
||||||
|
@ -42,22 +42,9 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||||
// NOTE: This should only be used for applications that are still using a concrete
|
// NOTE: This should only be used for applications that are still using a concrete
|
||||||
// Amino codec for serialization.
|
// Amino codec for serialization.
|
||||||
func RegisterProposalTypeCodec(o interface{}, name string) {
|
func RegisterProposalTypeCodec(o interface{}, name string) {
|
||||||
amino.RegisterConcrete(o, name, nil)
|
types.ModuleCdc.LegacyAmino.RegisterConcrete(o, name, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
amino = codec.NewLegacyAmino()
|
|
||||||
|
|
||||||
// ModuleCdc references the global x/gov module codec. Note, the codec should
|
|
||||||
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
|
||||||
// still used for that purpose.
|
|
||||||
//
|
|
||||||
// The actual codec used for serialization should be provided to x/gov and
|
|
||||||
// defined at the application level.
|
|
||||||
ModuleCdc = codec.NewAminoCodec(amino)
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterLegacyAminoCodec(amino)
|
RegisterLegacyAminoCodec(types.ModuleCdc.LegacyAmino)
|
||||||
cryptocodec.RegisterCrypto(amino)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,6 @@ package v1beta1
|
||||||
|
|
||||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
// Copied over from /x/gov/types/keys.go to avoid circular imports
|
|
||||||
const (
|
|
||||||
ModuleName = "gov"
|
|
||||||
|
|
||||||
RouterKey = ModuleName
|
|
||||||
)
|
|
||||||
|
|
||||||
// Content defines an interface that a proposal must implement. It contains
|
// Content defines an interface that a proposal must implement. It contains
|
||||||
// information such as the title and description along with the type and routing
|
// information such as the title and description along with the type and routing
|
||||||
// information for the appropriate handler to process the proposal. Content can
|
// information for the appropriate handler to process the proposal. Content can
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package v1beta1
|
|
||||||
|
|
||||||
import (
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Deprecated
|
|
||||||
ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 5, "invalid proposal content")
|
|
||||||
// Deprecated
|
|
||||||
ErrInvalidProposalType = sdkerrors.Register(ModuleName, 6, "invalid proposal type")
|
|
||||||
ErrInvalidVote = sdkerrors.Register(ModuleName, 7, "invalid vote option")
|
|
||||||
)
|
|
|
@ -3,13 +3,13 @@ package v1beta1
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gogo/protobuf/proto"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Governance message types and routes
|
// Governance message types and routes
|
||||||
|
@ -22,7 +22,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}
|
_, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}
|
||||||
_ types.UnpackInterfacesMessage = &MsgSubmitProposal{}
|
_ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgSubmitProposal creates a new MsgSubmitProposal.
|
// NewMsgSubmitProposal creates a new MsgSubmitProposal.
|
||||||
|
@ -67,7 +67,7 @@ func (m *MsgSubmitProposal) SetContent(content Content) error {
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("can't proto marshal %T", msg)
|
return fmt.Errorf("can't proto marshal %T", msg)
|
||||||
}
|
}
|
||||||
any, err := types.NewAnyWithValue(msg)
|
any, err := codectypes.NewAnyWithValue(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (m *MsgSubmitProposal) SetContent(content Content) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (m MsgSubmitProposal) Route() string { return RouterKey }
|
func (m MsgSubmitProposal) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }
|
func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }
|
||||||
|
@ -95,10 +95,10 @@ func (m MsgSubmitProposal) ValidateBasic() error {
|
||||||
|
|
||||||
content := m.GetContent()
|
content := m.GetContent()
|
||||||
if content == nil {
|
if content == nil {
|
||||||
return sdkerrors.Wrap(ErrInvalidProposalContent, "missing content")
|
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "missing content")
|
||||||
}
|
}
|
||||||
if !IsValidProposalType(content.ProposalType()) {
|
if !IsValidProposalType(content.ProposalType()) {
|
||||||
return sdkerrors.Wrap(ErrInvalidProposalType, content.ProposalType())
|
return sdkerrors.Wrap(types.ErrInvalidProposalType, content.ProposalType())
|
||||||
}
|
}
|
||||||
if err := content.ValidateBasic(); err != nil {
|
if err := content.ValidateBasic(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -109,7 +109,7 @@ func (m MsgSubmitProposal) ValidateBasic() error {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (m MsgSubmitProposal) GetSignBytes() []byte {
|
func (m MsgSubmitProposal) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&m)
|
bz := types.ModuleCdc.MustMarshalJSON(&m)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ func (m MsgSubmitProposal) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||||
var content Content
|
var content Content
|
||||||
return unpacker.UnpackAny(m.Content, &content)
|
return unpacker.UnpackAny(m.Content, &content)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgDeposit) Route() string { return RouterKey }
|
func (msg MsgDeposit) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgDeposit) Type() string { return TypeMsgDeposit }
|
func (msg MsgDeposit) Type() string { return TypeMsgDeposit }
|
||||||
|
@ -166,7 +166,7 @@ func (msg MsgDeposit) String() string {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgDeposit) GetSignBytes() []byte {
|
func (msg MsgDeposit) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) *Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgVote) Route() string { return RouterKey }
|
func (msg MsgVote) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgVote) Type() string { return TypeMsgVote }
|
func (msg MsgVote) Type() string { return TypeMsgVote }
|
||||||
|
@ -194,7 +194,7 @@ func (msg MsgVote) ValidateBasic() error {
|
||||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid voter address: %s", err)
|
return sdkerrors.ErrInvalidAddress.Wrapf("invalid voter address: %s", err)
|
||||||
}
|
}
|
||||||
if !ValidVoteOption(msg.Option) {
|
if !ValidVoteOption(msg.Option) {
|
||||||
return sdkerrors.Wrap(ErrInvalidVote, msg.Option.String())
|
return sdkerrors.Wrap(types.ErrInvalidVote, msg.Option.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -208,7 +208,7 @@ func (msg MsgVote) String() string {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgVote) GetSignBytes() []byte {
|
func (msg MsgVote) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgVoteWeighted) Route() string { return RouterKey }
|
func (msg MsgVoteWeighted) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted }
|
func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted }
|
||||||
|
@ -243,21 +243,21 @@ func (msg MsgVoteWeighted) ValidateBasic() error {
|
||||||
usedOptions := make(map[VoteOption]bool)
|
usedOptions := make(map[VoteOption]bool)
|
||||||
for _, option := range msg.Options {
|
for _, option := range msg.Options {
|
||||||
if !ValidWeightedVoteOption(option) {
|
if !ValidWeightedVoteOption(option) {
|
||||||
return sdkerrors.Wrap(ErrInvalidVote, option.String())
|
return sdkerrors.Wrap(types.ErrInvalidVote, option.String())
|
||||||
}
|
}
|
||||||
totalWeight = totalWeight.Add(option.Weight)
|
totalWeight = totalWeight.Add(option.Weight)
|
||||||
if usedOptions[option.Option] {
|
if usedOptions[option.Option] {
|
||||||
return sdkerrors.Wrap(ErrInvalidVote, "Duplicated vote option")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Duplicated vote option")
|
||||||
}
|
}
|
||||||
usedOptions[option.Option] = true
|
usedOptions[option.Option] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalWeight.GT(sdk.NewDec(1)) {
|
if totalWeight.GT(sdk.NewDec(1)) {
|
||||||
return sdkerrors.Wrap(ErrInvalidVote, "Total weight overflow 1.00")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight overflow 1.00")
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalWeight.LT(sdk.NewDec(1)) {
|
if totalWeight.LT(sdk.NewDec(1)) {
|
||||||
return sdkerrors.Wrap(ErrInvalidVote, "Total weight lower than 1.00")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight lower than 1.00")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -271,7 +271,7 @@ func (msg MsgVoteWeighted) String() string {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgVoteWeighted) GetSignBytes() []byte {
|
func (msg MsgVoteWeighted) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default period for deposits & voting
|
// Default period for deposits & voting
|
||||||
|
@ -23,22 +22,6 @@ var (
|
||||||
DefaultVetoThreshold = sdk.NewDecWithPrec(334, 3)
|
DefaultVetoThreshold = sdk.NewDecWithPrec(334, 3)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parameter store key
|
|
||||||
var (
|
|
||||||
ParamStoreKeyDepositParams = []byte("depositparams")
|
|
||||||
ParamStoreKeyVotingParams = []byte("votingparams")
|
|
||||||
ParamStoreKeyTallyParams = []byte("tallyparams")
|
|
||||||
)
|
|
||||||
|
|
||||||
// ParamKeyTable - Key declaration for parameters
|
|
||||||
func ParamKeyTable() paramtypes.KeyTable {
|
|
||||||
return paramtypes.NewKeyTable(
|
|
||||||
paramtypes.NewParamSetPair(ParamStoreKeyDepositParams, DepositParams{}, validateDepositParams),
|
|
||||||
paramtypes.NewParamSetPair(ParamStoreKeyVotingParams, VotingParams{}, validateVotingParams),
|
|
||||||
paramtypes.NewParamSetPair(ParamStoreKeyTallyParams, TallyParams{}, validateTallyParams),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDepositParams creates a new DepositParams object
|
// NewDepositParams creates a new DepositParams object
|
||||||
func NewDepositParams(minDeposit sdk.Coins, maxDepositPeriod time.Duration) DepositParams {
|
func NewDepositParams(minDeposit sdk.Coins, maxDepositPeriod time.Duration) DepositParams {
|
||||||
return DepositParams{
|
return DepositParams{
|
||||||
|
|
|
@ -8,9 +8,10 @@ import (
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultStartingProposalID is 1
|
// DefaultStartingProposalID is 1
|
||||||
|
@ -22,7 +23,7 @@ func NewProposal(content Content, id uint64, submitTime, depositEndTime time.Tim
|
||||||
return Proposal{}, fmt.Errorf("%T does not implement proto.Message", content)
|
return Proposal{}, fmt.Errorf("%T does not implement proto.Message", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
any, err := types.NewAnyWithValue(msg)
|
any, err := codectypes.NewAnyWithValue(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proposal{}, err
|
return Proposal{}, err
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,7 @@ func (p Proposal) GetTitle() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
func (p Proposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
func (p Proposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||||
var content Content
|
var content Content
|
||||||
return unpacker.UnpackAny(p.Content, &content)
|
return unpacker.UnpackAny(p.Content, &content)
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,7 @@ func (p Proposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
||||||
// Proposals is an array of proposal
|
// Proposals is an array of proposal
|
||||||
type Proposals []Proposal
|
type Proposals []Proposal
|
||||||
|
|
||||||
var _ types.UnpackInterfacesMessage = Proposals{}
|
var _ codectypes.UnpackInterfacesMessage = Proposals{}
|
||||||
|
|
||||||
// Equal returns true if two slices (order-dependant) of proposals are equal.
|
// Equal returns true if two slices (order-dependant) of proposals are equal.
|
||||||
func (p Proposals) Equal(other Proposals) bool {
|
func (p Proposals) Equal(other Proposals) bool {
|
||||||
|
@ -117,7 +118,7 @@ func (p Proposals) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
func (p Proposals) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
func (p Proposals) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||||
for _, x := range p {
|
for _, x := range p {
|
||||||
err := x.UnpackInterfaces(unpacker)
|
err := x.UnpackInterfaces(unpacker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -183,7 +184,7 @@ func (tp *TextProposal) GetTitle() string { return tp.Title }
|
||||||
func (tp *TextProposal) GetDescription() string { return tp.Description }
|
func (tp *TextProposal) GetDescription() string { return tp.Description }
|
||||||
|
|
||||||
// ProposalRoute returns the proposal router key
|
// ProposalRoute returns the proposal router key
|
||||||
func (tp *TextProposal) ProposalRoute() string { return RouterKey }
|
func (tp *TextProposal) ProposalRoute() string { return types.RouterKey }
|
||||||
|
|
||||||
// ProposalType is "Text"
|
// ProposalType is "Text"
|
||||||
func (tp *TextProposal) ProposalType() string { return ProposalTypeText }
|
func (tp *TextProposal) ProposalType() string { return ProposalTypeText }
|
||||||
|
@ -213,18 +214,18 @@ func ValidProposalStatus(status ProposalStatus) bool {
|
||||||
func ValidateAbstract(c Content) error {
|
func ValidateAbstract(c Content) error {
|
||||||
title := c.GetTitle()
|
title := c.GetTitle()
|
||||||
if len(strings.TrimSpace(title)) == 0 {
|
if len(strings.TrimSpace(title)) == 0 {
|
||||||
return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal title cannot be blank")
|
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal title cannot be blank")
|
||||||
}
|
}
|
||||||
if len(title) > MaxTitleLength {
|
if len(title) > MaxTitleLength {
|
||||||
return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength)
|
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
description := c.GetDescription()
|
description := c.GetDescription()
|
||||||
if len(description) == 0 {
|
if len(description) == 0 {
|
||||||
return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal description cannot be blank")
|
return sdkerrors.Wrap(types.ErrInvalidProposalContent, "proposal description cannot be blank")
|
||||||
}
|
}
|
||||||
if len(description) > MaxDescriptionLength {
|
if len(description) > MaxDescriptionLength {
|
||||||
return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength)
|
return sdkerrors.Wrapf(types.ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,55 +2,34 @@ package v1beta2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
|
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the
|
||||||
// governance module.
|
// governance module.
|
||||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
|
cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/v1beta2/MsgSubmitProposal", nil)
|
||||||
cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
|
cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/v1beta2/MsgDeposit", nil)
|
||||||
cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/MsgVote", nil)
|
cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/v1beta2/MsgVote", nil)
|
||||||
cdc.RegisterConcrete(&MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted", nil)
|
cdc.RegisterConcrete(&MsgVoteWeighted{}, "cosmos-sdk/v1beta2/MsgVoteWeighted", nil)
|
||||||
|
cdc.RegisterConcrete(&MsgExecLegacyContent{}, "cosmos-sdk/v1beta2/MsgExecLegacyContent", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||||
registry.RegisterImplementations((*sdk.Msg)(nil),
|
registry.RegisterImplementations((*sdk.Msg)(nil),
|
||||||
&MsgSubmitProposal{},
|
&MsgSubmitProposal{},
|
||||||
&MsgVote{},
|
&MsgVote{},
|
||||||
&MsgVoteWeighted{},
|
&MsgVoteWeighted{},
|
||||||
&MsgDeposit{},
|
&MsgDeposit{},
|
||||||
|
&MsgExecLegacyContent{},
|
||||||
)
|
)
|
||||||
|
|
||||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterProposalTypeCodec registers an external proposal content type defined
|
|
||||||
// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal
|
|
||||||
// to be correctly Amino encoded and decoded.
|
|
||||||
//
|
|
||||||
// NOTE: This should only be used for applications that are still using a concrete
|
|
||||||
// Amino codec for serialization.
|
|
||||||
func RegisterProposalTypeCodec(o interface{}, name string) {
|
|
||||||
amino.RegisterConcrete(o, name, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
amino = codec.NewLegacyAmino()
|
|
||||||
|
|
||||||
// ModuleCdc references the global x/gov module codec. Note, the codec should
|
|
||||||
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
|
||||||
// still used for that purpose.
|
|
||||||
//
|
|
||||||
// The actual codec used for serialization should be provided to x/gov and
|
|
||||||
// defined at the application level.
|
|
||||||
ModuleCdc = codec.NewAminoCodec(amino)
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterLegacyAminoCodec(amino)
|
RegisterLegacyAminoCodec(types.ModuleCdc.LegacyAmino)
|
||||||
cryptocodec.RegisterCrypto(amino)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,38 @@
|
||||||
package v1beta2
|
package v1beta2
|
||||||
|
|
||||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
// Copied over from /x/gov/types/keys.go to avoid circular imports
|
"github.com/gogo/protobuf/proto"
|
||||||
const (
|
|
||||||
ModuleName = "gov"
|
|
||||||
|
|
||||||
RouterKey = ModuleName
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Content defines an interface that a proposal must implement. It contains
|
// NewLegacyContent creates a new MsgExecLegacyContent from a legacy Content
|
||||||
// information such as the title and description along with the type and routing
|
// interface.
|
||||||
// information for the appropriate handler to process the proposal. Content can
|
func NewLegacyContent(content v1beta1.Content, authority string) (*MsgExecLegacyContent, error) {
|
||||||
// have additional fields, which will handled by a proposal's Handler.
|
msg, ok := content.(proto.Message)
|
||||||
type Content interface {
|
if !ok {
|
||||||
GetTitle() string
|
return nil, fmt.Errorf("%T does not implement proto.Message", content)
|
||||||
GetDescription() string
|
|
||||||
ProposalRoute() string
|
|
||||||
ProposalType() string
|
|
||||||
ValidateBasic() error
|
|
||||||
String() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler defines a function that handles a proposal after it has passed the
|
any, err := codectypes.NewAnyWithValue(msg)
|
||||||
// governance process.
|
if err != nil {
|
||||||
type Handler func(ctx sdk.Context, content Content) error
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewMsgExecLegacyContent(any, authority), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LegacyContentFromMessage extracts the legacy Content interface from a
|
||||||
|
// MsgExecLegacyContent.
|
||||||
|
func LegacyContentFromMessage(msg *MsgExecLegacyContent) (v1beta1.Content, error) {
|
||||||
|
content, ok := msg.Content.GetCachedValue().(v1beta1.Content)
|
||||||
|
if !ok {
|
||||||
|
return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (*v1beta1.Content)(nil), msg.Content.GetCachedValue())
|
||||||
|
}
|
||||||
|
|
||||||
|
return content, nil
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.Coins) D
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposits is a collection of Deposit objects
|
// Deposits is a collection of Deposit objects
|
||||||
type Deposits []Deposit
|
type Deposits []*Deposit
|
||||||
|
|
||||||
// Equal returns true if two slices (order-dependant) of deposits are equal.
|
// Equal returns true if two slices (order-dependant) of deposits are equal.
|
||||||
func (d Deposits) Equal(other Deposits) bool {
|
func (d Deposits) Equal(other Deposits) bool {
|
||||||
|
|
|
@ -41,15 +41,15 @@ func ValidateGenesis(data *GenesisState) error {
|
||||||
return errors.New("Starting proposal id must be greater than 0")
|
return errors.New("Starting proposal id must be greater than 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateTallyParams(data.TallyParams); err != nil {
|
if err := validateTallyParams(*data.TallyParams); err != nil {
|
||||||
return fmt.Errorf("invalid tally params: %w", err)
|
return fmt.Errorf("invalid tally params: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateVotingParams(data.VotingParams); err != nil {
|
if err := validateVotingParams(*data.VotingParams); err != nil {
|
||||||
return fmt.Errorf("invalid voting params: %w", err)
|
return fmt.Errorf("invalid voting params: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateDepositParams(data.DepositParams); err != nil {
|
if err := validateDepositParams(*data.DepositParams); err != nil {
|
||||||
return fmt.Errorf("invalid deposit params: %w", err)
|
return fmt.Errorf("invalid deposit params: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,12 @@ package v1beta2
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
|
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Governance message types and routes
|
// Governance message types and routes
|
||||||
|
@ -22,22 +21,25 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}
|
_, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}
|
||||||
_ types.UnpackInterfacesMessage = &MsgSubmitProposal{}
|
_, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgSubmitProposal creates a new MsgSubmitProposal.
|
// NewMsgSubmitProposal creates a new MsgSubmitProposal.
|
||||||
//nolint:interfacer
|
//nolint:interfacer
|
||||||
func NewMsgSubmitProposal(messages []sdk.Msg, initialDeposit sdk.Coins, proposer sdk.AccAddress) (*MsgSubmitProposal, error) {
|
func NewMsgSubmitProposal(messages []sdk.Msg, initialDeposit sdk.Coins, proposer string) (*MsgSubmitProposal, error) {
|
||||||
m := &MsgSubmitProposal{
|
m := &MsgSubmitProposal{
|
||||||
InitialDeposit: initialDeposit,
|
InitialDeposit: initialDeposit,
|
||||||
Proposer: proposer.String(),
|
Proposer: proposer,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.SetMessages(messages); err != nil {
|
anys, err := sdktx.SetMsgs(messages)
|
||||||
return &MsgSubmitProposal{}, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Messages = anys
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,34 +47,8 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) {
|
||||||
return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal")
|
return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MsgSubmitProposal) SetInitialDeposit(coins sdk.Coins) {
|
|
||||||
m.InitialDeposit = coins
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MsgSubmitProposal) SetProposer(address fmt.Stringer) {
|
|
||||||
m.Proposer = address.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MsgSubmitProposal) SetMessages(messages []sdk.Msg) error {
|
|
||||||
msgs := make([]*types.Any, len(messages))
|
|
||||||
for i, msg := range messages {
|
|
||||||
m, ok := msg.(proto.Message)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("can't proto marshal %T", msg)
|
|
||||||
}
|
|
||||||
any, err := types.NewAnyWithValue(m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msgs[i] = any
|
|
||||||
}
|
|
||||||
m.Messages = msgs
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (m MsgSubmitProposal) Route() string { return RouterKey }
|
func (m MsgSubmitProposal) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }
|
func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }
|
||||||
|
@ -105,7 +81,7 @@ func (m MsgSubmitProposal) ValidateBasic() error {
|
||||||
|
|
||||||
for idx, msg := range msgs {
|
for idx, msg := range msgs {
|
||||||
if err := msg.ValidateBasic(); err != nil {
|
if err := msg.ValidateBasic(); err != nil {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidProposalMsg,
|
return sdkerrors.Wrap(types.ErrInvalidProposalMsg,
|
||||||
fmt.Sprintf("msg: %d, err: %s", idx, err.Error()))
|
fmt.Sprintf("msg: %d, err: %s", idx, err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +91,7 @@ func (m MsgSubmitProposal) ValidateBasic() error {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (m MsgSubmitProposal) GetSignBytes() []byte {
|
func (m MsgSubmitProposal) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&m)
|
bz := types.ModuleCdc.MustMarshalJSON(&m)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +102,7 @@ func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||||
return sdktx.UnpackInterfaces(unpacker, m.Messages)
|
return sdktx.UnpackInterfaces(unpacker, m.Messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +113,7 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgDeposit) Route() string { return RouterKey }
|
func (msg MsgDeposit) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgDeposit) Type() string { return TypeMsgDeposit }
|
func (msg MsgDeposit) Type() string { return TypeMsgDeposit }
|
||||||
|
@ -160,7 +136,7 @@ func (msg MsgDeposit) ValidateBasic() error {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgDeposit) GetSignBytes() []byte {
|
func (msg MsgDeposit) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +153,7 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) *Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgVote) Route() string { return RouterKey }
|
func (msg MsgVote) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgVote) Type() string { return TypeMsgVote }
|
func (msg MsgVote) Type() string { return TypeMsgVote }
|
||||||
|
@ -188,7 +164,7 @@ func (msg MsgVote) ValidateBasic() error {
|
||||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid voter address: %s", err)
|
return sdkerrors.ErrInvalidAddress.Wrapf("invalid voter address: %s", err)
|
||||||
}
|
}
|
||||||
if !ValidVoteOption(msg.Option) {
|
if !ValidVoteOption(msg.Option) {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidVote, msg.Option.String())
|
return sdkerrors.Wrap(types.ErrInvalidVote, msg.Option.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -196,7 +172,7 @@ func (msg MsgVote) ValidateBasic() error {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgVote) GetSignBytes() []byte {
|
func (msg MsgVote) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +189,7 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route implements Msg
|
// Route implements Msg
|
||||||
func (msg MsgVoteWeighted) Route() string { return RouterKey }
|
func (msg MsgVoteWeighted) Route() string { return types.RouterKey }
|
||||||
|
|
||||||
// Type implements Msg
|
// Type implements Msg
|
||||||
func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted }
|
func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted }
|
||||||
|
@ -231,25 +207,25 @@ func (msg MsgVoteWeighted) ValidateBasic() error {
|
||||||
usedOptions := make(map[VoteOption]bool)
|
usedOptions := make(map[VoteOption]bool)
|
||||||
for _, option := range msg.Options {
|
for _, option := range msg.Options {
|
||||||
if !option.IsValid() {
|
if !option.IsValid() {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidVote, option.String())
|
return sdkerrors.Wrap(types.ErrInvalidVote, option.String())
|
||||||
}
|
}
|
||||||
weight, err := sdk.NewDecFromStr(option.Weight)
|
weight, err := sdk.NewDecFromStr(option.Weight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkerrors.Wrapf(govtypes.ErrInvalidVote, "Invalid weight: %s", err)
|
return sdkerrors.Wrapf(types.ErrInvalidVote, "Invalid weight: %s", err)
|
||||||
}
|
}
|
||||||
totalWeight = totalWeight.Add(weight)
|
totalWeight = totalWeight.Add(weight)
|
||||||
if usedOptions[option.Option] {
|
if usedOptions[option.Option] {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidVote, "Duplicated vote option")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Duplicated vote option")
|
||||||
}
|
}
|
||||||
usedOptions[option.Option] = true
|
usedOptions[option.Option] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalWeight.GT(sdk.NewDec(1)) {
|
if totalWeight.GT(sdk.NewDec(1)) {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidVote, "Total weight overflow 1.00")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight overflow 1.00")
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalWeight.LT(sdk.NewDec(1)) {
|
if totalWeight.LT(sdk.NewDec(1)) {
|
||||||
return sdkerrors.Wrap(govtypes.ErrInvalidVote, "Total weight lower than 1.00")
|
return sdkerrors.Wrap(types.ErrInvalidVote, "Total weight lower than 1.00")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -257,7 +233,7 @@ func (msg MsgVoteWeighted) ValidateBasic() error {
|
||||||
|
|
||||||
// GetSignBytes implements Msg
|
// GetSignBytes implements Msg
|
||||||
func (msg MsgVoteWeighted) GetSignBytes() []byte {
|
func (msg MsgVoteWeighted) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
bz := types.ModuleCdc.MustMarshalJSON(&msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,3 +242,30 @@ func (msg MsgVoteWeighted) GetSigners() []sdk.AccAddress {
|
||||||
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
|
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
|
||||||
return []sdk.AccAddress{voter}
|
return []sdk.AccAddress{voter}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewMsgExecLegacyContent(content *codectypes.Any, authority string) *MsgExecLegacyContent {
|
||||||
|
return &MsgExecLegacyContent{
|
||||||
|
Content: content,
|
||||||
|
Authority: authority,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress {
|
||||||
|
authority, _ := sdk.AccAddressFromBech32(c.Authority)
|
||||||
|
return []sdk.AccAddress{authority}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c MsgExecLegacyContent) ValidateBasic() error {
|
||||||
|
_, err := sdk.AccAddressFromBech32(c.Authority)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||||
|
func (m MsgExecLegacyContent) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||||
|
var content v1beta1.Content
|
||||||
|
return unpacker.UnpackAny(m.Content, &content)
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestMsgDepositGetSignBytes(t *testing.T) {
|
||||||
msg := v1beta2.NewMsgDeposit(addr, 0, coinsPos)
|
msg := v1beta2.NewMsgDeposit(addr, 0, coinsPos)
|
||||||
res := msg.GetSignBytes()
|
res := msg.GetSignBytes()
|
||||||
|
|
||||||
expected := `{"type":"cosmos-sdk/MsgDeposit","value":{"amount":[{"amount":"1000","denom":"stake"}],"depositor":"cosmos1v9jxgu33kfsgr5","proposal_id":"0"}}`
|
expected := `{"type":"cosmos-sdk/v1beta2/MsgDeposit","value":{"amount":[{"amount":"1000","denom":"stake"}],"depositor":"cosmos1v9jxgu33kfsgr5","proposal_id":"0"}}`
|
||||||
require.Equal(t, expected, string(res))
|
require.Equal(t, expected, string(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +129,12 @@ func TestMsgVoteWeighted(t *testing.T) {
|
||||||
// this tests that Amino JSON MsgSubmitProposal.GetSignBytes() still works with Content as Any using the ModuleCdc
|
// this tests that Amino JSON MsgSubmitProposal.GetSignBytes() still works with Content as Any using the ModuleCdc
|
||||||
func TestMsgSubmitProposal_GetSignBytes(t *testing.T) {
|
func TestMsgSubmitProposal_GetSignBytes(t *testing.T) {
|
||||||
proposal := []sdk.Msg{v1beta2.NewMsgVote(addrs[0], 1, v1beta2.OptionYes)}
|
proposal := []sdk.Msg{v1beta2.NewMsgVote(addrs[0], 1, v1beta2.OptionYes)}
|
||||||
msg, err := v1beta2.NewMsgSubmitProposal(proposal, sdk.NewCoins(), sdk.AccAddress{})
|
msg, err := v1beta2.NewMsgSubmitProposal(proposal, sdk.NewCoins(), sdk.AccAddress{}.String())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
var bz []byte
|
var bz []byte
|
||||||
require.NotPanics(t, func() {
|
require.NotPanics(t, func() {
|
||||||
bz = msg.GetSignBytes()
|
bz = msg.GetSignBytes()
|
||||||
})
|
})
|
||||||
require.Equal(t, "{\"type\":\"cosmos-sdk/MsgSubmitProposal\",\"value\":{\"initial_deposit\":[],\"messages\":[{\"type\":\"cosmos-sdk/MsgVote\",\"value\":{\"option\":1,\"proposal_id\":\"1\",\"voter\":\"cosmos1w3jhxap3gempvr\"}}]}}",
|
require.Equal(t, "{\"type\":\"cosmos-sdk/v1beta2/MsgSubmitProposal\",\"value\":{\"initial_deposit\":[],\"messages\":[{\"type\":\"cosmos-sdk/v1beta2/MsgVote\",\"value\":{\"option\":1,\"proposal_id\":\"1\",\"voter\":\"cosmos1w3jhxap3gempvr\"}}]}}",
|
||||||
string(bz))
|
string(bz))
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func DefaultDepositParams() DepositParams {
|
||||||
|
|
||||||
// Equal checks equality of DepositParams
|
// Equal checks equality of DepositParams
|
||||||
func (dp DepositParams) Equal(dp2 DepositParams) bool {
|
func (dp DepositParams) Equal(dp2 DepositParams) bool {
|
||||||
return sdk.NewCoins(dp.MinDeposit...).IsEqual(sdk.NewCoins(dp2.MinDeposit...)) && dp.MaxDepositPeriod == dp2.MaxDepositPeriod
|
return sdk.Coins(dp.MinDeposit).IsEqual(dp2.MinDeposit) && dp.MaxDepositPeriod == dp2.MaxDepositPeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDepositParams(i interface{}) error {
|
func validateDepositParams(i interface{}) error {
|
||||||
|
@ -65,8 +65,7 @@ func validateDepositParams(i interface{}) error {
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
minDeposit := sdk.NewCoins(v.MinDeposit...)
|
if !sdk.Coins(v.MinDeposit).IsValid() {
|
||||||
if !minDeposit.IsValid() {
|
|
||||||
return fmt.Errorf("invalid minimum deposit: %s", v.MinDeposit)
|
return fmt.Errorf("invalid minimum deposit: %s", v.MinDeposit)
|
||||||
}
|
}
|
||||||
if v.MaxDepositPeriod == nil || v.MaxDepositPeriod.Seconds() <= 0 {
|
if v.MaxDepositPeriod == nil || v.MaxDepositPeriod.Seconds() <= 0 {
|
||||||
|
|
|
@ -30,12 +30,13 @@ func NewProposal(messages []sdk.Msg, id uint64, submitTime, depositEndTime time.
|
||||||
return Proposal{}, err
|
return Proposal{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tally := EmptyTallyResult()
|
||||||
|
|
||||||
p := Proposal{
|
p := Proposal{
|
||||||
ProposalId: id,
|
ProposalId: id,
|
||||||
Messages: msgs,
|
Messages: msgs,
|
||||||
Status: StatusDepositPeriod,
|
Status: StatusDepositPeriod,
|
||||||
FinalTallyResult: EmptyTallyResult(),
|
FinalTallyResult: &tally,
|
||||||
TotalDeposit: sdk.NewCoins(),
|
|
||||||
SubmitTime: &submitTime,
|
SubmitTime: &submitTime,
|
||||||
DepositEndTime: &depositEndTime,
|
DepositEndTime: &depositEndTime,
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,7 @@ func (p Proposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proposals is an array of proposal
|
// Proposals is an array of proposal
|
||||||
type Proposals []Proposal
|
type Proposals []*Proposal
|
||||||
|
|
||||||
var _ types.UnpackInterfacesMessage = Proposals{}
|
var _ types.UnpackInterfacesMessage = Proposals{}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,13 @@ package v1beta2_test
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestProposalStatus_Format(t *testing.T) {
|
func TestProposalStatus_Format(t *testing.T) {
|
||||||
|
@ -23,3 +27,18 @@ func TestProposalStatus_Format(t *testing.T) {
|
||||||
require.Equal(t, tt.expectedStringOutput, got)
|
require.Equal(t, tt.expectedStringOutput, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestNestedAnys tests that we can call .String() on a struct with nested Anys.
|
||||||
|
// Here, we're creating a proposal which has a Msg (1st any) with a legacy
|
||||||
|
// content (2nd any).
|
||||||
|
func TestNestedAnys(t *testing.T) {
|
||||||
|
// TODO https://github.com/cosmos/cosmos-sdk/issues/10965
|
||||||
|
t.Skip()
|
||||||
|
testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal")
|
||||||
|
msgContent, err := v1beta2.NewLegacyContent(testProposal, "cosmos1govacct")
|
||||||
|
require.NoError(t, err)
|
||||||
|
proposal, err := v1beta2.NewProposal([]sdk.Msg{msgContent}, 1, time.Now(), time.Now())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, "TODO Fix panic here", proposal.String())
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ func NewValidatorGovInfo(address sdk.ValAddress, bondedTokens sdk.Int, delegator
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTallyResult creates a new TallyResult instance
|
// NewTallyResult creates a new TallyResult instance
|
||||||
func NewTallyResult(yes, abstain, no, noWithVeto sdk.Int) *TallyResult {
|
func NewTallyResult(yes, abstain, no, noWithVeto sdk.Int) TallyResult {
|
||||||
return &TallyResult{
|
return TallyResult{
|
||||||
Yes: yes.String(),
|
Yes: yes.String(),
|
||||||
Abstain: abstain.String(),
|
Abstain: abstain.String(),
|
||||||
No: no.String(),
|
No: no.String(),
|
||||||
|
@ -37,7 +37,7 @@ func NewTallyResult(yes, abstain, no, noWithVeto sdk.Int) *TallyResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTallyResultFromMap creates a new TallyResult instance from a Option -> Dec map
|
// NewTallyResultFromMap creates a new TallyResult instance from a Option -> Dec map
|
||||||
func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) *TallyResult {
|
func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult {
|
||||||
return NewTallyResult(
|
return NewTallyResult(
|
||||||
results[OptionYes].TruncateInt(),
|
results[OptionYes].TruncateInt(),
|
||||||
results[OptionAbstain].TruncateInt(),
|
results[OptionAbstain].TruncateInt(),
|
||||||
|
@ -47,7 +47,7 @@ func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) *TallyResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmptyTallyResult returns an empty TallyResult.
|
// EmptyTallyResult returns an empty TallyResult.
|
||||||
func EmptyTallyResult() *TallyResult {
|
func EmptyTallyResult() TallyResult {
|
||||||
return NewTallyResult(sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt())
|
return NewTallyResult(sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,99 @@ func (m *MsgSubmitProposalResponse) GetProposalId() uint64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MsgExecLegacyContent is used to wrap the legacy content field into a message.
|
||||||
|
// This ensures backwards compatibility with v1beta1.MsgSubmitProposal.
|
||||||
|
type MsgExecLegacyContent struct {
|
||||||
|
// content is the proposal's content.
|
||||||
|
Content *types.Any `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
// authority must be the gov module address.
|
||||||
|
Authority string `protobuf:"bytes,2,opt,name=authority,proto3" json:"authority,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) Reset() { *m = MsgExecLegacyContent{} }
|
||||||
|
func (m *MsgExecLegacyContent) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MsgExecLegacyContent) ProtoMessage() {}
|
||||||
|
func (*MsgExecLegacyContent) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_4214261f6b3f9ed4, []int{2}
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContent) XXX_Unmarshal(b []byte) error {
|
||||||
|
return m.Unmarshal(b)
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
if deterministic {
|
||||||
|
return xxx_messageInfo_MsgExecLegacyContent.Marshal(b, m, deterministic)
|
||||||
|
} else {
|
||||||
|
b = b[:cap(b)]
|
||||||
|
n, err := m.MarshalToSizedBuffer(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b[:n], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContent) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MsgExecLegacyContent.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContent) XXX_Size() int {
|
||||||
|
return m.Size()
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContent) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MsgExecLegacyContent.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MsgExecLegacyContent proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) GetContent() *types.Any {
|
||||||
|
if m != nil {
|
||||||
|
return m.Content
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) GetAuthority() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Authority
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgExecLegacyContentResponse defines the Msg/ExecLegacyContent response type.
|
||||||
|
type MsgExecLegacyContentResponse struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContentResponse) Reset() { *m = MsgExecLegacyContentResponse{} }
|
||||||
|
func (m *MsgExecLegacyContentResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*MsgExecLegacyContentResponse) ProtoMessage() {}
|
||||||
|
func (*MsgExecLegacyContentResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_4214261f6b3f9ed4, []int{3}
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) XXX_Unmarshal(b []byte) error {
|
||||||
|
return m.Unmarshal(b)
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
if deterministic {
|
||||||
|
return xxx_messageInfo_MsgExecLegacyContentResponse.Marshal(b, m, deterministic)
|
||||||
|
} else {
|
||||||
|
b = b[:cap(b)]
|
||||||
|
n, err := m.MarshalToSizedBuffer(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b[:n], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_MsgExecLegacyContentResponse.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) XXX_Size() int {
|
||||||
|
return m.Size()
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_MsgExecLegacyContentResponse.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_MsgExecLegacyContentResponse proto.InternalMessageInfo
|
||||||
|
|
||||||
// MsgVote defines a message to cast a vote.
|
// MsgVote defines a message to cast a vote.
|
||||||
type MsgVote struct {
|
type MsgVote struct {
|
||||||
ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id"`
|
ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id"`
|
||||||
|
@ -149,7 +242,7 @@ func (m *MsgVote) Reset() { *m = MsgVote{} }
|
||||||
func (m *MsgVote) String() string { return proto.CompactTextString(m) }
|
func (m *MsgVote) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgVote) ProtoMessage() {}
|
func (*MsgVote) ProtoMessage() {}
|
||||||
func (*MsgVote) Descriptor() ([]byte, []int) {
|
func (*MsgVote) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{2}
|
return fileDescriptor_4214261f6b3f9ed4, []int{4}
|
||||||
}
|
}
|
||||||
func (m *MsgVote) XXX_Unmarshal(b []byte) error {
|
func (m *MsgVote) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -207,7 +300,7 @@ func (m *MsgVoteResponse) Reset() { *m = MsgVoteResponse{} }
|
||||||
func (m *MsgVoteResponse) String() string { return proto.CompactTextString(m) }
|
func (m *MsgVoteResponse) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgVoteResponse) ProtoMessage() {}
|
func (*MsgVoteResponse) ProtoMessage() {}
|
||||||
func (*MsgVoteResponse) Descriptor() ([]byte, []int) {
|
func (*MsgVoteResponse) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{3}
|
return fileDescriptor_4214261f6b3f9ed4, []int{5}
|
||||||
}
|
}
|
||||||
func (m *MsgVoteResponse) XXX_Unmarshal(b []byte) error {
|
func (m *MsgVoteResponse) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -249,7 +342,7 @@ func (m *MsgVoteWeighted) Reset() { *m = MsgVoteWeighted{} }
|
||||||
func (m *MsgVoteWeighted) String() string { return proto.CompactTextString(m) }
|
func (m *MsgVoteWeighted) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgVoteWeighted) ProtoMessage() {}
|
func (*MsgVoteWeighted) ProtoMessage() {}
|
||||||
func (*MsgVoteWeighted) Descriptor() ([]byte, []int) {
|
func (*MsgVoteWeighted) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{4}
|
return fileDescriptor_4214261f6b3f9ed4, []int{6}
|
||||||
}
|
}
|
||||||
func (m *MsgVoteWeighted) XXX_Unmarshal(b []byte) error {
|
func (m *MsgVoteWeighted) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -309,7 +402,7 @@ func (m *MsgVoteWeightedResponse) Reset() { *m = MsgVoteWeightedResponse
|
||||||
func (m *MsgVoteWeightedResponse) String() string { return proto.CompactTextString(m) }
|
func (m *MsgVoteWeightedResponse) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgVoteWeightedResponse) ProtoMessage() {}
|
func (*MsgVoteWeightedResponse) ProtoMessage() {}
|
||||||
func (*MsgVoteWeightedResponse) Descriptor() ([]byte, []int) {
|
func (*MsgVoteWeightedResponse) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{5}
|
return fileDescriptor_4214261f6b3f9ed4, []int{7}
|
||||||
}
|
}
|
||||||
func (m *MsgVoteWeightedResponse) XXX_Unmarshal(b []byte) error {
|
func (m *MsgVoteWeightedResponse) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -349,7 +442,7 @@ func (m *MsgDeposit) Reset() { *m = MsgDeposit{} }
|
||||||
func (m *MsgDeposit) String() string { return proto.CompactTextString(m) }
|
func (m *MsgDeposit) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgDeposit) ProtoMessage() {}
|
func (*MsgDeposit) ProtoMessage() {}
|
||||||
func (*MsgDeposit) Descriptor() ([]byte, []int) {
|
func (*MsgDeposit) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{6}
|
return fileDescriptor_4214261f6b3f9ed4, []int{8}
|
||||||
}
|
}
|
||||||
func (m *MsgDeposit) XXX_Unmarshal(b []byte) error {
|
func (m *MsgDeposit) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -407,7 +500,7 @@ func (m *MsgDepositResponse) Reset() { *m = MsgDepositResponse{} }
|
||||||
func (m *MsgDepositResponse) String() string { return proto.CompactTextString(m) }
|
func (m *MsgDepositResponse) String() string { return proto.CompactTextString(m) }
|
||||||
func (*MsgDepositResponse) ProtoMessage() {}
|
func (*MsgDepositResponse) ProtoMessage() {}
|
||||||
func (*MsgDepositResponse) Descriptor() ([]byte, []int) {
|
func (*MsgDepositResponse) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_4214261f6b3f9ed4, []int{7}
|
return fileDescriptor_4214261f6b3f9ed4, []int{9}
|
||||||
}
|
}
|
||||||
func (m *MsgDepositResponse) XXX_Unmarshal(b []byte) error {
|
func (m *MsgDepositResponse) XXX_Unmarshal(b []byte) error {
|
||||||
return m.Unmarshal(b)
|
return m.Unmarshal(b)
|
||||||
|
@ -439,6 +532,8 @@ var xxx_messageInfo_MsgDepositResponse proto.InternalMessageInfo
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*MsgSubmitProposal)(nil), "cosmos.gov.v1beta2.MsgSubmitProposal")
|
proto.RegisterType((*MsgSubmitProposal)(nil), "cosmos.gov.v1beta2.MsgSubmitProposal")
|
||||||
proto.RegisterType((*MsgSubmitProposalResponse)(nil), "cosmos.gov.v1beta2.MsgSubmitProposalResponse")
|
proto.RegisterType((*MsgSubmitProposalResponse)(nil), "cosmos.gov.v1beta2.MsgSubmitProposalResponse")
|
||||||
|
proto.RegisterType((*MsgExecLegacyContent)(nil), "cosmos.gov.v1beta2.MsgExecLegacyContent")
|
||||||
|
proto.RegisterType((*MsgExecLegacyContentResponse)(nil), "cosmos.gov.v1beta2.MsgExecLegacyContentResponse")
|
||||||
proto.RegisterType((*MsgVote)(nil), "cosmos.gov.v1beta2.MsgVote")
|
proto.RegisterType((*MsgVote)(nil), "cosmos.gov.v1beta2.MsgVote")
|
||||||
proto.RegisterType((*MsgVoteResponse)(nil), "cosmos.gov.v1beta2.MsgVoteResponse")
|
proto.RegisterType((*MsgVoteResponse)(nil), "cosmos.gov.v1beta2.MsgVoteResponse")
|
||||||
proto.RegisterType((*MsgVoteWeighted)(nil), "cosmos.gov.v1beta2.MsgVoteWeighted")
|
proto.RegisterType((*MsgVoteWeighted)(nil), "cosmos.gov.v1beta2.MsgVoteWeighted")
|
||||||
|
@ -450,45 +545,50 @@ func init() {
|
||||||
func init() { proto.RegisterFile("cosmos/gov/v1beta2/tx.proto", fileDescriptor_4214261f6b3f9ed4) }
|
func init() { proto.RegisterFile("cosmos/gov/v1beta2/tx.proto", fileDescriptor_4214261f6b3f9ed4) }
|
||||||
|
|
||||||
var fileDescriptor_4214261f6b3f9ed4 = []byte{
|
var fileDescriptor_4214261f6b3f9ed4 = []byte{
|
||||||
// 600 bytes of a gzipped FileDescriptorProto
|
// 681 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xcf, 0x6e, 0xd3, 0x4e,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x4f, 0x4f, 0x13, 0x4f,
|
||||||
0x18, 0x8c, 0x9b, 0xfe, 0xfa, 0xe7, 0xeb, 0x4f, 0xad, 0xba, 0x8a, 0x84, 0xe3, 0x22, 0x37, 0x32,
|
0x18, 0xee, 0x52, 0x7e, 0x14, 0x5e, 0x7e, 0x81, 0x30, 0x69, 0xe2, 0x76, 0x21, 0x0b, 0x59, 0x23,
|
||||||
0xa2, 0x8a, 0x84, 0xb2, 0x4e, 0x02, 0x2a, 0x17, 0x0e, 0x34, 0x70, 0x28, 0x48, 0x11, 0xe0, 0x4a,
|
0x69, 0x62, 0xba, 0x5b, 0xaa, 0xc1, 0x83, 0x1e, 0xa4, 0x68, 0x82, 0xc6, 0x46, 0x5d, 0x12, 0x4d,
|
||||||
0x20, 0x71, 0x09, 0x76, 0xbc, 0xdd, 0xae, 0x48, 0xbc, 0x96, 0x77, 0x13, 0x35, 0x6f, 0xc1, 0x3b,
|
0xbc, 0xe0, 0xb6, 0x3b, 0x0c, 0x13, 0xe9, 0xbe, 0xeb, 0xce, 0xb4, 0xa1, 0xdf, 0xc2, 0xef, 0xe0,
|
||||||
0xf0, 0x00, 0x5c, 0xe0, 0x11, 0x90, 0x7a, 0xac, 0x38, 0x71, 0xaa, 0x50, 0x72, 0x43, 0x3c, 0x04,
|
0x07, 0xf0, 0x82, 0x1f, 0xc1, 0x84, 0x78, 0x22, 0x9e, 0xbc, 0x48, 0x0c, 0xdc, 0xfc, 0x14, 0xa6,
|
||||||
0x8a, 0xbd, 0x76, 0x43, 0x93, 0x26, 0xe5, 0xc2, 0x29, 0xce, 0x37, 0x33, 0x9f, 0x67, 0xec, 0xf1,
|
0xbb, 0xb3, 0x0b, 0xd2, 0x3f, 0xe0, 0xc5, 0x53, 0xa7, 0xef, 0xf3, 0x3c, 0xef, 0x3c, 0xcf, 0x64,
|
||||||
0xc2, 0x4e, 0x9b, 0x8b, 0x2e, 0x17, 0x36, 0xe5, 0x7d, 0xbb, 0x5f, 0xf3, 0x88, 0x74, 0xeb, 0xb6,
|
0xde, 0x1d, 0x58, 0x6c, 0xa1, 0x68, 0xa3, 0x70, 0x18, 0x76, 0x9d, 0xee, 0x5a, 0x93, 0x4a, 0xaf,
|
||||||
0x3c, 0xc5, 0x61, 0xc4, 0x25, 0x47, 0x28, 0x01, 0x31, 0xe5, 0x7d, 0xac, 0x40, 0xc3, 0x54, 0x02,
|
0xe6, 0xc8, 0x03, 0x3b, 0x8c, 0x50, 0x22, 0x21, 0x09, 0x68, 0x33, 0xec, 0xda, 0x0a, 0x34, 0x4c,
|
||||||
0xcf, 0x15, 0x44, 0x29, 0x6a, 0x76, 0x9b, 0xb3, 0x20, 0xd1, 0x18, 0xb7, 0x67, 0x2c, 0x1c, 0xeb,
|
0x25, 0x68, 0x7a, 0x82, 0x2a, 0xc5, 0x9a, 0xd3, 0x42, 0x1e, 0x24, 0x1a, 0x63, 0x69, 0x48, 0xc3,
|
||||||
0x13, 0xb4, 0x40, 0x39, 0xe5, 0xf1, 0xa5, 0x3d, 0xbe, 0x52, 0xd3, 0x62, 0xa2, 0x69, 0x25, 0x80,
|
0xbe, 0x3e, 0x41, 0x8b, 0x0c, 0x19, 0xc6, 0x4b, 0xa7, 0xbf, 0x52, 0xd5, 0x52, 0xa2, 0xd9, 0x49,
|
||||||
0xba, 0xa9, 0x82, 0x28, 0xe7, 0xb4, 0x43, 0xec, 0xf8, 0x9f, 0xd7, 0x3b, 0xb6, 0xdd, 0x60, 0x90,
|
0x00, 0xb5, 0xa9, 0x82, 0x18, 0x22, 0xdb, 0xa7, 0x4e, 0xfc, 0xaf, 0xd9, 0xd9, 0x75, 0xbc, 0xa0,
|
||||||
0x40, 0xd6, 0x57, 0x0d, 0xb6, 0x9b, 0x82, 0x1e, 0xf5, 0xbc, 0x2e, 0x93, 0x2f, 0x23, 0x1e, 0x72,
|
0x97, 0x40, 0xd6, 0x17, 0x0d, 0x16, 0x1a, 0x82, 0x6d, 0x77, 0x9a, 0x6d, 0x2e, 0x5f, 0x44, 0x18,
|
||||||
0xe1, 0x76, 0x50, 0x15, 0xd6, 0xba, 0x44, 0x08, 0x97, 0x12, 0xa1, 0x6b, 0xa5, 0x7c, 0x79, 0xa3,
|
0xa2, 0xf0, 0xf6, 0x49, 0x15, 0xa6, 0xdb, 0x54, 0x08, 0x8f, 0x51, 0xa1, 0x6b, 0x2b, 0xf9, 0xf2,
|
||||||
0x5e, 0xc0, 0xc9, 0x0e, 0x9c, 0xee, 0xc0, 0x07, 0xc1, 0xc0, 0xc9, 0x58, 0xe8, 0x10, 0xb6, 0x58,
|
0x6c, 0xad, 0x68, 0x27, 0x3d, 0xec, 0xb4, 0x87, 0xbd, 0x11, 0xf4, 0xdc, 0x8c, 0x45, 0xb6, 0x60,
|
||||||
0xc0, 0x24, 0x73, 0x3b, 0x2d, 0x9f, 0x84, 0x5c, 0x30, 0xa9, 0x2f, 0xc5, 0xc2, 0x22, 0x56, 0x56,
|
0x9e, 0x07, 0x5c, 0x72, 0x6f, 0x7f, 0xc7, 0xa7, 0x21, 0x0a, 0x2e, 0xf5, 0x89, 0x58, 0x58, 0xb2,
|
||||||
0xc6, 0x59, 0xd5, 0x03, 0xa8, 0xe1, 0x27, 0x9c, 0x05, 0x8d, 0xe5, 0xb3, 0x8b, 0xdd, 0x9c, 0xb3,
|
0x95, 0x95, 0x7e, 0x56, 0x75, 0x00, 0x6b, 0xf6, 0x26, 0xf2, 0xa0, 0x3e, 0x79, 0x74, 0xb2, 0x9c,
|
||||||
0xa9, 0x74, 0x4f, 0x13, 0x19, 0x7a, 0x00, 0x6b, 0x61, 0xec, 0x83, 0x44, 0x7a, 0xbe, 0xa4, 0x95,
|
0x73, 0xe7, 0x94, 0xee, 0x51, 0x22, 0x23, 0x77, 0x61, 0x3a, 0x8c, 0x7d, 0xd0, 0x48, 0xcf, 0xaf,
|
||||||
0xd7, 0x1b, 0xfa, 0xb7, 0xcf, 0x95, 0x82, 0xda, 0x72, 0xe0, 0xfb, 0x11, 0x11, 0xe2, 0x48, 0x46,
|
0x68, 0xe5, 0x99, 0xba, 0xfe, 0xed, 0xb0, 0x52, 0x54, 0x5d, 0x36, 0x7c, 0x3f, 0xa2, 0x42, 0x6c,
|
||||||
0x2c, 0xa0, 0x4e, 0xc6, 0xb4, 0x1e, 0x41, 0x71, 0x2a, 0x86, 0x43, 0x44, 0xc8, 0x03, 0x41, 0xd0,
|
0xcb, 0x88, 0x07, 0xcc, 0xcd, 0x98, 0xd6, 0x03, 0x28, 0x0d, 0xc4, 0x70, 0xa9, 0x08, 0x31, 0x10,
|
||||||
0x2e, 0x6c, 0x84, 0x6a, 0xd6, 0x62, 0xbe, 0xae, 0x95, 0xb4, 0xf2, 0xb2, 0x03, 0xe9, 0xe8, 0x99,
|
0x94, 0x2c, 0xc3, 0x6c, 0xa8, 0x6a, 0x3b, 0xdc, 0xd7, 0xb5, 0x15, 0xad, 0x3c, 0xe9, 0x42, 0x5a,
|
||||||
0x6f, 0x7d, 0xd4, 0x60, 0xb5, 0x29, 0xe8, 0x6b, 0x2e, 0x09, 0xaa, 0xce, 0x20, 0x37, 0xb6, 0x7e,
|
0x7a, 0xe2, 0x5b, 0xef, 0xa1, 0xd8, 0x10, 0xec, 0xf1, 0x01, 0x6d, 0x3d, 0xa3, 0xcc, 0x6b, 0xf5,
|
||||||
0x5e, 0xec, 0x4e, 0x8e, 0x27, 0xd5, 0x08, 0xc3, 0x7f, 0x7d, 0x2e, 0x49, 0xa4, 0x2f, 0x2d, 0xb0,
|
0x36, 0x31, 0x90, 0x34, 0x90, 0xe4, 0x3e, 0x14, 0x5a, 0xc9, 0x32, 0x16, 0x8d, 0x38, 0x86, 0xfa,
|
||||||
0x9b, 0xd0, 0xd0, 0x3e, 0xac, 0xf0, 0x50, 0x32, 0x1e, 0xc4, 0xf9, 0x36, 0xeb, 0x26, 0x9e, 0xae,
|
0xec, 0xd7, 0xc3, 0x4a, 0x41, 0x69, 0xdc, 0x54, 0x41, 0x96, 0x60, 0xc6, 0xeb, 0xc8, 0x3d, 0x8c,
|
||||||
0x08, 0x1e, 0x7b, 0x79, 0x11, 0xb3, 0x1c, 0xc5, 0xb6, 0xb6, 0x61, 0x4b, 0x99, 0x4c, 0x93, 0x59,
|
0xb8, 0xec, 0xe9, 0x13, 0xfd, 0x24, 0xee, 0x79, 0xc1, 0x32, 0x61, 0x69, 0xd8, 0x96, 0xa9, 0x67,
|
||||||
0x5f, 0xb4, 0x6c, 0xf6, 0x86, 0x30, 0x7a, 0x22, 0x89, 0xff, 0x0f, 0x02, 0x3c, 0x86, 0xd5, 0xc4,
|
0xeb, 0xa3, 0x06, 0x85, 0x86, 0x60, 0xaf, 0x50, 0x52, 0x52, 0x1d, 0xe2, 0xbf, 0x3e, 0xff, 0xeb,
|
||||||
0x92, 0xd0, 0xf3, 0xf1, 0x4b, 0xde, 0x9b, 0x95, 0x20, 0x35, 0x34, 0x91, 0x24, 0x95, 0x59, 0x45,
|
0x64, 0xf9, 0x62, 0xf9, 0x62, 0x20, 0x62, 0xc3, 0x7f, 0x5d, 0x94, 0x34, 0x4a, 0xf6, 0x1d, 0x73,
|
||||||
0xb8, 0x75, 0xc5, 0x76, 0x16, 0xe9, 0x93, 0x06, 0xd0, 0x14, 0x34, 0xad, 0xc3, 0xdf, 0xa7, 0xd9,
|
0x82, 0x09, 0x8d, 0xac, 0xc3, 0x14, 0x86, 0x92, 0x63, 0x10, 0x1f, 0xf9, 0x5c, 0xcd, 0xb4, 0x07,
|
||||||
0x87, 0x75, 0x55, 0x41, 0xbe, 0x38, 0xd1, 0x25, 0x15, 0x3d, 0x84, 0x15, 0xb7, 0xcb, 0x7b, 0x81,
|
0x6f, 0xad, 0xdd, 0xf7, 0xf2, 0x3c, 0x66, 0xb9, 0x8a, 0x6d, 0x2d, 0xc0, 0xbc, 0x32, 0x99, 0x19,
|
||||||
0x54, 0xa1, 0x16, 0x36, 0x57, 0xd1, 0xad, 0x02, 0xa0, 0x4b, 0xc3, 0x69, 0x8e, 0xfa, 0xaf, 0x25,
|
0xff, 0xac, 0x65, 0xb5, 0xd7, 0x94, 0xb3, 0x3d, 0x49, 0xfd, 0x7f, 0x10, 0xe0, 0x21, 0x14, 0x12,
|
||||||
0xc8, 0x37, 0x05, 0x45, 0xc7, 0xb0, 0x79, 0xe5, 0xeb, 0xba, 0x3b, 0xeb, 0x69, 0x4d, 0xb5, 0xd7,
|
0x4b, 0x42, 0xcf, 0xc7, 0xf7, 0x6e, 0x75, 0x58, 0x82, 0xd4, 0xd0, 0x85, 0x24, 0xa9, 0xcc, 0x2a,
|
||||||
0xa8, 0xdc, 0x88, 0x96, 0x95, 0xfc, 0x10, 0x96, 0xe3, 0xfe, 0xee, 0x5c, 0x23, 0x1b, 0x83, 0xc6,
|
0xc1, 0x8d, 0x4b, 0xb6, 0xb3, 0x48, 0x9f, 0x34, 0x80, 0x86, 0x60, 0xe9, 0x0d, 0xfd, 0xfb, 0x34,
|
||||||
0x9d, 0x39, 0x60, 0xb6, 0xe9, 0x1d, 0xfc, 0xff, 0x47, 0xa1, 0xe6, 0x89, 0x52, 0x92, 0x71, 0xef,
|
0xeb, 0x30, 0xa3, 0xa6, 0x02, 0xaf, 0x4e, 0x74, 0x4e, 0x25, 0xf7, 0x60, 0xca, 0x6b, 0x63, 0x27,
|
||||||
0x06, 0xa4, 0xec, 0x0e, 0xaf, 0x60, 0x35, 0x7d, 0xbf, 0xe6, 0x35, 0x3a, 0x85, 0x1b, 0x7b, 0xf3,
|
0x90, 0x2a, 0xd4, 0x95, 0xc3, 0xa4, 0xe8, 0x56, 0x11, 0xc8, 0xb9, 0xe1, 0x34, 0x47, 0xed, 0x47,
|
||||||
0xf1, 0x74, 0x65, 0xe3, 0xf9, 0xd9, 0xd0, 0xd4, 0xce, 0x87, 0xa6, 0xf6, 0x63, 0x68, 0x6a, 0x1f,
|
0x1e, 0xf2, 0x0d, 0xc1, 0xc8, 0x2e, 0xcc, 0x5d, 0x1a, 0xf8, 0x5b, 0xc3, 0x4e, 0x6b, 0x60, 0xa0,
|
||||||
0x46, 0x66, 0xee, 0x7c, 0x64, 0xe6, 0xbe, 0x8f, 0xcc, 0xdc, 0xdb, 0x2a, 0x65, 0xf2, 0xa4, 0xe7,
|
0x8c, 0xca, 0xb5, 0x68, 0xd9, 0xdc, 0x21, 0x2c, 0x0c, 0xce, 0x54, 0x79, 0x44, 0x8f, 0x01, 0xa6,
|
||||||
0xe1, 0x36, 0xef, 0xaa, 0x63, 0x51, 0xfd, 0x54, 0x84, 0xff, 0xde, 0x3e, 0x8d, 0x0f, 0x59, 0x39,
|
0x51, 0xbd, 0x2e, 0x33, 0xdb, 0x70, 0x0b, 0x26, 0xe3, 0x81, 0x59, 0x1c, 0xa1, 0xec, 0x83, 0xc6,
|
||||||
0x08, 0x89, 0x48, 0x8f, 0x5a, 0x6f, 0x25, 0x3e, 0xe4, 0xee, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff,
|
0xcd, 0x31, 0x60, 0xd6, 0xe9, 0x2d, 0xfc, 0xff, 0xc7, 0x0d, 0x1e, 0x27, 0x4a, 0x49, 0xc6, 0xed,
|
||||||
0x15, 0xe6, 0xf8, 0x9f, 0xd8, 0x05, 0x00, 0x00,
|
0x6b, 0x90, 0xb2, 0x1d, 0x5e, 0x42, 0x21, 0xbd, 0x50, 0xe6, 0x08, 0x9d, 0xc2, 0x8d, 0xd5, 0xf1,
|
||||||
|
0x78, 0xda, 0xb2, 0xfe, 0xf4, 0xe8, 0xd4, 0xd4, 0x8e, 0x4f, 0x4d, 0xed, 0xe7, 0xa9, 0xa9, 0x7d,
|
||||||
|
0x38, 0x33, 0x73, 0xc7, 0x67, 0x66, 0xee, 0xfb, 0x99, 0x99, 0x7b, 0x53, 0x65, 0x5c, 0xee, 0x75,
|
||||||
|
0x9a, 0x76, 0x0b, 0xdb, 0xea, 0x69, 0x50, 0x3f, 0x15, 0xe1, 0xbf, 0x73, 0x0e, 0xe2, 0x87, 0x46,
|
||||||
|
0xf6, 0x42, 0x2a, 0xd2, 0xe7, 0xa6, 0x39, 0x15, 0x7f, 0xe1, 0xee, 0xfc, 0x0e, 0x00, 0x00, 0xff,
|
||||||
|
0xff, 0xfd, 0xa4, 0xe8, 0x04, 0xdc, 0x06, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
@ -505,6 +605,9 @@ const _ = grpc.SupportPackageIsVersion4
|
||||||
type MsgClient interface {
|
type MsgClient interface {
|
||||||
// SubmitProposal defines a method to create new proposal given a content.
|
// SubmitProposal defines a method to create new proposal given a content.
|
||||||
SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error)
|
SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error)
|
||||||
|
// ExecLegacyContent defines a Msg to be in included in a MsgSubmitProposal
|
||||||
|
// to execute a legacy content-based proposal.
|
||||||
|
ExecLegacyContent(ctx context.Context, in *MsgExecLegacyContent, opts ...grpc.CallOption) (*MsgExecLegacyContentResponse, error)
|
||||||
// Vote defines a method to add a vote on a specific proposal.
|
// Vote defines a method to add a vote on a specific proposal.
|
||||||
Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error)
|
Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error)
|
||||||
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
||||||
|
@ -532,6 +635,15 @@ func (c *msgClient) SubmitProposal(ctx context.Context, in *MsgSubmitProposal, o
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *msgClient) ExecLegacyContent(ctx context.Context, in *MsgExecLegacyContent, opts ...grpc.CallOption) (*MsgExecLegacyContentResponse, error) {
|
||||||
|
out := new(MsgExecLegacyContentResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/ExecLegacyContent", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *msgClient) Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) {
|
func (c *msgClient) Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) {
|
||||||
out := new(MsgVoteResponse)
|
out := new(MsgVoteResponse)
|
||||||
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/Vote", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta2.Msg/Vote", in, out, opts...)
|
||||||
|
@ -563,6 +675,9 @@ func (c *msgClient) Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.Ca
|
||||||
type MsgServer interface {
|
type MsgServer interface {
|
||||||
// SubmitProposal defines a method to create new proposal given a content.
|
// SubmitProposal defines a method to create new proposal given a content.
|
||||||
SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error)
|
SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error)
|
||||||
|
// ExecLegacyContent defines a Msg to be in included in a MsgSubmitProposal
|
||||||
|
// to execute a legacy content-based proposal.
|
||||||
|
ExecLegacyContent(context.Context, *MsgExecLegacyContent) (*MsgExecLegacyContentResponse, error)
|
||||||
// Vote defines a method to add a vote on a specific proposal.
|
// Vote defines a method to add a vote on a specific proposal.
|
||||||
Vote(context.Context, *MsgVote) (*MsgVoteResponse, error)
|
Vote(context.Context, *MsgVote) (*MsgVoteResponse, error)
|
||||||
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
// VoteWeighted defines a method to add a weighted vote on a specific proposal.
|
||||||
|
@ -580,6 +695,9 @@ type UnimplementedMsgServer struct {
|
||||||
func (*UnimplementedMsgServer) SubmitProposal(ctx context.Context, req *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) {
|
func (*UnimplementedMsgServer) SubmitProposal(ctx context.Context, req *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method SubmitProposal not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method SubmitProposal not implemented")
|
||||||
}
|
}
|
||||||
|
func (*UnimplementedMsgServer) ExecLegacyContent(ctx context.Context, req *MsgExecLegacyContent) (*MsgExecLegacyContentResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ExecLegacyContent not implemented")
|
||||||
|
}
|
||||||
func (*UnimplementedMsgServer) Vote(ctx context.Context, req *MsgVote) (*MsgVoteResponse, error) {
|
func (*UnimplementedMsgServer) Vote(ctx context.Context, req *MsgVote) (*MsgVoteResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Vote not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Vote not implemented")
|
||||||
}
|
}
|
||||||
|
@ -612,6 +730,24 @@ func _Msg_SubmitProposal_Handler(srv interface{}, ctx context.Context, dec func(
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Msg_ExecLegacyContent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(MsgExecLegacyContent)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(MsgServer).ExecLegacyContent(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/cosmos.gov.v1beta2.Msg/ExecLegacyContent",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(MsgServer).ExecLegacyContent(ctx, req.(*MsgExecLegacyContent))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _Msg_Vote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _Msg_Vote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(MsgVote)
|
in := new(MsgVote)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
|
@ -674,6 +810,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||||
MethodName: "SubmitProposal",
|
MethodName: "SubmitProposal",
|
||||||
Handler: _Msg_SubmitProposal_Handler,
|
Handler: _Msg_SubmitProposal_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ExecLegacyContent",
|
||||||
|
Handler: _Msg_ExecLegacyContent_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "Vote",
|
MethodName: "Vote",
|
||||||
Handler: _Msg_Vote_Handler,
|
Handler: _Msg_Vote_Handler,
|
||||||
|
@ -777,6 +917,71 @@ func (m *MsgSubmitProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro
|
||||||
return len(dAtA) - i, nil
|
return len(dAtA) - i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
size := m.Size()
|
||||||
|
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
|
i := len(dAtA)
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Authority) > 0 {
|
||||||
|
i -= len(m.Authority)
|
||||||
|
copy(dAtA[i:], m.Authority)
|
||||||
|
i = encodeVarintTx(dAtA, i, uint64(len(m.Authority)))
|
||||||
|
i--
|
||||||
|
dAtA[i] = 0x12
|
||||||
|
}
|
||||||
|
if m.Content != nil {
|
||||||
|
{
|
||||||
|
size, err := m.Content.MarshalToSizedBuffer(dAtA[:i])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i -= size
|
||||||
|
i = encodeVarintTx(dAtA, i, uint64(size))
|
||||||
|
}
|
||||||
|
i--
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
}
|
||||||
|
return len(dAtA) - i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContentResponse) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContentResponse) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
size := m.Size()
|
||||||
|
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContentResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
|
i := len(dAtA)
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
return len(dAtA) - i, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MsgVote) Marshal() (dAtA []byte, err error) {
|
func (m *MsgVote) Marshal() (dAtA []byte, err error) {
|
||||||
size := m.Size()
|
size := m.Size()
|
||||||
dAtA = make([]byte, size)
|
dAtA = make([]byte, size)
|
||||||
|
@ -1032,6 +1237,32 @@ func (m *MsgSubmitProposalResponse) Size() (n int) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContent) Size() (n int) {
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if m.Content != nil {
|
||||||
|
l = m.Content.Size()
|
||||||
|
n += 1 + l + sovTx(uint64(l))
|
||||||
|
}
|
||||||
|
l = len(m.Authority)
|
||||||
|
if l > 0 {
|
||||||
|
n += 1 + l + sovTx(uint64(l))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgExecLegacyContentResponse) Size() (n int) {
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MsgVote) Size() (n int) {
|
func (m *MsgVote) Size() (n int) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -1347,6 +1578,174 @@ func (m *MsgSubmitProposalResponse) Unmarshal(dAtA []byte) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *MsgExecLegacyContent) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTx
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: MsgExecLegacyContent: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: MsgExecLegacyContent: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Content", wireType)
|
||||||
|
}
|
||||||
|
var msglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTx
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
msglen |= int(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msglen < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + msglen
|
||||||
|
if postIndex < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if m.Content == nil {
|
||||||
|
m.Content = &types.Any{}
|
||||||
|
}
|
||||||
|
if err := m.Content.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType)
|
||||||
|
}
|
||||||
|
var stringLen uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTx
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
stringLen |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intStringLen := int(stringLen)
|
||||||
|
if intStringLen < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + intStringLen
|
||||||
|
if postIndex < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Authority = string(dAtA[iNdEx:postIndex])
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTx(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *MsgExecLegacyContentResponse) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTx
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: MsgExecLegacyContentResponse: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: MsgExecLegacyContentResponse: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTx(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||||
|
return ErrInvalidLengthTx
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (m *MsgVote) Unmarshal(dAtA []byte) error {
|
func (m *MsgVote) Unmarshal(dAtA []byte) error {
|
||||||
l := len(dAtA)
|
l := len(dAtA)
|
||||||
iNdEx := 0
|
iNdEx := 0
|
||||||
|
|
|
@ -78,6 +78,15 @@ func NewNonSplitVoteOption(option VoteOption) WeightedVoteOptions {
|
||||||
return WeightedVoteOptions{{option, sdk.NewDec(1).String()}}
|
return WeightedVoteOptions{{option, sdk.NewDec(1).String()}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidWeightedVoteOption returns true if the sub vote is valid and false otherwise.
|
||||||
|
func ValidWeightedVoteOption(option WeightedVoteOption) bool {
|
||||||
|
weight, err := sdk.NewDecFromStr(option.Weight)
|
||||||
|
if err != nil || !weight.IsPositive() || weight.GT(sdk.NewDec(1)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return ValidVoteOption(option.Option)
|
||||||
|
}
|
||||||
|
|
||||||
// WeightedVoteOptions describes array of WeightedVoteOptions
|
// WeightedVoteOptions describes array of WeightedVoteOptions
|
||||||
type WeightedVoteOptions []*WeightedVoteOption
|
type WeightedVoteOptions []*WeightedVoteOption
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
|
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
|
||||||
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
||||||
)
|
)
|
||||||
|
@ -76,7 +76,7 @@ Where proposal.json contains:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
|
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
@ -20,7 +22,7 @@ type HandlerTestSuite struct {
|
||||||
|
|
||||||
app *simapp.SimApp
|
app *simapp.SimApp
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
govHandler govtypes.Handler
|
govHandler govv1beta1.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *HandlerTestSuite) SetupTest() {
|
func (suite *HandlerTestSuite) SetupTest() {
|
||||||
|
@ -63,14 +65,15 @@ func (suite *HandlerTestSuite) TestProposalHandler() {
|
||||||
"omit empty fields",
|
"omit empty fields",
|
||||||
testProposal(proposal.ParamChange{
|
testProposal(proposal.ParamChange{
|
||||||
Subspace: govtypes.ModuleName,
|
Subspace: govtypes.ModuleName,
|
||||||
Key: string(govtypes.ParamStoreKeyDepositParams),
|
Key: string(govv1beta2.ParamStoreKeyDepositParams),
|
||||||
Value: `{"min_deposit": [{"denom": "uatom","amount": "64000000"}], "max_deposit_period": "172800000000000"}`,
|
Value: `{"min_deposit": [{"denom": "uatom","amount": "64000000"}], "max_deposit_period": "172800000000000"}`,
|
||||||
}),
|
}),
|
||||||
func() {
|
func() {
|
||||||
depositParams := suite.app.GovKeeper.GetDepositParams(suite.ctx)
|
depositParams := suite.app.GovKeeper.GetDepositParams(suite.ctx)
|
||||||
suite.Require().Equal(govtypes.DepositParams{
|
defaultPeriod := govv1beta2.DefaultPeriod
|
||||||
|
suite.Require().Equal(govv1beta2.DepositParams{
|
||||||
MinDeposit: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(64000000))),
|
MinDeposit: sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(64000000))),
|
||||||
MaxDepositPeriod: govtypes.DefaultPeriod,
|
MaxDepositPeriod: &defaultPeriod,
|
||||||
}, depositParams)
|
}, depositParams)
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in New Issue