1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 05:48:23 +00:00
trezor-firmware/core/tests/test_apps.nem.address.py

123 lines
3.8 KiB
Python
Raw Normal View History

from common import * # isort:skip
from apps.common.paths import HARDENED
2018-04-04 19:06:37 +00:00
if not utils.BITCOIN_ONLY:
from trezor.crypto import nem
2023-06-28 10:46:29 +00:00
from apps.nem.helpers import (
NEM_NETWORK_MAINNET,
NEM_NETWORK_MIJIN,
NEM_NETWORK_TESTNET,
check_path,
2023-06-28 10:46:29 +00:00
)
2018-04-04 19:06:37 +00:00
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
2018-04-04 19:06:37 +00:00
class TestNemAddress(unittest.TestCase):
def test_addresses(self):
2023-06-28 10:46:29 +00:00
pubkey = unhexlify(
"c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844"
)
2018-04-04 19:06:37 +00:00
address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4")
2018-04-04 19:06:37 +00:00
2023-06-28 10:46:29 +00:00
pubkey = unhexlify(
"114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810"
)
2018-04-04 19:06:37 +00:00
address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP")
2018-04-04 19:06:37 +00:00
def test_validate_address(self):
2023-06-28 10:46:29 +00:00
validity = nem.validate_address(
"NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4", NEM_NETWORK_MAINNET
)
2018-04-04 19:06:37 +00:00
self.assertTrue(validity)
2023-06-28 10:46:29 +00:00
validity = nem.validate_address(
"NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP", NEM_NETWORK_MAINNET
)
2018-04-04 19:06:37 +00:00
self.assertTrue(validity)
2023-06-28 10:46:29 +00:00
validity = nem.validate_address(
"TAU5HO3DRQZNELFEMZZTUKQEZGQ7IUAHKPO7OOLK", NEM_NETWORK_TESTNET
)
2018-04-04 19:06:37 +00:00
self.assertTrue(validity)
2023-06-28 10:46:29 +00:00
validity = nem.validate_address("nope", NEM_NETWORK_TESTNET)
2018-04-04 19:06:37 +00:00
self.assertFalse(validity)
# not valid on testnet
2023-06-28 10:46:29 +00:00
validity = nem.validate_address(
"NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP", NEM_NETWORK_TESTNET
)
2018-04-04 19:06:37 +00:00
self.assertFalse(validity)
def test_check_path(self):
# mainnet path:
2023-06-28 10:46:29 +00:00
self.assertTrue(
check_path(
[
44 | HARDENED,
43 | HARDENED,
0 | HARDENED,
0 | HARDENED,
0 | HARDENED,
],
NEM_NETWORK_MAINNET,
)
)
# should be valid on mijin as well:
2023-06-28 10:46:29 +00:00
self.assertTrue(
check_path(
[
44 | HARDENED,
43 | HARDENED,
0 | HARDENED,
0 | HARDENED,
0 | HARDENED,
],
NEM_NETWORK_MIJIN,
)
)
# testnet path:
2023-06-28 10:46:29 +00:00
self.assertTrue(
check_path(
[44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED],
NEM_NETWORK_TESTNET,
)
)
# short path (check_path does not validate pattern match):
self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED], NEM_NETWORK_MAINNET))
# testnet path on mainnet:
2023-06-28 10:46:29 +00:00
self.assertFalse(
check_path(
[44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED],
NEM_NETWORK_MAINNET,
)
)
# mainnet path on testnet:
2023-06-28 10:46:29 +00:00
self.assertFalse(
check_path(
[
44 | HARDENED,
43 | HARDENED,
0 | HARDENED,
0 | HARDENED,
0 | HARDENED,
],
NEM_NETWORK_TESTNET,
)
)
# path too short to extract SLIP44:
self.assertFalse(check_path([44 | HARDENED], NEM_NETWORK_TESTNET))
# unknown SLIP44:
self.assertFalse(check_path([44 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET))
# unhardened SLIP44:
self.assertFalse(check_path([44 | HARDENED, 43, 0], NEM_NETWORK_MAINNET))
2018-04-04 19:06:37 +00:00
2023-06-28 10:46:29 +00:00
if __name__ == "__main__":
2018-04-04 19:06:37 +00:00
unittest.main()