Skip to content

Commit

Permalink
partial: update democ tests (use Param collections)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Oct 17, 2023
1 parent ae1cbf3 commit 5fc2f2e
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 519 deletions.
24 changes: 12 additions & 12 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,10 @@ func (app *App) GetTestSlashingKeeper() testutil.TestSlashingKeeper {
return app.SlashingKeeper
}

// // GetTestEvidenceKeeper implements the ConsumerApp interface.
// func (app *App) GetTestEvidenceKeeper() testutil.TestEvidenceKeeper {
// return app.EvidenceKeeper
// }
// GetTestEvidenceKeeper implements the ConsumerApp interface.
func (app *App) GetTestEvidenceKeeper() evidencekeeper.Keeper {
return app.EvidenceKeeper
}

// GetTestStakingKeeper implements the ConsumerApp interface.
func (app *App) GetTestStakingKeeper() testutil.TestStakingKeeper {
Expand All @@ -892,15 +892,15 @@ func (app *App) GetTestDistributionKeeper() testutil.TestDistributionKeeper {
return app.DistrKeeper
}

// // GetTestMintKeeper implements the ConsumerApp interface.
// func (app *App) GetTestMintKeeper() testutil.TestMintKeeper {
// return app.MintKeeper
// }
// GetTestMintKeeper implements the ConsumerApp interface.
func (app *App) GetTestMintKeeper() mintkeeper.Keeper {
return app.MintKeeper
}

// // GetTestGovKeeper implements the ConsumerApp interface.
// func (app *App) GetTestGovKeeper() testutil.TestGovKeeper {
// return app.GovKeeper
// }
// GetTestGovKeeper implements the ConsumerApp interface.
func (app *App) GetTestGovKeeper() govkeeper.Keeper {
return app.GovKeeper
}

// TestingApp functions

Expand Down
5 changes: 5 additions & 0 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ func (app *App) GetTestSlashingKeeper() testutil.TestSlashingKeeper {
return app.SlashingKeeper
}

// GetTestEvidenceKeeper implements the ConsumerApp interface.
func (app *App) GetTestEvidenceKeeper() evidencekeeper.Keeper {
return app.EvidenceKeeper
}

// TestingApp functions

// GetBaseApp implements the TestingApp interface.
Expand Down
18 changes: 9 additions & 9 deletions app/sovereign/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ func (app *App) GetTestSlashingKeeper() testutil.TestSlashingKeeper {
return app.SlashingKeeper
}

// func (app *App) GetTestEvidenceKeeper() testutil.TestEvidenceKeeper {
// return app.EvidenceKeeper
// }
func (app *App) GetTestEvidenceKeeper() evidencekeeper.Keeper {
return app.EvidenceKeeper
}

func (app *App) GetTestStakingKeeper() testutil.TestStakingKeeper {
return app.StakingKeeper
Expand All @@ -769,13 +769,13 @@ func (app *App) GetTestDistributionKeeper() testutil.TestDistributionKeeper {
return app.DistrKeeper
}

// func (app *App) GetTestMintKeeper() testutil.TestMintKeeper {
// return app.MintKeeper
// }
func (app *App) GetTestMintKeeper() mintkeeper.Keeper {
return app.MintKeeper
}

// func (app *App) GetTestGovKeeper() testutil.TestGovKeeper {
// return app.GovKeeper
// }
func (app *App) GetTestGovKeeper() govkeeper.Keeper {
return app.GovKeeper
}

// TestingApp functions

Expand Down
32 changes: 23 additions & 9 deletions tests/integration/democracy.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"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -159,9 +160,12 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() {
}
}

// @MSalopek -> this is broken for v50
func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
govKeeper := s.consumerApp.GetTestGovKeeper()
params := govKeeper.GetParams(s.consumerCtx())
params, err := govKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)

stakingKeeper := s.consumerApp.GetTestStakingKeeper()
bankKeeper := s.consumerApp.GetTestBankKeeper()
accountKeeper := s.consumerApp.GetTestAccountKeeper()
Expand All @@ -174,14 +178,15 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
depositAmount := params.MinDeposit
duration := (3 * time.Second)
params.VotingPeriod = &duration
err = govKeeper.SetParams(s.consumerCtx(), params)
err = govKeeper.Params.Set(s.consumerCtx(), params)
s.Assert().NoError(err)
proposer := s.consumerChain.SenderAccount
s.consumerChain.NextBlock()
votersOldBalances := getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts)

// submit proposal with forbidden and allowed changes
mintParams := mintKeeper.GetParams(s.consumerCtx())
mintParams, err := mintKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)
mintParams.InflationMax = newMintParamValue
msg_1 := &minttypes.MsgUpdateParams{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand All @@ -201,11 +206,15 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
s.consumerChain.NextBlock()
// at this moment, proposal is added, but not yet executed. we are saving old param values for comparison
oldAuthParamValue := accountKeeper.GetParams(s.consumerCtx()).MaxMemoCharacters
oldMintParamValue := mintKeeper.GetParams(s.consumerCtx()).InflationMax
oldMintParams, err := mintKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)
oldMintParamValue := oldMintParams.InflationMax
s.consumerChain.NextBlock()
// at this moment, proposal is executed or deleted if forbidden
currentAuthParamValue := accountKeeper.GetParams(s.consumerCtx()).MaxMemoCharacters
currentMintParamValue := mintKeeper.GetParams(s.consumerCtx()).InflationMax
currentMintParam, err := mintKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)
currentMintParamValue := currentMintParam.InflationMax
// check that parameters are not changed, since the proposal contained both forbidden and allowed changes
s.Assert().Equal(oldAuthParamValue, currentAuthParamValue)
s.Assert().NotEqual(newAuthParamValue, currentAuthParamValue)
Expand All @@ -219,9 +228,14 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
s.Assert().NoError(err)
s.consumerChain.CurrentHeader.Time = s.consumerChain.CurrentHeader.Time.Add(*params.VotingPeriod)
s.consumerChain.NextBlock()
oldMintParamValue = mintKeeper.GetParams(s.consumerCtx()).InflationMax
oldMintParam, err := mintKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)
oldMintParamValue = oldMintParam.InflationMax
s.consumerChain.NextBlock()
currentMintParamValue = mintKeeper.GetParams(s.consumerCtx()).InflationMax
currentMintParam, err = mintKeeper.Params.Get(s.consumerCtx())
s.Require().NoError(err)

currentMintParamValue = currentMintParam.InflationMax
// check that parameters are changed, since the proposal contained only allowed changes
s.Assert().Equal(newMintParamValue, currentMintParamValue)
s.Assert().NotEqual(oldMintParamValue, currentMintParamValue)
Expand All @@ -244,10 +258,10 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() {
s.Assert().Equal(votersOldBalances, getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts))
}

func submitProposalWithDepositAndVote(govKeeper testutil.TestGovKeeper, ctx sdk.Context, msgs []sdk.Msg,
func submitProposalWithDepositAndVote(govKeeper govkeeper.Keeper, ctx sdk.Context, msgs []sdk.Msg,
accounts []ibctesting.SenderAccount, proposer sdk.AccAddress, depositAmount sdk.Coins,
) error {
proposal, err := govKeeper.SubmitProposal(ctx, msgs, "", "title", "summary", proposer)
proposal, err := govKeeper.SubmitProposal(ctx, msgs, "", "title", "summary", proposer, false)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ func (s CCVTestSuite) validateEndpointsClientConfig(consumerBundle icstestinguti
"unexpected unbonding period in consumer client state",
)

providerUnbondingPeriod := providerStakingKeeper.UnbondingTime(s.providerCtx())
providerUnbondingPeriod, err := providerStakingKeeper.UnbondingTime(s.providerCtx())
s.Require().NoError(err)
cs, ok = consumerBundle.App.GetIBCKeeper().ClientKeeper.GetClientState(
consumerBundle.GetCtx(), consumerBundle.Path.EndpointA.ClientID)
s.Require().True(ok)
Expand Down
2 changes: 1 addition & 1 deletion testutil/ibc_testing/specific_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func ConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter {
func DemocracyConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter {
return func() (ibctesting.TestingApp, map[string]json.RawMessage) {
encoding := appConsumerDemocracy.MakeTestEncodingConfig()
testApp := appConsumerDemocracy.New(log.NewNopLogger(), tmdb.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{})
testApp := appConsumerDemocracy.New(log.NewNopLogger(), db.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{})
genesisState := appConsumerDemocracy.NewDefaultGenesisState(encoding.Codec)
// Feed consumer genesis with provider validators
// TODO See if useful for democracy
Expand Down
29 changes: 7 additions & 22 deletions testutil/integration/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -79,9 +79,10 @@ type DemocConsumerApp interface {
// Tests a staking keeper interface with more capabilities than the expected_keepers interface
GetTestStakingKeeper() TestStakingKeeper
// Tests a mint keeper interface with more capabilities than the expected_keepers interface
GetTestMintKeeper() TestMintKeeper
// Tests a gov keeper interface with more capabilities than the expected_keepers interface
GetTestGovKeeper() TestGovKeeper
GetTestMintKeeper() mintkeeper.Keeper

// @MSalopek -> on v50 we need to access the Params collection which does not have a getter
GetTestGovKeeper() govkeeper.Keeper
}

//
Expand Down Expand Up @@ -124,18 +125,14 @@ type TestAccountKeeper interface {

type TestSlashingKeeper interface {
ccvtypes.SlashingKeeper
IterateMissedBlockBitmap(ctx context.Context, addr sdk.ConsAddress, cb func(index int64, missed bool) (stop bool)) error
SetValidatorSigningInfo(ctx context.Context, address sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) error
SignedBlocksWindow(ctx context.Context) (int64, error)
HandleValidatorSignature(ctx context.Context, addr cryptotypes.Address, power int64, signed comet.BlockIDFlag) error
MinSignedPerWindow(ctx context.Context) (int64, error)
// NOTE: @MSalopek deprecated in v50
// IterateValidatorMissedBlockBitArray(ctx sdk.Context,
// address sdk.ConsAddress, handler func(index int64, missed bool) (stop bool))
}

type TestEvidenceKeeper interface {
// HandleEquivocationEvidence(ctx sdk.Context, evidence *evidencetypes.Equivocation)
IterateMissedBlockBitmap(ctx context.Context, addr sdk.ConsAddress, cb func(index int64, missed bool) (stop bool)) error
}

type TestDistributionKeeper interface {
Expand All @@ -145,15 +142,3 @@ type TestDistributionKeeper interface {
GetValidatorOutstandingRewards(ctx context.Context, val sdk.ValAddress) (rewards distributiontypes.ValidatorOutstandingRewards, err error)
GetCommunityTax(ctx context.Context) (math.LegacyDec, error)
}

type TestMintKeeper interface {
GetParams(ctx sdk.Context) (params minttypes.Params)
}

type TestGovKeeper interface {
GetParams(ctx sdk.Context) govv1.Params
SetParams(ctx sdk.Context, params govv1.Params) error
SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress) (govv1.Proposal, error)
AddDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress, depositAmount sdk.Coins) (bool, error)
AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress, options govv1.WeightedVoteOptions, metadata string) error
}
19 changes: 0 additions & 19 deletions testutil/simibc/README.md

This file was deleted.

114 changes: 0 additions & 114 deletions testutil/simibc/ordered_outbox.go

This file was deleted.

Loading

0 comments on commit 5fc2f2e

Please sign in to comment.