Skip to content

Commit

Permalink
fixup! core/tests: add unit tests for new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
matejcik committed Jul 24, 2020
1 parent 7289d84 commit 02fcf99
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/tests/test_apps.common.keychain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from common import *

from mock_storage import mock_storage

from storage import cache
import storage.device
from apps.common import HARDENED
from apps.common.paths import path_is_hardened
from apps.common.keychain import LRUCache, Keychain, with_slip44_keychain, get_keychain
Expand All @@ -9,13 +12,13 @@


class TestKeychain(unittest.TestCase):
@mock_storage
def test_verify_path(self):
n = [
[44 | HARDENED, 134 | HARDENED],
[44 | HARDENED, 11 | HARDENED],
]
keychain = Keychain(b"", "secp256k1", n)
unrestricted_keychain = Keychain(b"", "secp256k1", n, restrict=False)

correct = (
[44 | HARDENED, 134 | HARDENED],
Expand All @@ -24,18 +27,20 @@ def test_verify_path(self):
)
for path in correct:
keychain.verify_path(path)
unrestricted_keychain.verify_path(path)

fails = [
fails = (
[44 | HARDENED, 134], # path does not match
[44, 134], # path does not match (non-hardened items)
[44 | HARDENED, 13 | HARDENED], # invalid second item
]
)
for f in fails:
with self.assertRaises(wire.DataError):
keychain.verify_path(f)
# unrestricted keychain allows all paths
unrestricted_keychain.verify_path(f)

# turn off restrictions
storage.device.set_unsafe_prompts_allowed(True)
for path in correct + fails:
keychain.verify_path(path)

def test_verify_path_special_ed25519(self):
n = [[44 | HARDENED, 134 | HARDENED]]
Expand Down

0 comments on commit 02fcf99

Please sign in to comment.