Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Feb 20, 2024
1 parent fe23803 commit a4d034f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
11 changes: 6 additions & 5 deletions app/upgrades/v4_1_1/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package v4

import (
"fmt"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"time"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -60,10 +61,10 @@ func CreateUpgradeHandler(
}
}

// migrateMultisigVesting moves the unvested from the ContinuousVestingAccount -> the new multisig vesting account.
// migrateMultisigVesting moves the unvested from the ContinuousVestingAccount -> the new ContinuousVestingAccount
// - Retrieves the old multisig vesting account
// - Instantly finish all redelegations, then unbond all tokens.
// - Transfer all tokens unvested token to the new multisig vesting account
// - Transfer unvested token to the new multisign ContinuousVestingAccount
func migrateMultisigVesting(ctx sdk.Context,
stakingKeeper stakingKeeper.Keeper,
bankKeeper bankKeeper.Keeper,
Expand Down Expand Up @@ -116,14 +117,14 @@ func processMigrateMultisig(ctx sdk.Context, stakingKeeper stakingKeeper.Keeper,
ctx.BlockTime().Unix(), oldAcc.EndTime)
accountKeeper.SetAccount(ctx, newVestingAcc)

// end old continuous vesting account
// end current ContinuousVestingAccount
oldAcc.OriginalVesting = oldAcc.OriginalVesting.Sub(vestingCoin[0])
oldAcc.DelegatedFree = sdk.NewCoins()
oldAcc.DelegatedVesting = sdk.NewCoins()
oldAcc.EndTime = ctx.BlockTime().Unix()
accountKeeper.SetAccount(ctx, oldAcc)

// move vesting coin to newAddr
// move vesting coin to new ContinuousVestingAccount
err = bankKeeper.SendCoins(ctx, currentAddr, newAddr, vestingCoin)
if err != nil {
panic(err)
Expand Down
37 changes: 13 additions & 24 deletions app/upgrades/v4_1_1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,11 @@ func (s *UpgradeTestSuite) TestUpgrade() {
newVal1 := s.SetupValidator(stakingtypes.Bonded)
newVal2 := s.SetupValidator(stakingtypes.Bonded)
newVal3 := s.SetupValidator(stakingtypes.Bonded)
newVal4 := s.SetupValidator(stakingtypes.Bonded)
newVal5 := s.SetupValidator(stakingtypes.Bonded)
newVal6 := s.SetupValidator(stakingtypes.Bonded)
newVal7 := s.SetupValidator(stakingtypes.Bonded)
newVal8 := s.SetupValidator(stakingtypes.Bonded)
newVal9 := s.SetupValidator(stakingtypes.Bonded)
newVal10 := s.SetupValidator(stakingtypes.Bonded)
newVal11 := s.SetupValidator(stakingtypes.Bonded)
newVal12 := s.SetupValidator(stakingtypes.Bonded)

// Delegate tokens of the vesting multisig account
s.StakingHelper.Delegate(vestingAddr, newVal1, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal2, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal3, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal4, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal5, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal6, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal7, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal8, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal9, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal10, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal11, sdk.NewInt(300))
s.StakingHelper.Delegate(vestingAddr, newVal12, sdk.NewInt(300))

// Undelegate part of the tokens from val2 (test instant unbonding on undelegation started before upgrade)
s.StakingHelper.Undelegate(vestingAddr, newVal3, sdk.NewInt(10), true)
Expand All @@ -67,8 +49,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {
_, err := s.App.StakingKeeper.BeginRedelegation(s.Ctx, vestingAddr, newVal2, newVal3, sdk.NewDec(1))
s.Require().NoError(err)

// Confirm delegated to 12 validators
s.Require().Equal(12, len(s.App.StakingKeeper.GetAllDelegatorDelegations(s.Ctx, vestingAddr)))
// Confirm delegated to 3 validators
s.Require().Equal(3, len(s.App.StakingKeeper.GetAllDelegatorDelegations(s.Ctx, vestingAddr)))

// == UPGRADE ==
upgradeHeight := int64(5)
Expand All @@ -94,20 +76,27 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(0, len(s.App.StakingKeeper.GetRedelegations(s.Ctx, vestingAddr, 65535)))

vestingBalance := cVesting.GetVestingCoins(s.Ctx.BlockTime())

// check old multisign address balance
expectedBalance := accVestingBalance.AmountOf(params.BaseDenom).Sub(vestingBalance.AmountOf(params.BaseDenom))
oldMultisigBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NotionalMultisigVestingAccount))
fmt.Printf("Old multisign address Upgrade Balance: %s, expectedBalance %s\n", oldMultisigBalance, expectedBalance)
// check base account balance
s.Require().True(oldMultisigBalance.AmountOf(params.BaseDenom).Equal(expectedBalance))
s.Require().True(accAfterVestingAccount.OriginalVesting.AmountOf(params.BaseDenom).Equal(expectedBalance))

s.Require().True(oldMultisigBalance.AmountOf(v4.TestDenom).Equal(sdk.NewInt(v4.TestAmount)))
// check vesting info
s.Require().True(accAfterVestingAccount.OriginalVesting.AmountOf(params.BaseDenom).Equal(expectedBalance))
s.Require().True(accAfterVestingAccount.DelegatedVesting.Empty())
s.Require().True(accAfterVestingAccount.DelegatedFree.Empty())

// check new multisign address balance
fmt.Printf("New multisign Upgrade Balance: %s, vestingBalance %s\n", newNotionalAccVesting.GetOriginalVesting(), vestingBalance)
s.Require().True(vestingBalance.AmountOf(params.BaseDenom).
Equal(newNotionalAccVesting.GetOriginalVesting().AmountOf(params.BaseDenom)))
// check vesting info
s.Require().True(vestingBalance.AmountOf(params.BaseDenom).Equal(newNotionalAccVesting.GetOriginalVesting().AmountOf(params.BaseDenom)))
s.Require().True(newNotionalAccVesting.DelegatedVesting.Empty())
s.Require().True(newNotionalAccVesting.DelegatedFree.Empty())

// check base account balance
newMultisigBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NewNotionalMultisigAccount))
s.Require().True(newMultisigBalance.AmountOf(params.BaseDenom).Equal(vestingBalance.AmountOf(params.BaseDenom)))
}

0 comments on commit a4d034f

Please sign in to comment.