def _check_deploy(conf: dict, password: str = None): """Check keystore presence, and get password from user's terminal input (not validate password) password is an optional parameter for unit tests purposes :param conf: command configuration :param password: password for unit tests (optional) :return: password for keystore file """ # check if keystore exist. if exist, get password from user input if not conf['keyStore']: if not is_icon_address_valid(conf['from']): raise TBearsCommandException( f"You entered invalid 'from' address '{conf['from']}") else: if not password: password = getpass.getpass("Input your keystore password: "******"You entered invalid 'to' address '{conf['to']}") # check project directory check_project(conf.get('project', "")) return password
def test_is_icon_address_valid(self): address: str = str(create_address()) self.assertTrue(is_icon_address_valid(address)) # Remove prefix 'hx' a = address[2:] self.assertFalse(is_icon_address_valid(a)) # short address a = address[:-1] self.assertFalse(is_icon_address_valid(a)) # wrong param prefix self.assertFalse(is_icon_address_valid(1234)) # wrong hexadecimal format self.assertFalse(is_icon_address_valid( "0x00c3f694d84074f9145cd0bfa497290ce2d8052f"))
def __call__(self, string: str) -> str: # check prefix of given address (string). if not 'cx' or 'hx', raise error if not is_icon_address_valid(string): raise ArgumentTypeError(f"Invalid address '{string}'") if self._prefix != 'all': if self._prefix != string[:2]: raise ArgumentTypeError(f"Invalid address '{string}'. Address must start with '{self._prefix}'") return string
def _check_deploy(conf: dict, password: str = None): """Check keystore presence, and get password from user's terminal input(not validate password) the reason why receive password as parameter is for unit tests :param conf: command configuration :param password: password for unit tests(optional) :return: password for keystore file """ if not os.path.isdir(conf['project']): raise TBearsCommandException( f'There is no project directory.({conf["project"]})') if conf['contentType'] == 'zip': if conf.get('keyStore', None) is None: raise TBearsCommandException( f'If you want to deploy SCORE to ICON node, set --key-store option or ' f'write "keyStore" value in configuration file.') else: uri: str = conf.get('uri', "") if uri and uri.find('127.0.0.1') == -1: raise TBearsCommandException( f"TBears does not support deploying tbears SCORE to remote" ) # check if keystore exist. if exist, get password from user input if not conf['keyStore']: if not is_icon_address_valid(conf['from']): raise TBearsCommandException( f"You entered invalid 'from' address '{conf['from']}") else: if not password: password = getpass.getpass("input your keystore password: "******"You entered invalid 'to' address '{conf['to']}") return password
def _check_sendtx(conf: dict, password: str = None): if conf.get('keyStore', None): if not os.path.exists(conf['keyStore']): raise TBearsCommandException(f'There is no keystore file {conf["keyStore"]}') if not password: password = getpass.getpass("Input your keystore password: "******"from"]}') return password
def _check_transfer(conf: dict, password: str = None): if not is_icon_address_valid(conf['to']): raise TBearsCommandException(f'You entered invalid address') # value must be a integer value if conf['value'] != float(int(conf['value'])): raise TBearsCommandException( f'You entered invalid value {conf["value"]}') if conf.get('keyStore', None): if not password: password = getpass.getpass("input your keystore password: ") return password
def _check_transfer(conf: dict, password: str = None): if not is_icon_address_valid(conf['to']): raise TBearsCommandException(f'You entered invalid address') if conf['to'] == keystore_test1['address']: uri: str = conf['uri'] index = uri.find('127.0.0.1') if index == -1 or uri[index + len('127.0.0.1')] != ':': raise TBearsCommandException(f'Do not transfer to "test1" account') if conf.get('keyStore', None): if not password: password = getpass.getpass("Input your keystore password: ") return password
def test_is_icon_address_valid_invalid_cases(self, address_string): """without prefix, shorten data, wrong prefix data""" assert is_icon_address_valid(address_string) is False
def test_is_icon_address_valid_valid_case(self): address: str = str(create_address()) assert is_icon_address_valid(address)