0g-chain/x/cdp/keeper/integration_test.go

104 lines
3.3 KiB
Go
Raw Normal View History

2019-12-03 14:35:27 +00:00
package keeper_test
import (
2019-12-07 01:25:25 +00:00
"time"
2019-12-03 14:35:27 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
2019-12-07 01:25:25 +00:00
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/cdp"
2019-12-03 14:35:27 +00:00
"github.com/kava-labs/kava/x/cdp/types"
2019-12-07 01:25:25 +00:00
"github.com/kava-labs/kava/x/pricefeed"
2019-12-03 14:35:27 +00:00
)
// Avoid cluttering test cases with long function name
func i(in int64) sdk.Int { return sdk.NewInt(in) }
func d(str string) sdk.Dec { return sdk.MustNewDecFromStr(str) }
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }
2019-12-07 14:56:40 +00:00
func NewPricefeedGenState(asset string, price sdk.Dec) app.GenesisState {
2019-12-07 01:25:25 +00:00
pfGenesis := pricefeed.GenesisState{
2019-12-07 14:56:40 +00:00
Params: pricefeed.Params{
Markets: []pricefeed.Market{
pricefeed.Market{MarketID: asset, BaseAsset: asset, QuoteAsset: "usd", Oracles: pricefeed.Oracles{}, Active: true},
},
},
2019-12-07 01:25:25 +00:00
PostedPrices: []pricefeed.PostedPrice{
pricefeed.PostedPrice{
MarketID: asset,
OracleAddress: sdk.AccAddress{},
Price: price,
Expiry: time.Unix(9999999999, 0), // some deterministic future date,
2019-12-03 14:35:27 +00:00
},
2019-12-07 01:25:25 +00:00
},
}
return app.GenesisState{pricefeed.ModuleName: pricefeed.ModuleCdc.MustMarshalJSON(pfGenesis)}
}
func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState {
cdpGenesis := cdp.GenesisState{
Params: cdp.CdpParams{
GlobalDebtLimit: sdk.NewInt(1000000),
CollateralParams: []cdp.CollateralParams{
{
Denom: asset,
LiquidationRatio: liquidationRatio,
DebtLimit: sdk.NewInt(500000),
},
2019-12-03 14:35:27 +00:00
},
},
2019-12-07 01:25:25 +00:00
GlobalDebt: sdk.ZeroInt(),
CDPs: cdp.CDPs{},
2019-12-03 14:35:27 +00:00
}
2019-12-07 01:25:25 +00:00
return app.GenesisState{cdp.ModuleName: cdp.ModuleCdc.MustMarshalJSON(cdpGenesis)}
2019-12-03 14:35:27 +00:00
}
2019-12-07 14:56:40 +00:00
func NewPricefeedGenStateMulti() app.GenesisState {
2019-12-07 01:25:25 +00:00
pfGenesis := pricefeed.GenesisState{
2019-12-07 14:56:40 +00:00
Params: pricefeed.Params{
Markets: []pricefeed.Market{
pricefeed.Market{MarketID: "btc", BaseAsset: "btc", QuoteAsset: "usd", Oracles: pricefeed.Oracles{}, Active: true},
pricefeed.Market{MarketID: "xrp", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: pricefeed.Oracles{}, Active: true},
},
},
2019-12-07 01:25:25 +00:00
PostedPrices: []pricefeed.PostedPrice{
pricefeed.PostedPrice{
MarketID: "btc",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("8000.00"),
Expiry: time.Unix(9999999999, 0), // some deterministic future date,
},
pricefeed.PostedPrice{
MarketID: "xrp",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("0.25"),
Expiry: time.Unix(9999999999, 0), // some deterministic future date,
},
},
}
return app.GenesisState{pricefeed.ModuleName: pricefeed.ModuleCdc.MustMarshalJSON(pfGenesis)}
}
func NewCDPGenStateMulti() app.GenesisState {
cdpGenesis := cdp.GenesisState{
Params: cdp.CdpParams{
GlobalDebtLimit: sdk.NewInt(1000000),
CollateralParams: []types.CollateralParams{
{
Denom: "btc",
LiquidationRatio: sdk.MustNewDecFromStr("1.5"),
DebtLimit: sdk.NewInt(500000),
},
{
Denom: "xrp",
LiquidationRatio: sdk.MustNewDecFromStr("2.0"),
DebtLimit: sdk.NewInt(500000),
},
2019-12-03 14:35:27 +00:00
},
},
2019-12-07 01:25:25 +00:00
GlobalDebt: sdk.ZeroInt(),
CDPs: cdp.CDPs{},
2019-12-03 14:35:27 +00:00
}
2019-12-07 01:25:25 +00:00
return app.GenesisState{cdp.ModuleName: cdp.ModuleCdc.MustMarshalJSON(cdpGenesis)}
2019-12-03 14:35:27 +00:00
}