From a4d034f05d8a853be85193914f2df251790c627e Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 20 Feb 2024 22:25:09 +0700 Subject: [PATCH] test: update test --- app/upgrades/v4_1_1/upgrades.go | 11 +++++---- app/upgrades/v4_1_1/upgrades_test.go | 37 ++++++++++------------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/app/upgrades/v4_1_1/upgrades.go b/app/upgrades/v4_1_1/upgrades.go index c2575b43..195c3f0b 100644 --- a/app/upgrades/v4_1_1/upgrades.go +++ b/app/upgrades/v4_1_1/upgrades.go @@ -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" @@ -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, @@ -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) diff --git a/app/upgrades/v4_1_1/upgrades_test.go b/app/upgrades/v4_1_1/upgrades_test.go index 563741e5..5179a324 100644 --- a/app/upgrades/v4_1_1/upgrades_test.go +++ b/app/upgrades/v4_1_1/upgrades_test.go @@ -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) @@ -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) @@ -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))) }