Skip to content

Commit

Permalink
hygiene: rename method IsEqual to Equal
Browse files Browse the repository at this point in the history
Rename method IsEqual of the type Coins to Equal to follow standardize terminology for 'Equal; function on structs

Refs: #3246
  • Loading branch information
EmilGeorgiev committed Jan 23, 2023
1 parent 3a3362b commit 5066965
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/integration/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ func Test100PercentCommissionReward(t *testing.T) {
require.NoError(t, err)

zeroRewards := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.ZeroInt())}
require.True(t, rewards.IsEqual(zeroRewards))
require.True(t, rewards.Equal(zeroRewards))

events := ctx.EventManager().Events()
lastEvent := events[len(events)-1]
Expand Down
8 changes: 4 additions & 4 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (coins Coins) SafeQuoInt(x Int) (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})
Expand Down Expand Up @@ -509,7 +509,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})
Expand Down Expand Up @@ -652,8 +652,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
}
Expand Down
10 changes: 5 additions & 5 deletions types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (s *coinTestSuite) TestEqualCoins() {
}

for tcnum, tc := range cases {
res := tc.inputOne.IsEqual(tc.inputTwo)
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)
}
}
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestCoinsAddCoalescesDuplicateDenominations(t *testing.T) {
{"den", sdk.NewInt(11)},
}

if !got.IsEqual(want) {
if !got.Equal(want) {
t.Fatalf("Wrong result\n\tGot: %s\n\tWant: %s", got, want)
}
}
Expand Down Expand Up @@ -865,8 +865,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)
}
}

Expand Down Expand Up @@ -1168,7 +1168,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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/auth/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ func trackingCorrected(ctx sdk.Context, t *testing.T, ak keeper.AccountKeeper, a
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())
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (w *wrapper) AddAuxSignerData(data tx.AuxSignerData) error {
}
}
if w.tx.AuthInfo.Tip != nil && data.SignDoc.Tip != nil {
if !w.tx.AuthInfo.Tip.Amount.IsEqual(data.SignDoc.Tip.Amount) {
if !w.tx.AuthInfo.Tip.Amount.Equal(data.SignDoc.Tip.Amount) {
return sdkerrors.ErrInvalidRequest.Wrapf("TxBuilder has tip %+v, got %+v in AuxSignerData", w.tx.AuthInfo.Tip.Amount, data.SignDoc.Tip.Amount)
}
if w.tx.AuthInfo.Tip.Tipper != data.SignDoc.Tip.Tipper {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/vesting/types/vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,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")
}

Expand Down
12 changes: 6 additions & 6 deletions x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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
Expand All @@ -257,14 +257,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) {
Expand Down Expand Up @@ -612,18 +612,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) {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s
// CheckBalance checks the balance of an account.
func checkBalance(t *testing.T, baseApp *baseapp.BaseApp, addr sdk.AccAddress, balances sdk.Coins, keeper bankkeeper.Keeper) {
ctxCheck := baseApp.NewContext(true, tmproto.Header{})
require.True(t, balances.IsEqual(keeper.GetAllBalances(ctxCheck, addr)))
require.True(t, balances.Equal(keeper.GetAllBalances(ctxCheck, addr)))
}

func TestSendNotEnoughBalance(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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))
}

Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) error {
}

// make sure inputs and outputs match
if !totalIn.IsEqual(totalOut) {
if !totalIn.Equal(totalOut) {
return ErrInputOutputMismatch
}

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func Test100PercentCommissionReward(t *testing.T) {
require.NoError(t, err)

zeroRewards := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, math.ZeroInt())}
require.True(t, rewards.IsEqual(zeroRewards))
require.True(t, rewards.Equal(zeroRewards))

events := ctx.EventManager().Events()
lastEvent := events[len(events)-1]
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down
4 changes: 2 additions & 2 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestProposalPassedEndblocker(t *testing.T) {
moduleAccCoins := suite.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 = suite.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")
require.NoError(t, err)
Expand All @@ -327,7 +327,7 @@ func TestProposalPassedEndblocker(t *testing.T) {

macc = suite.GovKeeper.GetGovernanceAccount(ctx)
require.NotNil(t, macc)
require.True(t, suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).IsEqual(initialModuleAccCoins))
require.True(t, suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).Equal(initialModuleAccCoins))
}

func TestEndBlockerProposalHandlerFailed(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDeposits(t *testing.T) {
addr0Initial := bankKeeper.GetAllBalances(ctx, TestAddrs[0])
addr1Initial := bankKeeper.GetAllBalances(ctx, TestAddrs[1])

require.True(t, sdk.NewCoins(proposal.TotalDeposit...).IsEqual(sdk.NewCoins()))
require.True(t, sdk.NewCoins(proposal.TotalDeposit...).Equal(sdk.NewCoins()))

// Check no deposits at beginning
_, found := govKeeper.GetDeposit(ctx, proposalID, TestAddrs[1])
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/v1beta1/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DefaultDepositParams() DepositParams {

// 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
}

// NewTallyParams creates a new TallyParams object
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSlashingMsgs(t *testing.T) {
baseApp := app.BaseApp

ctxCheck := baseApp.NewContext(true, tmproto.Header{})
require.True(t, sdk.Coins{genCoin}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
require.True(t, sdk.Coins{genCoin}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))

require.NoError(t, err)

Expand All @@ -80,7 +80,7 @@ func TestSlashingMsgs(t *testing.T) {
txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig
_, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1)
require.NoError(t, err)
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))

header = tmproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down
12 changes: 6 additions & 6 deletions x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestStakingMsgs(t *testing.T) {
require.NoError(t, err)
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})

require.True(t, sdk.Coins{genCoin}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
require.True(t, sdk.Coins{genCoin}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr2)))
require.True(t, sdk.Coins{genCoin}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))
require.True(t, sdk.Coins{genCoin}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr2)))

// create validator
description := types.NewDescription("foo_moniker", "", "", "", "")
Expand All @@ -71,7 +71,7 @@ func TestStakingMsgs(t *testing.T) {
txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1)
require.NoError(t, err)
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))

header = tmproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -99,15 +99,15 @@ func TestStakingMsgs(t *testing.T) {
require.Equal(t, description, validator.Description)

// delegate
require.True(t, sdk.Coins{genCoin}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr2)))
require.True(t, sdk.Coins{genCoin}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr2)))
delegateMsg := types.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin)

header = tmproto.Header{Height: app.LastBlockHeight() + 1}
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2)
require.NoError(t, err)

ctxCheck = app.BaseApp.NewContext(true, tmproto.Header{})
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr2)))
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr2)))
_, found = stakingKeeper.GetDelegation(ctxCheck, addr2, sdk.ValAddress(addr1))
require.True(t, found)

Expand All @@ -123,5 +123,5 @@ func TestStakingMsgs(t *testing.T) {
require.False(t, found)

// balance should be the same because bonding not yet complete
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr2)))
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr2)))
}
4 changes: 2 additions & 2 deletions x/staking/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []ab
}

// 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))
}

Expand All @@ -133,7 +133,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []ab

// 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))
}

Expand Down

0 comments on commit 5066965

Please sign in to comment.