Skip to content

Commit

Permalink
feat(x/gov): remove ability for validators to add votes (#10)
Browse files Browse the repository at this point in the history
<!--
The production pull request template is for types feat, fix, deps, or
refactor.
-->

## Description

Closes: #7

---

### 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...

* [x] 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, client, or state breaking
change (i.e., requires minor or major version bump)
* [x] Targeted the correct branch (see [PR
Targeting](https://github.com/atomone-hub/govgen/blob/main/CONTRIBUTING.md#pr-targeting))
* [x] Provided a link to the relevant issue or specification
* [x] Followed the guidelines for [building SDK
modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
* [x] Included the necessary unit and integration
[tests](https://github.com/atomone-hub/govgen/blob/main/CONTRIBUTING.md#testing)
* [x] Added a changelog entry in `.changelog` (for details, see
[contributing guidelines](../../CONTRIBUTING.md#changelog))
* [ ] 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 <!--
relevant if the changes are not obvious -->
* [x] 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

---------

Co-authored-by: Thomas Bruyelle <[email protected]>
  • Loading branch information
giunatale and tbruyelle authored Feb 13, 2024
1 parent b8cdd2b commit eefd7ed
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 71 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@

### FEATURES

### STATE BREAKING
* Forked `x/gov` module from Cosmos SDK v0.46.16 for custom modifications
([#4](https://github.com/atomone-hub/govgen/pull/4)).
* Removed ability for validators to vote on proposals
([#10](https://github.com/atomone-hub/govgen/pull/10)).

### STATE BREAKING
4 changes: 2 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func appModules(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand All @@ -124,7 +124,7 @@ func simulationModules(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down
16 changes: 8 additions & 8 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
}

func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 10, valTokens)

Expand Down Expand Up @@ -146,7 +146,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
}

func TestTickPassedDepositPeriod(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 10, valTokens)

Expand Down Expand Up @@ -203,7 +203,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
}

func TestTickPassedVotingPeriod(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 10, valTokens)

Expand Down Expand Up @@ -271,7 +271,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
}

func TestProposalPassedEndblocker(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 10, valTokens)

Expand Down Expand Up @@ -307,7 +307,7 @@ func TestProposalPassedEndblocker(t *testing.T) {
deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...)
require.True(t, moduleAccCoins.IsEqual(deposits))

err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.NewNonSplitVoteOption(types.OptionYes))
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[1], types.NewNonSplitVoteOption(types.OptionYes))
require.NoError(t, err)

newHeader := ctx.BlockHeader()
Expand All @@ -322,9 +322,9 @@ func TestProposalPassedEndblocker(t *testing.T) {
}

func TestEndBlockerProposalHandlerFailed(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 1, valTokens)
addrs := govgenhelpers.AddTestAddrs(app, ctx, 2, valTokens)

SortAddresses(addrs)

Expand All @@ -348,7 +348,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {

handleAndCheck(t, gov.NewHandler(app.GovKeeper), ctx, newDepositMsg)

err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.NewNonSplitVoteOption(types.OptionYes))
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[1], types.NewNonSplitVoteOption(types.OptionYes))
require.NoError(t, err)

newHeader := ctx.BlockHeader()
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestDeposits(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

TestAddrs := govgenhelpers.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(10000000))
Expand Down
15 changes: 13 additions & 2 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
Expand Down Expand Up @@ -337,7 +338,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient

addrs := govgenhelpers.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000))
addrs := govgenhelpers.AddTestAddrs(app, ctx, 2, sdk.NewInt(30000000))

var (
req *types.QueryVotesRequest
Expand Down Expand Up @@ -714,7 +715,17 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
func (suite *KeeperTestSuite) TestGRPCQueryTally() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient

addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})
_, valAddrs := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 3, sdk.NewInt(50000000))

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 5)
val1, found := app.StakingKeeper.GetValidator(ctx, valAddrs[0])
suite.Require().True(found)

for _, addr := range addrs {
_, err := app.StakingKeeper.Delegate(ctx, addr, delTokens, stakingtypes.Unbonded, val1, true)
suite.Require().NoError(err)
}

var (
req *types.QueryTallyResultRequest
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *MockGovHooksReceiver) AfterProposalVotingPeriodEnded(ctx sdk.Context, p
}

func TestHooks(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

minDeposit := app.GovKeeper.GetDepositParams(ctx).MinDeposit
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func getQueriedVotes(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, quer
}

func TestQueries(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
legacyQuerierCdc := app.LegacyAmino()
querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc)
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestQueries(t *testing.T) {
}

func TestPaginatedVotesQuery(t *testing.T) {
app := govgenhelpers.Setup(t)
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
legacyQuerierCdc := app.LegacyAmino()

Expand Down
Loading

0 comments on commit eefd7ed

Please sign in to comment.