From 2b2911cd9e973a7ee27277de26325fe150bac402 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Tue, 6 Feb 2024 15:23:07 +0700 Subject: [PATCH] fix: calculate balanceDelegate --- app/upgrades/v4_1_0/upgrades.go | 8 ++++---- app/upgrades/v4_1_0/upgrades_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/upgrades/v4_1_0/upgrades.go b/app/upgrades/v4_1_0/upgrades.go index 0378c7c7..cf3a6386 100644 --- a/app/upgrades/v4_1_0/upgrades.go +++ b/app/upgrades/v4_1_0/upgrades.go @@ -103,6 +103,8 @@ func processMigrateMultisig(ctx sdk.Context, stakingKeeper stakingKeeper.Keeper, fmt.Printf("currentAddr Instant Redelegations: %s\n", redelegated) fmt.Printf("currentAddr Instant Unbonding: %s\n", unbonded) + // get vested + reward balance + totalBalance := bankKeeper.GetBalance(ctx, currentAddr, params.BaseDenom) // delegate vesting coin to validator err = delegateToValidator(ctx, stakingKeeper, currentAddr, oldAcc.GetVestingCoins(ctx.BlockTime())[0].Amount) @@ -110,11 +112,8 @@ func processMigrateMultisig(ctx sdk.Context, stakingKeeper stakingKeeper.Keeper, panic(err) } - // get vested + reward balance - totalBalance := bankKeeper.GetBalance(ctx, currentAddr, params.BaseDenom) fmt.Println("total balance before migration ", totalBalance) balanceCanSend := totalBalance.Amount.Sub(oldAcc.GetVestingCoins(ctx.BlockTime())[0].Amount) - fmt.Printf("total balance send to new multisig addr: %s\n", balanceCanSend) // send vested + reward balance no newAddr err = bankKeeper.SendCoins(ctx, currentAddr, newAddr, sdk.NewCoins(sdk.NewCoin(params.BaseDenom, balanceCanSend))) @@ -203,7 +202,8 @@ func delegateToValidator(ctx sdk.Context, ) error { listValidator := stakingKeeper.GetBondedValidatorsByPower(ctx) totalValidatorDelegate := math.Min(10, len(listValidator)) - balanceDelegate := totalVestingBalance.Quo(totalVestingBalance) + balanceDelegate := totalVestingBalance.Quo(math.NewInt(int64(totalValidatorDelegate))) + fmt.Printf("balanceDelegate each validator %v, total validator %d\n", balanceDelegate, totalValidatorDelegate) for i, validator := range listValidator { if i >= totalValidatorDelegate { diff --git a/app/upgrades/v4_1_0/upgrades_test.go b/app/upgrades/v4_1_0/upgrades_test.go index 2ec06a1f..c1b35306 100644 --- a/app/upgrades/v4_1_0/upgrades_test.go +++ b/app/upgrades/v4_1_0/upgrades_test.go @@ -74,13 +74,15 @@ func (s *UpgradeTestSuite) TestUpgrade() { // check old multisign address balance oldMultisigBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NotionalMultisigVestingAccount)) fmt.Printf("Old multisign address Upgrade Balance: %s\n", oldMultisigBalance) - s.Require().True(oldMultisigBalance.AmountOf(params.BaseDenom).GTE(unvested)) + totalDelegateBalance := s.App.StakingKeeper.GetDelegatorBonded(s.Ctx, sdk.MustAccAddressFromBech32(v4.NotionalMultisigVestingAccount)) + fmt.Printf("old multisign address totalDelegateBalance %v\n", totalDelegateBalance) + s.Require().True(totalDelegateBalance.Add(oldMultisigBalance[0].Amount).GTE(unvested)) // check new multisign address balance newBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, sdk.MustAccAddressFromBech32(v4.NewNotionalMultisigAccount)) vestedBalance := cVesting.GetVestedCoins(s.Ctx.BlockTime()) fmt.Printf("New multisign Upgrade Balance: %s, vestedBalance %s\n", newBalance, vestedBalance) - s.Require().True(newBalance.AmountOf(params.BaseDenom).LTE(vestedBalance.AmountOf(params.BaseDenom))) + s.Require().True(vestedBalance.AmountOf(params.BaseDenom).GTE(newBalance.AmountOf(params.BaseDenom))) } func (s *UpgradeTestSuite) TestMath() {