From 28882810c1941e853c255c57843015a501c85583 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:09:51 +0900 Subject: [PATCH] test(inflation): add additional burn test cases (#1828) * test(inflation): add negative burn tests * test(inflation): add total supply check to burn tests --- x/inflation/keeper/keeper_test.go | 24 +++++++++++++++++++++--- x/inflation/keeper/msg_server_test.go | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/x/inflation/keeper/keeper_test.go b/x/inflation/keeper/keeper_test.go index 4100e13c8..391efe14f 100644 --- a/x/inflation/keeper/keeper_test.go +++ b/x/inflation/keeper/keeper_test.go @@ -20,33 +20,51 @@ func TestBurn(t *testing.T) { testCases := []struct { name string sender sdk.AccAddress + mintCoin sdk.Coin burnCoin sdk.Coin expectedErr error }{ { name: "pass", sender: testutil.AccAddress(), - burnCoin: sdk.NewCoin("nibiru", sdk.NewInt(100)), + mintCoin: sdk.NewCoin("unibi", sdk.NewInt(100)), + burnCoin: sdk.NewCoin("unibi", sdk.NewInt(100)), expectedErr: nil, }, + { + name: "not enough coins", + sender: testutil.AccAddress(), + mintCoin: sdk.NewCoin("unibi", sdk.NewInt(100)), + burnCoin: sdk.NewCoin("unibi", sdk.NewInt(101)), + expectedErr: fmt.Errorf("spendable balance 100unibi is smaller than 101unibi: insufficient funds"), + }, } + for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { nibiruApp, ctx := testapp.NewNibiruTestAppAndContext() + + // mint and send money to the sender require.NoError(t, nibiruApp.BankKeeper.MintCoins( - ctx, types.ModuleName, sdk.NewCoins(tc.burnCoin))) + ctx, types.ModuleName, sdk.NewCoins(tc.mintCoin))) require.NoError(t, nibiruApp.BankKeeper.SendCoinsFromModuleToAccount( - ctx, types.ModuleName, tc.sender, sdk.NewCoins(tc.burnCoin)), + ctx, types.ModuleName, tc.sender, sdk.NewCoins(tc.mintCoin)), ) + supply := nibiruApp.BankKeeper.GetSupply(ctx, "unibi") + require.Equal(t, tc.mintCoin.Amount, supply.Amount) + // Burn coins err := nibiruApp.InflationKeeper.Burn(ctx, sdk.NewCoins(tc.burnCoin), tc.sender) + supply = nibiruApp.BankKeeper.GetSupply(ctx, "unibi") if tc.expectedErr != nil { require.EqualError(t, err, tc.expectedErr.Error()) + require.Equal(t, tc.mintCoin.Amount, supply.Amount) } else { require.NoError(t, err) + require.Equal(t, sdk.ZeroInt(), supply.Amount) } }) } diff --git a/x/inflation/keeper/msg_server_test.go b/x/inflation/keeper/msg_server_test.go index 49cfa1620..cc37a97a3 100644 --- a/x/inflation/keeper/msg_server_test.go +++ b/x/inflation/keeper/msg_server_test.go @@ -88,4 +88,27 @@ func TestMsgBurn(t *testing.T) { _, err = msgServer.Burn(ctx, &msg) require.NoError(t, err) + supply := app.BankKeeper.GetSupply(ctx, "unibi") + require.Equal(t, sdk.ZeroInt(), supply.Amount) +} + +func TestMsgBurn_NotEnoughCoins(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) + + msg := types.MsgBurn{ + Sender: sender.String(), + Coin: sdk.NewCoin("unibi", sdk.NewInt(101)), + } + + _, err = msgServer.Burn(ctx, &msg) + require.EqualError(t, err, "spendable balance 100unibi is smaller than 101unibi: insufficient funds") + supply := app.BankKeeper.GetSupply(ctx, "unibi") + require.Equal(t, sdk.NewInt(100), supply.Amount) }