Skip to content

Commit

Permalink
Revert "prevent nil DecCoin creation when converting Coins to DecCoins"
Browse files Browse the repository at this point in the history
This reverts commit 9a75a71.
  • Loading branch information
yun-yeo committed Aug 18, 2022
1 parent 9a75a71 commit b9c853f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
10 changes: 3 additions & 7 deletions types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions types/dec_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b9c853f

Please sign in to comment.