2021-01-07 10:23:05 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
2022-01-08 00:39:27 +00:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2021-01-07 10:23:05 +00:00
|
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/hard"
|
|
|
|
"github.com/kava-labs/kava/x/hard/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
2021-01-07 10:23:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestWithdraw() {
|
|
|
|
type args struct {
|
|
|
|
depositor sdk.AccAddress
|
|
|
|
initialModAccountBalance sdk.Coins
|
|
|
|
depositAmount sdk.Coins
|
|
|
|
withdrawAmount sdk.Coins
|
|
|
|
createDeposit bool
|
|
|
|
expectedAccountBalance sdk.Coins
|
|
|
|
expectedModAccountBalance sdk.Coins
|
|
|
|
finalDepositAmount sdk.Coins
|
|
|
|
}
|
|
|
|
type errArgs struct {
|
2021-01-18 09:43:20 +00:00
|
|
|
expectPass bool
|
|
|
|
expectDelete bool
|
|
|
|
contains string
|
2021-01-07 10:23:05 +00:00
|
|
|
}
|
|
|
|
type withdrawTest struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
errArgs errArgs
|
|
|
|
}
|
|
|
|
testCases := []withdrawTest{
|
|
|
|
{
|
|
|
|
"valid: partial withdraw",
|
|
|
|
args{
|
|
|
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
|
|
initialModAccountBalance: sdk.Coins(nil),
|
|
|
|
depositAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
|
|
|
withdrawAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
|
|
|
createDeposit: true,
|
|
|
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(900)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
|
|
|
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
|
|
|
finalDepositAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
|
|
|
},
|
|
|
|
errArgs{
|
2021-01-18 09:43:20 +00:00
|
|
|
expectPass: true,
|
|
|
|
expectDelete: false,
|
|
|
|
contains: "",
|
2021-01-07 10:23:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid: full withdraw",
|
|
|
|
args{
|
|
|
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
|
|
initialModAccountBalance: sdk.Coins(nil),
|
|
|
|
depositAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
|
|
|
withdrawAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
|
|
|
createDeposit: true,
|
|
|
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
|
|
|
expectedModAccountBalance: sdk.Coins(nil),
|
|
|
|
finalDepositAmount: sdk.Coins{},
|
|
|
|
},
|
|
|
|
errArgs{
|
2021-01-18 09:43:20 +00:00
|
|
|
expectPass: true,
|
|
|
|
expectDelete: true,
|
|
|
|
contains: "",
|
2021-01-07 10:23:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid: withdraw exceeds deposit but is adjusted to match max deposit",
|
|
|
|
args{
|
|
|
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
|
|
initialModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000))),
|
|
|
|
depositAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
|
|
|
withdrawAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(300))),
|
|
|
|
createDeposit: true,
|
|
|
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
|
|
|
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000))),
|
|
|
|
finalDepositAmount: sdk.Coins{},
|
|
|
|
},
|
|
|
|
errArgs{
|
2021-01-18 09:43:20 +00:00
|
|
|
expectPass: true,
|
|
|
|
expectDelete: true,
|
|
|
|
contains: "",
|
2021-01-07 10:23:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid: withdraw non-supplied coin type",
|
|
|
|
args{
|
|
|
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
|
|
initialModAccountBalance: sdk.Coins(nil),
|
|
|
|
depositAmount: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
|
|
|
withdrawAmount: sdk.NewCoins(sdk.NewCoin("btcb", sdk.NewInt(200))),
|
|
|
|
createDeposit: true,
|
|
|
|
expectedAccountBalance: sdk.Coins{},
|
|
|
|
expectedModAccountBalance: sdk.Coins{},
|
|
|
|
finalDepositAmount: sdk.Coins{},
|
|
|
|
},
|
|
|
|
errArgs{
|
2021-01-18 09:43:20 +00:00
|
|
|
expectPass: false,
|
|
|
|
expectDelete: false,
|
|
|
|
contains: "no coins of this type deposited",
|
2021-01-07 10:23:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
// create new app with one funded account
|
|
|
|
|
|
|
|
// Initialize test app and set context
|
|
|
|
tApp := app.NewTestApp()
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
authGS := app.NewFundedGenStateWithCoins(
|
|
|
|
tApp.AppCodec(),
|
|
|
|
[]sdk.Coins{sdk.NewCoins(
|
|
|
|
sdk.NewCoin("bnb", sdk.NewInt(1000)),
|
|
|
|
sdk.NewCoin("btcb", sdk.NewInt(1000)),
|
|
|
|
)},
|
2021-01-07 10:23:05 +00:00
|
|
|
[]sdk.AccAddress{tc.args.depositor},
|
|
|
|
)
|
|
|
|
|
|
|
|
loanToValue := sdk.MustNewDecFromStr("0.6")
|
|
|
|
hardGS := types.NewGenesisState(types.NewParams(
|
|
|
|
types.MoneyMarkets{
|
2021-02-10 14:59:23 +00:00
|
|
|
types.NewMoneyMarket("usdx", types.NewBorrowLimit(false, sdk.NewDec(1000000000000000), loanToValue), "usdx:usd", sdk.NewInt(1000000), types.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
|
|
types.NewMoneyMarket("ukava", types.NewBorrowLimit(false, sdk.NewDec(1000000000000000), loanToValue), "kava:usd", sdk.NewInt(1000000), types.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
|
|
types.NewMoneyMarket("bnb", types.NewBorrowLimit(false, sdk.NewDec(1000000000000000), loanToValue), "bnb:usd", sdk.NewInt(100000000), types.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
2021-01-07 10:23:05 +00:00
|
|
|
},
|
2021-02-12 15:28:05 +00:00
|
|
|
sdk.NewDec(10),
|
2021-01-23 05:17:40 +00:00
|
|
|
), types.DefaultAccumulationTimes, types.DefaultDeposits, types.DefaultBorrows,
|
|
|
|
types.DefaultTotalSupplied, types.DefaultTotalBorrowed, types.DefaultTotalReserves,
|
|
|
|
)
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
// Pricefeed module genesis state
|
2022-01-08 00:39:27 +00:00
|
|
|
pricefeedGS := pricefeedtypes.GenesisState{
|
|
|
|
Params: pricefeedtypes.Params{
|
|
|
|
Markets: []pricefeedtypes.Market{
|
2021-01-07 10:23:05 +00:00
|
|
|
{MarketID: "usdx:usd", BaseAsset: "usdx", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "kava:usd", BaseAsset: "kava", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "bnb:usd", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
PostedPrices: []pricefeedtypes.PostedPrice{
|
2021-01-07 10:23:05 +00:00
|
|
|
{
|
|
|
|
MarketID: "usdx:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("1.00"),
|
|
|
|
Expiry: time.Now().Add(100 * time.Hour),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "kava:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
|
|
Expiry: time.Now().Add(100 * time.Hour),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "bnb:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("10.00"),
|
|
|
|
Expiry: time.Now().Add(100 * time.Hour),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tApp.InitializeFromGenesisStates(authGS,
|
2022-01-08 00:39:27 +00:00
|
|
|
app.GenesisState{pricefeedtypes.ModuleName: tApp.AppCodec().MustMarshalJSON(&pricefeedGS)},
|
|
|
|
app.GenesisState{types.ModuleName: tApp.AppCodec().MustMarshalJSON(&hardGS)})
|
2021-01-07 10:23:05 +00:00
|
|
|
keeper := tApp.GetHardKeeper()
|
|
|
|
suite.app = tApp
|
|
|
|
suite.ctx = ctx
|
|
|
|
suite.keeper = keeper
|
|
|
|
|
|
|
|
// Mint coins to Hard module account
|
2022-01-08 00:39:27 +00:00
|
|
|
bankKeeper := tApp.GetBankKeeper()
|
|
|
|
err := bankKeeper.MintCoins(ctx, types.ModuleAccountName, tc.args.initialModAccountBalance)
|
|
|
|
suite.Require().NoError(err)
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
if tc.args.createDeposit {
|
|
|
|
err := suite.keeper.Deposit(suite.ctx, tc.args.depositor, tc.args.depositAmount)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
err = suite.keeper.Withdraw(suite.ctx, tc.args.depositor, tc.args.withdrawAmount)
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
if tc.errArgs.expectPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
acc := suite.getAccount(tc.args.depositor)
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Require().Equal(tc.args.expectedAccountBalance, bankKeeper.GetAllBalances(ctx, acc.GetAddress()))
|
2021-01-07 10:23:05 +00:00
|
|
|
mAcc := suite.getModuleAccount(types.ModuleAccountName)
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.Require().True(tc.args.expectedModAccountBalance.IsEqual(bankKeeper.GetAllBalances(ctx, mAcc.GetAddress())))
|
2021-01-07 10:23:05 +00:00
|
|
|
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, tc.args.depositor)
|
2021-01-18 09:43:20 +00:00
|
|
|
if tc.errArgs.expectDelete {
|
|
|
|
suite.Require().False(f)
|
|
|
|
} else {
|
2021-01-07 10:23:05 +00:00
|
|
|
suite.Require().True(f)
|
|
|
|
suite.Require().Equal(tc.args.finalDepositAmount, testDeposit.Amount)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestLtvWithdraw() {
|
|
|
|
type args struct {
|
|
|
|
borrower sdk.AccAddress
|
|
|
|
initialModuleCoins sdk.Coins
|
|
|
|
initialBorrowerCoins sdk.Coins
|
|
|
|
depositCoins sdk.Coins
|
|
|
|
borrowCoins sdk.Coins
|
2021-02-12 15:28:05 +00:00
|
|
|
repayCoins sdk.Coins
|
2021-01-07 10:23:05 +00:00
|
|
|
futureTime int64
|
|
|
|
}
|
|
|
|
|
|
|
|
type errArgs struct {
|
|
|
|
expectPass bool
|
|
|
|
contains string
|
|
|
|
}
|
|
|
|
|
|
|
|
type liqTest struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
errArgs errArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up test constants
|
|
|
|
model := types.NewInterestRateModel(sdk.MustNewDecFromStr("0"), sdk.MustNewDecFromStr("0.1"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("0.5"))
|
|
|
|
reserveFactor := sdk.MustNewDecFromStr("0.05")
|
|
|
|
oneMonthInSeconds := int64(2592000)
|
|
|
|
borrower := sdk.AccAddress(crypto.AddressHash([]byte("testborrower")))
|
|
|
|
|
|
|
|
testCases := []liqTest{
|
|
|
|
{
|
|
|
|
"invalid: withdraw is outside loan-to-value range",
|
|
|
|
args{
|
|
|
|
borrower: borrower,
|
|
|
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
|
|
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(100*KAVA_CF))),
|
2021-02-12 15:28:05 +00:00
|
|
|
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))), // 100 * 2 = $200
|
|
|
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(80*KAVA_CF))), // 80 * 2 = $160
|
|
|
|
repayCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(60*KAVA_CF))), // 60 * 2 = $120
|
2021-01-07 10:23:05 +00:00
|
|
|
futureTime: oneMonthInSeconds,
|
|
|
|
},
|
|
|
|
errArgs{
|
|
|
|
expectPass: false,
|
|
|
|
contains: "proposed withdraw outside loan-to-value range",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
// Initialize test app and set context
|
|
|
|
tApp := app.NewTestApp()
|
2022-01-08 00:39:27 +00:00
|
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
// Auth module genesis state
|
2022-01-08 00:39:27 +00:00
|
|
|
authGS := app.NewFundedGenStateWithCoins(
|
|
|
|
tApp.AppCodec(),
|
2021-01-07 10:23:05 +00:00
|
|
|
[]sdk.Coins{tc.args.initialBorrowerCoins},
|
2022-01-08 00:39:27 +00:00
|
|
|
[]sdk.AccAddress{tc.args.borrower},
|
2021-01-07 10:23:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Harvest module genesis state
|
|
|
|
harvestGS := types.NewGenesisState(types.NewParams(
|
|
|
|
types.MoneyMarkets{
|
|
|
|
types.NewMoneyMarket("ukava",
|
|
|
|
types.NewBorrowLimit(false, sdk.NewDec(100000000*KAVA_CF), sdk.MustNewDecFromStr("0.8")), // Borrow Limit
|
|
|
|
"kava:usd", // Market ID
|
|
|
|
sdk.NewInt(KAVA_CF), // Conversion Factor
|
|
|
|
model, // Interest Rate Model
|
|
|
|
reserveFactor, // Reserve Factor
|
|
|
|
sdk.MustNewDecFromStr("0.05")), // Keeper Reward Percent
|
|
|
|
types.NewMoneyMarket("usdx",
|
|
|
|
types.NewBorrowLimit(false, sdk.NewDec(100000000*KAVA_CF), sdk.MustNewDecFromStr("0.8")), // Borrow Limit
|
|
|
|
"usdx:usd", // Market ID
|
|
|
|
sdk.NewInt(KAVA_CF), // Conversion Factor
|
|
|
|
model, // Interest Rate Model
|
|
|
|
reserveFactor, // Reserve Factor
|
|
|
|
sdk.MustNewDecFromStr("0.05")), // Keeper Reward Percent
|
|
|
|
},
|
2021-02-12 15:28:05 +00:00
|
|
|
sdk.NewDec(10),
|
2021-01-23 05:17:40 +00:00
|
|
|
), types.DefaultAccumulationTimes, types.DefaultDeposits, types.DefaultBorrows,
|
|
|
|
types.DefaultTotalSupplied, types.DefaultTotalBorrowed, types.DefaultTotalReserves,
|
|
|
|
)
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
// Pricefeed module genesis state
|
2022-01-08 00:39:27 +00:00
|
|
|
pricefeedGS := pricefeedtypes.GenesisState{
|
|
|
|
Params: pricefeedtypes.Params{
|
|
|
|
Markets: []pricefeedtypes.Market{
|
2021-01-07 10:23:05 +00:00
|
|
|
{MarketID: "usdx:usd", BaseAsset: "usdx", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "kava:usd", BaseAsset: "kava", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
PostedPrices: []pricefeedtypes.PostedPrice{
|
2021-01-07 10:23:05 +00:00
|
|
|
{
|
|
|
|
MarketID: "usdx:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("1.00"),
|
|
|
|
Expiry: time.Now().Add(100 * time.Hour),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "kava:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
|
|
Expiry: time.Now().Add(100 * time.Hour),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize test application
|
|
|
|
tApp.InitializeFromGenesisStates(authGS,
|
2022-01-08 00:39:27 +00:00
|
|
|
app.GenesisState{pricefeedtypes.ModuleName: tApp.AppCodec().MustMarshalJSON(&pricefeedGS)},
|
|
|
|
app.GenesisState{types.ModuleName: tApp.AppCodec().MustMarshalJSON(&harvestGS)})
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
// Mint coins to Harvest module account
|
2022-01-08 00:39:27 +00:00
|
|
|
bankKeeper := tApp.GetBankKeeper()
|
|
|
|
err := bankKeeper.MintCoins(ctx, types.ModuleAccountName, tc.args.initialModuleCoins)
|
|
|
|
suite.Require().NoError(err)
|
2021-01-07 10:23:05 +00:00
|
|
|
|
|
|
|
auctionKeeper := tApp.GetAuctionKeeper()
|
|
|
|
|
|
|
|
keeper := tApp.GetHardKeeper()
|
|
|
|
suite.app = tApp
|
|
|
|
suite.ctx = ctx
|
|
|
|
suite.keeper = keeper
|
|
|
|
suite.auctionKeeper = auctionKeeper
|
|
|
|
|
|
|
|
// Run begin blocker to set up state
|
|
|
|
hard.BeginBlocker(suite.ctx, suite.keeper)
|
|
|
|
|
|
|
|
// Borrower deposits coins
|
|
|
|
err = suite.keeper.Deposit(suite.ctx, tc.args.borrower, tc.args.depositCoins)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
// Borrower borrows coins
|
|
|
|
err = suite.keeper.Borrow(suite.ctx, tc.args.borrower, tc.args.borrowCoins)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
// Attempting to withdraw fails
|
|
|
|
err = suite.keeper.Withdraw(suite.ctx, tc.args.borrower, sdk.NewCoins(sdk.NewCoin("ukava", sdk.OneInt())))
|
|
|
|
suite.Require().Error(err)
|
|
|
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
|
|
|
|
|
|
|
// Set up future chain context and run begin blocker, increasing user's owed borrow balance
|
|
|
|
runAtTime := time.Unix(suite.ctx.BlockTime().Unix()+(tc.args.futureTime), 0)
|
|
|
|
liqCtx := suite.ctx.WithBlockTime(runAtTime)
|
|
|
|
hard.BeginBlocker(liqCtx, suite.keeper)
|
|
|
|
|
|
|
|
// Attempted withdraw of 1 coin still fails
|
|
|
|
err = suite.keeper.Withdraw(suite.ctx, tc.args.borrower, sdk.NewCoins(sdk.NewCoin("ukava", sdk.OneInt())))
|
|
|
|
suite.Require().Error(err)
|
|
|
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
|
|
|
|
2021-02-12 15:28:05 +00:00
|
|
|
// Repay the initial principal. Over pay the position so the borrow is closed.
|
|
|
|
err = suite.keeper.Repay(suite.ctx, tc.args.borrower, tc.args.borrower, tc.args.repayCoins)
|
2021-01-07 10:23:05 +00:00
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
// Attempted withdraw of all deposited coins fails as user hasn't repaid interest debt
|
|
|
|
err = suite.keeper.Withdraw(suite.ctx, tc.args.borrower, tc.args.depositCoins)
|
|
|
|
suite.Require().Error(err)
|
|
|
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
|
|
|
|
2021-02-12 15:28:05 +00:00
|
|
|
// Withdrawing 10% of the coins should succeed
|
|
|
|
withdrawCoins := sdk.NewCoins(sdk.NewCoin("ukava", tc.args.depositCoins[0].Amount.Quo(sdk.NewInt(10))))
|
2021-01-07 10:23:05 +00:00
|
|
|
err = suite.keeper.Withdraw(suite.ctx, tc.args.borrower, withdrawCoins)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|