Skip to content

Commit 75c29ec

Browse files
authored
test(inflation): add additional burn test cases (#1828)
* test(inflation): add negative burn tests * test(inflation): add total supply check to burn tests
1 parent a5e0e10 commit 75c29ec

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

x/inflation/keeper/keeper_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,51 @@ func TestBurn(t *testing.T) {
2020
testCases := []struct {
2121
name string
2222
sender sdk.AccAddress
23+
mintCoin sdk.Coin
2324
burnCoin sdk.Coin
2425
expectedErr error
2526
}{
2627
{
2728
name: "pass",
2829
sender: testutil.AccAddress(),
29-
burnCoin: sdk.NewCoin("nibiru", sdk.NewInt(100)),
30+
mintCoin: sdk.NewCoin("unibi", sdk.NewInt(100)),
31+
burnCoin: sdk.NewCoin("unibi", sdk.NewInt(100)),
3032
expectedErr: nil,
3133
},
34+
{
35+
name: "not enough coins",
36+
sender: testutil.AccAddress(),
37+
mintCoin: sdk.NewCoin("unibi", sdk.NewInt(100)),
38+
burnCoin: sdk.NewCoin("unibi", sdk.NewInt(101)),
39+
expectedErr: fmt.Errorf("spendable balance 100unibi is smaller than 101unibi: insufficient funds"),
40+
},
3241
}
42+
3343
for _, tc := range testCases {
3444
t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) {
3545
nibiruApp, ctx := testapp.NewNibiruTestAppAndContext()
46+
47+
// mint and send money to the sender
3648
require.NoError(t,
3749
nibiruApp.BankKeeper.MintCoins(
38-
ctx, types.ModuleName, sdk.NewCoins(tc.burnCoin)))
50+
ctx, types.ModuleName, sdk.NewCoins(tc.mintCoin)))
3951
require.NoError(t,
4052
nibiruApp.BankKeeper.SendCoinsFromModuleToAccount(
41-
ctx, types.ModuleName, tc.sender, sdk.NewCoins(tc.burnCoin)),
53+
ctx, types.ModuleName, tc.sender, sdk.NewCoins(tc.mintCoin)),
4254
)
4355

56+
supply := nibiruApp.BankKeeper.GetSupply(ctx, "unibi")
57+
require.Equal(t, tc.mintCoin.Amount, supply.Amount)
58+
4459
// Burn coins
4560
err := nibiruApp.InflationKeeper.Burn(ctx, sdk.NewCoins(tc.burnCoin), tc.sender)
61+
supply = nibiruApp.BankKeeper.GetSupply(ctx, "unibi")
4662
if tc.expectedErr != nil {
4763
require.EqualError(t, err, tc.expectedErr.Error())
64+
require.Equal(t, tc.mintCoin.Amount, supply.Amount)
4865
} else {
4966
require.NoError(t, err)
67+
require.Equal(t, sdk.ZeroInt(), supply.Amount)
5068
}
5169
})
5270
}

x/inflation/keeper/msg_server_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,27 @@ func TestMsgBurn(t *testing.T) {
8888

8989
_, err = msgServer.Burn(ctx, &msg)
9090
require.NoError(t, err)
91+
supply := app.BankKeeper.GetSupply(ctx, "unibi")
92+
require.Equal(t, sdk.ZeroInt(), supply.Amount)
93+
}
94+
95+
func TestMsgBurn_NotEnoughCoins(t *testing.T) {
96+
app, ctx := testapp.NewNibiruTestAppAndContext()
97+
sender := testutil.AccAddress()
98+
err := app.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
99+
require.NoError(t, err)
100+
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
101+
require.NoError(t, err)
102+
103+
msgServer := keeper.NewMsgServerImpl(app.InflationKeeper)
104+
105+
msg := types.MsgBurn{
106+
Sender: sender.String(),
107+
Coin: sdk.NewCoin("unibi", sdk.NewInt(101)),
108+
}
109+
110+
_, err = msgServer.Burn(ctx, &msg)
111+
require.EqualError(t, err, "spendable balance 100unibi is smaller than 101unibi: insufficient funds")
112+
supply := app.BankKeeper.GetSupply(ctx, "unibi")
113+
require.Equal(t, sdk.NewInt(100), supply.Amount)
91114
}

0 commit comments

Comments
 (0)