From 54ac0b84e916f4f026e3a3a5062e2efa492f9d63 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Thu, 16 May 2024 16:32:30 +0200 Subject: [PATCH] test(vesting): add vesting_account test for cliff spendable coins --- x/vesting/types/vesting_account_test.go | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/x/vesting/types/vesting_account_test.go b/x/vesting/types/vesting_account_test.go index bc0b072a2..b5584ab83 100644 --- a/x/vesting/types/vesting_account_test.go +++ b/x/vesting/types/vesting_account_test.go @@ -855,6 +855,36 @@ func TestGetVestingCoinsCliffVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}, vestingCoins) } +func TestSpendableCoinsCliffVestingAcc(t *testing.T) { + now := tmtime.Now() + cliffTime := now.Add(12 * time.Hour) + endTime := now.Add(24 * time.Hour) + + bacc, origCoins := initBaseAccount() + cva, err := types.NewCliffVestingAccount(bacc, origCoins, now.Unix(), cliffTime.Unix(), endTime.Unix()) + require.NoError(t, err) + + // require all coins are locked at the beginning of the vesting schedule + lockedCoins := cva.LockedCoins(now) + require.Equal(t, origCoins, lockedCoins) + + // require all coins are locked before the cliff time but after the beginning + lockedCoins = cva.LockedCoins(now.Add(6 * time.Hour)) + require.Equal(t, origCoins, lockedCoins) + + // require no coins are locked at the end of the vesting schedule + lockedCoins = cva.LockedCoins(endTime) + require.Equal(t, sdk.NewCoins(), lockedCoins) + + // require 50% of coins are locked at the cliff time + lockedCoins = cva.LockedCoins(cliffTime.Add(1 * time.Second)) + require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, lockedCoins) + + // require 25% of coins are locked + lockedCoins = cva.LockedCoins(now.Add(18 * time.Hour)) + require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}, lockedCoins) +} + func TestTrackDelegationCliffVestingAcc(t *testing.T) { now := tmtime.Now() cliffTime := now.Add(12 * time.Hour)