Skip to content

Commit

Permalink
Merge PR cosmos#3522: get rid of double negatives: IsNotNegative -> I…
Browse files Browse the repository at this point in the history
…sAnyNegative
  • Loading branch information
alessio authored and jackzampolin committed Feb 6, 2019
1 parent 17c84ab commit b63b625
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ test_sim_gaia_profile:
-SimulationEnabled=true -SimulationNumBlocks=$(SIM_NUM_BLOCKS) -SimulationBlockSize=$(SIM_BLOCK_SIZE) -SimulationCommit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out

test_cover:
@export VERSION=$(VERSION); bash tests/test_cover.sh
@export VERSION=$(VERSION); bash -x tests/test_cover.sh

test_lint:
gometalinter --config=tools/gometalinter.json ./...
Expand Down
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

0 comments on commit b63b625

Please sign in to comment.