Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: get rid of double negatives: IsNotNegative -> IsAnyNegative #3522

Merged
merged 3 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BREAKING CHANGES
* [\#3514](https://github.com/cosmos/cosmos-sdk/pull/3514) Various clean ups:
- Replace all GetKeyBase* functions family in favor of NewKeyBaseFromDir and NewKeyBaseFromHomeFlag.
- Remove Get prefix from all TxBuilder's getters.
* [\#3522](https://github.com/cosmos/cosmos-sdk/pull/3522) Get rid of double negatives: Coins.IsNotNegative() -> Coins.IsAnyNegative().

* Tendermint

Expand Down
2 changes: 1 addition & 1 deletion docs/_attic/sdk/core/examples/app1.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func handleFrom(store sdk.KVStore, from sdk.AccAddress, amt sdk.Coins) sdk.Resul
senderCoins := acc.Coins.Minus(amt)

// If any coin has negative amount, return insufficient coins error.
if !senderCoins.IsNotNegative() {
if senderCoins.IsAnyNegative() {
return sdk.ErrInsufficientCoins("Insufficient coins in account").Result()
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PKGS=$(go list ./... | grep -v /vendor/ | grep -v github.com/cosmos/cosmos-sdk/c

set -e
echo "mode: atomic" > coverage.txt
for pkg in ${PKGS[@]}; do
for pkg in ${PKGS}; do
go test -v -timeout 30m -race -coverprofile=profile.out -covermode=atomic "$pkg"
if [ -f profile.out ]; then
tail -n +2 profile.out >> coverage.txt;
Expand Down
18 changes: 9 additions & 9 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (coins Coins) Minus(coinsB Coins) Coins {
// negative coin amount was returned.
func (coins Coins) SafeMinus(coinsB Coins) (Coins, bool) {
diff := coins.safePlus(coinsB.negative())
return diff, !diff.IsNotNegative()
return diff, diff.IsAnyNegative()
}

// IsAllGT returns true if for every denom in coins, the denom is present at a
Expand All @@ -284,7 +284,7 @@ func (coins Coins) IsAllGTE(coinsB Coins) bool {
return true
}

return diff.IsNotNegative()
return !diff.IsAnyNegative()
}

// IsAllLT returns True iff for every denom in coins, the denom is present at
Expand Down Expand Up @@ -380,22 +380,22 @@ func (coins Coins) IsPositive() bool {
return true
}

// IsNotNegative returns true if there is no coin amount with a negative value
// (even no coins is true here).
//
// IsAnyNegative returns true if there is at least one coin whose amount
// is negative; returns false otherwise. It returns false if the coin set
// is empty too.
// TODO: Remove once unsigned integers are used.
func (coins Coins) IsNotNegative() bool {
func (coins Coins) IsAnyNegative() bool {
if len(coins) == 0 {
return true
return false
}

for _, coin := range coins {
if coin.IsNegative() {
return false
return true
}
}

return true
return false
}

// negative returns a set of coins with all amount negative.
Expand Down
2 changes: 1 addition & 1 deletion x/auth/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (tx StdTx) ValidateBasic() sdk.Error {
if tx.Fee.Gas > maxGasWanted {
return sdk.ErrGasOverflow(fmt.Sprintf("invalid gas supplied; %d > %d", tx.Fee.Gas, maxGasWanted))
}
if !tx.Fee.Amount.IsNotNegative() {
if tx.Fee.Amount.IsAnyNegative() {
return sdk.ErrInsufficientFee(fmt.Sprintf("invalid fee %s amount provided", tx.Fee.Amount))
}
if len(stdSigs) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func addCoins(ctx sdk.Context, am auth.AccountKeeper, addr sdk.AccAddress, amt s
oldCoins := getCoins(ctx, am, addr)
newCoins := oldCoins.Plus(amt)

if !newCoins.IsNotNegative() {
if newCoins.IsAnyNegative() {
return amt, nil, sdk.ErrInsufficientCoins(fmt.Sprintf("%s < %s", oldCoins, amt))
}

Expand Down
2 changes: 1 addition & 1 deletion x/bank/simulation/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NonnegativeBalanceInvariant(mapper auth.AccountKeeper) simulation.Invariant
accts := mock.GetAllAccounts(mapper, ctx)
for _, acc := range accts {
coins := acc.GetCoins()
if !coins.IsNotNegative() {
if coins.IsAnyNegative() {
return fmt.Errorf("%s has a negative denomination of %s",
acc.GetAddress().String(),
coins.String())
Expand Down
4 changes: 2 additions & 2 deletions x/gov/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
if !msg.InitialDeposit.IsValid() {
return sdk.ErrInvalidCoins(msg.InitialDeposit.String())
}
if !msg.InitialDeposit.IsNotNegative() {
if msg.InitialDeposit.IsAnyNegative() {
return sdk.ErrInvalidCoins(msg.InitialDeposit.String())
}
return nil
Expand Down Expand Up @@ -120,7 +120,7 @@ func (msg MsgDeposit) ValidateBasic() sdk.Error {
if !msg.Amount.IsValid() {
return sdk.ErrInvalidCoins(msg.Amount.String())
}
if !msg.Amount.IsNotNegative() {
if msg.Amount.IsAnyNegative() {
return sdk.ErrInvalidCoins(msg.Amount.String())
}
if msg.ProposalID < 0 {
Expand Down