diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1dffdac..c55fba215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/types/coin.go b/types/coin.go index ffffa5a66..cee605356 100644 --- a/types/coin.go +++ b/types/coin.go @@ -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") } @@ -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() } diff --git a/types/coin_test.go b/types/coin_test.go index 4ede386e3..64a39c813 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -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) } diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 4bf61146b..40aa258dd 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -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. diff --git a/x/auth/middleware/tips_test.go b/x/auth/middleware/tips_test.go index 769aa0c41..7fb50f7e0 100644 --- a/x/auth/middleware/tips_test.go +++ b/x/auth/middleware/tips_test.go @@ -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)) diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index 1b21e882f..7316e6afd 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -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{} } @@ -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) } } } @@ -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), @@ -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), @@ -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), diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 6d85b8e75..db2d52141 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -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) { @@ -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) { diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index de57acf71..223e3ad32 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -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...)) }, }, { diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index ef5db52fd..d62f698ae 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -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 } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 3c181d65d..7c3feb4c1 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -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. @@ -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() { @@ -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)) @@ -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() { @@ -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() { @@ -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() { @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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)) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index fb68fc9c4..109b33bc0 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -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) } diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index c6feb7278..cf66c1962 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -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 diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 05d14a737..96b0d3d2a 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -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 { @@ -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) @@ -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) @@ -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 { diff --git a/x/bank/types/send_authorization.go b/x/bank/types/send_authorization.go index 08a7b641f..a8a785594 100644 --- a/x/bank/types/send_authorization.go +++ b/x/bank/types/send_authorization.go @@ -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") } diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index f82e92129..9c1976cc2 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -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 { diff --git a/x/feegrant/basic_fee.go b/x/feegrant/basic_fee.go index 703b509b3..81419b6d5 100644 --- a/x/feegrant/basic_fee.go +++ b/x/feegrant/basic_fee.go @@ -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") } diff --git a/x/feegrant/periodic_fee.go b/x/feegrant/periodic_fee.go index 43229247f..0e496ce5a 100644 --- a/x/feegrant/periodic_fee.go +++ b/x/feegrant/periodic_fee.go @@ -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") } @@ -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 diff --git a/x/feegrant/periodic_fee_test.go b/x/feegrant/periodic_fee_test.go index b6a8d39bd..439ef19a0 100644 --- a/x/feegrant/periodic_fee_test.go +++ b/x/feegrant/periodic_fee_test.go @@ -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": { diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 9183f16de..8d0a1986a 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -47,7 +47,7 @@ func TestDeposits(t *testing.T) { proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake, sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) // Check a second deposit from same address votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fiveStake) @@ -60,7 +60,7 @@ func TestDeposits(t *testing.T) { proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr0Initial.Sub(fourStake).Sub(fiveStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...).Sub(fiveStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) // Check third deposit from a new address votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[1], fourStake) @@ -73,7 +73,7 @@ func TestDeposits(t *testing.T) { proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr1Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])) + require.Equal(t, addr1Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])) // Check that proposal moved to voting period proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) @@ -109,5 +109,5 @@ func TestDeposits(t *testing.T) { app.GovKeeper.DeleteAndBurnDeposits(ctx, proposalID) deposits = app.GovKeeper.GetDeposits(ctx, proposalID) require.Len(t, deposits, 0) - require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index e619dfabc..08637c8f6 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -161,7 +161,7 @@ func SimulateMsgSubmitProposal( spendable := bk.SpendableCoins(ctx, account.GetAddress()) var fees sdk.Coins - coins, hasNeg := spendable.SafeSub(deposit) + coins, hasNeg := spendable.SafeSub(deposit...) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { @@ -248,7 +248,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke spendable := bk.SpendableCoins(ctx, account.GetAddress()) var fees sdk.Coins - coins, hasNeg := spendable.SafeSub(deposit) + coins, hasNeg := spendable.SafeSub(deposit...) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { diff --git a/x/nft/simulation/operations.go b/x/nft/simulation/operations.go index d430c3c12..57cf714a1 100644 --- a/x/nft/simulation/operations.go +++ b/x/nft/simulation/operations.go @@ -81,7 +81,7 @@ func SimulateMsgSend( return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, err.Error()), nil, err } - spendLimit := spendableCoins.Sub(fees) + spendLimit := spendableCoins.Sub(fees...) if spendLimit == nil { return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, "spend limit is nil"), nil, nil } diff --git a/x/simulation/util.go b/x/simulation/util.go index 498c056eb..f32e1bdf6 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -85,7 +85,7 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [ var fees sdk.Coins var err error - coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg) + coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg...) if hasNeg { return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err } diff --git a/x/staking/keeper/slash_test.go b/x/staking/keeper/slash_test.go index 8b987d0e8..014173d9d 100644 --- a/x/staking/keeper/slash_test.go +++ b/x/staking/keeper/slash_test.go @@ -112,7 +112,7 @@ func TestSlashUnbondingDelegation(t *testing.T) { // balance decreased require.Equal(t, sdk.NewInt(5), ubd.Entries[0].Balance) newUnbondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) - diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances) + diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances...) require.True(t, diffTokens.AmountOf(app.StakingKeeper.BondDenom(ctx)).Equal(sdk.NewInt(5))) } @@ -180,7 +180,7 @@ func TestSlashRedelegation(t *testing.T) { // pool bonded tokens should decrease burnedCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), slashAmount)) - require.Equal(t, balances.Sub(burnedCoins), app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())) + require.Equal(t, balances.Sub(burnedCoins...), app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())) } // tests Slash at a future height (must panic) @@ -220,7 +220,7 @@ func TestSlashAtNegativeHeight(t *testing.T) { // pool bonded shares decreased newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String()) } @@ -251,7 +251,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) { // pool bonded shares decreased newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String()) } @@ -290,7 +290,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) { // bonded tokens burned newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 3), diffTokens) // read updated validator @@ -316,7 +316,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) { // bonded tokens burned again newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 6), diffTokens) // read updated validator @@ -342,7 +342,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) { // bonded tokens burned again newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 9), diffTokens) // read updated validator @@ -368,7 +368,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) { // just 1 bonded token burned again since that's all the validator now has newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) - diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx)) + diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx)) require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 10), diffTokens) // apply TM updates diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 1a702b150..257588d76 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -135,7 +135,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k var fees sdk.Coins - coins, hasNeg := spendable.SafeSub(sdk.Coins{selfDelegation}) + coins, hasNeg := spendable.SafeSub(selfDelegation) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { @@ -277,7 +277,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K var fees sdk.Coins - coins, hasNeg := spendable.SafeSub(sdk.Coins{bondAmt}) + coins, hasNeg := spendable.SafeSub(bondAmt) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil {