1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-28 02:18:20 +00:00
trezor-firmware/trezorlib/tests/device_tests/test_bip32_speed.py

74 lines
2.5 KiB
Python
Raw Normal View History

# This file is part of the Trezor project.
2017-01-03 18:40:05 +00:00
#
# Copyright (C) 2012-2018 SatoshiLabs and contributors
2017-01-03 18:40:05 +00:00
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
2017-01-03 18:40:05 +00:00
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import time
import pytest
from .common import TrezorTest
2017-06-23 19:31:42 +00:00
from trezorlib.tools import H_
2018-08-10 12:04:58 +00:00
from trezorlib import btc
class TestBip32Speed(TrezorTest):
2015-01-26 18:24:31 +00:00
def test_public_ckd(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', []) # to compute root node via BIP39
for depth in range(8):
start = time.time()
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', range(depth))
delay = time.time() - start
expected = (depth + 1) * 0.26
2016-05-05 01:16:17 +00:00
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
assert delay <= expected
def test_private_ckd(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', []) # to compute root node via BIP39
for depth in range(8):
start = time.time()
address_n = [H_(-i) for i in range(-depth, 0)]
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', address_n)
delay = time.time() - start
expected = (depth + 1) * 0.26
2016-05-05 01:16:17 +00:00
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
assert delay <= expected
@pytest.mark.skip_t2
2015-01-26 12:08:29 +00:00
def test_cache(self):
self.setup_mnemonic_nopin_nopassphrase()
start = time.time()
2015-01-26 18:24:31 +00:00
for x in range(10):
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', [x, 2, 3, 4, 5, 6, 7, 8])
2015-01-26 12:08:29 +00:00
nocache_time = time.time() - start
start = time.time()
2015-01-26 18:24:31 +00:00
for x in range(10):
2018-08-10 12:04:58 +00:00
btc.get_address(self.client, 'Bitcoin', [1, 2, 3, 4, 5, 6, 7, x])
2015-01-26 12:08:29 +00:00
cache_time = time.time() - start
2016-05-05 01:16:17 +00:00
print("NOCACHE TIME", nocache_time)
print("CACHED TIME", cache_time)
2015-01-26 12:08:29 +00:00
# Cached time expected to be at least 2x faster
assert cache_time <= nocache_time / 2.