0g-chain/x/committee/keeper/_param_permission_test.go

269 lines
8.3 KiB
Go
Raw Normal View History

package keeper_test
import (
"testing"
"time"
Update cosmos-sdk to v0.47.7 (#1811) * Update cometbft, cosmos, ethermint, and ibc-go * Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft * Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db * Replace gogo/protobuf with cosmos/gogoproto & simapp replacement * Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims * Remove no longer used simulations * Replace ibchost with ibcexported See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants * Add new consensus params keeper * Add consensus keeper to blockers * Fix keeper and module issues in app.go * Add IsSendEnabledCoins and update SetParams interface changes * Fix protobuf build for cosmos 47 (#1800) * fix cp errors by using -f; fix lint by only linting our proto dir; and use proofs.proto directly from ics23 for ibc-go v7 * run proto-all; commit updated third party deps and swagger changes * regenerate proto files * use correct gocosmos build plugin for buf * re-gen all protobuf files to update paths for new gocosmos plugin * update protoc and buf to latest versions * fix staking keeper issues in app.go * update tally handler for gov changes * chain id fix and flag fixes * update deps for cometbft 47.7 upgrade * remove all module legacy queriers * update stakingKeeper to pointer * Replace ModuleCdc from govv1beta1 to govcodec * remove simulations * abci.LastCommitInfo → abci.CommitInfo * Remove unused code in keys.go * simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi * Fix chain id issues in tests * Fix remaining unit test issues * Update changelog for upgrade * Fix e2e tests using updated kvtool * Update protonet to v47 compatible genesis * Bump cometbft-db to v0.9.1-kava.1 * Update kvtool * Remove extra changelog * Fix merged rocksdb issues * go mod cleanup * Bump cometbft-db to v9 and go to 1.21 * Bump rocksdb version to v8.10.0 * Update kvtool to latest version * Update gin to v1.9.0 * Use ibctm.ModuleName in app_test * Fallback to genesis chain id instead of client toml * Remove all simulations * Fix cdp migrations issue with v47 * Update dependencies to correct tags --------- Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2024-02-06 22:54:10 +00:00
sdkmath "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/suite"
2024-05-01 03:17:24 +00:00
"github.com/0glabs/0g-chain/app"
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
"github.com/0glabs/0g-chain/x/committee/types"
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
)
type PermissionTestSuite struct {
suite.Suite
cdc codec.Codec
}
func (suite *PermissionTestSuite) SetupTest() {
app := app.NewTestApp()
suite.cdc = app.AppCodec()
}
2024-05-01 05:53:58 +00:00
// func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() {
// // cdp CollateralParams
// testCPs := cdptypes.CollateralParams{
// {
// Denom: "bnb",
// Type: "bnb-a",
// LiquidationRatio: d("2.0"),
// DebtLimit: c("usdx", 1000000000000),
// StabilityFee: d("1.000000001547125958"),
// LiquidationPenalty: d("0.05"),
// AuctionSize: i(100),
// Prefix: 0x20,
// ConversionFactor: i(6),
// SpotMarketID: "bnb:usd",
// LiquidationMarketID: "bnb:usd",
// },
// {
// Denom: "btc",
// Type: "btc-a",
// LiquidationRatio: d("1.5"),
// DebtLimit: c("usdx", 1000000000),
// StabilityFee: d("1.000000001547125958"),
// LiquidationPenalty: d("0.10"),
// AuctionSize: i(1000),
// Prefix: 0x30,
// ConversionFactor: i(8),
// SpotMarketID: "btc:usd",
// LiquidationMarketID: "btc:usd",
// },
// }
// testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs))
// copy(testCPUpdatedDebtLimit, testCPs)
// testCPUpdatedDebtLimit[0].DebtLimit = c("usdx", 5000000)
2024-05-01 05:53:58 +00:00
// // cdp DebtParam
// testDP := cdptypes.DebtParam{
// Denom: "usdx",
// ReferenceAsset: "usd",
// ConversionFactor: i(6),
// DebtFloor: i(10000000),
// }
// testDPUpdatedDebtFloor := testDP
// testDPUpdatedDebtFloor.DebtFloor = i(1000)
2024-05-01 05:53:58 +00:00
// // cdp Genesis
// testCDPParams := cdptypes.DefaultParams()
// testCDPParams.CollateralParams = testCPs
// testCDPParams.DebtParam = testDP
// testCDPParams.GlobalDebtLimit = testCPs[0].DebtLimit.Add(testCPs[0].DebtLimit) // correct global debt limit to pass genesis validation
2024-05-01 05:53:58 +00:00
// testDeputy, err := sdk.AccAddressFromBech32("0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj")
// suite.Require().NoError(err)
// // bep3 Asset Params
// testAPs := bep3types.AssetParams{
// bep3types.AssetParam{
// Denom: "bnb",
// CoinID: 714,
// SupplyLimit: bep3types.SupplyLimit{
// Limit: sdkmath.NewInt(350000000000000),
// TimeLimited: false,
// TimeBasedLimit: sdk.ZeroInt(),
// TimePeriod: time.Hour,
// },
// Active: true,
// DeputyAddress: testDeputy,
// FixedFee: sdkmath.NewInt(1000),
// MinSwapAmount: sdk.OneInt(),
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
// MinBlockLock: bep3types.DefaultMinBlockLock,
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
// },
// bep3types.AssetParam{
// Denom: "inc",
// CoinID: 9999,
// SupplyLimit: bep3types.SupplyLimit{
// Limit: sdkmath.NewInt(100000000000000),
// TimeLimited: true,
// TimeBasedLimit: sdkmath.NewInt(50000000000),
// TimePeriod: time.Hour,
// },
// Active: false,
// DeputyAddress: testDeputy,
// FixedFee: sdkmath.NewInt(1000),
// MinSwapAmount: sdk.OneInt(),
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
// MinBlockLock: bep3types.DefaultMinBlockLock,
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
// },
// }
// testAPsUpdatedActive := make(bep3types.AssetParams, len(testAPs))
// copy(testAPsUpdatedActive, testAPs)
// testAPsUpdatedActive[1].Active = true
2024-05-01 05:53:58 +00:00
// // bep3 Genesis
// testBep3Params := bep3types.DefaultParams()
// testBep3Params.AssetParams = testAPs
2024-05-01 05:53:58 +00:00
// // pricefeed Markets
// testMs := pricefeedtypes.Markets{
// {
// MarketID: "bnb:usd",
// BaseAsset: "bnb",
// QuoteAsset: "usd",
// Oracles: []sdk.AccAddress{},
// Active: true,
// },
// {
// MarketID: "btc:usd",
// BaseAsset: "btc",
// QuoteAsset: "usd",
// Oracles: []sdk.AccAddress{},
// Active: true,
// },
// }
// testMsUpdatedActive := make(pricefeedtypes.Markets, len(testMs))
// copy(testMsUpdatedActive, testMs)
// testMsUpdatedActive[1].Active = true
2024-05-01 05:53:58 +00:00
// testcases := []struct {
// name string
// genState []app.GenesisState
// permission types.SubParamChangePermission
// pubProposal types.PubProposal
// expectAllowed bool
// }{
// {
// name: "normal",
// genState: []app.GenesisState{
// newPricefeedGenState([]string{"bnb", "btc"}, []sdk.Dec{d("15.01"), d("9500")}),
// newCDPGenesisState(testCDPParams),
// newBep3GenesisState(testBep3Params),
// },
// permission: types.SubParamChangePermission{
// AllowedParams: types.AllowedParams{
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtThreshold)},
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyCollateralParams)},
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtParam)},
// {Subspace: bep3types.ModuleName, Key: string(bep3types.KeyAssetParams)},
// {Subspace: pricefeedtypes.ModuleName, Key: string(pricefeedtypes.KeyMarkets)},
// },
// AllowedCollateralParams: types.AllowedCollateralParams{
// {
// Type: "bnb-a",
// DebtLimit: true,
// StabilityFee: true,
// },
// { // TODO currently even if a perm doesn't allow a change in one element it must still be present in list
// Type: "btc-a",
// },
// },
// AllowedDebtParam: types.AllowedDebtParam{
// DebtFloor: true,
// },
// AllowedAssetParams: types.AllowedAssetParams{
// {
// Denom: "bnb",
// },
// {
// Denom: "inc",
// Active: true,
// },
// },
// AllowedMarkets: types.AllowedMarkets{
// {
// MarketID: "bnb:usd",
// },
// {
// MarketID: "btc:usd",
// Active: true,
// },
// },
// },
// pubProposal: paramstypes.NewParameterChangeProposal(
// "A Title",
// "A description for this proposal.",
// []paramstypes.ParamChange{
// {
// Subspace: cdptypes.ModuleName,
// Key: string(cdptypes.KeyDebtThreshold),
// Value: string(suite.cdc.MustMarshalJSON(i(1234))),
// },
// {
// Subspace: cdptypes.ModuleName,
// Key: string(cdptypes.KeyCollateralParams),
// Value: string(suite.cdc.MustMarshalJSON(testCPUpdatedDebtLimit)),
// },
// {
// Subspace: cdptypes.ModuleName,
// Key: string(cdptypes.KeyDebtParam),
// Value: string(suite.cdc.MustMarshalJSON(testDPUpdatedDebtFloor)),
// },
// {
// Subspace: bep3types.ModuleName,
// Key: string(bep3types.KeyAssetParams),
// Value: string(suite.cdc.MustMarshalJSON(testAPsUpdatedActive)),
// },
// {
// Subspace: pricefeedtypes.ModuleName,
// Key: string(pricefeedtypes.KeyMarkets),
// Value: string(suite.cdc.MustMarshalJSON(testMsUpdatedActive)),
// },
// },
// ),
// expectAllowed: true,
// },
// {
// name: "not allowed (wrong pubproposal type)",
// permission: types.SubParamChangePermission{},
// pubProposal: govtypes.NewTextProposal("A Title", "A description for this proposal."),
// expectAllowed: false,
// },
// {
// name: "not allowed (nil pubproposal)",
// permission: types.SubParamChangePermission{},
// pubProposal: nil,
// expectAllowed: false,
// },
// // TODO more cases
// }
2024-05-01 05:53:58 +00:00
// for _, tc := range testcases {
// suite.Run(tc.name, func() {
// tApp := app.NewTestApp()
// ctx := tApp.NewContext(true, abci.Header{})
// tApp.InitializeFromGenesisStates(tc.genState...)
2024-05-01 05:53:58 +00:00
// suite.Equal(
// tc.expectAllowed,
// tc.permission.Allows(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
// )
// })
// }
// }
func TestPermissionTestSuite(t *testing.T) {
suite.Run(t, new(PermissionTestSuite))
}