You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
8 years ago
|
from __future__ import print_function
|
||
|
|
||
11 years ago
|
import unittest
|
||
|
import common
|
||
|
import time
|
||
|
from trezorlib import tools
|
||
|
|
||
10 years ago
|
class TestBip32Speed(common.TrezorTest):
|
||
10 years ago
|
|
||
11 years ago
|
def test_public_ckd(self):
|
||
10 years ago
|
self.setup_mnemonic_nopin_nopassphrase()
|
||
11 years ago
|
|
||
10 years ago
|
self.client.get_address('Bitcoin', []) # to compute root node via BIP39
|
||
10 years ago
|
|
||
11 years ago
|
for depth in range(8):
|
||
|
start = time.time()
|
||
|
self.client.get_address('Bitcoin', range(depth))
|
||
|
delay = time.time() - start
|
||
10 years ago
|
expected = (depth + 1) * 0.26
|
||
8 years ago
|
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
|
||
11 years ago
|
self.assertLessEqual(delay, expected)
|
||
|
|
||
|
def test_private_ckd(self):
|
||
10 years ago
|
self.setup_mnemonic_nopin_nopassphrase()
|
||
11 years ago
|
|
||
10 years ago
|
self.client.get_address('Bitcoin', []) # to compute root node via BIP39
|
||
10 years ago
|
|
||
11 years ago
|
for depth in range(8):
|
||
|
start = time.time()
|
||
|
self.client.get_address('Bitcoin', range(-depth, 0))
|
||
|
delay = time.time() - start
|
||
10 years ago
|
expected = (depth + 1) * 0.26
|
||
8 years ago
|
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
|
||
11 years ago
|
self.assertLessEqual(delay, expected)
|
||
|
|
||
10 years ago
|
def test_cache(self):
|
||
|
self.setup_mnemonic_nopin_nopassphrase()
|
||
|
|
||
|
start = time.time()
|
||
10 years ago
|
for x in range(10):
|
||
10 years ago
|
self.client.get_address('Bitcoin', [x, 2, 3, 4, 5, 6, 7, 8])
|
||
|
nocache_time = time.time() - start
|
||
|
|
||
|
start = time.time()
|
||
10 years ago
|
for x in range(10):
|
||
10 years ago
|
self.client.get_address('Bitcoin', [1, 2, 3, 4, 5, 6, 7, x])
|
||
|
cache_time = time.time() - start
|
||
|
|
||
8 years ago
|
print("NOCACHE TIME", nocache_time)
|
||
|
print("CACHED TIME", cache_time)
|
||
10 years ago
|
|
||
|
# Cached time expected to be at least 2x faster
|
||
|
self.assertLessEqual(cache_time, nocache_time / 2.)
|
||
|
|
||
11 years ago
|
if __name__ == '__main__':
|
||
|
unittest.main()
|