From d8347fd49c241a2f6388980d1f85748d7486d27b Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Sat, 7 Dec 2019 14:56:40 +0000 Subject: [PATCH] tidy test genesis states --- x/cdp/keeper/integration_test.go | 30 +++++++++++-------------- x/cdp/keeper/keeper_test.go | 6 ++--- x/liquidator/keeper/integration_test.go | 14 +++++------- x/liquidator/keeper/keeper_test.go | 4 ++-- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/x/cdp/keeper/integration_test.go b/x/cdp/keeper/integration_test.go index 0e465b85..af8ad4c6 100644 --- a/x/cdp/keeper/integration_test.go +++ b/x/cdp/keeper/integration_test.go @@ -17,15 +17,13 @@ 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...) } -func NewPFGenState(asset string, price sdk.Dec) app.GenesisState { - quote := "usd" - ap := pricefeed.Params{ - Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: asset, BaseAsset: asset, QuoteAsset: quote, Oracles: pricefeed.Oracles{}, Active: true}, - }, - } +func NewPricefeedGenState(asset string, price sdk.Dec) app.GenesisState { pfGenesis := pricefeed.GenesisState{ - Params: ap, + Params: pricefeed.Params{ + Markets: []pricefeed.Market{ + pricefeed.Market{MarketID: asset, BaseAsset: asset, QuoteAsset: "usd", Oracles: pricefeed.Oracles{}, Active: true}, + }, + }, PostedPrices: []pricefeed.PostedPrice{ pricefeed.PostedPrice{ MarketID: asset, @@ -56,16 +54,14 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState { return app.GenesisState{cdp.ModuleName: cdp.ModuleCdc.MustMarshalJSON(cdpGenesis)} } -func NewPFGenStateMulti() app.GenesisState { - quote := "usd" - ap := pricefeed.Params{ - Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc", BaseAsset: "btc", QuoteAsset: quote, Oracles: pricefeed.Oracles{}, Active: true}, - pricefeed.Market{MarketID: "xrp", BaseAsset: "xrp", QuoteAsset: quote, Oracles: pricefeed.Oracles{}, Active: true}, - }, - } +func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := pricefeed.GenesisState{ - Params: ap, + 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}, + }, + }, PostedPrices: []pricefeed.PostedPrice{ pricefeed.PostedPrice{ MarketID: "btc", diff --git a/x/cdp/keeper/keeper_test.go b/x/cdp/keeper/keeper_test.go index bded6ff8..33983c85 100644 --- a/x/cdp/keeper/keeper_test.go +++ b/x/cdp/keeper/keeper_test.go @@ -98,7 +98,7 @@ func TestKeeper_ModifyCDP(t *testing.T) { // initialize cdp owner account with coins, and collateral with price and params tApp.InitializeFromGenesisStates( app.NewAuthGenState([]sdk.AccAddress{ownerAddr}, []sdk.Coins{tc.priorState.OwnerCoins}), - NewPFGenState("xrp", d(tc.price)), + NewPricefeedGenState("xrp", d(tc.price)), NewCDPGenState("xrp", d("2.0")), ) // create a context for db access @@ -151,7 +151,7 @@ func TestKeeper_PartialSeizeCDP(t *testing.T) { tApp := app.NewTestApp() tApp.InitializeFromGenesisStates( app.NewAuthGenState(addrs, []sdk.Coins{cs(c(collateral, 100))}), - NewPFGenState(collateral, d("1.00")), + NewPricefeedGenState(collateral, d("1.00")), NewCDPGenState(collateral, d("2.00")), ) @@ -182,7 +182,7 @@ func TestKeeper_PartialSeizeCDP(t *testing.T) { func TestKeeper_GetCDPs(t *testing.T) { // setup test app tApp := app.NewTestApp().InitializeFromGenesisStates( - NewPFGenStateMulti(), // collateral needs to be in pricefeed for cdp InitGenesis to validate + NewPricefeedGenStateMulti(), // collateral needs to be in pricefeed for cdp InitGenesis to validate NewCDPGenStateMulti(), ) ctx := tApp.NewContext(true, abci.Header{}) diff --git a/x/liquidator/keeper/integration_test.go b/x/liquidator/keeper/integration_test.go index 01c825f8..32f57bbf 100644 --- a/x/liquidator/keeper/integration_test.go +++ b/x/liquidator/keeper/integration_test.go @@ -18,16 +18,14 @@ 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...) } -// Default genesis states to initialize test apps +// Genesis states to initialize test apps -func NewPFGenState(asset string, price sdk.Dec) app.GenesisState { - quote := "usd" - ap := pricefeed.Params{ - Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: asset, BaseAsset: asset, QuoteAsset: quote, Oracles: pricefeed.Oracles{}, Active: true}}, - } +func NewPricefeedGenState(asset string, price sdk.Dec) app.GenesisState { pfGenesis := pricefeed.GenesisState{ - Params: ap, + Params: pricefeed.Params{ + Markets: []pricefeed.Market{ + pricefeed.Market{MarketID: asset, BaseAsset: asset, QuoteAsset: "usd", Oracles: pricefeed.Oracles{}, Active: true}}, + }, PostedPrices: []pricefeed.PostedPrice{ pricefeed.PostedPrice{ MarketID: asset, diff --git a/x/liquidator/keeper/keeper_test.go b/x/liquidator/keeper/keeper_test.go index 3dae54fe..c6598f06 100644 --- a/x/liquidator/keeper/keeper_test.go +++ b/x/liquidator/keeper/keeper_test.go @@ -20,7 +20,7 @@ func TestKeeper_SeizeAndStartCollateralAuction(t *testing.T) { tApp := app.NewTestApp() tApp.InitializeFromGenesisStates( app.NewAuthGenState(addrs, []sdk.Coins{cs(c("btc", 100))}), - NewPFGenState("btc", d("8000.00")), + NewPricefeedGenState("btc", d("8000.00")), NewCDPGenState(), NewLiquidatorGenState(), ) @@ -81,7 +81,7 @@ func TestKeeper_partialSeizeCDP(t *testing.T) { tApp := app.NewTestApp() tApp.InitializeFromGenesisStates( app.NewAuthGenState(addrs, []sdk.Coins{cs(c("btc", 100))}), - NewPFGenState("btc", d("8000.00")), + NewPricefeedGenState("btc", d("8000.00")), NewCDPGenState(), NewLiquidatorGenState(), )