From a4d7ccfc842dac9ef24fd12780019ecbd28bf154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:41:34 +0200 Subject: [PATCH] add mock module acc balance and refactor test case (#1942) * add mock module acc balance and refactor test case * add changelog entry (cherry picked from commit f0f7ce4fbe069adff6607538f54ac38d2dca44d5) # Conflicts: # CHANGELOG.md # modules/apps/29-fee/keeper/msg_server_test.go --- CHANGELOG.md | 5 +++++ modules/apps/29-fee/keeper/escrow_test.go | 2 +- modules/apps/29-fee/keeper/msg_server_test.go | 11 ++++++++++- testing/chain.go | 11 +++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a57e96b33e..098b3f3f0a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +<<<<<<< HEAD +======= +* (testing) [\#1942](https://github.com/cosmos/ibc-go/pull/1942) Add a balance for the mock module account upon testing package initialization. +* (linting) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) Fix linting errors, resulting compatiblity with go1.18 linting style, golangci-lint 1.46.2 and the revivie linter. This caused breaking changes in core/04-channel, core/ante, and the testing library. +>>>>>>> f0f7ce4 (add mock module acc balance and refactor test case (#1942)) * (app/20-transfer) [\#1680](https://github.com/cosmos/ibc-go/pull/1680) Adds migration to correct any malformed trace path information of tokens with denoms that contains slashes. The transfer module consensus version has been bumped to 2. * (app/20-transfer) [\#1730](https://github.com/cosmos/ibc-go/pull/1730) parse the ics20 denomination provided via a packet using the channel identifier format specified by ibc-go. * (cleanup) [\#1335](https://github.com/cosmos/ibc-go/pull/1335/) `gofumpt -w -l .` to standardize the code layout more strictly than `go fmt ./...` diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index b1891e4e4e4..6b0a9f9be4a 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -76,7 +76,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { }, func() { // check if the refund acc has been refunded the timeoutFee - expectedRefundAccBal := defaultTimeoutFee[0].Add(defaultTimeoutFee[0]) + expectedRefundAccBal := refundAccBal.Add(defaultTimeoutFee[0]).Add(defaultTimeoutFee[0]) balance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) suite.Require().Equal(expectedRefundAccBal, balance) }, diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 73c7caadc9c..c0c25506487 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -2,12 +2,21 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" +<<<<<<< HEAD disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v4/testing" +======= + + "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v5/testing" + ibcmock "github.com/cosmos/ibc-go/v5/testing/mock" +>>>>>>> f0f7ce4 (add mock module acc balance and refactor test case (#1942)) ) func (suite *KeeperTestSuite) TestRegisterPayee() { @@ -187,7 +196,7 @@ func (suite *KeeperTestSuite) TestPayPacketFee() { { "refund account is module account", func() { - msg.Signer = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(disttypes.ModuleName).String() + msg.Signer = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(ibcmock.ModuleName).String() expPacketFee := types.NewPacketFee(fee, msg.Signer, nil) expFeesInEscrow = []types.PacketFee{expPacketFee} }, diff --git a/testing/chain.go b/testing/chain.go index 82972ce1831..7233776a192 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -103,6 +103,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va amount, ok := sdk.NewIntFromString("10000000000000000000") require.True(t, ok) + // add sender account balance := banktypes.Balance{ Address: acc.GetAddress().String(), Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), @@ -119,6 +120,12 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va senderAccs = append(senderAccs, senderAcc) } + // add mock module account balance + genBals = append(genBals, banktypes.Balance{ + Address: authtypes.NewModuleAddress(mock.ModuleName).String(), + Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000000))}, + }) + app := SetupWithGenesisValSet(t, valSet, genAccs, chainID, sdk.DefaultPowerReduction, genBals...) // create current header and call begin block @@ -148,6 +155,10 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va SenderAccounts: senderAccs, } + // creates mock module account + mockModuleAcc := chain.GetSimApp().AccountKeeper.GetModuleAccount(chain.GetContext(), mock.ModuleName) + require.NotNil(t, mockModuleAcc) + coord.CommitBlock(chain) return chain