2018-09-11 11:32:15 +00:00
|
|
|
from common import *
|
|
|
|
|
2018-08-30 11:45:09 +00:00
|
|
|
from apps.common.paths import HARDENED
|
2018-07-27 12:05:00 +00:00
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
if not utils.BITCOIN_ONLY:
|
|
|
|
from apps.tezos.sign_tx import _get_address_from_contract
|
|
|
|
from apps.tezos.helpers import validate_full_path
|
|
|
|
from trezor.messages import TezosContractType
|
|
|
|
from trezor.messages.TezosContractID import TezosContractID
|
|
|
|
|
2018-07-27 12:05:00 +00:00
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
2018-07-27 12:05:00 +00:00
|
|
|
class TestTezosAddress(unittest.TestCase):
|
|
|
|
def test_get_address_from_contract(self):
|
|
|
|
contracts = [
|
|
|
|
TezosContractID(
|
|
|
|
tag=TezosContractType.Implicit,
|
2018-09-11 11:32:15 +00:00
|
|
|
hash=unhexlify("0090ec585b4d5fa39b20213e46b232cc57a4cfab4b"),
|
2018-07-27 12:05:00 +00:00
|
|
|
),
|
|
|
|
TezosContractID(
|
|
|
|
tag=TezosContractType.Implicit,
|
2018-09-11 11:32:15 +00:00
|
|
|
hash=unhexlify("017dfb3fef44082eca8cd3eccebd77db44633ffc9e"),
|
2018-07-27 12:05:00 +00:00
|
|
|
),
|
|
|
|
TezosContractID(
|
|
|
|
tag=TezosContractType.Implicit,
|
2018-09-11 11:32:15 +00:00
|
|
|
hash=unhexlify("02c1fc1b7e503825068ff4fe2f8916f98af981eab1"),
|
2018-07-27 12:05:00 +00:00
|
|
|
),
|
|
|
|
TezosContractID(
|
|
|
|
tag=TezosContractType.Originated,
|
2018-09-11 11:32:15 +00:00
|
|
|
hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00"),
|
|
|
|
),
|
2018-07-27 12:05:00 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
outputs = [
|
|
|
|
"tz1YrK8Hqt6GAPYRHAaeJmhETYyPSQCHTrkj",
|
|
|
|
"tz2KoN7TFjhp96V2XikqYSGyDmVVUHXvkzko",
|
|
|
|
"tz3e1k3QzCwEbRZrfHCwT3Npvw1rezmMQArY",
|
2018-09-11 11:32:15 +00:00
|
|
|
"KT1HpwLq2AjZgEQspiSnYmdtaHy4NgXw6BDC",
|
2018-07-27 12:05:00 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for i, contract in enumerate(contracts):
|
|
|
|
self.assertEqual(_get_address_from_contract(contract), outputs[i])
|
|
|
|
|
2018-08-30 11:45:09 +00:00
|
|
|
def test_paths(self):
|
|
|
|
# 44'/1729'/a' is correct
|
|
|
|
incorrect_paths = [
|
|
|
|
[44 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0],
|
2019-04-18 10:32:43 +00:00
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0],
|
2018-08-30 11:45:09 +00:00
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 1, 0],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0, 0],
|
2019-04-18 10:32:43 +00:00
|
|
|
[44 | HARDENED, 1729 | HARDENED, 1 | HARDENED, 1 | HARDENED],
|
2018-08-30 11:45:09 +00:00
|
|
|
[44 | HARDENED, 1729 | HARDENED, 9999000 | HARDENED],
|
|
|
|
[44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0],
|
|
|
|
[1 | HARDENED, 1 | HARDENED, 1 | HARDENED],
|
|
|
|
]
|
|
|
|
correct_paths = [
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 3 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 9 | HARDENED],
|
2019-04-18 10:32:43 +00:00
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 3 | HARDENED],
|
|
|
|
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 9 | HARDENED],
|
2018-08-30 11:45:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for path in incorrect_paths:
|
|
|
|
self.assertFalse(validate_full_path(path))
|
|
|
|
|
|
|
|
for path in correct_paths:
|
|
|
|
self.assertTrue(validate_full_path(path))
|
|
|
|
|
2018-07-27 12:05:00 +00:00
|
|
|
|
2018-09-11 11:32:15 +00:00
|
|
|
if __name__ == "__main__":
|
2018-07-27 12:05:00 +00:00
|
|
|
unittest.main()
|