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

refactor!: Coins Add and Sub Consistency #11689

Merged
merged 6 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (types) [\#11689](https://github.com/cosmos/cosmos-sdk/pull/11689) Make `Coins#Sub` and `Coins#SafeSub` consistent with `Coins#Add`.
* (store)[\#11152](https://github.com/cosmos/cosmos-sdk/pull/11152) Remove `keep-every` from pruning options.
* [\#10950](https://github.com/cosmos/cosmos-sdk/pull/10950) Add `envPrefix` parameter to `cmd.Execute`.
* (x/mint) [\#10441](https://github.com/cosmos/cosmos-sdk/pull/10441) The `NewAppModule` function now accepts an inflation calculation function as an argument.
Expand Down
8 changes: 4 additions & 4 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ func (coins Coins) DenomsSubsetOf(coinsB Coins) bool {
//
// CONTRACT: Sub will never return Coins where one Coin has a non-positive
// amount. In otherwords, IsValid will always return true.
func (coins Coins) Sub(coinsB Coins) Coins {
diff, hasNeg := coins.SafeSub(coinsB)
func (coins Coins) Sub(coinsB ...Coin) Coins {
diff, hasNeg := coins.SafeSub(coinsB...)
if hasNeg {
panic("negative coin amount")
}
Expand All @@ -405,8 +405,8 @@ func (coins Coins) Sub(coinsB Coins) Coins {
// SafeSub performs the same arithmetic as Sub but returns a boolean if any
// negative coin amount was returned.
// The function panics if `coins` or `coinsB` are not sorted (ascending).
func (coins Coins) SafeSub(coinsB Coins) (Coins, bool) {
diff := coins.safeAdd(coinsB.negative())
func (coins Coins) SafeSub(coinsB ...Coin) (Coins, bool) {
diff := coins.safeAdd(NewCoins(coinsB...).negative())
return diff, diff.IsAnyNegative()
}

Expand Down
4 changes: 2 additions & 2 deletions types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ func (s *coinTestSuite) TestSubCoins() {
for i, tc := range testCases {
tc := tc
if tc.shouldPanic {
assert.Panics(func() { tc.inputOne.Sub(tc.inputTwo) })
assert.Panics(func() { tc.inputOne.Sub(tc.inputTwo...) })
} else {
res := tc.inputOne.Sub(tc.inputTwo)
res := tc.inputOne.Sub(tc.inputTwo...)
assert.True(res.IsValid())
assert.Equal(tc.expected, res, "sum of coins is incorrect, tc #%d", i)
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {

err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
diff, _ := balRes.Balances.SafeSub(intialCoins)
diff, _ := balRes.Balances.SafeSub(intialCoins...)
s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))

// Generate multisig transaction.
Expand Down
4 changes: 2 additions & 2 deletions x/auth/middleware/tips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (s *MWTestSuite) TestTips() {
s.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: ctx.BlockHeight()}})

// Make sure tip is correctly transferred to feepayer, and fee is paid.
expTipperRegens := initialRegens.Sub(tc.tip)
expTipperRegens := initialRegens.Sub(tc.tip...)
expFeePayerRegens := initialRegens.Add(tc.tip...)
expFeePayerAtoms := initialAtoms.Sub(tc.fee)
expFeePayerAtoms := initialAtoms.Sub(tc.fee...)
s.Require().True(expTipperRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, tipper.acc.GetAddress(), "regen").Amount))
s.Require().True(expFeePayerRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "regen").Amount))
s.Require().True(expFeePayerAtoms.AmountOf("atom").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "atom").Amount))
Expand Down
12 changes: 6 additions & 6 deletions x/auth/vesting/types/vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewBaseVestingAccount(baseAccount *authtypes.BaseAccount, originalVesting s
//
// CONTRACT: Delegated vesting coins and vestingCoins must be sorted.
func (bva BaseVestingAccount) LockedCoinsFromVesting(vestingCoins sdk.Coins) sdk.Coins {
lockedCoins := vestingCoins.Sub(vestingCoins.Min(bva.DelegatedVesting))
lockedCoins := vestingCoins.Sub(vestingCoins.Min(bva.DelegatedVesting)...)
if lockedCoins == nil {
return sdk.Coins{}
}
Expand Down Expand Up @@ -111,12 +111,12 @@ func (bva *BaseVestingAccount) TrackUndelegation(amount sdk.Coins) {

if !x.IsZero() {
xCoin := sdk.NewCoin(coin.Denom, x)
bva.DelegatedFree = bva.DelegatedFree.Sub(sdk.Coins{xCoin})
bva.DelegatedFree = bva.DelegatedFree.Sub(xCoin)
}

if !y.IsZero() {
yCoin := sdk.NewCoin(coin.Denom, y)
bva.DelegatedVesting = bva.DelegatedVesting.Sub(sdk.Coins{yCoin})
bva.DelegatedVesting = bva.DelegatedVesting.Sub(yCoin)
}
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func (cva ContinuousVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coin
// GetVestingCoins returns the total number of vesting coins. If no coins are
// vesting, nil is returned.
func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime))
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime)...)
}

// LockedCoins returns the set of coins that are not spendable (i.e. locked),
Expand Down Expand Up @@ -374,7 +374,7 @@ func (pva PeriodicVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins
// GetVestingCoins returns the total number of vesting coins. If no coins are
// vesting, nil is returned.
func (pva PeriodicVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
return pva.OriginalVesting.Sub(pva.GetVestedCoins(blockTime))
return pva.OriginalVesting.Sub(pva.GetVestedCoins(blockTime)...)
}

// LockedCoins returns the set of coins that are not spendable (i.e. locked),
Expand Down Expand Up @@ -485,7 +485,7 @@ func (dva DelayedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins {
// GetVestingCoins returns the total number of vesting coins for a delayed
// vesting account.
func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime))
return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime)...)
}

// LockedCoins returns the set of coins that are not spendable (i.e. locked),
Expand Down
4 changes: 2 additions & 2 deletions x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
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.IsEqual(origCoins.Sub(delegatedAmount...)))
}

func TestTrackDelegationDelVestingAcc(t *testing.T) {
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) {
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.IsEqual(origCoins.Sub(delegatedAmount...)))
}

func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (s *TestSuite) TestDispatchAction() {
require.Len(authzs, 1)
authorization := authzs[0].(*banktypes.SendAuthorization)
require.NotNil(authorization)
require.Equal(authorization.SpendLimit, coins100.Sub(coins10))
require.Equal(authorization.SpendLimit, coins100.Sub(coins10...))
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion x/authz/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err
}

spendLimit := spendableCoins.Sub(fees)
spendLimit := spendableCoins.Sub(fees...)
if spendLimit == nil {
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, "spend limit is nil"), nil, nil
}
Expand Down
26 changes: 13 additions & 13 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() {
supplyAfterBurn, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
suite.Require().NoError(err)
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, authtypes.Burner).String())
suite.Require().Equal(supplyAfterInflation.Sub(initCoins), supplyAfterBurn)
suite.Require().Equal(supplyAfterInflation.Sub(initCoins...), supplyAfterBurn)

// test same functionality on module account with multiple permissions
suite.
Expand All @@ -304,7 +304,7 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() {
suite.Require().NoError(err)
suite.Require().NoError(err)
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName()).String())
suite.Require().Equal(supplyAfterInflation.Sub(initCoins), supplyAfterBurn)
suite.Require().Equal(supplyAfterInflation.Sub(initCoins...), supplyAfterBurn)
}

func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
Expand All @@ -331,7 +331,7 @@ func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
acc2Balances := app.BankKeeper.GetAllBalances(ctx, addr2)
acc1Balances = app.BankKeeper.GetAllBalances(ctx, addr1)
suite.Require().Equal(sendAmt, acc2Balances)
updatedAcc1Bal := balances.Sub(sendAmt)
updatedAcc1Bal := balances.Sub(sendAmt...)
suite.Require().Len(acc1Balances, len(updatedAcc1Bal))
suite.Require().Equal(acc1Balances, updatedAcc1Bal)
suite.Require().NotNil(app.AccountKeeper.GetAccount(ctx, addr2))
Expand Down Expand Up @@ -713,7 +713,7 @@ func (suite *IntegrationTestSuite) TestSpendableCoins() {

ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.SpendableCoins(ctx, addr1))
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.SpendableCoins(ctx, addr1))
}

func (suite *IntegrationTestSuite) TestVestingAccountSend() {
Expand Down Expand Up @@ -806,10 +806,10 @@ func (suite *IntegrationTestSuite) TestVestingAccountReceive() {
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.ContinuousVestingAccount)
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)), sendCoins)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)...), sendCoins)

// require coins are spendable plus any that have vested
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))), origCoins)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))...), origCoins)
}

func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() {
Expand Down Expand Up @@ -845,10 +845,10 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() {
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.PeriodicVestingAccount)
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)), sendCoins)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)...), sendCoins)

// require coins are spendable plus any that have vested
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))), origCoins)
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))...), origCoins)
}

func (suite *IntegrationTestSuite) TestDelegateCoins() {
Expand Down Expand Up @@ -879,7 +879,7 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() {

// require the ability for a non-vesting account to delegate
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr2))
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr2))
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))

// require the ability for a vesting account to delegate
Expand Down Expand Up @@ -945,7 +945,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {
err := app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins)
suite.Require().NoError(err)

suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr2))
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr2))
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))

// require the ability for a non-vesting account to undelegate
Expand All @@ -957,7 +957,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {
// require the ability for a vesting account to delegate
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr1, addrModule, delCoins))

suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr1))
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr1))
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))

// require the ability for a vesting account to undelegate
Expand Down Expand Up @@ -1095,7 +1095,7 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
case types.EventTypeCoinBurn:
burnedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
suite.Require().NoError(err)
supply = supply.Sub(burnedCoins)
supply = supply.Sub(burnedCoins...)

case types.EventTypeCoinMint:
mintedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
Expand All @@ -1107,7 +1107,7 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
suite.Require().NoError(err)
spender, err := sdk.AccAddressFromBech32((string)(e.Attributes[0].Value))
suite.Require().NoError(err)
balances[spender.String()] = balances[spender.String()].Sub(coinsSpent)
balances[spender.String()] = balances[spender.String()].Sub(coinsSpent...)

case types.EventTypeCoinReceived:
coinsRecv, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, a
locked := sdk.NewCoin(coin.Denom, lockedCoins.AmountOf(coin.Denom))
spendable := balance.Sub(locked)

_, hasNeg := sdk.Coins{spendable}.SafeSub(sdk.Coins{coin})
_, hasNeg := sdk.Coins{spendable}.SafeSub(coin)
if hasNeg {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
}
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (k BaseViewKeeper) spendableCoins(ctx sdk.Context, addr sdk.AccAddress) (sp
total = k.GetAllBalances(ctx, addr)
locked := k.LockedCoins(ctx, addr)

spendable, hasNeg := total.SafeSub(locked)
spendable, hasNeg := total.SafeSub(locked...)
if hasNeg {
spendable = sdk.NewCoins()
return
Expand Down
8 changes: 4 additions & 4 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func sendMsgSend(
account := ak.GetAccount(ctx, from)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

coins, hasNeg := spendable.SafeSub(msg.Amount)
coins, hasNeg := spendable.SafeSub(msg.Amount...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
if err != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope
// take random subset of remaining coins for output
// and update remaining coins
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
totalSentCoins = totalSentCoins.Sub(outCoins)
totalSentCoins = totalSentCoins.Sub(outCoins...)
}

outputs[o] = types.NewOutput(outAddr.Address, outCoins)
Expand Down Expand Up @@ -286,7 +286,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe
// take random subset of remaining coins for output
// and update remaining coins
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
totalSentCoins = totalSentCoins.Sub(outCoins)
totalSentCoins = totalSentCoins.Sub(outCoins...)
}

outputs[i] = types.NewOutput(moduleAccounts[i].Address, outCoins)
Expand Down Expand Up @@ -351,7 +351,7 @@ func sendMsgMultiSend(
feePayer := ak.GetAccount(ctx, addr)
spendable := bk.SpendableCoins(ctx, feePayer.GetAddress())

coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins)
coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/send_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (a SendAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRes
if !ok {
return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
}
limitLeft, isNegative := a.SpendLimit.SafeSub(mSend.Amount)
limitLeft, isNegative := a.SpendLimit.SafeSub(mSend.Amount...)
if isNegative {
return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit")
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k
err error
)

coins, hasNeg := spendable.SafeSub(fundAmount)
coins, hasNeg := spendable.SafeSub(fundAmount...)
if !hasNeg {
fees, err = simtypes.RandomFees(r, ctx, coins)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/feegrant/basic_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *BasicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bo
}

if a.SpendLimit != nil {
left, invalid := a.SpendLimit.SafeSub(fee)
left, invalid := a.SpendLimit.SafeSub(fee...)
if invalid {
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "basic allowance")
}
Expand Down
6 changes: 3 additions & 3 deletions x/feegrant/periodic_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (a *PeriodicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg)

// deduct from both the current period and the max amount
var isNeg bool
a.PeriodCanSpend, isNeg = a.PeriodCanSpend.SafeSub(fee)
a.PeriodCanSpend, isNeg = a.PeriodCanSpend.SafeSub(fee...)
if isNeg {
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "period limit")
}

if a.Basic.SpendLimit != nil {
a.Basic.SpendLimit, isNeg = a.Basic.SpendLimit.SafeSub(fee)
a.Basic.SpendLimit, isNeg = a.Basic.SpendLimit.SafeSub(fee...)
if isNeg {
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "absolute limit")
}
Expand All @@ -59,7 +59,7 @@ func (a *PeriodicAllowance) tryResetPeriod(blockTime time.Time) {
}

// set PeriodCanSpend to the lesser of Basic.SpendLimit and PeriodSpendLimit
if _, isNeg := a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit); isNeg && !a.Basic.SpendLimit.Empty() {
if _, isNeg := a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit...); isNeg && !a.Basic.SpendLimit.Empty() {
a.PeriodCanSpend = a.Basic.SpendLimit
} else {
a.PeriodCanSpend = a.PeriodSpendLimit
Expand Down
4 changes: 2 additions & 2 deletions x/feegrant/periodic_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
blockTime: oneHour,
accept: true,
remove: false,
remainsPeriod: smallAtom.Sub(oneAtom),
remains: smallAtom.Sub(oneAtom),
remainsPeriod: smallAtom.Sub(oneAtom...),
remains: smallAtom.Sub(oneAtom...),
periodReset: oneHour.Add(tenMinutes), // one step from last reset, not now
},
"period reset no spend limit": {
Expand Down
Loading