-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: expedited related gov params are not adjusted (#1623)
* Problem: expedited related gov params are not adjusted * test * test expedited * lint
- Loading branch information
Showing
12 changed files
with
331 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package app_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"cosmossdk.io/math" | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
"github.com/crypto-org-chain/cronos/v2/app" | ||
"github.com/evmos/ethermint/crypto/ethsecp256k1" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type AppTestSuite struct { | ||
suite.Suite | ||
|
||
ctx sdk.Context | ||
app *app.App | ||
govParams govv1.Params | ||
} | ||
|
||
func TestAppTestSuite(t *testing.T) { | ||
suite.Run(t, new(AppTestSuite)) | ||
} | ||
|
||
func (suite *AppTestSuite) SetupTest() { | ||
checkTx := false | ||
privKey, err := ethsecp256k1.GenerateKey() | ||
suite.Require().NoError(err) | ||
suite.app = app.Setup(suite.T(), sdk.AccAddress(privKey.PubKey().Address()).String()) | ||
suite.ctx = suite.app.NewContext(checkTx).WithBlockHeader(tmproto.Header{Height: 1, ChainID: app.TestAppChainID, Time: time.Now().UTC()}) | ||
suite.govParams, err = suite.app.GovKeeper.Params.Get(suite.ctx) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(govv1.DefaultParams(), suite.govParams) | ||
} | ||
|
||
func (suite *AppTestSuite) TestUpdateExpeditedParams() { | ||
const baseDenom = "basetcro" | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
exp func(params govv1.Params) | ||
}{ | ||
{ | ||
name: "update ExpeditedMinDeposit with baseDenom", | ||
malleate: func() { | ||
suite.govParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(baseDenom, math.NewInt(2000000000000))) | ||
}, | ||
exp: func(params govv1.Params) { | ||
expected := sdk.NewCoins(sdk.NewCoin(suite.govParams.MinDeposit[0].Denom, suite.govParams.MinDeposit[0].Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio))) | ||
suite.Require().Equal(expected[0], params.ExpeditedMinDeposit[0]) | ||
}, | ||
}, | ||
{ | ||
name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold", | ||
malleate: func() { | ||
suite.govParams.Threshold = "0.99" | ||
}, | ||
exp: func(params govv1.Params) { | ||
suite.Require().Equal(math.LegacyOneDec().String(), params.ExpeditedThreshold) | ||
}, | ||
}, | ||
{ | ||
name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold", | ||
malleate: func() { | ||
suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.String() | ||
}, | ||
exp: func(params govv1.Params) { | ||
expected := app.DefaultThresholdRatio().Mul(math.LegacyMustNewDecFromStr(suite.govParams.Threshold)) | ||
suite.Require().Equal(expected.String(), params.ExpeditedThreshold) | ||
}, | ||
}, | ||
{ | ||
name: "no update ExpeditedThreshold when DefaultExpeditedThreshold < Threshold", | ||
malleate: func() { | ||
suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.Quo(math.LegacyMustNewDecFromStr("1.1")).String() | ||
}, | ||
exp: func(params govv1.Params) { | ||
suite.Require().Equal(suite.govParams.ExpeditedThreshold, params.ExpeditedThreshold) | ||
}, | ||
}, | ||
{ | ||
name: "update ExpeditedVotingPeriod when DefaultExpeditedPeriod >= VotingPeriod", | ||
malleate: func() { | ||
period := govv1.DefaultExpeditedPeriod | ||
suite.govParams.VotingPeriod = &period | ||
}, | ||
exp: func(params govv1.Params) { | ||
votingPeriod := app.DurationToDec(*suite.govParams.VotingPeriod) | ||
expected := app.DecToDuration(app.DefaultPeriodRatio().Mul(votingPeriod)) | ||
suite.Require().Equal(expected, *params.ExpeditedVotingPeriod) | ||
}, | ||
}, | ||
{ | ||
name: "no update ExpeditedVotingPeriod when DefaultExpeditedPeriod < VotingPeriod", | ||
malleate: func() { | ||
period := govv1.DefaultExpeditedPeriod + 1 | ||
suite.govParams.VotingPeriod = &period | ||
}, | ||
exp: func(params govv1.Params) { | ||
suite.Require().Equal(*suite.govParams.ExpeditedVotingPeriod, *params.ExpeditedVotingPeriod) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
tc.malleate() | ||
suite.Require().NoError(suite.app.GovKeeper.Params.Set(suite.ctx, suite.govParams)) | ||
suite.Require().NoError(app.UpdateExpeditedParams(suite.ctx, suite.app.GovKeeper)) | ||
params, err := suite.app.GovKeeper.Params.Get(suite.ctx) | ||
suite.Require().NoError(err) | ||
tc.exp(params) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.