feat: allow setting the base denom (#16257)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
81ba019e5e
commit
995d2bc94b
@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (tx) [#15992](https://github.com/cosmos/cosmos-sdk/pull/15992) Add `WithExtensionOptions` in tx Factory to allow `SetExtensionOptions` with given extension options.
|
||||
* (types/simulation) [#16074](https://github.com/cosmos/cosmos-sdk/pull/16074) Add generic SimulationStoreDecoder for modules using collections.
|
||||
* (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Make `StartCmd` more customizable.
|
||||
* (types) [#16257](https://github.com/cosmos/cosmos-sdk/pull/16257) Allow setting the base denom in the denom registry.
|
||||
|
||||
### Improvements
|
||||
|
||||
|
||||
@ -47,6 +47,17 @@ func GetDenomUnit(denom string) (Dec, bool) {
|
||||
return unit, true
|
||||
}
|
||||
|
||||
// SetBaseDenom allow overwritting the base denom
|
||||
// if the denom has registered before, otherwise return error
|
||||
func SetBaseDenom(denom string) error {
|
||||
_, ok := denomUnits[denom]
|
||||
if !ok {
|
||||
return fmt.Errorf("denom %s not registered", denom)
|
||||
}
|
||||
baseDenom = denom
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseDenom returns the denom of smallest unit registered
|
||||
func GetBaseDenom() (string, error) {
|
||||
if baseDenom == "" {
|
||||
|
||||
@ -36,6 +36,13 @@ func (s *internalDenomTestSuite) TestRegisterDenom() {
|
||||
s.Require().False(ok)
|
||||
s.Require().Equal(math.LegacyZeroDec(), res)
|
||||
|
||||
err := SetBaseDenom(atom)
|
||||
s.Require().NoError(err)
|
||||
|
||||
res, ok = GetDenomUnit(atom)
|
||||
s.Require().True(ok)
|
||||
s.Require().Equal(atomUnit, res)
|
||||
|
||||
// reset registration
|
||||
baseDenom = ""
|
||||
denomUnits = map[string]Dec{}
|
||||
@ -192,3 +199,12 @@ func (s *internalDenomTestSuite) TestDecOperationOrder() {
|
||||
baseDenom = ""
|
||||
denomUnits = map[string]Dec{}
|
||||
}
|
||||
|
||||
func (s *internalDenomTestSuite) TestSetBaseDenomError() {
|
||||
err := SetBaseDenom(atom)
|
||||
s.Require().Error(err)
|
||||
|
||||
// reset registration
|
||||
baseDenom = ""
|
||||
denomUnits = map[string]Dec{}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user