Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update x/gov to match module spec #4665

Merged
merged 42 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
62cb057
reestructure gov module according to spec
fedekunze Jul 2, 2019
026ba68
updates
fedekunze Jul 2, 2019
4d1b71a
revert sim changes
fedekunze Jul 2, 2019
3084601
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into go…
fedekunze Jul 3, 2019
fa6706c
updates
fedekunze Jul 3, 2019
34d9dae
more updates/fixes
fedekunze Jul 3, 2019
78dcba6
more updates
fedekunze Jul 4, 2019
04fcd5f
merge master
fedekunze Jul 12, 2019
71034f5
updates
fedekunze Jul 12, 2019
593f5a8
more restructuring
fedekunze Jul 12, 2019
d9ed433
cleanup
fedekunze Jul 15, 2019
e277bf8
more cleanup
fedekunze Jul 15, 2019
fdbaffc
fix more tests
fedekunze Jul 15, 2019
f4ef7b0
set router on tests
fedekunze Jul 15, 2019
dc4f663
add key
fedekunze Jul 16, 2019
ddfe980
cleanup
fedekunze Jul 18, 2019
187faa0
replace staking handler for keeper funcs
fedekunze Jul 22, 2019
6174792
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into go…
fedekunze Jul 22, 2019
f76dd7b
fix tally tests
fedekunze Jul 22, 2019
3f6b237
update iterator tests
fedekunze Jul 22, 2019
038f4e2
minor changes
fedekunze Jul 22, 2019
6fbb120
delete iterator getter
fedekunze Jul 23, 2019
8bebc28
remove empty deposits iterator check in tests
rigelrozanski Jul 23, 2019
c026988
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into go…
fedekunze Jul 24, 2019
88f30e6
minor changes
fedekunze Jul 24, 2019
807fdb3
fix nondeterminism in iteration within tests
rigelrozanski Jul 24, 2019
f42ab0c
cleanup
fedekunze Jul 25, 2019
45627f2
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into go…
fedekunze Jul 25, 2019
3014491
clog
fedekunze Jul 25, 2019
19a4966
merge master
fedekunze Aug 6, 2019
a912bf3
GetAddress()
fedekunze Aug 6, 2019
b99ace7
gov keeper fixes
fedekunze Aug 6, 2019
420ed5b
Update x/gov/module.go
fedekunze Aug 7, 2019
d28ac5f
Update x/gov/types/tally.go
fedekunze Aug 7, 2019
11ddcd1
Update x/gov/test_common.go
fedekunze Aug 7, 2019
bfae5e3
Update x/gov/types/params.go
fedekunze Aug 7, 2019
a015d0e
Update x/gov/types/expected_keepers.go
fedekunze Aug 7, 2019
dfbddbb
address @colin-axner comments
fedekunze Aug 7, 2019
4170427
Update .pending/improvements/modules/_4665-update-gov
alexanderbez Aug 7, 2019
b8025b5
update expected keeper
fedekunze Aug 7, 2019
dfe86d6
address @rigelrozanski comments
fedekunze Aug 8, 2019
a76f19d
update pending
fedekunze Aug 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pending/improvements/modules/_4665-update-gov
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4665 update `x/gov` to match module spec
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func NewSimApp(
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper))
app.govKeeper = gov.NewKeeper(app.cdc, keys[gov.StoreKey], app.paramsKeeper, govSubspace,
app.govKeeper = gov.NewKeeper(app.cdc, keys[gov.StoreKey], govSubspace,
app.supplyKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter)

// register the staking hooks
Expand Down
8 changes: 4 additions & 4 deletions x/distribution/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
bondPool := supply.NewEmptyModuleAccount(staking.BondedPoolName, supply.Burner, supply.Staking)

blacklistedAddrs := make(map[string]bool)
blacklistedAddrs[feeCollectorAcc.String()] = true
blacklistedAddrs[notBondedPool.String()] = true
blacklistedAddrs[bondPool.String()] = true
blacklistedAddrs[distrAcc.String()] = true
blacklistedAddrs[feeCollectorAcc.GetAddress().String()] = true
blacklistedAddrs[notBondedPool.GetAddress().String()] = true
blacklistedAddrs[bondPool.GetAddress().String()] = true
blacklistedAddrs[distrAcc.GetAddress().String()] = true

cdc := MakeTestCodec()
pk := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)
Expand Down
4 changes: 2 additions & 2 deletions x/gov/endblocker.go → x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) {
keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal Proposal) bool {
var tagValue, logMsg string

passes, burnDeposits, tallyResults := tally(ctx, keeper, proposal)
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)

if burnDeposits {
keeper.DeleteDeposits(ctx, proposal.ProposalID)
Expand All @@ -48,7 +48,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) {
}

if passes {
handler := keeper.router.GetRoute(proposal.ProposalRoute())
handler := keeper.Router().GetRoute(proposal.ProposalRoute())
cacheCtx, writeCache := ctx.CacheContext()

// The proposal handler may execute state mutating logic depending
Expand Down
36 changes: 16 additions & 20 deletions x/gov/endblocker_test.go → x/gov/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov

import (
"encoding/binary"
"testing"
"time"

Expand All @@ -9,11 +10,12 @@ import (
abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
keep "github.com/cosmos/cosmos-sdk/x/gov/keeper"
"github.com/cosmos/cosmos-sdk/x/staking"
)

func TestTickExpiredDepositPeriod(t *testing.T) {
input := getMockApp(t, 10, GenesisState{}, nil)
input := getMockApp(t, 10, GenesisState{}, nil, ProposalHandler)

header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -62,7 +64,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
}

func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
input := getMockApp(t, 10, GenesisState{}, nil)
input := getMockApp(t, 10, GenesisState{}, nil, ProposalHandler)

header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -130,7 +132,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
}

func TestTickPassedDepositPeriod(t *testing.T) {
input := getMockApp(t, 10, GenesisState{}, nil)
input := getMockApp(t, 10, GenesisState{}, nil, ProposalHandler)

header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand All @@ -153,8 +155,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {

res := govHandler(ctx, newProposalMsg)
require.True(t, res.IsOK())
var proposalID uint64
input.keeper.cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID)
proposalID := binary.LittleEndian.Uint64(res.Data)

inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
require.False(t, inactiveQueue.Valid())
Expand All @@ -178,7 +179,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
}

func TestTickPassedVotingPeriod(t *testing.T) {
input := getMockApp(t, 10, GenesisState{}, nil)
input := getMockApp(t, 10, GenesisState{}, nil, ProposalHandler)
SortAddresses(input.addrs)

header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
Expand All @@ -195,12 +196,11 @@ func TestTickPassedVotingPeriod(t *testing.T) {
activeQueue.Close()

proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(5))}
newProposalMsg := NewMsgSubmitProposal(testProposal(), proposalCoins, input.addrs[0])
newProposalMsg := NewMsgSubmitProposal(keep.TestProposal, proposalCoins, input.addrs[0])

res := govHandler(ctx, newProposalMsg)
require.True(t, res.IsOK())
var proposalID uint64
input.keeper.cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID)
proposalID := binary.LittleEndian.Uint64(res.Data)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

newHeader := ctx.BlockHeader()
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
Expand All @@ -223,13 +223,11 @@ func TestTickPassedVotingPeriod(t *testing.T) {

var activeProposalID uint64

require.NoError(t, input.keeper.cdc.UnmarshalBinaryLengthPrefixed(activeQueue.Value(), &activeProposalID))
require.NoError(t, input.mApp.Cdc.UnmarshalBinaryLengthPrefixed(activeQueue.Value(), &activeProposalID))
proposal, ok := input.keeper.GetProposal(ctx, activeProposalID)
require.True(t, ok)
require.Equal(t, StatusVotingPeriod, proposal.Status)
depositsIterator := input.keeper.GetDepositsIterator(ctx, proposalID)
require.True(t, depositsIterator.Valid())
depositsIterator.Close()

activeQueue.Close()

EndBlocker(ctx, input.keeper)
Expand All @@ -240,7 +238,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
}

func TestProposalPassedEndblocker(t *testing.T) {
input := getMockApp(t, 1, GenesisState{}, nil)
input := getMockApp(t, 1, GenesisState{}, nil, ProposalHandler)
SortAddresses(input.addrs)

handler := NewHandler(input.keeper)
Expand All @@ -259,7 +257,7 @@ func TestProposalPassedEndblocker(t *testing.T) {
require.NotNil(t, macc)
initialModuleAccCoins := macc.GetCoins()

proposal, err := input.keeper.SubmitProposal(ctx, testProposal())
proposal, err := input.keeper.SubmitProposal(ctx, keep.TestProposal)
require.NoError(t, err)

proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10))}
Expand Down Expand Up @@ -289,11 +287,9 @@ func TestProposalPassedEndblocker(t *testing.T) {
}

func TestEndBlockerProposalHandlerFailed(t *testing.T) {
input := getMockApp(t, 1, GenesisState{}, nil)
SortAddresses(input.addrs)

// hijack the router to one that will fail in a proposal's handler
input.keeper.router = NewRouter().AddRoute(RouterKey, badProposalHandler)
input := getMockApp(t, 1, GenesisState{}, nil, badProposalHandler)
SortAddresses(input.addrs)

handler := NewHandler(input.keeper)
stakingHandler := staking.NewHandler(input.sk)
Expand All @@ -310,7 +306,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
// Create a proposal where the handler will pass for the test proposal
// because the value of contextKeyBadProposal is true.
ctx = ctx.WithValue(contextKeyBadProposal, true)
proposal, err := input.keeper.SubmitProposal(ctx, testProposal())
proposal, err := input.keeper.SubmitProposal(ctx, keep.TestProposal)
require.NoError(t, err)

proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10)))
Expand Down
26 changes: 20 additions & 6 deletions x/gov/alias.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/gov/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/gov/types
package gov

import (
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)

Expand All @@ -23,6 +25,7 @@ const (
CodeInvalidGenesis = types.CodeInvalidGenesis
CodeInvalidProposalStatus = types.CodeInvalidProposalStatus
CodeProposalHandlerNotExists = types.CodeProposalHandlerNotExists
DefaultPeriod = types.DefaultPeriod
ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
Expand Down Expand Up @@ -59,20 +62,26 @@ const (

var (
// functions aliases
RegisterInvariants = keeper.RegisterInvariants
AllInvariants = keeper.AllInvariants
ModuleAccountInvariant = keeper.ModuleAccountInvariant
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
RegisterCodec = types.RegisterCodec
RegisterProposalTypeCodec = types.RegisterProposalTypeCodec
ValidateAbstract = types.ValidateAbstract
NewDeposit = types.NewDeposit
ErrUnknownProposal = types.ErrUnknownProposal
ErrInactiveProposal = types.ErrInactiveProposal
ErrAlreadyActiveProposal = types.ErrAlreadyActiveProposal
ErrAlreadyFinishedProposal = types.ErrAlreadyFinishedProposal
ErrAddressNotStaked = types.ErrAddressNotStaked
ErrInvalidProposalContent = types.ErrInvalidProposalContent
ErrInvalidProposalType = types.ErrInvalidProposalType
ErrInvalidVote = types.ErrInvalidVote
ErrInvalidGenesis = types.ErrInvalidGenesis
ErrNoProposalHandlerExists = types.ErrNoProposalHandlerExists
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis
ProposalKey = types.ProposalKey
ActiveProposalByTimeKey = types.ActiveProposalByTimeKey
ActiveProposalQueueKey = types.ActiveProposalQueueKey
Expand All @@ -96,11 +105,9 @@ var (
NewVotingParams = types.NewVotingParams
NewParams = types.NewParams
NewProposal = types.NewProposal
NewRouter = types.NewRouter
ProposalStatusFromString = types.ProposalStatusFromString
ValidProposalStatus = types.ValidProposalStatus
NewTallyResult = types.NewTallyResult
NewTallyResultFromMap = types.NewTallyResultFromMap
EmptyTallyResult = types.EmptyTallyResult
NewTextProposal = types.NewTextProposal
NewSoftwareUpgradeProposal = types.NewSoftwareUpgradeProposal
RegisterProposalType = types.RegisterProposalType
Expand All @@ -111,6 +118,10 @@ var (
NewQueryDepositParams = types.NewQueryDepositParams
NewQueryVoteParams = types.NewQueryVoteParams
NewQueryProposalsParams = types.NewQueryProposalsParams
NewValidatorGovInfo = types.NewValidatorGovInfo
NewTallyResult = types.NewTallyResult
NewTallyResultFromMap = types.NewTallyResultFromMap
EmptyTallyResult = types.EmptyTallyResult
NewVote = types.NewVote
VoteOptionFromString = types.VoteOptionFromString
ValidVoteOption = types.ValidVoteOption
Expand All @@ -129,10 +140,12 @@ var (
)

type (
Keeper = keeper.Keeper
Content = types.Content
Handler = types.Handler
Deposit = types.Deposit
Deposits = types.Deposits
GenesisState = types.GenesisState
MsgSubmitProposal = types.MsgSubmitProposal
MsgDeposit = types.MsgDeposit
MsgVote = types.MsgVote
Expand All @@ -144,13 +157,14 @@ type (
Proposals = types.Proposals
ProposalQueue = types.ProposalQueue
ProposalStatus = types.ProposalStatus
TallyResult = types.TallyResult
TextProposal = types.TextProposal
SoftwareUpgradeProposal = types.SoftwareUpgradeProposal
QueryProposalParams = types.QueryProposalParams
QueryDepositParams = types.QueryDepositParams
QueryVoteParams = types.QueryVoteParams
QueryProposalsParams = types.QueryProposalsParams
ValidatorGovInfo = types.ValidatorGovInfo
TallyResult = types.TallyResult
Vote = types.Vote
Votes = types.Votes
VoteOption = types.VoteOption
Expand Down
Loading