Skip to content

Commit

Permalink
add mock module acc balance and refactor test case (backport cosmos#1942
Browse files Browse the repository at this point in the history
) (cosmos#1952)

* add mock module acc balance and refactor test case (cosmos#1942)

* add mock module acc balance and refactor test case

* add changelog entry

(cherry picked from commit f0f7ce4)

* fix conflict

* fix conflict

Co-authored-by: colin axnér <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
3 people authored and ulbqb committed Jul 31, 2023
1 parent 4802796 commit 8c1283d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (testing) [\#1942](https://github.com/cosmos/ibc-go/pull/1942) Add a balance for the mock module account upon testing package initialization.
* (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 ./...`
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package keeper_test

import (
sdk "github.com/Finschia/finschia-sdk/types"
disttypes "github.com/Finschia/finschia-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"
ibcmock "github.com/cosmos/ibc-go/v4/testing/mock"
)

func (suite *KeeperTestSuite) TestRegisterPayee() {
Expand Down Expand Up @@ -187,7 +187,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}
},
Expand Down
11 changes: 11 additions & 0 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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)),
Expand All @@ -120,6 +121,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
Expand Down Expand Up @@ -149,6 +156,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
Expand Down

0 comments on commit 8c1283d

Please sign in to comment.