def test_extending_currency(self): new_currency = Currency('testcoin', ticker='ttc', validator='Base58Check', networks=dict(main=(0x00, 0x05), test=(0x6f, 0xc4))) self.assertEqual(new_currency, Currencies.get(new_currency.name)) self.assertEqual(new_currency, Currencies.get(new_currency.ticker)) test_data = [(new_currency.name, new_currency.ticker, b'1BoatSLRHtKNngkdXEeobR76b53LETtpyT', 'main')] for name, ticker, addr, net in test_data: with self.subTest(name=name, ticker=ticker, address=addr, net=net): res = coinaddrng.validate(name, addr) self.assertEqual(name, res.name) self.assertEqual(ticker, res.ticker) self.assertEqual(addr, res.address) self.assertEqual(True, res.valid) self.assertEqual(net, res.network) with self.subTest(name=name, ticker=ticker, address=addr, net=net): res = coinaddrng.validate(ticker, addr) self.assertEqual(name, res.name) self.assertEqual(ticker, res.ticker) self.assertEqual(addr, res.address) self.assertEqual(True, res.valid) self.assertEqual(net, res.network)
def test_validation_by_name(self): for name, ticker, addr, net in TEST_DATA: with self.subTest(name=name, address=addr, net=net): res = coinaddrng.validate(name, addr) self.assertEqual(name, res.name) self.assertEqual(ticker, res.ticker) self.assertEqual(addr, res.address) self.assertEqual(True, res.valid) self.assertEqual(net, res.network) for name, ticker, addr, net in WRONG_DATA: with self.subTest(name=name, address=addr, net=net): res = coinaddrng.validate(name, addr) self.assertNotEqual(True, res.valid)
def test_validation_from_text(self): for name, ticker, addr, net in TEST_DATA: with self.subTest(name=name, address=addr, net=net): res = coinaddrng.validate(name, addr.decode()) self.assertEqual(name, res.name) self.assertEqual(ticker, res.ticker) self.assertEqual(addr, res.address) self.assertEqual(True, res.valid) self.assertEqual(net, res.network)
def get_address_info(symbol: str, address: str): try: return coinaddrng.validate(symbol.lower(), address) except TypeError: # if validator for symbol doesn't exist return default object; # 'valid' attribute is set to True, because there may not exist # validator for every supported coin return coinaddrng.validation.ValidationResult(name='', ticker=symbol, address=address.encode(), valid=True, network='', address_type='', is_extended=False)
def test_validation_wrong_data(self): for currency in Currencies.instances.values(): for addr in WRONG_ADDRESSES: with self.subTest(name=currency.name, address=addr): res = coinaddrng.validate(currency.name, addr) self.assertEqual(res.valid, False)