Skip to content

Commit

Permalink
Merge branch 'main' into tuan/refactor-error
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 authored Apr 30, 2024
2 parents 818fced + 0a2481d commit b60c9fa
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 803 deletions.
2 changes: 1 addition & 1 deletion client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (ctx Context) WithKeyringOptions(opts ...keyring.Option) Context {
// WithInput returns a copy of the context with an updated input.
func (ctx Context) WithInput(r io.Reader) Context {
// convert to a bufio.Reader to have a shared buffer between the keyring and the
// the Commands, ensuring a read from one advance the read pointer for the other.
// Commands, ensuring a read from one advance the read pointer for the other.
// see https://github.com/cosmos/cosmos-sdk/issues/9566.
ctx.Input = bufio.NewReader(r)
return ctx
Expand Down
5 changes: 5 additions & 0 deletions x/auth/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"cosmossdk.io/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
)

// AccountKeeper defines the contract needed for AccountKeeper related APIs.
Expand All @@ -26,3 +27,7 @@ type AccountKeeper interface {
type FeegrantKeeper interface {
UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
}

type ConsensusKeeper interface {
Params(context.Context, *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error)
}
5 changes: 3 additions & 2 deletions x/gov/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func NormalizeProposalType(proposalType string) v1.ProposalType {

// NormalizeWeightedVoteOptions - normalize vote options param string
func NormalizeWeightedVoteOptions(options string) string {
newOptions := []string{}
for _, option := range strings.Split(options, ",") {
tmpOptions := strings.Split(options, ",")
newOptions := make([]string, 0, len(tmpOptions))
for _, option := range tmpOptions {
fields := strings.Split(option, "=")
fields[0] = NormalizeVoteOption(fields[0])
if len(fields) < 2 {
Expand Down
1 change: 0 additions & 1 deletion x/gov/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func (k Keeper) EndBlocker(ctx context.Context) error {
// once the regular voting period expires again, the tally is repeated
// according to the regular proposal rules.
proposal.ProposalType = v1.ProposalType_PROPOSAL_TYPE_STANDARD
proposal.Expedited = false // can be removed as never read but kept for state coherence
params, err := k.Params.Get(ctx)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (k Keeper) validateInitialDeposit(params v1.Params, initialDeposit sdk.Coin

// validateDepositDenom validates if the deposit denom is accepted by the governance module.
func (k Keeper) validateDepositDenom(params v1.Params, depositAmount sdk.Coins) error {
denoms := []string{}
denoms := make([]string, 0, len(params.MinDeposit))
acceptedDenoms := make(map[string]bool, len(params.MinDeposit))
for _, coin := range params.MinDeposit {
acceptedDenoms[coin.Denom] = true
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
}
}

msgs := []string{} // will hold a string slice of all Msg type URLs.
msgs := make([]string, 0, len(messages)) // will hold a string slice of all Msg type URLs.

// Loop through all messages and confirm that each has a handler and the gov module account as the only signer
for _, msg := range messages {
Expand Down
4 changes: 3 additions & 1 deletion x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ func SimulateMsgDeposit(
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "unable to get proposal"), nil, err
}

deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, p.Expedited)
isExpedited := p.ProposalType == v1.ProposalType_PROPOSAL_TYPE_EXPEDITED

deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, false, isExpedited)
switch {
case skip:
return simtypes.NoOpMsg(types.ModuleName, TypeMsgDeposit, "skip deposit"), nil, nil
Expand Down
35 changes: 30 additions & 5 deletions x/gov/testutil/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,40 @@ package testutil
import (
"context"

addresscodec "cosmossdk.io/core/address"
"cosmossdk.io/math"
bankkeeper "cosmossdk.io/x/bank/keeper"
"cosmossdk.io/x/gov/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// AccountKeeper extends gov's actual expected AccountKeeper with additional
// methods used in tests.
type AccountKeeper interface {
types.AccountKeeper
AddressCodec() addresscodec.Codec

GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI

GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI

// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(context.Context, sdk.ModuleAccountI)

IterateAccounts(ctx context.Context, cb func(account sdk.AccountI) (stop bool))
}

// BankKeeper extends gov's actual expected BankKeeper with additional
// methods used in tests.
type BankKeeper interface {
bankkeeper.Keeper
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx context.Context, address []byte, amt sdk.Coins) error
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

// PoolKeeper extends the gov's actual expected PoolKeeper.
Expand All @@ -34,7 +49,17 @@ type PoolKeeper interface {
// StakingKeeper extends gov's actual expected StakingKeeper with additional
// methods used in tests.
type StakingKeeper interface {
types.StakingKeeper
ValidatorAddressCodec() addresscodec.Codec
// iterate through bonded validators by operator address, execute func for each validator
IterateBondedValidatorsByPower(
context.Context, func(index int64, validator sdk.ValidatorI) (stop bool),
) error

TotalBondedTokens(context.Context) (math.Int, error) // total bonded tokens within the validator set
IterateDelegations(
ctx context.Context, delegator sdk.AccAddress,
fn func(index int64, delegation sdk.DelegationI) (stop bool),
) error

BondDenom(ctx context.Context) (string, error)
TokensFromConsensusPower(ctx context.Context, power int64) math.Int
Expand Down
Loading

0 comments on commit b60c9fa

Please sign in to comment.