Skip to content

Commit

Permalink
fix(basket)!: store basket denom units in ascending order (#1202)
Browse files Browse the repository at this point in the history
* fix(basket)!: save basket denom units in asc order

* chore: cleanup

* chore: fix test

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
  • Loading branch information
aleem1314 and ryanchristo authored Jun 21, 2022
1 parent 1853c2b commit 5de1015
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 14 additions & 5 deletions x/ecocredit/server/basket/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,23 @@ func (k Keeper) Create(ctx context.Context, msg *basket.MsgCreate) (*basket.MsgC
return nil, err
}

denomUnits := []*banktypes.DenomUnit{{
Denom: displayDenom,
Exponent: creditType.Precision,
}}
if creditType.Precision != 0 {
denomUnits := make([]*banktypes.DenomUnit, 0)

// Set denomination units in ascending order and
// the first denomination unit must be the base
if creditType.Precision == 0 {
denomUnits = append(denomUnits, &banktypes.DenomUnit{
Denom: displayDenom,
Exponent: creditType.Precision,
})
} else {
denomUnits = append(denomUnits, &banktypes.DenomUnit{
Denom: denom,
})
denomUnits = append(denomUnits, &banktypes.DenomUnit{
Denom: displayDenom,
Exponent: creditType.Precision,
})
}

k.bankKeeper.SetDenomMetaData(sdkCtx, banktypes.Metadata{
Expand Down
10 changes: 5 additions & 5 deletions x/ecocredit/server/basket/msg_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ func (s *createSuite) getDenomMetadata() bank.Metadata {
denom, displayDenom, err := basket.FormatBasketDenom(s.basketName, s.creditTypeAbbrev, s.creditTypePrecision)
require.NoError(s.t, err)

denomUnits := []*bank.DenomUnit{{
Denom: displayDenom,
Exponent: s.creditTypePrecision,
}}

denomUnits := make([]*bank.DenomUnit, 0)
if denom != displayDenom {
denomUnits = append(denomUnits, &bank.DenomUnit{
Denom: denom,
})
}
denomUnits = append(denomUnits, &bank.DenomUnit{
Denom: displayDenom,
Exponent: s.creditTypePrecision,
})

return bank.Metadata{
Name: s.basketName,
Expand Down

0 comments on commit 5de1015

Please sign in to comment.