From b9c853fd716520d21bf66baedce739b8bfc589a3 Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 18 Aug 2022 10:32:58 +0900 Subject: [PATCH] Revert "prevent nil DecCoin creation when converting Coins to DecCoins" This reverts commit 9a75a7130a772fff9e31654f158190432217dee6. --- types/dec_coin.go | 10 +++------- types/dec_coin_test.go | 23 ----------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/types/dec_coin.go b/types/dec_coin.go index 10856d0fe2f9..68fe3b9f958e 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -182,14 +182,10 @@ func sanitizeDecCoins(decCoins []DecCoin) DecCoins { // NewDecCoinsFromCoins constructs a new coin set with decimal values // from regular Coins. func NewDecCoinsFromCoins(coins ...Coin) DecCoins { - if len(coins) == 0 { - return DecCoins{} - } - - decCoins := make([]DecCoin, 0, len(coins)) + decCoins := make(DecCoins, len(coins)) newCoins := NewCoins(coins...) - for _, coin := range newCoins { - decCoins = append(decCoins, NewDecCoinFromCoin(coin)) + for i, coin := range newCoins { + decCoins[i] = NewDecCoinFromCoin(coin) } return decCoins diff --git a/types/dec_coin_test.go b/types/dec_coin_test.go index b8885ca78bfe..938f7dddffb4 100644 --- a/types/dec_coin_test.go +++ b/types/dec_coin_test.go @@ -545,29 +545,6 @@ func (s *decCoinTestSuite) TestNewDecCoinsWithIsValid() { } } -func (s *decCoinTestSuite) TestNewDecCoinsWithZeroCoins() { - zeroCoins := append(sdk.NewCoins(sdk.NewCoin("mytoken", sdk.NewInt(0))), sdk.Coin{Denom: "wbtc", Amount: sdk.NewInt(10)}) - - tests := []struct { - coins sdk.Coins - expectLength int - }{ - { - sdk.NewCoins(sdk.NewCoin("mytoken", sdk.NewInt(10)), sdk.NewCoin("wbtc", sdk.NewInt(10))), - 2, - }, - { - zeroCoins, - 1, - }, - } - - for _, tc := range tests { - tc := tc - s.Require().Equal(sdk.NewDecCoinsFromCoins(tc.coins...).Len(), tc.expectLength) - } -} - func (s *decCoinTestSuite) TestDecCoins_AddDecCoinWithIsValid() { lengthTestDecCoins := sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(10)}) s.Require().Equal(2, len(lengthTestDecCoins), "should be 2")