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

Improve the Gov Module Mechanism by BLV Labs #534

Open
wants to merge 67 commits into
base: blv/gov
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
cff38ea
[tutm][Proposal1][initialize]: added note props#1 file
TuSoict Sep 29, 2024
a92ee1b
add new param, custom module gov
duonghb53 Sep 29, 2024
ee4aa1a
add proto
duonghb53 Sep 30, 2024
5af0ad2
Merge commit 'ee4aa1a1b867660050d89d924802aeff99312988' into origin/b…
TuSoict Sep 30, 2024
02fc71c
generated pb.go files
TuSoict Oct 1, 2024
062774b
added value in 500$ for param: minUusdDeposit
TuSoict Oct 1, 2024
03990d2
added TotalDepositKey func
TuSoict Oct 1, 2024
4e366a6
Implemented a logic:
TuSoict Oct 1, 2024
9b22f54
Updated the converting logic in SubmitProposal Func
TuSoict Oct 1, 2024
22141bd
marshall amount before store in SetPriceLuncBaseUusd func
TuSoict Oct 2, 2024
6d7fa29
Handle the CheckLimitlDeposit rule in AddDeposit func:
TuSoict Oct 2, 2024
b80170f
Updated the HandleCheckMinInitialDeposit logic in ante of auth module
TuSoict Oct 3, 2024
76927b6
Overided keeper instance in keeper.go (gov module)
TuSoict Oct 3, 2024
2badfc1
chang proto
duonghb53 Oct 3, 2024
e26da00
Overided keeper instance in keeper.go (gov module)
TuSoict Oct 3, 2024
f63eefb
add get query cmd
duonghb53 Oct 3, 2024
b422289
move gov types to v2lunc1
duonghb53 Oct 4, 2024
5e4b632
update types the HandleCheckMinInitialDeposit logic in ante of auth m…
TuSoict Oct 4, 2024
562e610
move gov types to v2lunc1
duonghb53 Oct 4, 2024
7df5045
Merge commit 'b422289350edcdd7fcb55e6cb55badba6de5f74e' into blv-labs…
TuSoict Oct 4, 2024
d1213e8
Merge commit '562e6101037a665964ae29f5b5e80e0a50ddf568' into blv-labs…
TuSoict Oct 4, 2024
435086a
Updated a logic in genesis module
TuSoict Oct 7, 2024
c7429a4
Fixed types in MinInitialDeposit.go
TuSoict Oct 8, 2024
869d296
add keys_test.go (unitest for keys.go)
TuSoict Oct 10, 2024
eeef11a
Completed migrate from version 4 to 5.
TuSoict Oct 12, 2024
5bf6106
added missing file
TuSoict Oct 12, 2024
a4cc750
Merge branch 'blv-labs/gov-improve' into blv-labs/gov-unitest
TuSoict Oct 12, 2024
fb0f953
Update codec & fix config test
TuSoict Oct 13, 2024
a749a91
Done min_initial_deposit_test.go
TuSoict Oct 13, 2024
f8a724e
Done Genesis_test.go
TuSoict Oct 13, 2024
0c594e7
add keeper & proposal unit test
duonghb53 Oct 13, 2024
fa14819
add deposit test
duonghb53 Oct 14, 2024
61ea499
remove debug
duonghb53 Oct 14, 2024
6e9ed9b
added files for unitest:
TuSoict Oct 15, 2024
6265c9d
added migrator_test.go
TuSoict Oct 15, 2024
03ec02b
add msg server test
duonghb53 Oct 16, 2024
fa06f7e
add min uusd to genesis and debug error
duonghb53 Oct 19, 2024
5240f63
fix bug and run chain ok
duonghb53 Oct 20, 2024
10bcfdc
remove log
duonghb53 Oct 21, 2024
909c3ed
Merge branch 'blv-labs/gov-unitest' into duonghb/add-msg-server-test
duonghb53 Oct 21, 2024
3fa6092
fix msg query server and test
duonghb53 Oct 25, 2024
2c81f7b
add upgrade plan
duonghb53 Oct 26, 2024
00dfc79
add integration test upgrade chain and sub mit proposal ok
duonghb53 Oct 26, 2024
eb941ca
Review, clean and fix some bugs
TuSoict Oct 27, 2024
9e52573
revert register distribution codec
TuSoict Oct 27, 2024
6e0cf5e
update scripts, logic get min deposit
TuSoict Oct 27, 2024
a5ae5fa
added script for intergration testing
TuSoict Oct 28, 2024
68f6d12
review and clean code
TuSoict Oct 28, 2024
36a1f6e
added README.md for custom gov module
TuSoict Oct 28, 2024
3914bc8
revert register code from gov in others module
TuSoict Oct 28, 2024
6035640
Review and clean code (if needed)
TuSoict Oct 28, 2024
bec6d63
fixed checking rule: MinInitialDeposit in ante of auth module
TuSoict Oct 28, 2024
e957bfa
removed unused import in proto files
TuSoict Oct 28, 2024
a7ad120
Fixed error (unknown field "min_uusd_deposit" in v1.Params) e2e test…
TuSoict Oct 28, 2024
6e3a28c
fixed bugs when build & Test / liveness-test in testnet.go
TuSoict Oct 28, 2024
30c7ccc
fixed golangci-lint-Related Bugs
ntluongdev95 Oct 30, 2024
0832c67
removed .history files
ntluongdev95 Oct 30, 2024
4cd9346
add logic get uusd
duonghb53 Nov 3, 2024
ae8d370
fix lint
duonghb53 Nov 3, 2024
2f33b29
Merge pull request #2 from BLV-Labs/fix/get-uusd-price
duonghb53 Nov 4, 2024
d780c04
fix generate address by order
duonghb53 Nov 4, 2024
4c44c75
Deleted useless file to clean code
TuSoict Nov 6, 2024
7955ba0
added offset buffet to reduce limit initial deposit when creating prop
TuSoict Nov 10, 2024
2f1168f
Updated unitest
TuSoict Nov 10, 2024
69c5019
update uusd amount
duonghb53 Nov 16, 2024
71143d8
Merge branch 'blv/gov' into blv-labs/optimize-calculation-deposit-gov…
TuSoict Nov 25, 2024
43ef592
resolve comment
duonghb53 Nov 29, 2024
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
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
v8_1 "github.com/classic-terra/core/v3/app/upgrades/v8_1"
v8_2 "github.com/classic-terra/core/v3/app/upgrades/v8_2"
v8_3 "github.com/classic-terra/core/v3/app/upgrades/v8_3"
v8_4 "github.com/classic-terra/core/v3/app/upgrades/v8_4"

// v9 had been used by tax2gas and has to be skipped
v10 "github.com/classic-terra/core/v3/app/upgrades/v10"
Expand Down Expand Up @@ -94,6 +95,7 @@ var (
v8_1.Upgrade,
v8_2.Upgrade,
v8_3.Upgrade,
v8_4.Upgrade,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change to v10_1 as the current prepared release will use v10

v10.Upgrade,
}

Expand Down
9 changes: 6 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
Expand All @@ -62,6 +61,8 @@ import (
customwasmkeeper "github.com/classic-terra/core/v3/custom/wasm/keeper"
terrawasm "github.com/classic-terra/core/v3/wasmbinding"

customgovkeeper "github.com/classic-terra/core/v3/custom/gov/keeper"

dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper"
dyncommtypes "github.com/classic-terra/core/v3/x/dyncomm/types"
marketkeeper "github.com/classic-terra/core/v3/x/market/keeper"
Expand All @@ -87,7 +88,7 @@ type AppKeepers struct {
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
GovKeeper customgovkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
Expand Down Expand Up @@ -444,18 +445,20 @@ func NewAppKeepers(
// register the proposal types
govRouter := appKeepers.newGovRouter()
govConfig := govtypes.DefaultConfig()
govKeeper := govkeeper.NewKeeper(
govKeeper := customgovkeeper.NewKeeper(
appCodec,
appKeepers.keys[govtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.OracleKeeper,
bApp.MsgServiceRouter(),
govConfig,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)

appKeepers.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
Expand Down
7 changes: 4 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
customdistr "github.com/classic-terra/core/v3/custom/distribution"
customevidence "github.com/classic-terra/core/v3/custom/evidence"
customfeegrant "github.com/classic-terra/core/v3/custom/feegrant"
// "github.com/classic-terra/core/v3/custom/gov"
customgov "github.com/classic-terra/core/v3/custom/gov"
custommint "github.com/classic-terra/core/v3/custom/mint"
customparams "github.com/classic-terra/core/v3/custom/params"
Expand Down Expand Up @@ -50,7 +51,7 @@ import (
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"

govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
Expand Down Expand Up @@ -171,7 +172,7 @@ func appModules(
taxbank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.TreasuryKeeper, app.GetSubspace(banktypes.ModuleName), app.TaxKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
customgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
Expand Down Expand Up @@ -207,7 +208,7 @@ func simulationModules(
custombank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
customgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
Expand Down
13 changes: 13 additions & 0 deletions app/upgrades/v8_4/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//nolint:revive
package v8_4

import (
"github.com/classic-terra/core/v3/app/upgrades"
)

const UpgradeName = "v8_4"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV84UpgradeHandler,
}
21 changes: 21 additions & 0 deletions app/upgrades/v8_4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//nolint:revive
package v8_4

import (
"github.com/classic-terra/core/v3/app/keepers"
"github.com/classic-terra/core/v3/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateV84UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
4 changes: 2 additions & 2 deletions cmd/terrad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"path/filepath"
"time"

govv2lunc1 "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
tmconfig "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/types"
tmtime "github.com/cometbft/cometbft/types/time"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -309,7 +309,7 @@ func initGenFiles(
appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState)

// set gov in the genesis state
var govGenState govv1.GenesisState
var govGenState govv2lunc1.GenesisState
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid namings like "lunc" in types, if you want to use something non-generic, you might use "terra" or similar

clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)
votingPeriod := time.Minute * 3
govGenState.Params.VotingPeriod = &votingPeriod
Expand Down
4 changes: 2 additions & 2 deletions custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"

customgovkeeper "github.com/classic-terra/core/v3/custom/gov/keeper"
dyncommante "github.com/classic-terra/core/v3/x/dyncomm/ante"
dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -37,7 +37,7 @@ type HandlerOptions struct {
IBCKeeper ibckeeper.Keeper
WasmKeeper *wasmkeeper.Keeper
DistributionKeeper distributionkeeper.Keeper
GovKeeper govkeeper.Keeper
GovKeeper customgovkeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
DyncommKeeper dyncommkeeper.Keeper
Expand Down
34 changes: 17 additions & 17 deletions custom/auth/ante/min_initial_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"fmt"

errorsmod "cosmossdk.io/errors"
core "github.com/classic-terra/core/v3/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

core "github.com/classic-terra/core/v3/types"
customgovkeeper "github.com/classic-terra/core/v3/custom/gov/keeper"
)

// MinInitialDeposit Decorator will check Initial Deposits for MsgSubmitProposal
type MinInitialDepositDecorator struct {
govKeeper govkeeper.Keeper
govKeeper customgovkeeper.Keeper
treasuryKeeper TreasuryKeeper
}

// NewMinInitialDeposit returns new min initial deposit decorator instance
func NewMinInitialDepositDecorator(govKeeper govkeeper.Keeper, treasuryKeeper TreasuryKeeper) MinInitialDepositDecorator {
func NewMinInitialDepositDecorator(govKeeper customgovkeeper.Keeper, treasuryKeeper TreasuryKeeper) MinInitialDepositDecorator {
return MinInitialDepositDecorator{
govKeeper: govKeeper,
treasuryKeeper: treasuryKeeper,
Expand All @@ -38,9 +38,8 @@ func IsMsgSubmitProposal(msg sdk.Msg) bool {
}

// HandleCheckMinInitialDeposit
func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper govkeeper.Keeper, treasuryKeeper TreasuryKeeper) (err error) {
func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper customgovkeeper.Keeper, treasuryKeeper TreasuryKeeper) (err error) {
var initialDepositCoins sdk.Coins

switch submitPropMsg := msg.(type) {
case *govv1beta1.MsgSubmitProposal:
initialDepositCoins = submitPropMsg.GetInitialDeposit()
Expand All @@ -49,18 +48,19 @@ func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper govkee
default:
return fmt.Errorf("could not dereference msg as MsgSubmitProposal")
}
minDeposit := govKeeper.GetParams(ctx).MinDeposit
requiredAmount := sdk.NewDecFromInt(minDeposit[0].Amount).Mul(treasuryKeeper.GetMinInitialDepositRatio(ctx)).TruncateInt()

requiredDepositCoins := sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, requiredAmount),
)

if !initialDepositCoins.IsAllGTE(requiredDepositCoins) {
return fmt.Errorf("not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
// set offset price change 3%
offsetPrice := sdk.NewDecWithPrec(97, 2)
minLuncAmount, err := govKeeper.GetMinimumDepositBaseUusd(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please to not use "Lunc" in variables. The denom would be "minUlunaAmount" if you want to include the denom in the variable name. Lunc would not be the microunit.

minInitialDepositRatio := treasuryKeeper.GetMinInitialDepositRatio(ctx)
if err == nil && minLuncAmount.GT(sdk.ZeroInt()) {
requiredDeposit := sdk.NewDecFromInt(minLuncAmount).Mul(minInitialDepositRatio).Mul(offsetPrice).TruncateInt()
requiredDepositCoins := sdk.NewCoins(sdk.NewCoin(core.MicroLunaDenom, requiredDeposit))
if initialDepositCoins.IsAllLT(requiredDepositCoins) {
return fmt.Errorf("not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
}
return nil
}

return nil
return fmt.Errorf("could not get minimum deposit base uusd")
}

// AnteHandle handles checking MsgSubmitProposal
Expand Down
65 changes: 37 additions & 28 deletions custom/auth/ante/min_initial_deposit_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
package ante_test

import (
// "fmt"
"fmt"

"github.com/classic-terra/core/v3/custom/auth/ante"
govv2lunc1 "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
core "github.com/classic-terra/core/v3/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"

// banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/classic-terra/core/v3/custom/auth/ante"
core "github.com/classic-terra/core/v3/types"

// core "github.com/terra-money/core/types"
// treasury "github.com/terra-money/core/x/treasury/types"

// "github.com/cosmos/cosmos-sdk/types/query"
// cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"
// "github.com/cosmos/cosmos-sdk/x/auth/types"
// minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
Expand All @@ -30,14 +20,19 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioDefault() {
midd := ante.NewMinInitialDepositDecorator(suite.app.GovKeeper, suite.app.TreasuryKeeper)
antehandler := sdk.ChainAnteDecorators(midd)

lunaPriceInUSD := sdk.MustNewDecFromStr("0.10008905")
fmt.Printf("\n lunaPriceInUSD %s", lunaPriceInUSD.String())
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinDeposit = sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, sdk.NewInt(1_000_000)),
)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())

// set initial deposit ratio to 0.0
ratio := sdk.ZeroDec()
suite.app.TreasuryKeeper.SetMinInitialDepositRatio(suite.ctx, ratio)
Expand Down Expand Up @@ -85,23 +80,32 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioWithSufficientDeposit() {
midd := ante.NewMinInitialDepositDecorator(suite.app.GovKeeper, suite.app.TreasuryKeeper)
antehandler := sdk.ChainAnteDecorators(midd)

lunaPriceInUSD := sdk.MustNewDecFromStr("0.0001")
fmt.Printf("\n lunaPriceInUSD %s", lunaPriceInUSD.String())
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinDeposit = sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, sdk.NewInt(1_000_000)),
)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())

// set initial deposit ratio to 0.2
ratio := sdk.NewDecWithPrec(2, 1)
suite.app.TreasuryKeeper.SetMinInitialDepositRatio(suite.ctx, ratio)

// keys and addresses

initDeposit, _ := sdk.NewIntFromString("1000000000000")
fmt.Printf("\n initDeposit %s", initDeposit.String())

priv1, _, addr1 := testdata.KeyTestPubAddr()
prop1 := govv1beta1.NewTextProposal("prop1", "prop1")
depositCoins1 := sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, sdk.NewInt(200_000)),
sdk.NewCoin(core.MicroLunaDenom, initDeposit),
)

// create prop tx
Expand Down Expand Up @@ -142,14 +146,19 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioWithInsufficientDeposit()
midd := ante.NewMinInitialDepositDecorator(suite.app.GovKeeper, suite.app.TreasuryKeeper)
antehandler := sdk.ChainAnteDecorators(midd)

lunaPriceInUSD := sdk.MustNewDecFromStr("0.00008905")
fmt.Printf("\n lunaPriceInUSD %s", lunaPriceInUSD.String())
suite.app.OracleKeeper.SetLunaExchangeRate(suite.ctx, core.MicroUSDDenom, lunaPriceInUSD)

// set required deposit to uluna
suite.app.GovKeeper.SetParams(suite.ctx, govv1.DefaultParams())
suite.app.GovKeeper.SetParams(suite.ctx, govv2lunc1.DefaultParams())
govparams := suite.app.GovKeeper.GetParams(suite.ctx)
govparams.MinDeposit = sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, sdk.NewInt(1_000_000)),
)
govparams.MinUusdDeposit = sdk.NewCoin(core.MicroUSDDenom, sdk.NewInt(500_000_000))
suite.app.GovKeeper.SetParams(suite.ctx, govparams)

price, _ := suite.app.GovKeeper.GetMinimumDepositBaseUusd(suite.ctx)
fmt.Printf("\n GetMinimumDepositBaseUusd %s", price.String())

// set initial deposit ratio to 0.2
ratio := sdk.NewDecWithPrec(2, 1)
suite.app.TreasuryKeeper.SetMinInitialDepositRatio(suite.ctx, ratio)
Expand Down Expand Up @@ -187,7 +196,7 @@ func (suite *AnteTestSuite) TestMinInitialDepositRatioWithInsufficientDeposit()
txv1, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)

// ante handler should error for v1 proposal with insufficient deposit
// // ante handler should error for v1 proposal with insufficient deposit
_, err = antehandler(suite.ctx, txv1, false)
suite.Require().Error(err, "error: v1 proposal with insufficient initial deposit should have failed")
}
2 changes: 1 addition & 1 deletion custom/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/x/distribution/types"

govtypes "github.com/classic-terra/core/v3/custom/gov/types"
govtypes "github.com/classic-terra/core/v3/custom/gov/types/v2lunc1"
)

// RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types
Expand Down
Loading
Loading