diff --git a/testutil/vesting/mock_vesting_accounts.go b/testutil/vesting/mock_vesting_accounts.go index d9a0b81e5c44..a31aa8fd4805 100644 --- a/testutil/vesting/mock_vesting_accounts.go +++ b/testutil/vesting/mock_vesting_accounts.go @@ -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 { diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 2a8f91eb1660..d0310f156b4b 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -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() @@ -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___________")) @@ -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() { diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 1441a1aae776..b17aceb3c388 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -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 }