def get_token_by_symbol(cls, symbol: str): """ Get raw_transaction by encoding Transaction object token by provided symbol """ token = cls.get_token_by_attribute('symbol', symbol) if not token: logger.warning(f'No token found for symbol {symbol}') return return EthToken.from_namedtuple(token)
def get_token_by_address(self, address: str): token = self.get_token_by_attribute( 'address', address) or self.get_token_from_token_contract(address) if not token: logger.warning(f'No token found for address {address}') return return EthToken.from_namedtuple(token)
def test_token_precision_validation(value, token_decimals): token = EthToken.from_namedtuple( Token('Test_token', 'TST', '0x123', token_decimals)) with pytest.raises(ValueError) as error: token.validate_precision(value) assert str( error.value ) == f'Test_token token supports at most {token_decimals} decimal places.'
def get_token_by_symbol(cls, symbol: str) -> Optional[EthToken]: ''' Get a known token (from clove) by its symbol. Args: symbol (str): token symbol Returns: EthToken, None: Ethereum Token namedtuple or None if there is no matching token Example: >>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_by_symbol('PGT') <clove.network.ethereum.token.EthToken at 0x7f7b3fdffe48> ''' token = cls.get_token_by_attribute('symbol', symbol) if not token: logger.warning(f'No token found for symbol {symbol}') return return EthToken.from_namedtuple(token)
def get_token_by_address(self, address: str) -> Optional[EthToken]: ''' Get token by its address. Args: address (str): token address Returns: EthToken, None: Ethereum Token namedtuple Example: >>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_by_address('0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6') <clove.network.ethereum.token.EthToken at 0x7f7b3fed1eb8> ''' token = self.get_token_by_attribute( 'address', address) or self.get_token_from_token_contract(address) if not token: logger.warning(f'No token found for address {address}') return return EthToken.from_namedtuple(token)
def test_token_value_base_units_conversion(base_unit_value, float_value): token = EthToken() assert token.value_to_base_units(float_value) == base_unit_value assert token.value_from_base_units(base_unit_value) == Decimal( str(float_value))