Skip to content

Commit

Permalink
Improve unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
0a1c committed Mar 28, 2023
1 parent 29760f1 commit 8f23457
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion testutil/vesting/mock_vesting_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import (
// LockedCoinsFromDelegating prevents the mock vesting account from delegating
// any unvested tokens.
func (mvdva MockVestedDelegateVestingAccount) LockedCoinsFromDelegating(blockTime time.Time) sdk.Coins {
return mvdva.ContinuousVestingAccount.LockedCoins(blockTime)
locked := mvdva.ContinuousVestingAccount.GetVestingCoins(blockTime)
if locked == nil {
return sdk.NewCoins()
}

return locked
}

func NewMockVestedDelegateVestingAccount(cva *types.ContinuousVestingAccount) *MockVestedDelegateVestingAccount {
Expand Down
8 changes: 5 additions & 3 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (suite *IntegrationTestSuite) initKeepersWithmAccPerms(blockedAddrs map[str
return authKeeper, keeper
}

func (suite *IntegrationTestSuite) initKeepersWithMockVesting() (authkeeper.AccountKeeper, keeper.BaseKeeper) {
func (suite *IntegrationTestSuite) initKeepersWithMockVestingTypes() (authkeeper.AccountKeeper, keeper.BaseKeeper) {
app := suite.app

encCfg := simapp.MakeTestEncodingConfig()
Expand Down Expand Up @@ -941,7 +941,7 @@ func (suite *IntegrationTestSuite) TestDelegatableCoins() {
ctx = ctx.WithBlockHeader(tmproto.Header{Time: now})
endTime := now.Add(24 * time.Hour)

authKeeper, keeper := suite.initKeepersWithMockVesting()
authKeeper, keeper := suite.initKeepersWithMockVestingTypes()

testAddr := sdk.AccAddress([]byte("addr1_______________"))
addrModule := sdk.AccAddress([]byte("moduleAcc___________"))
Expand All @@ -960,7 +960,9 @@ func (suite *IntegrationTestSuite) TestDelegatableCoins() {

ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
suite.Require().NoError(keeper.DelegateCoins(ctx, testAddr, addrModule, delCoins))
suite.Require().Equal(origCoins.Sub(delCoins...), keeper.DelegatableCoins(ctx, testAddr))
suite.Require().Equal(sdk.NewCoins(), keeper.DelegatableCoins(ctx, testAddr))

suite.Require().Error(keeper.DelegateCoins(ctx, testAddr, addrModule, delCoins))
}

func (suite *IntegrationTestSuite) TestUndelegateCoins() {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (k BaseViewKeeper) DelegatableCoins(ctx sdk.Context, addr sdk.AccAddress) s

func (k BaseViewKeeper) unlockedCoins(total, locked sdk.Coins) (spendable sdk.Coins) {
spendable, hasNeg := total.SafeSub(locked...)
if hasNeg {
if hasNeg || spendable == nil {
spendable = sdk.NewCoins()
return
}
Expand Down

0 comments on commit 8f23457

Please sign in to comment.