diff --git a/CHANGELOG.md b/CHANGELOG.md index eb197ca3e7..ac099670a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features ### Improvements +* (types) [\#1314](https://github.com/Finschia/finschia-sdk/pull/1314) replace IsEqual with Equal ### Bug Fixes * (x/auth) [#1281](https://github.com/Finschia/finschia-sdk/pull/1281) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. (backport #1274) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index fa656570f0..947322b64a 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -371,7 +371,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) { // CheckBalance checks the balance of an account. func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.Coins) { ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) - require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr))) + require.True(t, balances.Equal(app.BankKeeper.GetAllBalances(ctxCheck, addr))) } // SignCheckDeliver checks a generated signed transaction and simulates a diff --git a/types/coin.go b/types/coin.go index 01358f414b..0e46a38fa0 100644 --- a/types/coin.go +++ b/types/coin.go @@ -82,12 +82,9 @@ func (coin Coin) IsLT(other Coin) bool { } // IsEqual returns true if the two sets of Coins have the same value +// Deprecated: Use Coin.Equal instead. func (coin Coin) IsEqual(other Coin) bool { - if coin.Denom != other.Denom { - panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) - } - - return coin.Amount.Equal(other.Amount) + return coin.Equal(other) } // Add adds amounts of two coins with same denom. If the coins differ in denom then @@ -399,7 +396,7 @@ func (coins Coins) SafeSub(coinsB Coins) (Coins, bool) { // a.IsAllLTE(a.Max(b)) // b.IsAllLTE(a.Max(b)) // a.IsAllLTE(c) && b.IsAllLTE(c) == a.Max(b).IsAllLTE(c) -// a.Add(b...).IsEqual(a.Min(b).Add(a.Max(b)...)) +// a.Add(b...).Equal(a.Min(b).Add(a.Max(b)...)) // // E.g. // {1A, 3B, 2C}.Max({4A, 2B, 2C} == {4A, 3B, 2C}) @@ -445,7 +442,7 @@ func (coins Coins) Max(coinsB Coins) Coins { // a.Min(b).IsAllLTE(a) // a.Min(b).IsAllLTE(b) // c.IsAllLTE(a) && c.IsAllLTE(b) == c.IsAllLTE(a.Min(b)) -// a.Add(b...).IsEqual(a.Min(b).Add(a.Max(b)...)) +// a.Add(b...).Equal(a.Min(b).Add(a.Max(b)...)) // // E.g. // {1A, 3B, 2C}.Min({4A, 2B, 2C} == {1A, 2B, 2C}) @@ -588,8 +585,8 @@ func (coins Coins) IsZero() bool { return true } -// IsEqual returns true if the two sets of Coins have the same value -func (coins Coins) IsEqual(coinsB Coins) bool { +// Equal returns true if the two sets of Coins have the same value +func (coins Coins) Equal(coinsB Coins) bool { if len(coins) != len(coinsB) { return false } @@ -598,7 +595,7 @@ func (coins Coins) IsEqual(coinsB Coins) bool { coinsB = coinsB.Sort() for i := 0; i < len(coins); i++ { - if !coins[i].IsEqual(coinsB[i]) { + if !coins[i].Equal(coinsB[i]) { return false } } diff --git a/types/coin_test.go b/types/coin_test.go index 8f48e89fec..d5203ad67e 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -56,21 +56,15 @@ func (s *coinTestSuite) TestIsEqualCoin() { inputOne sdk.Coin inputTwo sdk.Coin expected bool - panics bool }{ - {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 1), true, false}, - {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom2, 1), false, true}, - {sdk.NewInt64Coin("stake", 1), sdk.NewInt64Coin("stake", 10), false, false}, + {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 1), true}, + {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom2, 1), false}, + {sdk.NewInt64Coin("stake", 1), sdk.NewInt64Coin("stake", 10), false}, } for tcIndex, tc := range cases { - tc := tc - if tc.panics { - s.Require().Panics(func() { tc.inputOne.IsEqual(tc.inputTwo) }) - } else { - res := tc.inputOne.IsEqual(tc.inputTwo) - s.Require().Equal(tc.expected, res, "coin equality relation is incorrect, tc #%d", tcIndex) - } + res := tc.inputOne.IsEqual(tc.inputTwo) + s.Require().Equal(tc.expected, res, "coin equality relation is incorrect, tc #%d", tcIndex) } } @@ -405,25 +399,19 @@ func (s *coinTestSuite) TestEqualCoins() { inputOne sdk.Coins inputTwo sdk.Coins expected bool - panics bool }{ - {sdk.Coins{}, sdk.Coins{}, true, false}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, true, false}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true, false}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom2, 0)}, false, true}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 1)}, false, false}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, false, false}, - {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true, false}, + {sdk.Coins{}, sdk.Coins{}, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom2, 0)}, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 1)}, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true}, } for tcnum, tc := range cases { - tc := tc - if tc.panics { - s.Require().Panics(func() { tc.inputOne.IsEqual(tc.inputTwo) }) - } else { - res := tc.inputOne.IsEqual(tc.inputTwo) - s.Require().Equal(tc.expected, res, "Equality is differed from exported. tc #%d, expected %b, actual %b.", tcnum, tc.expected, res) - } + res := tc.inputOne.Equal(tc.inputTwo) + s.Require().Equal(tc.expected, res, "Equality is differed from exported. tc #%d, expected %b, actual %b.", tcnum, tc.expected, res) } } @@ -684,8 +672,8 @@ func (s *coinTestSuite) TestMinMax() { for _, tc := range cases { min := tc.input1.Min(tc.input2) max := tc.input1.Max(tc.input2) - s.Require().True(min.IsEqual(tc.min), tc.name) - s.Require().True(max.IsEqual(tc.max), tc.name) + s.Require().True(min.Equal(tc.min), tc.name) + s.Require().True(max.Equal(tc.max), tc.name) } } @@ -961,7 +949,7 @@ func (s *coinTestSuite) TestNewCoins() { continue } got := sdk.NewCoins(tt.coins...) - s.Require().True(got.IsEqual(tt.want)) + s.Require().True(got.Equal(tt.want)) } } diff --git a/types/dec_coin.go b/types/dec_coin.go index 68fe3b9f95..68aaf6e366 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -79,12 +79,9 @@ func (coin DecCoin) IsLT(other DecCoin) bool { } // IsEqual returns true if the two sets of Coins have the same value. +// Deprecated: Use DecCoin.Equal instead. func (coin DecCoin) IsEqual(other DecCoin) bool { - if coin.Denom != other.Denom { - panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) - } - - return coin.Amount.Equal(other.Amount) + return coin.Equal(other) } // Add adds amounts of two decimal coins with same denom. @@ -476,8 +473,8 @@ func (coins DecCoins) AmountOf(denom string) Dec { } } -// IsEqual returns true if the two sets of DecCoins have the same value. -func (coins DecCoins) IsEqual(coinsB DecCoins) bool { +// Equal returns true if the two sets of DecCoins have the same value. +func (coins DecCoins) Equal(coinsB DecCoins) bool { if len(coins) != len(coinsB) { return false } @@ -486,7 +483,7 @@ func (coins DecCoins) IsEqual(coinsB DecCoins) bool { coinsB = coinsB.Sort() for i := 0; i < len(coins); i++ { - if !coins[i].IsEqual(coinsB[i]) { + if !coins[i].Equal(coinsB[i]) { return false } } diff --git a/types/dec_coin_test.go b/types/dec_coin_test.go index 9017bda27c..1e39d27544 100644 --- a/types/dec_coin_test.go +++ b/types/dec_coin_test.go @@ -445,7 +445,7 @@ func (s *decCoinTestSuite) TestDecCoinsIntersect() { s.Require().NoError(err, "unexpected parse error in %v", i) exr, err := sdk.ParseDecCoins(tc.expectedResult) s.Require().NoError(err, "unexpected parse error in %v", i) - s.Require().True(in1.Intersect(in2).IsEqual(exr), "in1.cap(in2) != exr in %v", i) + s.Require().True(in1.Intersect(in2).Equal(exr), "in1.cap(in2) != exr in %v", i) } } diff --git a/x/auth/legacy/v043/store_test.go b/x/auth/legacy/v043/store_test.go index cd5f73a5dc..097b0f9d59 100644 --- a/x/auth/legacy/v043/store_test.go +++ b/x/auth/legacy/v043/store_test.go @@ -595,8 +595,8 @@ func trackingCorrected(ctx sdk.Context, t *testing.T, ak authkeeper.AccountKeepe vDA, ok := baseAccount.(exported.VestingAccount) require.True(t, ok) - vestedOk := expDelVesting.IsEqual(vDA.GetDelegatedVesting()) - freeOk := expDelFree.IsEqual(vDA.GetDelegatedFree()) + vestedOk := expDelVesting.Equal(vDA.GetDelegatedVesting()) + freeOk := expDelFree.Equal(vDA.GetDelegatedFree()) require.True(t, vestedOk, vDA.GetDelegatedVesting().String()) require.True(t, freeOk, vDA.GetDelegatedFree().String()) } diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index d3e385cab6..9571568ba2 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -419,7 +419,7 @@ func (pva PeriodicVestingAccount) Validate() error { if endTime != pva.EndTime { return errors.New("vesting end time does not match length of all vesting periods") } - if !originalVesting.IsEqual(pva.OriginalVesting) { + if !originalVesting.Equal(pva.OriginalVesting) { return errors.New("original vesting coins does not match the sum of all coins in vesting periods") } diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index a9c0abbdf9..0327d2cf9a 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -209,7 +209,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { // schedule dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) lockedCoins := dva.LockedCoins(now) - require.True(t, lockedCoins.IsEqual(origCoins)) + require.True(t, lockedCoins.Equal(origCoins)) // require that all coins are spendable after the maturation of the vesting // schedule @@ -218,14 +218,14 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { // require that all coins are still vesting after some time lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour)) - require.True(t, lockedCoins.IsEqual(origCoins)) + require.True(t, lockedCoins.Equal(origCoins)) // delegate some locked coins // require that locked is reduced delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50)) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount) lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour)) - require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount))) + require.True(t, lockedCoins.Equal(origCoins.Sub(delegatedAmount))) } func TestTrackDelegationDelVestingAcc(t *testing.T) { @@ -573,18 +573,18 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) { // schedule plva := types.NewPermanentLockedAccount(bacc, origCoins) lockedCoins := plva.LockedCoins(now) - require.True(t, lockedCoins.IsEqual(origCoins)) + require.True(t, lockedCoins.Equal(origCoins)) // require that all coins are still locked at end time lockedCoins = plva.LockedCoins(endTime) - require.True(t, lockedCoins.IsEqual(origCoins)) + require.True(t, lockedCoins.Equal(origCoins)) // delegate some locked coins // require that locked is reduced delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50)) plva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount) lockedCoins = plva.LockedCoins(now.Add(12 * time.Hour)) - require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount))) + require.True(t, lockedCoins.Equal(origCoins.Sub(delegatedAmount))) } func TestTrackDelegationPermLockedVestingAcc(t *testing.T) { diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index e957112c12..fe680e04ee 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -25,7 +25,7 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { totalSupply = totalSupply.Add(balance.Coins...) } - if !genState.Supply.Empty() && !genState.Supply.IsEqual(totalSupply) { + if !genState.Supply.Empty() && !genState.Supply.Equal(totalSupply) { panic(fmt.Errorf("genesis supply is incorrect, expected %v, got %v", genState.Supply, totalSupply)) } diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 6eb107a569..6d18ddd11c 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -41,7 +41,7 @@ func (suite *IntegrationTestSuite) TestQueryBalance() { res, err = queryClient.Balance(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.True(res.Balance.IsEqual(newFooCoin(50))) + suite.True(res.Balance.Equal(newFooCoin(50))) } func (suite *IntegrationTestSuite) TestQueryAllBalances() { diff --git a/x/bank/keeper/invariants.go b/x/bank/keeper/invariants.go index 361ba8b4c1..2191104db4 100644 --- a/x/bank/keeper/invariants.go +++ b/x/bank/keeper/invariants.go @@ -62,7 +62,7 @@ func TotalSupply(k Keeper) sdk.Invariant { return false }) - broken := !expectedTotal.IsEqual(supply) + broken := !expectedTotal.Equal(supply) return sdk.FormatInvariant(types.ModuleName, "total supply", fmt.Sprintf( diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index a47865d061..cde8f83df6 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -48,7 +48,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().NoError(legacyAmino.UnmarshalJSON(res, &balance)) - suite.True(balance.IsEqual(newFooCoin(50))) + suite.True(balance.Equal(newFooCoin(50))) } func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { @@ -84,7 +84,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { suite.Require().NoError(err) suite.Require().NotNil(res) suite.Require().NoError(legacyAmino.UnmarshalJSON(res, &balances)) - suite.True(balances.IsEqual(origCoins)) + suite.True(balances.Equal(origCoins)) } func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { diff --git a/x/bank/types/genesis.go b/x/bank/types/genesis.go index 2ee0f7612f..a343af7144 100644 --- a/x/bank/types/genesis.go +++ b/x/bank/types/genesis.go @@ -53,7 +53,7 @@ func (gs GenesisState) Validate() error { return err } - if !gs.Supply.IsEqual(totalSupply) { + if !gs.Supply.Equal(totalSupply) { return fmt.Errorf("genesis supply is incorrect, expected %v, got %v", gs.Supply, totalSupply) } } diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index ec4f4f07c4..7b1848e357 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -185,7 +185,7 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) error { } // make sure inputs and outputs match - if !totalIn.IsEqual(totalOut) { + if !totalIn.Equal(totalOut) { return ErrInputOutputMismatch } diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 191e037282..aac2b18625 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -150,7 +150,7 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.Vali // defensive edge case may happen on the very final digits // of the decCoins due to operation order of the distribution mechanism. rewards := rewardsRaw.Intersect(outstanding) - if !rewards.IsEqual(rewardsRaw) { + if !rewards.Equal(rewardsRaw) { logger := k.Logger(ctx) logger.Info( "rounding error withdrawing rewards from validator", diff --git a/x/distribution/keeper/genesis.go b/x/distribution/keeper/genesis.go index 66ddb0add6..1349f28e97 100644 --- a/x/distribution/keeper/genesis.go +++ b/x/distribution/keeper/genesis.go @@ -90,7 +90,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { if balances.IsZero() { k.authKeeper.SetModuleAccount(ctx, moduleAcc) } - if !balances.IsEqual(moduleHoldingsInt) { + if !balances.Equal(moduleHoldingsInt) { panic(fmt.Sprintf("distribution module balance does not match the module holdings: %s <-> %s", balances, moduleHoldingsInt)) } } diff --git a/x/distribution/keeper/invariants.go b/x/distribution/keeper/invariants.go index c3b9c3a2e2..ee638c3f27 100644 --- a/x/distribution/keeper/invariants.go +++ b/x/distribution/keeper/invariants.go @@ -147,7 +147,7 @@ func ModuleAccountInvariant(k Keeper) sdk.Invariant { macc := k.GetDistributionAccount(ctx) balances := k.bankKeeper.GetAllBalances(ctx, macc.GetAddress()) - broken := !balances.IsEqual(expectedInt) + broken := !balances.Equal(expectedInt) return sdk.FormatInvariant( types.ModuleName, "ModuleAccount coins", fmt.Sprintf("\texpected ModuleAccount coins: %s\n"+ diff --git a/x/foundation/keeper/internal/invariants.go b/x/foundation/keeper/internal/invariants.go index 3c6c19b9ef..f831b269ec 100644 --- a/x/foundation/keeper/internal/invariants.go +++ b/x/foundation/keeper/internal/invariants.go @@ -33,7 +33,7 @@ func ModuleAccountInvariant(k Keeper) sdk.Invariant { treasury := k.GetTreasury(ctx) msg := fmt.Sprintf("coins in the treasury; expected %s, got %s\n", treasury, balance) - broken := !treasury.IsEqual(sdk.NewDecCoinsFromCoins(balance...)) + broken := !treasury.Equal(sdk.NewDecCoinsFromCoins(balance...)) return sdk.FormatInvariant(foundation.ModuleName, moduleAccountInvariant, msg), broken } diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 870b939268..6073dcb403 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -306,7 +306,7 @@ func TestProposalPassedEndblocker(t *testing.T) { moduleAccCoins := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...) - require.True(t, moduleAccCoins.IsEqual(deposits)) + require.True(t, moduleAccCoins.Equal(deposits)) err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.NewNonSplitVoteOption(types.OptionYes)) require.NoError(t, err) @@ -319,7 +319,7 @@ func TestProposalPassedEndblocker(t *testing.T) { macc = app.GovKeeper.GetGovernanceAccount(ctx) require.NotNil(t, macc) - require.True(t, app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).IsEqual(initialModuleAccCoins)) + require.True(t, app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).Equal(initialModuleAccCoins)) } func TestEndBlockerProposalHandlerFailed(t *testing.T) { diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 4b9e7974be..a4333a7fb3 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -48,7 +48,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k } // check if total deposits equals balance, if it doesn't panic because there were export/import errors - if !balance.IsEqual(totalDeposits) { + if !balance.Equal(totalDeposits) { panic(fmt.Sprintf("expected module account was %s but we got %s", balance.String(), totalDeposits.String())) } } diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 3c27bb4913..a92a19bdb6 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -28,7 +28,7 @@ func TestDeposits(t *testing.T) { addr0Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]) addr1Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]) - require.True(t, proposal.TotalDeposit.IsEqual(sdk.NewCoins())) + require.True(t, proposal.TotalDeposit.Equal(sdk.NewCoins())) // Check no deposits at beginning deposit, found := app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) diff --git a/x/gov/keeper/invariants.go b/x/gov/keeper/invariants.go index 0325887873..3270c5e35e 100644 --- a/x/gov/keeper/invariants.go +++ b/x/gov/keeper/invariants.go @@ -34,7 +34,7 @@ func ModuleAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant { macc := keeper.GetGovernanceAccount(ctx) balances := bk.GetAllBalances(ctx, macc.GetAddress()) - broken := !balances.IsEqual(expectedDeposits) + broken := !balances.Equal(expectedDeposits) return sdk.FormatInvariant(types.ModuleName, "deposits", fmt.Sprintf("\tgov ModuleAccount coins: %s\n\tsum of deposit amounts: %s\n", diff --git a/x/gov/types/params.go b/x/gov/types/params.go index c433fa8f63..1f4111f8da 100644 --- a/x/gov/types/params.go +++ b/x/gov/types/params.go @@ -63,7 +63,7 @@ func (dp DepositParams) String() string { // Equal checks equality of DepositParams func (dp DepositParams) Equal(dp2 DepositParams) bool { - return dp.MinDeposit.IsEqual(dp2.MinDeposit) && dp.MaxDepositPeriod == dp2.MaxDepositPeriod + return dp.MinDeposit.Equal(dp2.MinDeposit) && dp.MaxDepositPeriod == dp2.MaxDepositPeriod } func validateDepositParams(i interface{}) error { diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go index b5849379dc..bb32d58a63 100644 --- a/x/mint/types/minter_test.go +++ b/x/mint/types/minter_test.go @@ -80,7 +80,7 @@ func TestBlockProvision(t *testing.T) { expProvisions := sdk.NewCoin(params.MintDenom, sdk.NewInt(tc.expProvisions)) - require.True(t, expProvisions.IsEqual(provisions), + require.True(t, expProvisions.Equal(provisions), "test: %v\n\tExp: %v\n\tGot: %v\n", i, tc.expProvisions, provisions) } diff --git a/x/staking/genesis.go b/x/staking/genesis.go index 75a93c8452..269b38336c 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -110,7 +110,7 @@ func InitGenesis( accountKeeper.SetModuleAccount(ctx, bondedPool) } // if balance is different from bonded coins panic because genesis is most likely malformed - if !bondedBalance.IsEqual(bondedCoins) { + if !bondedBalance.Equal(bondedCoins) { panic(fmt.Sprintf("bonded pool balance is different from bonded coins: %s <-> %s", bondedBalance, bondedCoins)) } notBondedPool := keeper.GetNotBondedPool(ctx) @@ -123,7 +123,7 @@ func InitGenesis( accountKeeper.SetModuleAccount(ctx, notBondedPool) } // if balance is different from non bonded coins panic because genesis is most likely malformed - if !notBondedBalance.IsEqual(notBondedCoins) { + if !notBondedBalance.Equal(notBondedCoins) { panic(fmt.Sprintf("not bonded pool balance is different from not bonded coins: %s <-> %s", notBondedBalance, notBondedCoins)) } // don't need to run Tendermint updates if we exported diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 5af927f3f2..9929819d6b 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -47,7 +47,7 @@ func TestMsgDecode(t *testing.T) { require.NoError(t, err) msg2, ok := msgUnmarshaled.(*types.MsgCreateValidator) require.True(t, ok) - require.True(t, msg.Value.IsEqual(msg2.Value)) + require.True(t, msg.Value.Equal(msg2.Value)) require.True(t, msg.Pubkey.Equal(msg2.Pubkey)) }