Skip to content

Commit

Permalink
test(inflation): add additional burn test cases (#1828)
Browse files Browse the repository at this point in the history
* test(inflation): add negative burn tests

* test(inflation): add total supply check to burn tests
  • Loading branch information
k-yang committed Mar 28, 2024
1 parent 9178e4f commit 2888281
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
24 changes: 21 additions & 3 deletions x/inflation/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
23 changes: 23 additions & 0 deletions x/inflation/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 2888281

Please sign in to comment.