Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex in Coin.from_str() unable to parse denoms containing a hyphen #187

Open
ibjc opened this issue Apr 13, 2023 · 0 comments
Open

Regex in Coin.from_str() unable to parse denoms containing a hyphen #187

ibjc opened this issue Apr 13, 2023 · 0 comments

Comments

@ibjc
Copy link

ibjc commented Apr 13, 2023

  • terra_sdk version: 3.0.0
  • Python version: 3.8
  • Operating System: linux

Description

tokenfactory denoms can have a hyphen in the name, which seems to break the Coin.from_str regex.

the normal constructor works fine, ex: Coin(denom="factory/terra1xyz/my-denom", amount=69420)

pattern = r"^(\-?[0-9]+(\.[0-9]+)?)([0-9a-zA-Z/]+)$"

What I Did

In [5]: Coins.from_str("69420factory/terra1xyz/my-denom")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 Coins.from_str("69420factory/terra1xyz/my-denom")

File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:52, in Coins.from_str(cls, s)
     43 """Converts a comma-separated list of Coin-format strings to :class:`Coins`.
     44 
     45 >>> Coins.from_str('1000uluna,1234ukrw')
   (...)
     49     s (str): string to convert
     50 """
     51 coin_strings = s.split(r",")
---> 52 return Coins(Coin.from_str(cs) for cs in coin_strings)

File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:82, in Coins.__init__(self, arg, **denoms)
     80 else:
     81     coins = arg
---> 82 for coin in coins:
     83     x = self._coins.get(coin.denom)
     84     if x is not None:

File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:52, in <genexpr>(.0)
     43 """Converts a comma-separated list of Coin-format strings to :class:`Coins`.
     44 
     45 >>> Coins.from_str('1000uluna,1234ukrw')
   (...)
     49     s (str): string to convert
     50 """
     51 coin_strings = s.split(r",")
---> 52 return Coins(Coin.from_str(cs) for cs in coin_strings)

File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coin.py:113, in Coin.from_str(cls, string)
    111 match = re.match(pattern, string)
    112 if match is None:
--> 113     raise ValueError(f"failed to parse Coin: {string}")
    114 else:
    115     return cls(match.group(3), match.group(1))

ValueError: failed to parse Coin: 69420factory/terra1xyz/my-denom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant