tw.py: get_tw_label() bugfix

This commit is contained in:
The MMGen Project 2020-06-01 21:34:11 +00:00
commit bc439e0b3d
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 8 additions and 1 deletions

View file

@ -40,6 +40,7 @@ class InvalidTokenAddress(Exception): mmcode = 2
class UnrecognizedTokenSymbol(Exception): mmcode = 2
class TokenNotInBlockchain(Exception): mmcode = 2
class TokenNotInWallet(Exception): mmcode = 2
class BadTwComment(Exception): mmcode = 2
class BadTwLabel(Exception): mmcode = 2
class BaseConversionError(Exception): mmcode = 2
class BaseConversionPadError(Exception): mmcode = 2

View file

@ -876,6 +876,7 @@ class MMGenWalletLabel(MMGenLabel):
class TwComment(MMGenLabel):
max_screen_width = 80
desc = 'tracking wallet comment'
exc = BadTwComment
class MMGenTxLabel(MMGenLabel):
max_len = 72

View file

@ -32,9 +32,13 @@ CUR_HOME,ERASE_ALL = '\033[H','\033[0J'
def CUR_RIGHT(n): return '\033[{}C'.format(n)
def get_tw_label(proto,s):
"""
We must fail only on malformed comment, not on empty label.
Otherwise, listaddresses showempty=1 will fail.
"""
try:
return TwLabel(proto,s)
except BadTwLabel:
except BadTwComment:
raise
except:
return None

View file

@ -265,6 +265,7 @@ tests = {
'good': (utf8_text[:48],)
},
'TwComment': {
'exc_name': 'BadTwComment',
'arg1': 's',
'bad': ( utf8_combining[:40],
utf8_ctrl[:40],