Skip to content

Commit

Permalink
max withdaw test
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Jun 27, 2023
1 parent 2be1218 commit 62d3297
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
34 changes: 28 additions & 6 deletions x/leverage/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ func (s *IntegrationTestSuite) TestMsgMaxWithdraw() {
// borrowed value is $10 (current) or $5 (historic)
// collateral weights are always 0.25 in testing

// create an UMEE borrower using STABLE collateral
stableUmeeBorrower := s.newAccount(coin.New(stableDenom, 100_000000))
s.supply(stableUmeeBorrower, coin.New(stableDenom, 100_000000))
s.collateralize(stableUmeeBorrower, coin.New("u/"+stableDenom, 100_000000))
s.borrow(stableUmeeBorrower, coin.New(umeeDenom, 30_000000))
// UMEE and STABLE have the same price but different collateral weights

zeroUmee := coin.Zero(umeeDenom)
zeroUUmee := coin.New("u/"+umeeDenom, 0)
tcs := []struct {
Expand All @@ -574,47 +581,53 @@ func (s *IntegrationTestSuite) TestMsgMaxWithdraw() {
sdk.Coin{},
sdk.Coin{},
types.ErrNotRegisteredToken,
}, {
},
{
"can't borrow uToken",
supplier,
"u/" + umeeDenom,
sdk.Coin{},
sdk.Coin{},
sdk.Coin{},
types.ErrUToken,
}, {
},
{
"max withdraw umee",
supplier,
umeeDenom,
coin.New("u/"+umeeDenom, 100_000000),
coin.New("u/"+umeeDenom, 75_000000),
coin.New(umeeDenom, 100_000000),
nil,
}, {
},
{
"duplicate max withdraw umee",
supplier,
umeeDenom,
zeroUUmee,
zeroUUmee,
zeroUmee,
nil,
}, {
},
{
"max withdraw with borrow",
other,
umeeDenom,
coin.New("u/"+umeeDenom, 60_000000),
coin.New("u/"+umeeDenom, 60_000000),
coin.New(umeeDenom, 60_000000),
nil,
}, {
},
{
"max withdrawal (dump borrower)",
dumpborrower,
pumpDenom,
coin.New("u/"+pumpDenom, 20_000000),
coin.New("u/"+pumpDenom, 20_000000),
coin.New(pumpDenom, 20_000000),
nil,
}, {
},
{
"max withdrawal (pump borrower)",
pumpborrower,
dumpDenom,
Expand All @@ -623,6 +636,15 @@ func (s *IntegrationTestSuite) TestMsgMaxWithdraw() {
coin.New(dumpDenom, 20_000000),
nil,
},
{
"max withdrawal (borrow factor 2 with stablecoin collateral)",
stableUmeeBorrower,
stableDenom,
coin.New("u/"+stableDenom, 40_000000),
coin.New("u/"+stableDenom, 40_000000),
coin.New(stableDenom, 40_000000),
nil,
},
}

for _, tc := range tcs {
Expand Down
22 changes: 12 additions & 10 deletions x/leverage/keeper/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ func (m *mockOracleKeeper) Clear(denom string) {
// Reset restores the mock oracle's prices to its default values.
func (m *mockOracleKeeper) Reset() {
m.symbolExchangeRates = map[string]sdk.Dec{
"UMEE": sdk.MustNewDecFromStr("4.21"),
"ATOM": sdk.MustNewDecFromStr("39.38"),
"DAI": sdk.MustNewDecFromStr("1.00"),
"DUMP": sdk.MustNewDecFromStr("0.50"), // A token which has recently halved in price
"PUMP": sdk.MustNewDecFromStr("2.00"), // A token which has recently doubled in price
"UMEE": sdk.MustNewDecFromStr("4.21"),
"ATOM": sdk.MustNewDecFromStr("39.38"),
"DAI": sdk.MustNewDecFromStr("1.00"),
"DUMP": sdk.MustNewDecFromStr("0.50"), // A token which has recently halved in price
"PUMP": sdk.MustNewDecFromStr("2.00"), // A token which has recently doubled in price
"STABLE": sdk.MustNewDecFromStr("4.21"), // Same price as umee
}
m.historicExchangeRates = map[string]sdk.Dec{
"UMEE": sdk.MustNewDecFromStr("4.21"),
"ATOM": sdk.MustNewDecFromStr("39.38"),
"DAI": sdk.MustNewDecFromStr("1.00"),
"DUMP": sdk.MustNewDecFromStr("1.00"),
"PUMP": sdk.MustNewDecFromStr("1.00"),
"UMEE": sdk.MustNewDecFromStr("4.21"),
"ATOM": sdk.MustNewDecFromStr("39.38"),
"DAI": sdk.MustNewDecFromStr("1.00"),
"DUMP": sdk.MustNewDecFromStr("1.00"),
"PUMP": sdk.MustNewDecFromStr("1.00"),
"STABLE": sdk.MustNewDecFromStr("4.21"),
}
}

Expand Down

0 comments on commit 62d3297

Please sign in to comment.