Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x/inflation/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func TestBurn(t *testing.T) {
)

// Burn coins
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))
Comment on lines +45 to +50
Copy link
Contributor

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.

Suggested change
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))

} else {
require.NoError(t, err)
}
Expand Down
9 changes: 7 additions & 2 deletions x/inflation/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,23 @@ func TestMsgEditInflationParams(t *testing.T) {
func TestMsgBurn(t *testing.T) {
app, ctx := testapp.NewNibiruTestAppAndContext()
sender := testutil.AccAddress()

err := app.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)

msgServer := keeper.NewMsgServerImpl(app.InflationKeeper)

supplyBefore := app.BankKeeper.GetSupply(ctx, "unibi")
coinToBurn := sdk.NewCoin("unibi", sdk.NewInt(100))
msg := types.MsgBurn{
Sender: sender.String(),
Coin: sdk.NewCoin("unibi", sdk.NewInt(100)),
Coin: coinToBurn,
}

_, err = msgServer.Burn(ctx, &msg)
require.NoError(t, err)

supplyAfter := app.BankKeeper.GetSupply(ctx, "unibi")
require.EqualValues(t, coinToBurn, supplyBefore.Sub(supplyAfter))
}
Loading