diff --git a/tests/integration/x/precisebank/test_genesis.go b/tests/integration/x/precisebank/test_genesis.go index b555238ed..e3086236a 100644 --- a/tests/integration/x/precisebank/test_genesis.go +++ b/tests/integration/x/precisebank/test_genesis.go @@ -48,29 +48,6 @@ func (s *GenesisTestSuite) SetupTestWithChainID(chainID testconstants.ChainID) { }) } -func (s *GenesisTestSuite) adjustModuleBalance(expectedAmt sdkmath.Int) { - moduleAddr := s.network.App.GetAccountKeeper().GetModuleAddress(types.ModuleName) - balance := s.network.App.GetBankKeeper().GetBalance(s.network.GetContext(), moduleAddr, types.IntegerCoinDenom()) - - if balance.Amount.GT(expectedAmt) { - // Burn excess - err := s.network.App.GetBankKeeper().BurnCoins( - s.network.GetContext(), - types.ModuleName, - sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), balance.Amount.Sub(expectedAmt))), - ) - s.Require().NoError(err) - } else if balance.Amount.LT(expectedAmt) { - // Mint deficit - err := s.network.App.GetBankKeeper().MintCoins( - s.network.GetContext(), - types.ModuleName, - sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), expectedAmt.Sub(balance.Amount))), - ) - s.Require().NoError(err) - } -} - func (s *GenesisTestSuite) TestInitGenesis() { tests := []struct { name string @@ -95,7 +72,8 @@ func (s *GenesisTestSuite) TestInitGenesis() { func() { // The network setup creates an initial balance of 1, so we need to mint 1 more // to get to the expected amount of 2 for this test case - s.adjustModuleBalance(sdkmath.NewInt(2)) + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, (sdkmath.NewInt(2))) + s.Require().NoError(err) }, types.NewGenesisState( types.FractionalBalances{ @@ -125,7 +103,8 @@ func (s *GenesisTestSuite) TestInitGenesis() { func() { // The network setup creates an initial balance of 1, so we need to burn that // to get to 0 balance for this test case - s.adjustModuleBalance(sdkmath.ZeroInt()) + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, (sdkmath.ZeroInt())) + s.Require().NoError(err) }, types.NewGenesisState( types.FractionalBalances{ @@ -143,7 +122,8 @@ func (s *GenesisTestSuite) TestInitGenesis() { func() { // The network setup creates an initial balance of 1, so we need to mint 99 more // to get to 100 total balance for this test case - s.adjustModuleBalance(sdkmath.NewInt(100)) + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, (sdkmath.NewInt(100))) + s.Require().NoError(err) }, types.NewGenesisState( types.FractionalBalances{ @@ -243,7 +223,8 @@ func (s *GenesisTestSuite) TestExportGenesis() { "balances, no remainder", func() *types.GenesisState { // Burn the initial balance created by network setup, then mint the expected amount - s.adjustModuleBalance(sdkmath.NewInt(1)) + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, (sdkmath.NewInt(1))) + s.Require().NoError(err) return types.NewGenesisState( types.FractionalBalances{ @@ -258,7 +239,8 @@ func (s *GenesisTestSuite) TestExportGenesis() { "balances, remainder", func() *types.GenesisState { // Burn the initial balance created by network setup, then mint the expected amount - s.adjustModuleBalance(sdkmath.NewInt(1)) + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, (sdkmath.NewInt(1))) + s.Require().NoError(err) return types.NewGenesisState( types.FractionalBalances{ diff --git a/tests/integration/x/precisebank/test_utils.go b/tests/integration/x/precisebank/test_utils.go index 2ac668c87..187a47f8e 100644 --- a/tests/integration/x/precisebank/test_utils.go +++ b/tests/integration/x/precisebank/test_utils.go @@ -1,6 +1,7 @@ package precisebank import ( + "github.com/cosmos/evm" "github.com/cosmos/evm/x/precisebank/types" sdkmath "cosmossdk.io/math" @@ -91,6 +92,31 @@ func ConvertCoinsToExtendedCoinDenom(coins sdk.Coins) sdk.Coins { return coins.Sub(integerCoin).Add(extendedCoin) } +// AdjustModuleBalance adjusts the precisebank module account balance to the expected amount. +// TODO: This is a test utility function and should ideally not be needed. +// Consider refactoring tests to avoid needing this. +func AdjustModuleBalance(sdkCtx sdk.Context, evmApp evm.EvmApp, expectedAmt sdkmath.Int) error { + moduleAddr := evmApp.GetAccountKeeper().GetModuleAddress(types.ModuleName) + balance := evmApp.GetBankKeeper().GetBalance(sdkCtx, moduleAddr, types.IntegerCoinDenom()) + + if balance.Amount.GT(expectedAmt) { + // Burn excess + return evmApp.GetBankKeeper().BurnCoins( + sdkCtx, + types.ModuleName, + sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), balance.Amount.Sub(expectedAmt))), + ) + } else if balance.Amount.LT(expectedAmt) { + // Mint deficit + return evmApp.GetBankKeeper().MintCoins( + sdkCtx, + types.ModuleName, + sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), expectedAmt.Sub(balance.Amount))), + ) + } + return nil +} + func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) } func ci(denom string, amount sdkmath.Int) sdk.Coin { return sdk.NewCoin(denom, amount) } func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) } diff --git a/tests/integration/x/precisebank/test_view_integration.go b/tests/integration/x/precisebank/test_view_integration.go index 48c877ef2..3cb3a86f9 100644 --- a/tests/integration/x/precisebank/test_view_integration.go +++ b/tests/integration/x/precisebank/test_view_integration.go @@ -136,12 +136,16 @@ func (s *KeeperIntegrationTestSuite) TestKeeperHiddenReserve() { ), ) + // Adjust the module balance to be exactly 1 integer coin + err := AdjustModuleBalance(s.network.GetContext(), s.network.App, sdkmath.NewInt(1)) + s.Require().NoError(err) + // Check underlying x/bank balance for reserve reserveIntCoin := s.network.App.GetBankKeeper().GetBalance(s.network.GetContext(), moduleAddr, types.IntegerCoinDenom()) s.Require().Equal( - sdkmath.NewInt(2), // Network setup creates 1, test mints 1 more = 2 total + sdkmath.NewInt(1), reserveIntCoin.Amount, - "reserve should hold 2 integer coins (1 from network setup + 1 from test mint)", + "reserve should hold 1 integer coin", ) tests := []struct { @@ -160,7 +164,7 @@ func (s *KeeperIntegrationTestSuite) TestKeeperHiddenReserve() { "reserve account - visible integer denom", moduleAddr, types.IntegerCoinDenom(), - sdkmath.NewInt(2), // Network setup creates 1, test mints 1 more = 2 total + sdkmath.OneInt(), }, { "user account - visible extended denom",