diff --git a/CHANGELOG.md b/CHANGELOG.md index be6b7cec3274..84aaaa61e0c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ logic has been implemented for v0.38 target version. Applications can migrate vi ### API Breaking Changes +* (types) [\#5430](https://github.com/cosmos/cosmos-sdk/pull/5430) `DecCoins#Add` parameter changed from `DecCoins` + to `...DecCoin`, `Coins#Add` parameter changed from `Coins` to `...Coin` * (baseapp/types) [\#5421](https://github.com/cosmos/cosmos-sdk/pull/5421) The `Error` interface (`types/errors.go`) has been removed in favor of the concrete type defined in `types/errors/` which implements the standard `error` interface. As a result, the `Handler` and `Querier` implementations now return a standard `error`. diff --git a/simapp/export.go b/simapp/export.go index ea384ba22500..01b1424032cf 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -91,7 +91,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str // donate any unwithdrawn outstanding reward fraction tokens to the community pool scraps := app.DistrKeeper.GetValidatorOutstandingRewards(ctx, val.GetOperator()) feePool := app.DistrKeeper.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(scraps) + feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) app.DistrKeeper.SetFeePool(ctx, feePool) app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) diff --git a/simapp/genesis_account_test.go b/simapp/genesis_account_test.go index db5c7fce2f3a..6c0c6d6775c5 100644 --- a/simapp/genesis_account_test.go +++ b/simapp/genesis_account_test.go @@ -82,7 +82,7 @@ func TestSimGenesisAccountValidate(t *testing.T) { "valid basic account with invalid original vesting coins", simapp.SimGenesisAccount{ BaseAccount: baseAcc, - OriginalVesting: coins.Add(coins), + OriginalVesting: coins.Add(coins...), StartTime: vestingStart.Unix(), EndTime: vestingStart.Add(1 * time.Hour).Unix(), }, diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index f06af61948d8..5192e59feab0 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -88,7 +88,7 @@ func AddTestAddrs(app *SimApp, ctx sdk.Context, accNum int, accAmt sdk.Int) []sd initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt)) totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(len(testAddrs))))) prevSupply := app.SupplyKeeper.GetSupply(ctx) - app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply))) + app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...))) // fill all the addresses with some coins, set the loose pool tokens simultaneously for _, addr := range testAddrs { diff --git a/types/coin.go b/types/coin.go index 94b9dc901c77..98eaa6b806df 100644 --- a/types/coin.go +++ b/types/coin.go @@ -244,7 +244,7 @@ func (coins Coins) IsValid() bool { // // CONTRACT: Add will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins Coins) Add(coinsB Coins) Coins { +func (coins Coins) Add(coinsB ...Coin) Coins { return coins.safeAdd(coinsB) } @@ -506,6 +506,11 @@ func (coins Coins) AmountOf(denom string) Int { } } +// GetDenomByIndex returns the Denom of the certain coin to make the findDup generic +func (coins Coins) GetDenomByIndex(i int) string { + return coins[i].Denom +} + // IsAllPositive returns true if there is at least one coin and all currencies // have a positive value. func (coins Coins) IsAllPositive() bool { @@ -669,18 +674,23 @@ func ParseCoins(coinsStr string) (Coins, error) { return coins, nil } +type findDupDescriptor interface { + GetDenomByIndex(int) string + Len() int +} + // findDup works on the assumption that coins is sorted -func findDup(coins Coins) int { - if len(coins) <= 1 { +func findDup(coins findDupDescriptor) int { + if coins.Len() <= 1 { return -1 } - prevDenom := coins[0].Denom - for i := 1; i < len(coins); i++ { - if coins[i].Denom == prevDenom { + prevDenom := coins.GetDenomByIndex(0) + for i := 1; i < coins.Len(); i++ { + if coins.GetDenomByIndex(i) == prevDenom { return i } - prevDenom = coins[i].Denom + prevDenom = coins.GetDenomByIndex(i) } return -1 diff --git a/types/coin_benchmark_test.go b/types/coin_benchmark_test.go index 93a3fc8914b8..34e93d6229e4 100644 --- a/types/coin_benchmark_test.go +++ b/types/coin_benchmark_test.go @@ -21,7 +21,7 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - coinsA.Add(coinsB) + coinsA.Add(coinsB...) } } } @@ -50,7 +50,7 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - coinsA.Add(coinsB) + coinsA.Add(coinsB...) } } } diff --git a/types/coin_test.go b/types/coin_test.go index f18ff036500a..a090deb01518 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -251,7 +251,7 @@ func TestAddCoins(t *testing.T) { } for tcIndex, tc := range cases { - res := tc.inputOne.Add(tc.inputTwo) + res := tc.inputOne.Add(tc.inputTwo...) assert.True(t, res.IsValid()) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", tcIndex) } diff --git a/types/dec_coin.go b/types/dec_coin.go index e26a88f8755e..9b6e700104e7 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -157,9 +157,32 @@ func (coin DecCoin) IsValid() bool { // DecCoins defines a slice of coins with decimal values type DecCoins []DecCoin -// NewDecCoins constructs a new coin set with decimal values +// NewDecCoins constructs a new coin set with with decimal values +// from DecCoins. +func NewDecCoins(decCoins ...DecCoin) DecCoins { + // remove zeroes + newDecCoins := removeZeroDecCoins(DecCoins(decCoins)) + if len(newDecCoins) == 0 { + return DecCoins{} + } + + newDecCoins.Sort() + + // detect duplicate Denoms + if dupIndex := findDup(newDecCoins); dupIndex != -1 { + panic(fmt.Errorf("find duplicate denom: %s", newDecCoins[dupIndex])) + } + + if !newDecCoins.IsValid() { + panic(fmt.Errorf("invalid coin set: %s", newDecCoins)) + } + + return newDecCoins +} + +// NewDecCoinsFromCoin constructs a new coin set with decimal values // from regular Coins. -func NewDecCoins(coins Coins) DecCoins { +func NewDecCoinsFromCoins(coins ...Coin) DecCoins { decCoins := make(DecCoins, len(coins)) newCoins := NewCoins(coins...) for i, coin := range newCoins { @@ -191,10 +214,10 @@ func (coins DecCoins) TruncateDecimal() (truncatedCoins Coins, changeCoins DecCo for _, coin := range coins { truncated, change := coin.TruncateDecimal() if !truncated.IsZero() { - truncatedCoins = truncatedCoins.Add(NewCoins(truncated)) + truncatedCoins = truncatedCoins.Add(truncated) } if !change.IsZero() { - changeCoins = changeCoins.Add(DecCoins{change}) + changeCoins = changeCoins.Add(change) } } @@ -208,7 +231,7 @@ func (coins DecCoins) TruncateDecimal() (truncatedCoins Coins, changeCoins DecCo // // CONTRACT: Add will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins DecCoins) Add(coinsB DecCoins) DecCoins { +func (coins DecCoins) Add(coinsB ...DecCoin) DecCoins { return coins.safeAdd(coinsB) } @@ -311,6 +334,11 @@ func (coins DecCoins) Intersect(coinsB DecCoins) DecCoins { return removeZeroDecCoins(res) } +// GetDenomByIndex returns the Denom to make the findDup generic +func (coins DecCoins) GetDenomByIndex(i int) string { + return coins[i].Denom +} + // IsAnyNegative returns true if there is at least one coin whose amount // is negative; returns false otherwise. It returns false if the DecCoins set // is empty too. @@ -338,7 +366,7 @@ func (coins DecCoins) MulDec(d Dec) DecCoins { } if !product.IsZero() { - res = res.Add(DecCoins{product}) + res = res.Add(product) } } @@ -359,7 +387,7 @@ func (coins DecCoins) MulDecTruncate(d Dec) DecCoins { } if !product.IsZero() { - res = res.Add(DecCoins{product}) + res = res.Add(product) } } @@ -382,7 +410,7 @@ func (coins DecCoins) QuoDec(d Dec) DecCoins { } if !quotient.IsZero() { - res = res.Add(DecCoins{quotient}) + res = res.Add(quotient) } } @@ -406,7 +434,7 @@ func (coins DecCoins) QuoDecTruncate(d Dec) DecCoins { } if !quotient.IsZero() { - res = res.Add(DecCoins{quotient}) + res = res.Add(quotient) } } diff --git a/types/dec_coin_test.go b/types/dec_coin_test.go index 65408a0b3ab3..2a20bd6469f4 100644 --- a/types/dec_coin_test.go +++ b/types/dec_coin_test.go @@ -91,7 +91,7 @@ func TestAddDecCoins(t *testing.T) { } for tcIndex, tc := range cases { - res := tc.inputOne.Add(tc.inputTwo) + res := tc.inputOne.Add(tc.inputTwo...) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", tcIndex) } } @@ -172,7 +172,7 @@ func TestSubDecCoins(t *testing.T) { msg string }{ { - NewDecCoins(Coins{NewCoin("mytoken", NewInt(10)), NewCoin("btc", NewInt(20)), NewCoin("eth", NewInt(30))}), + NewDecCoinsFromCoins(NewCoin("mytoken", NewInt(10)), NewCoin("btc", NewInt(20)), NewCoin("eth", NewInt(30))), true, "sorted coins should have passed", }, @@ -188,7 +188,7 @@ func TestSubDecCoins(t *testing.T) { }, } - decCoins := NewDecCoins(Coins{NewCoin("btc", NewInt(10)), NewCoin("eth", NewInt(15)), NewCoin("mytoken", NewInt(5))}) + decCoins := NewDecCoinsFromCoins(NewCoin("btc", NewInt(10)), NewCoin("eth", NewInt(15)), NewCoin("mytoken", NewInt(5))) for _, tc := range tests { tc := tc @@ -421,3 +421,75 @@ func TestDecCoinsQuoDecTruncate(t *testing.T) { } } } + +func TestNewDecCoinsWithIsValid(t *testing.T) { + fake1 := append(NewDecCoins(NewDecCoin("mytoken", NewInt(10))), DecCoin{Denom: "BTC", Amount: NewDec(10)}) + fake2 := append(NewDecCoins(NewDecCoin("mytoken", NewInt(10))), DecCoin{Denom: "BTC", Amount: NewDec(-10)}) + + tests := []struct { + coin DecCoins + expectPass bool + msg string + }{ + { + NewDecCoins(NewDecCoin("mytoken", NewInt(10))), + true, + "valid coins should have passed", + }, + { + fake1, + false, + "invalid denoms", + }, + { + fake2, + false, + "negative amount", + }, + } + + for _, tc := range tests { + tc := tc + if tc.expectPass { + require.True(t, tc.coin.IsValid(), tc.msg) + } else { + require.False(t, tc.coin.IsValid(), tc.msg) + } + } +} + +func TestDecCoins_AddDecCoinWithIsValid(t *testing.T) { + lengthTestDecCoins := NewDecCoins().Add(NewDecCoin("mytoken", NewInt(10))).Add(DecCoin{Denom: "BTC", Amount: NewDec(10)}) + require.Equal(t, 2, len(lengthTestDecCoins), "should be 2") + + tests := []struct { + coin DecCoins + expectPass bool + msg string + }{ + { + NewDecCoins().Add(NewDecCoin("mytoken", NewInt(10))), + true, + "valid coins should have passed", + }, + { + NewDecCoins().Add(NewDecCoin("mytoken", NewInt(10))).Add(DecCoin{Denom: "BTC", Amount: NewDec(10)}), + false, + "invalid denoms", + }, + { + NewDecCoins().Add(NewDecCoin("mytoken", NewInt(10))).Add(DecCoin{Denom: "BTC", Amount: NewDec(-10)}), + false, + "negative amount", + }, + } + + for _, tc := range tests { + tc := tc + if tc.expectPass { + require.True(t, tc.coin.IsValid(), tc.msg) + } else { + require.False(t, tc.coin.IsValid(), tc.msg) + } + } +} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index bc6042abbbb2..34cd11b934a6 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -203,7 +203,7 @@ func (fee StdFee) Bytes() []byte { // originally part of the submitted transaction because the fee is computed // as fee = ceil(gasWanted * gasPrices). func (fee StdFee) GasPrices() sdk.DecCoins { - return sdk.NewDecCoins(fee.Amount).QuoDec(sdk.NewDec(int64(fee.Gas))) + return sdk.NewDecCoinsFromCoins(fee.Amount...).QuoDec(sdk.NewDec(int64(fee.Gas))) } //__________________________________________________________ diff --git a/x/auth/vesting/types/genesis_test.go b/x/auth/vesting/types/genesis_test.go index 4c90e52a42fd..aee8d1fa091a 100644 --- a/x/auth/vesting/types/genesis_test.go +++ b/x/auth/vesting/types/genesis_test.go @@ -25,7 +25,7 @@ func TestValidateGenesisInvalidAccounts(t *testing.T) { baseVestingAcc, err := NewBaseVestingAccount(&acc1, acc1.Coins, 1548775410) require.NoError(t, err) // invalid delegated vesting - baseVestingAcc.DelegatedVesting = acc1.Coins.Add(acc1.Coins) + baseVestingAcc.DelegatedVesting = acc1.Coins.Add(acc1.Coins...) acc2 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) acc2.Coins = sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index da9343024f14..05dca2857e33 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -74,7 +74,7 @@ func (bva BaseVestingAccount) SpendableCoinsVestingAccount(vestingCoins sdk.Coin spendableCoin := sdk.NewCoin(coin.Denom, min) if !spendableCoin.IsZero() { - spendableCoins = spendableCoins.Add(sdk.Coins{spendableCoin}) + spendableCoins = spendableCoins.Add(spendableCoin) } } @@ -108,12 +108,12 @@ func (bva *BaseVestingAccount) TrackDelegation(vestingCoins, amount sdk.Coins) { if !x.IsZero() { xCoin := sdk.NewCoin(coin.Denom, x) - bva.DelegatedVesting = bva.DelegatedVesting.Add(sdk.Coins{xCoin}) + bva.DelegatedVesting = bva.DelegatedVesting.Add(xCoin) } if !y.IsZero() { yCoin := sdk.NewCoin(coin.Denom, y) - bva.DelegatedFree = bva.DelegatedFree.Add(sdk.Coins{yCoin}) + bva.DelegatedFree = bva.DelegatedFree.Add(yCoin) } } } @@ -543,7 +543,7 @@ func (pva PeriodicVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins if x < period.Length { break } - vestedCoins = vestedCoins.Add(period.Amount) + vestedCoins = vestedCoins.Add(period.Amount...) // Update the start time of the next period currentPeriodStartTime += period.Length } @@ -589,7 +589,7 @@ func (pva PeriodicVestingAccount) Validate() error { originalVesting := sdk.NewCoins() for _, p := range pva.VestingPeriods { endTime += p.Length - originalVesting = originalVesting.Add(p.Amount) + originalVesting = originalVesting.Add(p.Amount...) } if endTime != pva.EndTime { return errors.New("vesting end time does not match length of all vesting periods") diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 8c87cbb9af1e..651416338c06 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -96,7 +96,7 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { // receive some coins recvAmt := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)} - cva.SetCoins(cva.GetCoins().Add(recvAmt)) + cva.SetCoins(cva.GetCoins().Add(recvAmt...)) // require that all vested coins (50%) are spendable plus any received spendableCoins = cva.SpendableCoins(now.Add(12 * time.Hour)) @@ -268,7 +268,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { // receive some coins recvAmt := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)} - dva.SetCoins(dva.GetCoins().Add(recvAmt)) + dva.SetCoins(dva.GetCoins().Add(recvAmt...)) // require that only received coins are spendable since the account is still // vesting @@ -497,7 +497,7 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { // receive some coins recvAmt := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)} - pva.SetCoins(pva.GetCoins().Add(recvAmt)) + pva.SetCoins(pva.GetCoins().Add(recvAmt...)) // require that all vested coins (50%) are spendable plus any received spendableCoins = pva.SpendableCoins(now.Add(12 * time.Hour)) @@ -549,7 +549,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { // delegate 75% of coins, split between vested and vesting bacc.SetCoins(origCoins) pva = NewPeriodicVestingAccount(&bacc, now.Unix(), periods) - pva.TrackDelegation(now.Add(12*time.Hour), periods[0].Amount.Add(periods[1].Amount)) + pva.TrackDelegation(now.Add(12*time.Hour), periods[0].Amount.Add(periods[1].Amount...)) // require that the maximum possible amount of vesting coins are chosen for delegation. require.Equal(t, pva.DelegatedFree, periods[1].Amount) require.Equal(t, pva.DelegatedVesting, periods[0].Amount) diff --git a/x/bank/internal/keeper/keeper.go b/x/bank/internal/keeper/keeper.go index f36477f3c3b1..64e539c44ce2 100644 --- a/x/bank/internal/keeper/keeper.go +++ b/x/bank/internal/keeper/keeper.go @@ -280,7 +280,7 @@ func (keeper BaseSendKeeper) AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt } oldCoins := keeper.GetCoins(ctx, addr) - newCoins := oldCoins.Add(amt) + newCoins := oldCoins.Add(amt...) if newCoins.IsAnyNegative() { return amt, sdkerrors.Wrapf( @@ -387,5 +387,5 @@ func trackUndelegation(acc authexported.Account, amt sdk.Coins) error { vacc.TrackUndelegation(amt) } - return acc.SetCoins(acc.GetCoins().Add(amt)) + return acc.SetCoins(acc.GetCoins().Add(amt...)) } diff --git a/x/bank/internal/keeper/keeper_test.go b/x/bank/internal/keeper/keeper_test.go index f93ddaa52969..f028f054f840 100644 --- a/x/bank/internal/keeper/keeper_test.go +++ b/x/bank/internal/keeper/keeper_test.go @@ -240,7 +240,7 @@ func TestVestingAccountSend(t *testing.T) { require.Error(t, err) // receive some coins - vacc.SetCoins(origCoins.Add(sendCoins)) + vacc.SetCoins(origCoins.Add(sendCoins...)) app.AccountKeeper.SetAccount(ctx, vacc) // require that all vested coins are spendable plus any received @@ -275,7 +275,7 @@ func TestPeriodicVestingAccountSend(t *testing.T) { require.Error(t, err) // receive some coins - vacc.SetCoins(origCoins.Add(sendCoins)) + vacc.SetCoins(origCoins.Add(sendCoins...)) app.AccountKeeper.SetAccount(ctx, vacc) // require that all vested coins are spendable plus any received @@ -311,7 +311,7 @@ func TestVestingAccountReceive(t *testing.T) { // require the coins are spendable vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.ContinuousVestingAccount) - require.Equal(t, origCoins.Add(sendCoins), vacc.GetCoins()) + require.Equal(t, origCoins.Add(sendCoins...), vacc.GetCoins()) require.Equal(t, vacc.SpendableCoins(now), sendCoins) // require coins are spendable plus any that have vested @@ -347,7 +347,7 @@ func TestPeriodicVestingAccountReceive(t *testing.T) { // require the coins are spendable vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.PeriodicVestingAccount) - require.Equal(t, origCoins.Add(sendCoins), vacc.GetCoins()) + require.Equal(t, origCoins.Add(sendCoins...), vacc.GetCoins()) require.Equal(t, vacc.SpendableCoins(now), sendCoins) // require coins are spendable plus any that have vested diff --git a/x/bank/internal/types/msgs.go b/x/bank/internal/types/msgs.go index c8fdaa5afe92..50f8e3f06ff1 100644 --- a/x/bank/internal/types/msgs.go +++ b/x/bank/internal/types/msgs.go @@ -168,7 +168,7 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) error { return err } - totalIn = totalIn.Add(in.Coins) + totalIn = totalIn.Add(in.Coins...) } for _, out := range outputs { @@ -176,7 +176,7 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) error { return err } - totalOut = totalOut.Add(out.Coins) + totalOut = totalOut.Add(out.Coins...) } // make sure inputs and outputs match diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7cf08a8452f2..123e0b8eb45a 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -170,7 +170,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simulation.O // set next input and accumulate total sent coins inputs[i] = types.NewInput(simAccount.Address, coins) - totalSentCoins = totalSentCoins.Add(coins) + totalSentCoins = totalSentCoins.Add(coins...) } for o := range outputs { diff --git a/x/crisis/handler_test.go b/x/crisis/handler_test.go index 290b0c373cdb..912bd863f7c5 100644 --- a/x/crisis/handler_test.go +++ b/x/crisis/handler_test.go @@ -36,7 +36,7 @@ func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { app.CrisisKeeper.RegisterRoute(testModuleName, dummyRouteWhichFails.Route, dummyRouteWhichFails.Invar) feePool := distr.InitialFeePool() - feePool.CommunityPool = sdk.NewDecCoins(sdk.NewCoins(constantFee)) + feePool.CommunityPool = sdk.NewDecCoinsFromCoins(sdk.NewCoins(constantFee)...) app.DistrKeeper.SetFeePool(ctx, feePool) app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(sdk.Coins{})) diff --git a/x/distribution/genesis.go b/x/distribution/genesis.go index 3da1710fe6ec..c0fc05b9ea71 100644 --- a/x/distribution/genesis.go +++ b/x/distribution/genesis.go @@ -23,7 +23,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper keeper.SetPreviousProposerConsAddr(ctx, data.PreviousProposer) for _, rew := range data.OutstandingRewards { keeper.SetValidatorOutstandingRewards(ctx, rew.ValidatorAddress, rew.OutstandingRewards) - moduleHoldings = moduleHoldings.Add(rew.OutstandingRewards) + moduleHoldings = moduleHoldings.Add(rew.OutstandingRewards...) } for _, acc := range data.ValidatorAccumulatedCommissions { keeper.SetValidatorAccumulatedCommission(ctx, acc.ValidatorAddress, acc.Accumulated) @@ -41,7 +41,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper keeper.SetValidatorSlashEvent(ctx, evt.ValidatorAddress, evt.Height, evt.Period, evt.Event) } - moduleHoldings = moduleHoldings.Add(data.FeePool.CommunityPool) + moduleHoldings = moduleHoldings.Add(data.FeePool.CommunityPool...) moduleHoldingsInt, _ := moduleHoldings.TruncateDecimal() // check if the module account exists diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 43a659999a7c..b6a34a3d643b 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -23,7 +23,7 @@ func (k Keeper) AllocateTokens( // (and distributed to the previous proposer) feeCollector := k.supplyKeeper.GetModuleAccount(ctx, k.feeCollectorName) feesCollectedInt := feeCollector.GetCoins() - feesCollected := sdk.NewDecCoins(feesCollectedInt) + feesCollected := sdk.NewDecCoinsFromCoins(feesCollectedInt...) // transfer collected fees to the distribution module account err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, k.feeCollectorName, types.ModuleName, feesCollectedInt) @@ -35,7 +35,7 @@ func (k Keeper) AllocateTokens( // general discussions here: https://github.com/cosmos/cosmos-sdk/issues/2906#issuecomment-441867634 feePool := k.GetFeePool(ctx) if totalPreviousPower == 0 { - feePool.CommunityPool = feePool.CommunityPool.Add(feesCollected) + feePool.CommunityPool = feePool.CommunityPool.Add(feesCollected...) k.SetFeePool(ctx, feePool) return } @@ -95,7 +95,7 @@ func (k Keeper) AllocateTokens( } // allocate community funding - feePool.CommunityPool = feePool.CommunityPool.Add(remaining) + feePool.CommunityPool = feePool.CommunityPool.Add(remaining...) k.SetFeePool(ctx, feePool) } @@ -114,12 +114,12 @@ func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val exported.Validato ), ) currentCommission := k.GetValidatorAccumulatedCommission(ctx, val.GetOperator()) - currentCommission = currentCommission.Add(commission) + currentCommission = currentCommission.Add(commission...) k.SetValidatorAccumulatedCommission(ctx, val.GetOperator(), currentCommission) // update current rewards currentRewards := k.GetValidatorCurrentRewards(ctx, val.GetOperator()) - currentRewards.Rewards = currentRewards.Rewards.Add(shared) + currentRewards.Rewards = currentRewards.Rewards.Add(shared...) k.SetValidatorCurrentRewards(ctx, val.GetOperator(), currentRewards) // update outstanding rewards @@ -131,6 +131,6 @@ func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val exported.Validato ), ) outstanding := k.GetValidatorOutstandingRewards(ctx, val.GetOperator()) - outstanding = outstanding.Add(tokens) + outstanding = outstanding.Add(tokens...) k.SetValidatorOutstandingRewards(ctx, val.GetOperator(), outstanding) } diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 7b28b6048eaf..7d79a35b40b9 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -81,7 +81,7 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val exported.Validat func(height uint64, event types.ValidatorSlashEvent) (stop bool) { endingPeriod := event.ValidatorPeriod if endingPeriod > startingPeriod { - rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) + rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)...) // Note: It is necessary to truncate so we don't allow withdrawing // more rewards than owed. @@ -132,7 +132,7 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val exported.Validat } // calculate rewards for final period - rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) + rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)...) return rewards } @@ -173,7 +173,7 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val exported.Validato // transaction was successful k.SetValidatorOutstandingRewards(ctx, del.GetValidatorAddr(), outstanding.Sub(rewards)) feePool := k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(remainder) + feePool.CommunityPool = feePool.CommunityPool.Add(remainder...) k.SetFeePool(ctx, feePool) // decrement reference count of starting period diff --git a/x/distribution/keeper/fee_pool.go b/x/distribution/keeper/fee_pool.go index 34ad5f0d0d06..02107bb815aa 100644 --- a/x/distribution/keeper/fee_pool.go +++ b/x/distribution/keeper/fee_pool.go @@ -13,7 +13,7 @@ func (k Keeper) DistributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receive // NOTE the community pool isn't a module account, however its coins // are held in the distribution module account. Thus the community pool // must be reduced separately from the SendCoinsFromModuleToAccount call - newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoins(amount)) + newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...)) if negative { return types.ErrBadDistribution } diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 598809b30a72..e7f843dd2bd7 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -39,7 +39,7 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr // remainder to community pool feePool := h.k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(remainder) + feePool.CommunityPool = feePool.CommunityPool.Add(remainder...) h.k.SetFeePool(ctx, feePool) // add to validator account @@ -56,7 +56,7 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr // add outstanding to community pool feePool := h.k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(outstanding) + feePool.CommunityPool = feePool.CommunityPool.Add(outstanding...) h.k.SetFeePool(ctx, feePool) // delete outstanding diff --git a/x/distribution/keeper/invariants.go b/x/distribution/keeper/invariants.go index 4ae8dfb469f6..cff02da07691 100644 --- a/x/distribution/keeper/invariants.go +++ b/x/distribution/keeper/invariants.go @@ -140,12 +140,12 @@ func ModuleAccountInvariant(k Keeper) sdk.Invariant { var expectedCoins sdk.DecCoins k.IterateValidatorOutstandingRewards(ctx, func(_ sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { - expectedCoins = expectedCoins.Add(rewards) + expectedCoins = expectedCoins.Add(rewards...) return false }) communityPool := k.GetFeePoolCommunityCoins(ctx) - expectedInt, _ := expectedCoins.Add(communityPool).TruncateDecimal() + expectedInt, _ := expectedCoins.Add(communityPool...).TruncateDecimal() macc := k.GetDistributionAccount(ctx) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 76b582bae209..1ce723d11418 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -118,7 +118,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr // update outstanding outstanding := k.GetValidatorOutstandingRewards(ctx, valAddr) - k.SetValidatorOutstandingRewards(ctx, valAddr, outstanding.Sub(sdk.NewDecCoins(commission))) + k.SetValidatorOutstandingRewards(ctx, valAddr, outstanding.Sub(sdk.NewDecCoinsFromCoins(commission...))) if !commission.IsZero() { accAddr := sdk.AccAddress(valAddr) @@ -143,7 +143,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr func (k Keeper) GetTotalRewards(ctx sdk.Context) (totalRewards sdk.DecCoins) { k.IterateValidatorOutstandingRewards(ctx, func(_ sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool) { - totalRewards = totalRewards.Add(rewards) + totalRewards = totalRewards.Add(rewards...) return false }, ) @@ -161,7 +161,7 @@ func (k Keeper) FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk. } feePool := k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoins(amount)) + feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) k.SetFeePool(ctx, feePool) return nil diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index f0421d80ee5a..2536104c3b6b 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -105,6 +105,6 @@ func TestFundCommunityPool(t *testing.T) { err := keeper.FundCommunityPool(ctx, amount, delAddr1) assert.Nil(t, err) - assert.Equal(t, initPool.CommunityPool.Add(sdk.NewDecCoins(amount)), keeper.GetFeePool(ctx).CommunityPool) + assert.Equal(t, initPool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...), keeper.GetFeePool(ctx).CommunityPool) assert.Empty(t, bk.GetCoins(ctx, delAddr1)) } diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index 7e7c404cee14..641f59c29123 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -202,8 +202,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue delReward := k.calculateDelegationRewards(ctx, val, del, endingPeriod) delRewards = append(delRewards, types.NewDelegationDelegatorReward(valAddr, delReward)) - total = total.Add(delReward) - + total = total.Add(delReward...) return false }, ) diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index 4b0a4bbd6c42..ccedb7ede163 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -37,7 +37,7 @@ func (k Keeper) incrementValidatorPeriod(ctx sdk.Context, val exported.Validator // ergo we instead add to the community pool feePool := k.GetFeePool(ctx) outstanding := k.GetValidatorOutstandingRewards(ctx, val.GetOperator()) - feePool.CommunityPool = feePool.CommunityPool.Add(rewards.Rewards) + feePool.CommunityPool = feePool.CommunityPool.Add(rewards.Rewards...) outstanding = outstanding.Sub(rewards.Rewards) k.SetFeePool(ctx, feePool) k.SetValidatorOutstandingRewards(ctx, val.GetOperator(), outstanding) @@ -55,7 +55,7 @@ func (k Keeper) incrementValidatorPeriod(ctx sdk.Context, val exported.Validator k.decrementReferenceCount(ctx, val.GetOperator(), rewards.Period-1) // set new historical rewards with reference count of 1 - k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), rewards.Period, types.NewValidatorHistoricalRewards(historical.Add(current), 1)) + k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), rewards.Period, types.NewValidatorHistoricalRewards(historical.Add(current...), 1)) // set current rewards, incrementing period by 1 k.SetValidatorCurrentRewards(ctx, val.GetOperator(), types.NewValidatorCurrentRewards(sdk.DecCoins{}, rewards.Period+1)) diff --git a/x/distribution/proposal_handler_test.go b/x/distribution/proposal_handler_test.go index 6a451b41e0ac..1aeee1f2880a 100644 --- a/x/distribution/proposal_handler_test.go +++ b/x/distribution/proposal_handler_test.go @@ -33,7 +33,7 @@ func TestProposalHandlerPassed(t *testing.T) { // add coins to the module account macc := keeper.GetDistributionAccount(ctx) - err := macc.SetCoins(macc.GetCoins().Add(amount)) + err := macc.SetCoins(macc.GetCoins().Add(amount...)) require.NoError(t, err) supplyKeeper.SetModuleAccount(ctx, macc) @@ -43,7 +43,7 @@ func TestProposalHandlerPassed(t *testing.T) { accountKeeper.SetAccount(ctx, account) feePool := keeper.GetFeePool(ctx) - feePool.CommunityPool = sdk.NewDecCoins(amount) + feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...) keeper.SetFeePool(ctx, feePool) tp := testProposal(recipient, amount) diff --git a/x/genaccounts/legacy/v0_36/migrate.go b/x/genaccounts/legacy/v0_36/migrate.go index d69aece98156..7fea5fed3f28 100644 --- a/x/genaccounts/legacy/v0_36/migrate.go +++ b/x/genaccounts/legacy/v0_36/migrate.go @@ -75,7 +75,7 @@ func Migrate( var expDeposits sdk.Coins for _, deposit := range deposits { - expDeposits = expDeposits.Add(deposit.Deposit.Amount) + expDeposits = expDeposits.Add(deposit.Deposit.Amount...) } if !expDeposits.IsEqual(govCoins) { @@ -113,10 +113,10 @@ func Migrate( // get distr module account coins var distrDecCoins sdk.DecCoins for _, reward := range valOutRewards { - distrDecCoins = distrDecCoins.Add(reward.OutstandingRewards) + distrDecCoins = distrDecCoins.Add(reward.OutstandingRewards...) } - distrCoins, _ := distrDecCoins.Add(communityPool).TruncateDecimal() + distrCoins, _ := distrDecCoins.Add(communityPool...).TruncateDecimal() // get module account addresses feeCollectorAddr := sdk.AccAddress(crypto.AddressHash([]byte(feeCollectorName))) diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 6ee3a3075920..db5509f45e18 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -279,7 +279,7 @@ func TestProposalPassedEndblocker(t *testing.T) { require.NotNil(t, macc) moduleAccCoins := macc.GetCoins() - deposits := initialModuleAccCoins.Add(proposal.TotalDeposit).Add(proposalCoins) + deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...) require.True(t, moduleAccCoins.IsEqual(deposits)) err = input.keeper.AddVote(ctx, proposal.ProposalID, input.addrs[0], OptionYes) diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 0eb019fc2d86..b487c23ef85d 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -24,7 +24,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, supplyKeeper types.SupplyKeeper, dat var totalDeposits sdk.Coins for _, deposit := range data.Deposits { k.SetDeposit(ctx, deposit) - totalDeposits = totalDeposits.Add(deposit.Amount) + totalDeposits = totalDeposits.Add(deposit.Amount...) } for _, vote := range data.Votes { diff --git a/x/gov/keeper/deposit.go b/x/gov/keeper/deposit.go index c86df046e5e0..423679998b44 100644 --- a/x/gov/keeper/deposit.go +++ b/x/gov/keeper/deposit.go @@ -113,7 +113,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd } // Update proposal - proposal.TotalDeposit = proposal.TotalDeposit.Add(depositAmount) + proposal.TotalDeposit = proposal.TotalDeposit.Add(depositAmount...) keeper.SetProposal(ctx, proposal) // Check if deposit has provided sufficient total funds to transition the proposal into the voting period @@ -126,7 +126,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd // Add or update deposit object deposit, found := keeper.GetDeposit(ctx, proposalID, depositorAddr) if found { - deposit.Amount = deposit.Amount.Add(depositAmount) + deposit.Amount = deposit.Amount.Add(depositAmount...) } else { deposit = types.NewDeposit(proposalID, depositorAddr, depositAmount) } diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index b5d6cce405a2..edf452464094 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -51,11 +51,11 @@ func TestDeposits(t *testing.T) { require.False(t, votingStarted) deposit, found = keeper.GetDeposit(ctx, proposalID, TestAddrs[0]) require.True(t, found) - require.Equal(t, fourStake.Add(fiveStake), deposit.Amount) + require.Equal(t, fourStake.Add(fiveStake...), deposit.Amount) require.Equal(t, TestAddrs[0], deposit.Depositor) proposal, ok = keeper.GetProposal(ctx, proposalID) require.True(t, ok) - require.Equal(t, fourStake.Add(fiveStake), proposal.TotalDeposit) + require.Equal(t, fourStake.Add(fiveStake...), proposal.TotalDeposit) require.Equal(t, addr0Initial.Sub(fourStake).Sub(fiveStake), ak.GetAccount(ctx, TestAddrs[0]).GetCoins()) // Check third deposit from a new address @@ -68,7 +68,7 @@ func TestDeposits(t *testing.T) { require.Equal(t, fourStake, deposit.Amount) proposal, ok = keeper.GetProposal(ctx, proposalID) require.True(t, ok) - require.Equal(t, fourStake.Add(fiveStake).Add(fourStake), proposal.TotalDeposit) + require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), proposal.TotalDeposit) require.Equal(t, addr1Initial.Sub(fourStake), ak.GetAccount(ctx, TestAddrs[1]).GetCoins()) // Check that proposal moved to voting period @@ -82,7 +82,7 @@ func TestDeposits(t *testing.T) { require.Len(t, deposits, 2) require.Equal(t, deposits, keeper.GetDeposits(ctx, proposalID)) require.Equal(t, TestAddrs[0], deposits[0].Depositor) - require.Equal(t, fourStake.Add(fiveStake), deposits[0].Amount) + require.Equal(t, fourStake.Add(fiveStake...), deposits[0].Amount) require.Equal(t, TestAddrs[1], deposits[1].Depositor) require.Equal(t, fourStake, deposits[1].Amount) diff --git a/x/gov/keeper/invariants.go b/x/gov/keeper/invariants.go index 2350ea553e6b..1ebe62c15d0a 100644 --- a/x/gov/keeper/invariants.go +++ b/x/gov/keeper/invariants.go @@ -28,7 +28,7 @@ func ModuleAccountInvariant(keeper Keeper) sdk.Invariant { var expectedDeposits sdk.Coins keeper.IterateAllDeposits(ctx, func(deposit types.Deposit) bool { - expectedDeposits = expectedDeposits.Add(deposit.Amount) + expectedDeposits = expectedDeposits.Add(deposit.Amount...) return false }) diff --git a/x/gov/keeper/querier_test.go b/x/gov/keeper/querier_test.go index b8cce877608c..f79057f03e96 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -159,7 +159,7 @@ func TestQueries(t *testing.T) { _, err = keeper.AddDeposit(ctx, deposit1.ProposalID, deposit1.Depositor, deposit1.Amount) require.NoError(t, err) - proposal1.TotalDeposit = proposal1.TotalDeposit.Add(deposit1.Amount) + proposal1.TotalDeposit = proposal1.TotalDeposit.Add(deposit1.Amount...) proposal2, err := keeper.SubmitProposal(ctx, tp) require.NoError(t, err) @@ -167,7 +167,7 @@ func TestQueries(t *testing.T) { _, err = keeper.AddDeposit(ctx, deposit2.ProposalID, deposit2.Depositor, deposit2.Amount) require.NoError(t, err) - proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit2.Amount) + proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit2.Amount...) // TestAddrs[1] proposes (and deposits) on proposal #3 proposal3, err := keeper.SubmitProposal(ctx, tp) @@ -176,14 +176,14 @@ func TestQueries(t *testing.T) { _, err = keeper.AddDeposit(ctx, deposit3.ProposalID, deposit3.Depositor, deposit3.Amount) require.NoError(t, err) - proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit3.Amount) + proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit3.Amount...) // TestAddrs[1] deposits on proposals #2 & #3 deposit4 := types.NewDeposit(proposal2.ProposalID, TestAddrs[1], depositParams.MinDeposit) _, err = keeper.AddDeposit(ctx, deposit4.ProposalID, deposit4.Depositor, deposit4.Amount) require.NoError(t, err) - proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit4.Amount) + proposal2.TotalDeposit = proposal2.TotalDeposit.Add(deposit4.Amount...) proposal2.Status = types.StatusVotingPeriod proposal2.VotingEndTime = proposal2.VotingEndTime.Add(types.DefaultPeriod) @@ -191,11 +191,11 @@ func TestQueries(t *testing.T) { _, err = keeper.AddDeposit(ctx, deposit5.ProposalID, deposit5.Depositor, deposit5.Amount) require.NoError(t, err) - proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit5.Amount) + proposal3.TotalDeposit = proposal3.TotalDeposit.Add(deposit5.Amount...) proposal3.Status = types.StatusVotingPeriod proposal3.VotingEndTime = proposal3.VotingEndTime.Add(types.DefaultPeriod) // total deposit of TestAddrs[1] on proposal #3 is worth the proposal deposit + individual deposit - deposit5.Amount = deposit5.Amount.Add(deposit3.Amount) + deposit5.Amount = deposit5.Amount.Add(deposit3.Amount...) // check deposits on proposal1 match individual deposits deposits := getQueriedDeposits(t, ctx, keeper.cdc, querier, proposal1.ProposalID) diff --git a/x/mock/app.go b/x/mock/app.go index d0cee9f592af..29448e8a9067 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -299,7 +299,7 @@ func RandomSetGenesis(r *rand.Rand, app *App, addrs []sdk.AccAddress, denoms []s } } - app.TotalCoinsSupply = app.TotalCoinsSupply.Add(coins) + app.TotalCoinsSupply = app.TotalCoinsSupply.Add(coins...) baseAcc := auth.NewBaseAccountWithAddress(addrs[i]) (&baseAcc).SetCoins(coins) diff --git a/x/mock/types.go b/x/mock/types.go index 56912780dac1..43dfbaecbb94 100644 --- a/x/mock/types.go +++ b/x/mock/types.go @@ -31,7 +31,7 @@ func (sk DummySupplyKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, fromAd return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, fromAcc.GetCoins().String()) } - newToCoins := moduleAcc.GetCoins().Add(amt) + newToCoins := moduleAcc.GetCoins().Add(amt...) if err := fromAcc.SetCoins(newFromCoins); err != nil { return err diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index 01620d762cfa..e3e619697679 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -296,7 +296,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -308,7 +308,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { // add bonded tokens to pool for delegations bondedPool := keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -320,7 +320,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { // add bonded tokens to pool for delegations bondedPool = keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -356,7 +356,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -367,7 +367,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { keeper.SetDelegation(ctx, selfDelegation) bondedPool := keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -378,7 +378,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { require.Equal(t, delTokens, issuedShares.RoundInt()) bondedPool = keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -387,7 +387,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { keeper.SetDelegation(ctx, delegation) bondedPool = keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -438,7 +438,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -456,7 +456,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { keeper.SetDelegation(ctx, selfDelegation) bondedPool := keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -517,7 +517,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -541,7 +541,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { require.Equal(t, delTokens, issuedShares.RoundInt()) bondedPool := keeper.GetBondedPool(ctx) - err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins)) + err = bondedPool.SetCoins(bondedPool.GetCoins().Add(delCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -672,7 +672,7 @@ func TestRedelegateToSameValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -699,7 +699,7 @@ func TestRedelegationMaxEntries(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -752,7 +752,7 @@ func TestRedelegateSelfDelegation(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -804,7 +804,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) @@ -883,7 +883,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) { // add bonded tokens to pool for delegations notBondedPool := keeper.GetNotBondedPool(ctx) - err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins)) + err := notBondedPool.SetCoins(notBondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) diff --git a/x/staking/keeper/slash_test.go b/x/staking/keeper/slash_test.go index bd46400edcdc..cc4d4651731a 100644 --- a/x/staking/keeper/slash_test.go +++ b/x/staking/keeper/slash_test.go @@ -117,7 +117,7 @@ func TestSlashRedelegation(t *testing.T) { // add bonded tokens to pool for (re)delegations startCoins := sdk.NewCoins(sdk.NewInt64Coin(keeper.BondDenom(ctx), 15)) bondedPool := keeper.GetBondedPool(ctx) - err := bondedPool.SetCoins(bondedPool.GetCoins().Add(startCoins)) + err := bondedPool.SetCoins(bondedPool.GetCoins().Add(startCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -371,7 +371,7 @@ func TestSlashWithRedelegation(t *testing.T) { bondedPool := keeper.GetBondedPool(ctx) notBondedPool := keeper.GetNotBondedPool(ctx) rdCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdTokens.MulRaw(2))) - err := bondedPool.SetCoins(bondedPool.GetCoins().Add(rdCoins)) + err := bondedPool.SetCoins(bondedPool.GetCoins().Add(rdCoins...)) require.NoError(t, err) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) @@ -515,8 +515,8 @@ func TestSlashBoth(t *testing.T) { // update bonded tokens bondedPool := keeper.GetBondedPool(ctx) notBondedPool := keeper.GetNotBondedPool(ctx) - require.NoError(t, bondedPool.SetCoins(bondedPool.GetCoins().Add(bondedCoins))) - require.NoError(t, bondedPool.SetCoins(notBondedPool.GetCoins().Add(notBondedCoins))) + require.NoError(t, bondedPool.SetCoins(bondedPool.GetCoins().Add(bondedCoins...))) + require.NoError(t, bondedPool.SetCoins(notBondedPool.GetCoins().Add(notBondedCoins...))) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index 2f030428870d..c01fabbca2da 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -449,7 +449,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { tokens := sdk.TokensFromConsensusPower(power) validators[i], _ = validators[i].AddTokensFromDel(tokens) notBondedPool := keeper.GetNotBondedPool(ctx) - require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens))))) + require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(sdk.NewCoin(params.BondDenom, tokens)))) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) validators[i] = TestingUpdateValidator(keeper, ctx, validators[i], true) } @@ -465,8 +465,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) { delTokens := sdk.TokensFromConsensusPower(500) validators[0], _ = validators[0].AddTokensFromDel(delTokens) notBondedPool := keeper.GetNotBondedPool(ctx) - newTokens := sdk.NewCoins(sdk.NewCoin(params.BondDenom, delTokens)) - require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(newTokens))) + newTokens := sdk.NewCoins() + require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(newTokens...))) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) // test that the two largest validators are @@ -496,7 +496,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { notBondedPool = keeper.GetNotBondedPool(ctx) newTokens = sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.TokensFromConsensusPower(1))) - require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(newTokens))) + require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(newTokens...))) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true) @@ -511,7 +511,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { validators[3], _ = validators[3].RemoveDelShares(sdk.NewDec(201)) bondedPool := keeper.GetBondedPool(ctx) - require.NoError(t, bondedPool.SetCoins(bondedPool.GetCoins().Add(sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens))))) + require.NoError(t, bondedPool.SetCoins(bondedPool.GetCoins().Add(sdk.NewCoin(params.BondDenom, rmTokens)))) keeper.supplyKeeper.SetModuleAccount(ctx, bondedPool) validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true) @@ -525,7 +525,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { validators[3], _ = validators[3].AddTokensFromDel(sdk.NewInt(200)) notBondedPool = keeper.GetNotBondedPool(ctx) - require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200)))))) + require.NoError(t, notBondedPool.SetCoins(notBondedPool.GetCoins().Add(sdk.NewCoin(params.BondDenom, sdk.NewInt(200))))) keeper.supplyKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true) diff --git a/x/supply/genesis.go b/x/supply/genesis.go index 7af02a61c7f3..e1dfc41ff555 100644 --- a/x/supply/genesis.go +++ b/x/supply/genesis.go @@ -15,7 +15,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data Ge var totalSupply sdk.Coins ak.IterateAccounts(ctx, func(acc authexported.Account) (stop bool) { - totalSupply = totalSupply.Add(acc.GetCoins()) + totalSupply = totalSupply.Add(acc.GetCoins()...) return false }, ) diff --git a/x/supply/internal/keeper/bank_test.go b/x/supply/internal/keeper/bank_test.go index bdd0a9430a1d..6a817a164f8d 100644 --- a/x/supply/internal/keeper/bank_test.go +++ b/x/supply/internal/keeper/bank_test.go @@ -60,7 +60,7 @@ func TestSendCoins(t *testing.T) { keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) }) - err = keeper.SendCoinsFromModuleToAccount(ctx, holderAcc.GetName(), baseAcc.GetAddress(), initCoins.Add(initCoins)) + err = keeper.SendCoinsFromModuleToAccount(ctx, holderAcc.GetName(), baseAcc.GetAddress(), initCoins.Add(initCoins...)) require.Error(t, err) err = keeper.SendCoinsFromModuleToModule(ctx, holderAcc.GetName(), types.Burner, initCoins) @@ -102,7 +102,7 @@ func TestMintCoins(t *testing.T) { err = keeper.MintCoins(ctx, types.Minter, initCoins) require.NoError(t, err) require.Equal(t, initCoins, getCoinsByName(ctx, keeper, ak, types.Minter)) - require.Equal(t, initialSupply.GetTotal().Add(initCoins), keeper.GetSupply(ctx).GetTotal()) + require.Equal(t, initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal()) // test same functionality on module account with multiple permissions initialSupply = keeper.GetSupply(ctx) @@ -110,7 +110,7 @@ func TestMintCoins(t *testing.T) { err = keeper.MintCoins(ctx, multiPermAcc.GetName(), initCoins) require.NoError(t, err) require.Equal(t, initCoins, getCoinsByName(ctx, keeper, ak, multiPermAcc.GetName())) - require.Equal(t, initialSupply.GetTotal().Add(initCoins), keeper.GetSupply(ctx).GetTotal()) + require.Equal(t, initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal()) require.Panics(t, func() { keeper.MintCoins(ctx, types.Burner, initCoins) }) } diff --git a/x/supply/internal/keeper/invariants.go b/x/supply/internal/keeper/invariants.go index d72bf4e0134d..aeec368e4bf9 100644 --- a/x/supply/internal/keeper/invariants.go +++ b/x/supply/internal/keeper/invariants.go @@ -27,7 +27,7 @@ func TotalSupply(k Keeper) sdk.Invariant { supply := k.GetSupply(ctx) k.ak.IterateAccounts(ctx, func(acc exported.Account) bool { - expectedTotal = expectedTotal.Add(acc.GetCoins()) + expectedTotal = expectedTotal.Add(acc.GetCoins()...) return false }) diff --git a/x/supply/internal/types/supply.go b/x/supply/internal/types/supply.go index 6009b22fac6e..92e4a3e5d2f5 100644 --- a/x/supply/internal/types/supply.go +++ b/x/supply/internal/types/supply.go @@ -40,7 +40,7 @@ func DefaultSupply() exported.SupplyI { // Inflate adds coins to the total supply func (supply Supply) Inflate(amount sdk.Coins) exported.SupplyI { - supply.Total = supply.Total.Add(amount) + supply.Total = supply.Total.Add(amount...) return supply }