2024-01-26 11:16:55 +00:00
|
|
|
from common import * # isort:skip
|
2023-06-28 10:58:54 +00:00
|
|
|
|
2018-06-14 12:05:41 +00:00
|
|
|
from trezor.wire import ProcessError
|
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
if not utils.BITCOIN_ONLY:
|
2020-09-23 10:31:07 +00:00
|
|
|
from apps.stellar.helpers import address_from_public_key, public_key_from_address
|
2018-06-14 12:05:41 +00:00
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
|
|
|
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
2018-08-30 11:45:09 +00:00
|
|
|
class TestStellarAddress(unittest.TestCase):
|
2018-06-14 12:05:41 +00:00
|
|
|
def test_address_to_pubkey(self):
|
2023-06-28 10:46:29 +00:00
|
|
|
self.assertEqual(
|
|
|
|
public_key_from_address(
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
),
|
|
|
|
unhexlify(
|
|
|
|
"5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0"
|
|
|
|
),
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
self.assertEqual(
|
|
|
|
public_key_from_address(
|
|
|
|
"GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6"
|
|
|
|
),
|
|
|
|
unhexlify(
|
|
|
|
"9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4"
|
|
|
|
),
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
|
|
|
def test_pubkey_to_address(self):
|
2023-06-28 10:46:29 +00:00
|
|
|
addr = address_from_public_key(
|
|
|
|
unhexlify(
|
|
|
|
"5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
addr, "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
addr = address_from_public_key(
|
|
|
|
unhexlify(
|
|
|
|
"9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
addr, "GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6"
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
|
|
|
def test_both(self):
|
2023-06-28 10:46:29 +00:00
|
|
|
pubkey = unhexlify(
|
|
|
|
"dfcc77d08588601702e02de2dc603f5c5281bea23baa894ae3b3b4778e5bbe40"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
public_key_from_address(address_from_public_key(pubkey)), pubkey
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
pubkey = unhexlify(
|
|
|
|
"53214e6155469c32fb882b1b1d94930d5445a78202867b7ddc6a33ad42ff4464"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
public_key_from_address(address_from_public_key(pubkey)), pubkey
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
pubkey = unhexlify(
|
|
|
|
"5ed4690134e5ef79b290ea1e7a4b8f3b6b3bcf287463c18bfe36baa030e7efbd"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
public_key_from_address(address_from_public_key(pubkey)), pubkey
|
|
|
|
)
|
2018-06-14 12:05:41 +00:00
|
|
|
|
|
|
|
def test_invalid_address(self):
|
|
|
|
with self.assertRaises(ProcessError):
|
2023-06-28 10:46:29 +00:00
|
|
|
public_key_from_address(
|
|
|
|
"GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2AA"
|
|
|
|
) # invalid checksum
|
2018-06-14 12:05:41 +00:00
|
|
|
|
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
if __name__ == "__main__":
|
2018-06-14 12:05:41 +00:00
|
|
|
unittest.main()
|