Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/integration/x/erc20/test_dynamic_precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *KeeperTestSuite) TestRegisterERC20CodeHash() {
s.Require().Equal(nonce, acc.Nonce)
if tc.vesting {
totalBalance = s.network.App.GetBankKeeper().GetBalance(ctx, account.Bytes(), s.network.GetBaseDenom()).Amount
s.Require().Equal(totalBalance.BigInt(), common.U2560.Add(balance, balance).ToBig())
s.Require().Equal(totalBalance.BigInt(), uint256.NewInt(0).Add(balance, balance).ToBig())
}
} else {
s.Require().Equal(common.U2560, acc.Balance)
Expand All @@ -128,7 +128,7 @@ func (s *KeeperTestSuite) TestRegisterERC20CodeHash() {
s.Require().Equal(nonce, acc.Nonce)
if tc.vesting {
totalBalance = s.network.App.GetBankKeeper().GetBalance(ctx, account.Bytes(), s.network.GetBaseDenom()).Amount
s.Require().Equal(totalBalance.BigInt(), common.U2560.Add(balance, balance).ToBig())
s.Require().Equal(totalBalance.BigInt(), uint256.NewInt(0).Add(balance, balance).ToBig())
}
} else {
s.Require().Equal(common.U2560, acc.Balance)
Expand Down
75 changes: 39 additions & 36 deletions tests/integration/x/precisebank/test_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -93,9 +70,13 @@ func (s *GenesisTestSuite) TestInitGenesis() {
{
"valid - module balance matches non-zero amount",
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))
// Mint the expected amount of 2 integer coins to back the fractional balances
err := s.network.App.GetBankKeeper().MintCoins(
s.network.GetContext(),
types.ModuleName,
sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), sdkmath.NewInt(2))),
)
s.Require().NoError(err)
},
types.NewGenesisState(
types.FractionalBalances{
Expand Down Expand Up @@ -123,9 +104,17 @@ func (s *GenesisTestSuite) TestInitGenesis() {
{
"invalid - module balance insufficient",
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())
// Ensure module account has 0 balance
moduleAddr := s.network.App.GetAccountKeeper().GetModuleAddress(types.ModuleName)
existingBalance := s.network.App.GetBankKeeper().GetBalance(s.network.GetContext(), moduleAddr, types.IntegerCoinDenom())
if existingBalance.IsPositive() {
err := s.network.App.GetBankKeeper().BurnCoins(
s.network.GetContext(),
types.ModuleName,
sdk.NewCoins(existingBalance),
)
s.Require().NoError(err)
}
},
types.NewGenesisState(
types.FractionalBalances{
Expand All @@ -141,9 +130,13 @@ func (s *GenesisTestSuite) TestInitGenesis() {
{
"invalid - module balance excessive",
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))
// Mint 100 integer coins (excessive for expected 2)
err := s.network.App.GetBankKeeper().MintCoins(
s.network.GetContext(),
types.ModuleName,
sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), sdkmath.NewInt(100))),
)
s.Require().NoError(err)
},
types.NewGenesisState(
types.FractionalBalances{
Expand Down Expand Up @@ -242,8 +235,13 @@ 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))
// Mint the expected amount to back the fractional balances
err := s.network.App.GetBankKeeper().MintCoins(
s.network.GetContext(),
types.ModuleName,
sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), sdkmath.NewInt(1))),
)
s.Require().NoError(err)

return types.NewGenesisState(
types.FractionalBalances{
Expand All @@ -257,8 +255,13 @@ 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))
// Mint the expected amount to back the fractional balances
err := s.network.App.GetBankKeeper().MintCoins(
s.network.GetContext(),
types.ModuleName,
sdk.NewCoins(sdk.NewCoin(types.IntegerCoinDenom(), sdkmath.NewInt(1))),
)
s.Require().NoError(err)

return types.NewGenesisState(
types.FractionalBalances{
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/x/precisebank/test_view_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func (s *KeeperIntegrationTestSuite) TestKeeperHiddenReserve() {
// 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 from test mint",
)

tests := []struct {
Expand All @@ -160,7 +160,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.NewInt(1), // 1 integer coin from test mint
},
{
"user account - visible extended denom",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/x/vm/test_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (s *KeeperTestSuite) TestSetBalance() {
},
false,
func() *uint256.Int {
return common.U2560.Add(totalBalance, amount)
return uint256.NewInt(0).Add(totalBalance, amount)
},
},
{
Expand Down
Loading