mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-19 09:36:06 +00:00
fix path validation and update unit tests
This commit is contained in:
parent
c588d0b4f3
commit
da7bb8abf8
@ -47,15 +47,16 @@ def validate_full_path(path: list) -> bool:
|
||||
where `a` is an account index from 0 to 1 000 000.
|
||||
"""
|
||||
length = len(path)
|
||||
print(path)
|
||||
if length < 3 or length > 4:
|
||||
return False
|
||||
if path[0] != 44 | HARDENED:
|
||||
return False
|
||||
if path[1] != 1729 | HARDENED:
|
||||
return False
|
||||
if path[2] < HARDENED or path[2] > 1000000 | HARDENED:
|
||||
if length == 3 and (path[2] < HARDENED or path[2] > 1000000 | HARDENED):
|
||||
return False
|
||||
if length > 3 and (path[3] < HARDENED or path[3] > 1000000 | HARDENED):
|
||||
if length == 4 and (path[2] != 0 | HARDENED or path[3] < HARDENED or path[3] > 1000000 | HARDENED):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -46,10 +46,11 @@ class TestTezosAddress(unittest.TestCase):
|
||||
[44 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0],
|
||||
[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],
|
||||
[44 | HARDENED, 1729 | HARDENED, 1 | HARDENED, 1 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 9999000 | HARDENED],
|
||||
[44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 0],
|
||||
[1 | HARDENED, 1 | HARDENED, 1 | HARDENED],
|
||||
@ -58,6 +59,9 @@ class TestTezosAddress(unittest.TestCase):
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 3 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 9 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 0 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 3 | HARDENED],
|
||||
[44 | HARDENED, 1729 | HARDENED, 0 | HARDENED, 9 | HARDENED],
|
||||
]
|
||||
|
||||
for path in incorrect_paths:
|
||||
|
@ -4,9 +4,8 @@ from common import *
|
||||
from trezor.messages import TezosContractType
|
||||
from trezor.messages.TezosContractID import TezosContractID
|
||||
|
||||
from apps.tezos.helpers import base58_decode_check, base58_encode_check
|
||||
from apps.tezos.helpers import base58_decode_check, base58_encode_check, write_bool
|
||||
from apps.tezos.sign_tx import (
|
||||
_encode_bool,
|
||||
_encode_contract_id,
|
||||
_encode_data_with_bool_prefix,
|
||||
_encode_zarith,
|
||||
@ -35,11 +34,11 @@ class TestTezosEncoding(unittest.TestCase):
|
||||
|
||||
def test_tezos_encode_bool(self):
|
||||
w = bytearray()
|
||||
_encode_bool(w, True)
|
||||
write_bool(w, True)
|
||||
self.assertEqual(bytes(w), bytes([255]))
|
||||
|
||||
w = bytearray()
|
||||
_encode_bool(w, False)
|
||||
write_bool(w, False)
|
||||
self.assertEqual(bytes(w), bytes([0]))
|
||||
|
||||
def test_tezos_encode_contract_id(self):
|
||||
|
Loading…
Reference in New Issue
Block a user