mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
9b1bf55be7
* wip: tpyes and keeper methods * wip: iterators * wip: types and keeper methods * wip: add msgs * wip: client methods * wip: rebase develop * wip: types tests * wip: keeper tests, small fixes * wip: add cdp tests * wip: deposit tests * wip: keeper tests * wip: tests and module methods * feat: error when fetching expired price * feat: conversion factor for external assets * feat: debt floor for new cdps * feat: save deposits on export genesis * feat: ensure messages implement msg * feat: index deposits by status * fix: stray comment * wip: address review comments * address review comments * wip: move liquidation to cdp module * wip: handle liquidations directly * wip: use new auction interface * feat: auction collateral in cdp begin block * feat: update param validation * feat: surplus and debt auctions * address review comments * address review comments * fix: auction multiple deposits * clean up netting function
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/auction"
|
|
"github.com/kava-labs/kava/x/cdp/keeper"
|
|
"github.com/kava-labs/kava/x/cdp/types"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
)
|
|
|
|
type AuctionTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
}
|
|
|
|
func (suite *AuctionTestSuite) SetupTest() {
|
|
config := sdk.GetConfig()
|
|
app.SetBech32AddressPrefixes(config)
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
tApp.InitializeFromGenesisStates(
|
|
NewPricefeedGenStateMulti(),
|
|
NewCDPGenStateMulti(),
|
|
)
|
|
keeper := tApp.GetCDPKeeper()
|
|
suite.app = tApp
|
|
suite.ctx = ctx
|
|
suite.keeper = keeper
|
|
return
|
|
}
|
|
|
|
func (suite *AuctionTestSuite) TestNetDebtSurplus() {
|
|
sk := suite.app.GetSupplyKeeper()
|
|
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 100)))
|
|
suite.NoError(err)
|
|
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 10)))
|
|
suite.NoError(err)
|
|
suite.NotPanics(func() { suite.keeper.NetSurplusAndDebt(suite.ctx) })
|
|
acc := sk.GetModuleAccount(suite.ctx, types.LiquidatorMacc)
|
|
suite.Equal(cs(c("debt", 90)), acc.GetCoins())
|
|
}
|
|
|
|
func (suite *AuctionTestSuite) TestSurplusAuction() {
|
|
sk := suite.app.GetSupplyKeeper()
|
|
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 10000)))
|
|
suite.NoError(err)
|
|
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 1000)))
|
|
suite.NoError(err)
|
|
suite.keeper.RunSurplusAndDebtAuctions(suite.ctx)
|
|
acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName)
|
|
suite.Equal(cs(c("usdx", 9000)), acc.GetCoins())
|
|
}
|
|
|
|
func (suite *AuctionTestSuite) TestDebtAuction() {
|
|
sk := suite.app.GetSupplyKeeper()
|
|
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 1000)))
|
|
suite.NoError(err)
|
|
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 10000)))
|
|
suite.NoError(err)
|
|
suite.keeper.RunSurplusAndDebtAuctions(suite.ctx)
|
|
acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName)
|
|
suite.Equal(cs(c("debt", 9000)), acc.GetCoins())
|
|
}
|
|
|
|
func TestAuctionTestSuite(t *testing.T) {
|
|
suite.Run(t, new(AuctionTestSuite))
|
|
}
|