-
Notifications
You must be signed in to change notification settings - Fork 202
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
test(inflation): add supply checks #1827
Conversation
WalkthroughThis update enhances code clarity and reusability related to burn coin supply checks within the inflation module. By moving these checks to separate functions, the changes facilitate better testing and maintenance. Additionally, the update aims to align with best practices by using bank total supply queries for validating state changes in MsgBurn, addressing specific objectives from linked issues. Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- x/inflation/keeper/keeper_test.go (1 hunks)
- x/inflation/keeper/msg_server_test.go (1 hunks)
Additional comments: 1
x/inflation/keeper/msg_server_test.go (1)
- 77-95: The addition of supply checks before and after the burn operation in the
TestMsgBurn
function is a solid improvement for validating the correctness of the burn functionality. This ensures that the test accurately reflects the expected behavior of the system when tokens are burned. The implementation correctly places the supply check outside of any conditional error handling, ensuring it's always executed. This is a good practice and aligns with the changes recommended forkeeper_test.go
.
supplyBefore := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | ||
err := nibiruApp.InflationKeeper.Burn(ctx, sdk.NewCoins(tc.burnCoin), tc.sender) | ||
if tc.expectedErr != nil { | ||
require.EqualError(t, err, tc.expectedErr.Error()) | ||
supplyAfter := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | ||
require.EqualValues(t, tc.burnCoin, supplyBefore.Sub(supplyAfter)) |
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.
The addition of supply checks before and after burning coins is a good practice for ensuring the correctness of the burn operation. However, there's a logical issue in the conditional block that checks for tc.expectedErr != nil
. The supply comparison should occur outside this conditional block to ensure it's always executed, regardless of whether an error was expected or not. This ensures that the supply check is performed in all test scenarios.
- if tc.expectedErr != nil {
- require.EqualError(t, err, tc.expectedErr.Error())
- supplyAfter := nibiruApp.BankKeeper.GetSupply(ctx, "unibi")
- require.EqualValues(t, tc.burnCoin, supplyBefore.Sub(supplyAfter))
- } else {
- require.NoError(t, err)
- }
+ if tc.expectedErr != nil {
+ require.EqualError(t, err, tc.expectedErr.Error())
+ } else {
+ require.NoError(t, err)
+ }
+ supplyAfter := nibiruApp.BankKeeper.GetSupply(ctx, "unibi")
+ require.EqualValues(t, tc.burnCoin, supplyBefore.Sub(supplyAfter))
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
supplyBefore := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | |
err := nibiruApp.InflationKeeper.Burn(ctx, sdk.NewCoins(tc.burnCoin), tc.sender) | |
if tc.expectedErr != nil { | |
require.EqualError(t, err, tc.expectedErr.Error()) | |
supplyAfter := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | |
require.EqualValues(t, tc.burnCoin, supplyBefore.Sub(supplyAfter)) | |
supplyBefore := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | |
err := nibiruApp.InflationKeeper.Burn(ctx, sdk.NewCoins(tc.burnCoin), tc.sender) | |
if tc.expectedErr != nil { | |
require.EqualError(t, err, tc.expectedErr.Error()) | |
} else { | |
require.NoError(t, err) | |
} | |
supplyAfter := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") | |
require.EqualValues(t, tc.burnCoin, supplyBefore.Sub(supplyAfter)) |
Summary by CodeRabbit