def test_correct_lower_currency_code_format(self): # lower case is discouraged but allowed obj = IssuedCurrency( currency="usd", issuer=_ACCOUNT, ) self.assertTrue(obj.is_valid())
def test_xrp_lower_currency_is_invalid(self): # issued currencies can't use XRP (just use a string amount then) with self.assertRaises(XRPLModelException): IssuedCurrency( currency="xrp", issuer=_ACCOUNT, )
def test_invalid_currency_length(self): # length of currency must be either 3 or 40 with self.assertRaises(XRPLModelException): IssuedCurrency( currency="XXXX", issuer=_ACCOUNT, )
def test_incorrect_hex_format(self): # the "+" is not allowed in a currency format" with self.assertRaises(XRPLModelException): IssuedCurrency( currency="+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", issuer=_ACCOUNT, )
def test_correct_lower_currency_code_format(self): # lower case is not allowed with self.assertRaises(XRPLModelException): IssuedCurrency( currency="usd", issuer=_ACCOUNT, )
def _from_dict_special_cases( cls: Type[BaseModel], param: str, param_type: Type[Any], param_value: Dict[str, Any], ) -> Union[str, Enum, BaseModel, Dict[str, Any]]: """Handles all the recursive/more complex cases for `from_dict`.""" from xrpl.models.amounts import Amount, IssuedCurrencyAmount from xrpl.models.currencies import XRP, Currency, IssuedCurrency from xrpl.models.transactions.transaction import Transaction # TODO: figure out how to make Unions work generically (if possible) if param_type == Amount: # special case, Union if isinstance(param_value, str): return param_value if not isinstance(param_value, dict): raise XRPLModelException( f"{param_type} requires a dictionary of params") return IssuedCurrencyAmount.from_dict(param_value) if param_type == Currency: # special case, Union if not isinstance(param_value, dict): raise XRPLModelException( f"{param_type} requires a dictionary of params") if "currency" in param_value and "issuer" in param_value: return IssuedCurrency.from_dict(param_value) if "currency" in param_value: param_value_copy = {**param_value} del param_value_copy["currency"] return XRP.from_dict(param_value_copy) raise XRPLModelException(f"No valid type for {param}") if param_type == Transaction: # special case, multiple options (could be any Transaction type) if "transaction_type" not in param_value: raise XRPLModelException( f"{param} not a valid parameter for {cls.__name__}") type_str = param_value["transaction_type"] # safely convert type string into the actual type transaction_type = Transaction.get_transaction_type(type_str) param_value_copy = {**param_value} del param_value_copy["transaction_type"] return transaction_type.from_dict(param_value_copy) if param_type in BaseModel.__subclasses__(): # any other BaseModel if not isinstance(param_value, dict): raise XRPLModelException( f"{param_type} requires a dictionary of params") # mypy doesn't know that the If checks that it's a subclass of BaseModel return param_type.from_dict(param_value) # type: ignore if param_type in Enum.__subclasses__(): # mypy doesn't know that the If checks that it's a subclass of Enum return param_type(param_value) # type: ignore return param_value
async def test_basic_functionality(self, client): response = await client.request( BookOffers( taker=WALLET.classic_address, taker_gets=XRP(), taker_pays=IssuedCurrency( currency="USD", issuer="rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", ), ledger_index="validated", ), ) self.assertTrue(response.is_successful())
def test_correct_currency_code_format(self): obj = IssuedCurrency( currency="USD", issuer=_ACCOUNT, ) self.assertTrue(obj.is_valid())
def test_correct_hex_format(self): obj = IssuedCurrency( currency="0158415500000000C1F76FF6ECB0BAC600000000", issuer=_ACCOUNT, ) self.assertTrue(obj.is_valid())