Skip to content

Commit

Permalink
rename GasLeft to GasRemaining
Browse files Browse the repository at this point in the history
  • Loading branch information
likhita-809 committed Jul 9, 2021
1 parent 9876744 commit 1d1bf27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasLeft func to GasMeter.
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.
* [\#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`)
* (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt`
* (x/genutil) [\#9574](https://github.com/cosmos/cosmos-sdk/pull/9575) Actually use the `gentx` client tx flags (like `--keyring-dir`)
Expand Down
6 changes: 3 additions & 3 deletions store/types/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ErrorGasOverflow struct {
type GasMeter interface {
GasConsumed() Gas
GasConsumedToLimit() Gas
GasLeft() Gas
GasRemaining() Gas
Limit() Gas
ConsumeGas(amount Gas, descriptor string)
RefundGas(amount Gas, descriptor string)
Expand All @@ -67,7 +67,7 @@ func (g *basicGasMeter) GasConsumed() Gas {
return g.consumed
}

func (g *basicGasMeter) GasLeft() Gas {
func (g *basicGasMeter) GasRemaining() Gas {
if g.IsPastLimit() {
return 0
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (g *infiniteGasMeter) GasConsumedToLimit() Gas {
return g.consumed
}

func (g *infiniteGasMeter) GasLeft() Gas {
func (g *infiniteGasMeter) GasRemaining() Gas {
return math.MaxUint64
}

Expand Down
18 changes: 9 additions & 9 deletions store/types/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ func TestInfiniteGasMeter(t *testing.T) {
t.Parallel()
meter := NewInfiniteGasMeter()
require.Equal(t, uint64(math.MaxUint64), meter.Limit())
require.Equal(t, uint64(math.MaxUint64), meter.GasLeft())
require.Equal(t, uint64(math.MaxUint64), meter.GasRemaining())
require.Equal(t, uint64(0), meter.GasConsumed())
require.Equal(t, uint64(0), meter.GasConsumedToLimit())
meter.ConsumeGas(10, "consume 10")
require.Equal(t, uint64(math.MaxUint64), meter.GasLeft())
require.Equal(t, uint64(math.MaxUint64), meter.GasRemaining())
require.Equal(t, uint64(10), meter.GasConsumed())
require.Equal(t, uint64(10), meter.GasConsumedToLimit())
meter.RefundGas(1, "refund 1")
require.Equal(t, uint64(math.MaxUint64), meter.GasLeft())
require.Equal(t, uint64(math.MaxUint64), meter.GasRemaining())
require.Equal(t, uint64(9), meter.GasConsumed())
require.False(t, meter.IsPastLimit())
require.False(t, meter.IsOutOfGas())
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestGasMeter(t *testing.T) {
used += usage
require.NotPanics(t, func() { meter.ConsumeGas(usage, "") }, "Not exceeded limit but panicked. tc #%d, usage #%d", tcnum, unum)
require.Equal(t, used, meter.GasConsumed(), "Gas consumption not match. tc #%d, usage #%d", tcnum, unum)
require.Equal(t, tc.limit-used, meter.GasLeft(), "Gas left not match. tc #%d, usage #%d", tcnum, unum)
require.Equal(t, tc.limit-used, meter.GasRemaining(), "Gas left not match. tc #%d, usage #%d", tcnum, unum)
require.Equal(t, used, meter.GasConsumedToLimit(), "Gas consumption (to limit) not match. tc #%d, usage #%d", tcnum, unum)
require.False(t, meter.IsPastLimit(), "Not exceeded limit but got IsPastLimit() true")
if unum < len(tc.usage)-1 {
Expand All @@ -64,20 +64,20 @@ func TestGasMeter(t *testing.T) {
require.Panics(t, func() { meter.ConsumeGas(1, "") }, "Exceeded but not panicked. tc #%d", tcnum)
require.Equal(t, meter.GasConsumedToLimit(), meter.Limit(), "Gas consumption (to limit) not match limit")
require.Equal(t, meter.GasConsumed(), meter.Limit()+1, "Gas consumption not match limit+1")
require.Equal(t, uint64(0), meter.GasLeft())
require.Equal(t, uint64(0), meter.GasRemaining())

require.NotPanics(t, func() { meter.RefundGas(1, "refund 1") })
require.Equal(t, meter.GasConsumed(), meter.Limit(), "Gas consumption not match with limit")
require.Equal(t, uint64(0), meter.GasLeft())
require.Equal(t, uint64(0), meter.GasRemaining())
require.Panics(t, func() { meter.RefundGas(meter.GasConsumed()+1, "refund greater than consumed") })

require.NotPanics(t, func() { meter.RefundGas(meter.GasConsumed(), "refund consumed gas") })
require.Equal(t, meter.Limit(), meter.GasLeft())
require.Equal(t, meter.Limit(), meter.GasRemaining())

meter2 := NewGasMeter(math.MaxUint64)
require.Equal(t, uint64(math.MaxUint64), meter2.GasLeft())
require.Equal(t, uint64(math.MaxUint64), meter2.GasRemaining())
meter2.ConsumeGas(Gas(math.MaxUint64/2), "consume half max uint64")
require.Equal(t, Gas(math.MaxUint64-(math.MaxUint64/2)), meter2.GasLeft())
require.Equal(t, Gas(math.MaxUint64-(math.MaxUint64/2)), meter2.GasRemaining())
require.Panics(t, func() { meter2.ConsumeGas(Gas(math.MaxUint64/2)+2, "panic") })
}
}
Expand Down

0 comments on commit 1d1bf27

Please sign in to comment.