2017-01-03 18:40:05 +00:00
|
|
|
# This file is part of the TREZOR project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
|
|
|
|
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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 GNU Lesser General Public License
|
|
|
|
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-05-20 20:27:20 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-12-23 20:20:49 +00:00
|
|
|
from .common import *
|
2014-02-04 15:12:52 +00:00
|
|
|
import time
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2014-02-04 15:12:52 +00:00
|
|
|
|
2017-12-23 20:20:49 +00:00
|
|
|
class TestBip32Speed(TrezorTest):
|
2015-01-26 18:24:31 +00:00
|
|
|
|
2014-02-04 15:12:52 +00:00
|
|
|
def test_public_ckd(self):
|
2014-02-17 00:54:54 +00:00
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
2014-02-04 15:12:52 +00:00
|
|
|
|
2014-02-13 15:50:16 +00:00
|
|
|
self.client.get_address('Bitcoin', []) # to compute root node via BIP39
|
2014-02-11 20:03:17 +00:00
|
|
|
|
2014-02-04 15:12:52 +00:00
|
|
|
for depth in range(8):
|
|
|
|
start = time.time()
|
|
|
|
self.client.get_address('Bitcoin', range(depth))
|
|
|
|
delay = time.time() - start
|
2014-02-21 06:28:56 +00:00
|
|
|
expected = (depth + 1) * 0.26
|
2016-05-05 01:16:17 +00:00
|
|
|
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
|
2017-12-23 20:20:49 +00:00
|
|
|
assert delay <= expected
|
2014-02-04 15:12:52 +00:00
|
|
|
|
|
|
|
def test_private_ckd(self):
|
2014-02-17 00:54:54 +00:00
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
2014-02-04 15:12:52 +00:00
|
|
|
|
2014-02-13 15:50:16 +00:00
|
|
|
self.client.get_address('Bitcoin', []) # to compute root node via BIP39
|
2014-02-11 20:03:17 +00:00
|
|
|
|
2014-02-04 15:12:52 +00:00
|
|
|
for depth in range(8):
|
|
|
|
start = time.time()
|
|
|
|
self.client.get_address('Bitcoin', range(-depth, 0))
|
|
|
|
delay = time.time() - start
|
2014-02-21 06:28:56 +00:00
|
|
|
expected = (depth + 1) * 0.26
|
2016-05-05 01:16:17 +00:00
|
|
|
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
|
2017-12-23 20:20:49 +00:00
|
|
|
assert delay <= expected
|
2014-02-04 15:12:52 +00:00
|
|
|
|
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):
|
2015-01-26 12:08:29 +00:00
|
|
|
self.client.get_address('Bitcoin', [x, 2, 3, 4, 5, 6, 7, 8])
|
|
|
|
nocache_time = time.time() - start
|
|
|
|
|
|
|
|
start = time.time()
|
2015-01-26 18:24:31 +00:00
|
|
|
for x in range(10):
|
2015-01-26 12:08:29 +00:00
|
|
|
self.client.get_address('Bitcoin', [1, 2, 3, 4, 5, 6, 7, x])
|
|
|
|
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
|
2017-12-23 20:20:49 +00:00
|
|
|
assert cache_time <= nocache_time / 2.
|