Skip to content

Commit

Permalink
feat: test migrate balance
Browse files Browse the repository at this point in the history
  • Loading branch information
kien6034 committed Nov 13, 2024
1 parent 1cfbba3 commit 005cf95
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/upgrades/v4_2_6/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ package v4
const (
UpgradeName = "v4.2.6"
)

const (
Denom = "ibc/BC5C0BAFD19A5E4133FDA0F3E04AE1FBEE75A4A226554B2CBB021089FF2E1F8A"
DeadContract = "migaloo1qelh4gv5drg3yhj282l6n84a6wrrz033kwyak3ee3syvqg3mu3msgphpk4"
Foundation = "migaloo10zqfqhw44e6gvu97frjzcghunndskhu40uyztwu00y6dr9qxrz6qcjfrf7"
)
68 changes: 68 additions & 0 deletions app/upgrades/v4_2_6/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package v4_test

import (
"testing"

"cosmossdk.io/math"
v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_6"
sdk "github.com/cosmos/cosmos-sdk/types"

apptesting "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app"
"github.com/stretchr/testify/suite"
)

const (
MockDeadContractBalance = 1000000000000000000
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) MockBankBalances() {
deadContractAddr := sdk.MustAccAddressFromBech32(v4.DeadContract)

coins := sdk.NewCoins(
sdk.NewCoin(v4.Denom, math.NewInt(MockDeadContractBalance)),
)

// Replace FundAccount with BankKeeper's MintCoins and SendCoinsFromModuleToAccount
err := s.App.BankKeeper.MintCoins(s.Ctx, "mint", coins)
s.Require().NoError(err)

err = s.App.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, "mint", deadContractAddr, coins)
s.Require().NoError(err)

// require the balance is correct
balance := s.App.BankKeeper.GetAllBalances(s.Ctx, deadContractAddr)
s.Require().Equal(coins, balance)
}

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup(s.T())
// == CREATE MOCK VESTING ACCOUNT ==
s.MockBankBalances()

// == UPGRADE ==
upgradeHeight := int64(5)

// Execute upgrade
s.ConfirmUpgradeSucceeded(v4.UpgradeName, upgradeHeight)

// Dead contract balance get drained
deadContractAddr := sdk.MustAccAddressFromBech32(v4.DeadContract)
contractBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, deadContractAddr)
s.Require().Equal(int64(0), contractBalance.AmountOf(v4.Denom).Int64())

// Foundation balance get drained
foundationAddr := sdk.MustAccAddressFromBech32(v4.Foundation)
foundationBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, foundationAddr)
s.T().Logf("balance: %v", foundationBalance)
s.Require().Equal(int64(MockDeadContractBalance), foundationBalance.AmountOf(v4.Denom).Int64()) // Add int64 cast

}
6 changes: 0 additions & 6 deletions app/upgrades/v4_2_6/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const (
Denom = "ibc/BC5C0BAFD19A5E4133FDA0F3E04AE1FBEE75A4A226554B2CBB021089FF2E1F8A"
DeadContract = "migaloo1qelh4gv5drg3yhj282l6n84a6wrrz033kwyak3ee3syvqg3mu3msgphpk4"
Foundation = "migaloo10zqfqhw44e6gvu97frjzcghunndskhu40uyztwu00y6dr9qxrz6qcjfrf7"
)

// CreateUpgradeHandler that migrates the chain from v4.2.5 to v4.2.6
func CreateUpgradeHandler(
mm *module.Manager,
Expand Down
5 changes: 3 additions & 2 deletions scripts/upgrade_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}

OLD_VERSION=v4.2.4
OLD_VERSION=v4.2.5
UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=mytestnet
ROOT=$(pwd)
DENOM=uwhale
CHAIN_ID=localmigaloo
SOFTWARE_UPGRADE_NAME="v4.2.5"
SOFTWARE_UPGRADE_NAME="v4.2.6"
ADDITIONAL_PRE_SCRIPTS=${ADDITIONAL_PRE_SCRIPTS:-""}
ADDITIONAL_AFTER_SCRIPTS=${ADDITIONAL_AFTER_SCRIPTS:-""}

Expand Down Expand Up @@ -43,6 +43,7 @@ then
GOBIN="$ROOT/_build/new" go install -mod=readonly ./...
fi

exit 0
# run old node
if [[ "$OSTYPE" == "darwin"* ]]; then
screen -L -dmS node1 bash scripts/run-node.sh _build/old/migalood $DENOM --Logfile $HOME/log-screen.txt
Expand Down

0 comments on commit 005cf95

Please sign in to comment.