-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: improve leverage keeper tests and errors #1300
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1300 +/- ##
==========================================
+ Coverage 51.65% 51.67% +0.02%
==========================================
Files 68 68
Lines 6870 6697 -173
==========================================
- Hits 3549 3461 -88
+ Misses 3063 2969 -94
- Partials 258 267 +9
|
Note: markdown link test fail was http |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
late review. Good job a nice improvements. Left few small things / suggestions.
s.Require().Equal(sdk.NewInt64Coin(uDenom, 0), collateral) | ||
// get u/umee collateral amount of empty account address | ||
collateral := s.tk.GetCollateralAmount(ctx, sdk.AccAddress{}, uDenom) | ||
require.Equal(coin(uDenom, 0), collateral) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coin
could be a keyword :D
fmt.Sprintf("amount of uToken exchange rates lower than one %d\n%s", count, msg), | ||
), broken | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really want to check it after each block by every validator? I think we should have that function only invalidate genesis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these would be expensive computationally to do each block, but having checked other modules (e.g. x/bank invariants) I see that iteration over balances is done there as well.
Is there some setting that validators are using to run invariants less often as they operate other chains?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there is no such setting. But we can code it. The x/bank invariants are often disabled, because they take lot of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a task for this issue: #1324
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, the bank invariants are not even registered in the simapp.
|
||
// check invariants | ||
_, broken := keeper.ReserveAmountInvariant(app.LeverageKeeper)(ctx) | ||
require.False(broken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also test negative scenarios
// Note: Setting umee liquidation threshold to 0.05 to make the user eligible for liquidation | ||
umeeToken := newToken("uumee", "UMEE") | ||
umeeToken.CollateralWeight = sdk.MustNewDecFromStr("0.05") | ||
umeeToken.LiquidationThreshold = sdk.MustNewDecFromStr("0.05") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this 3 lines are repeated often. Could be better to create a function: newUmeeToken(collateraW, liquidationT)
} | ||
|
||
// newAccount creates a new account for testing, and funds it with any input tokens. | ||
func (s *IntegrationTestSuite) newAccount(funds ...sdk.Coin) sdk.AccAddress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Except small behavior changes, this PR is limited to
x/leverage/keeper/*_test.go
Behavior changes:
Main improvements:
x/leverage/client/tests
which would make it hard to identify the root cause of a failures.initBorrowScenario
in favor of more specific test setup functions (e.g.s.borrow
)keeper_test.go
functionsrequire.ErrorIs(err, types.ErrNotRegisteredToken)
Cosmetic improvements:
400_000000
when creating400 UMEE
expected
value is always on the left inrequire.Equal(expected,actual)
for accurate test fail messagescloses: #1310
closes: #1242
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...