move device (=TREZOR) tests to tests/device_tests, create tests/unit_tests for unit tests

pull/25/head
Pavol Rusnak 8 years ago
parent ec966a0111
commit 06cedd2150
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -2,9 +2,13 @@ from __future__ import print_function
import unittest
from trezorlib.client import TrezorClient, TrezorDebugClient
from trezorlib.tx_api import TxApiBitcoin
from trezorlib import tx_api
import config
tx_api.cache_dir = '../txcache'
class TrezorTest(unittest.TestCase):
def setUp(self):
transport = config.TRANSPORT(*config.TRANSPORT_ARGS, **config.TRANSPORT_KWARGS)
@ -14,7 +18,7 @@ class TrezorTest(unittest.TestCase):
self.client.set_debuglink(debug_transport)
else:
self.client = TrezorClient(transport)
self.client.set_tx_api(TxApiBitcoin)
self.client.set_tx_api(tx_api.TxApiBitcoin)
# self.client.set_buttonwait(3)
# 1 2 3 4 5 6 7 8 9 10 11 12

@ -1,7 +1,7 @@
from __future__ import print_function
import sys
sys.path = ['../',] + sys.path
sys.path = ['../../'] + sys.path
from trezorlib.transport_pipe import PipeTransport
from trezorlib.transport_hid import HidTransport

@ -0,0 +1,8 @@
from __future__ import print_function
import sys
sys.path = ['../../'] + sys.path
from trezorlib import tx_api
tx_api.cache_dir = '../txcache'

@ -0,0 +1,21 @@
import common
import unittest
from trezorlib import ckd_public
class TestCkdPublic(unittest.TestCase):
def test_ckd(self):
xpub1 = 'xpub661MyMwAqRbcEnKbXcCqD2GT1di5zQxVqoHPAgHNe8dv5JP8gWmDproS6kFHJnLZd23tWevhdn4urGJ6b264DfTGKr8zjmYDjyDTi9U7iyT'
node1 = ckd_public.deserialize(xpub1)
node2 = ckd_public.public_ckd(node1, [0])
node3 = ckd_public.public_ckd(node1, [0, 0])
xpub2 = ckd_public.serialize(node2)
xpub3 = ckd_public.serialize(node3)
self.assertEqual(xpub2, 'xpub67ymn1YTdE2iSGXitxUEZeUdHF2FsejJATroeAxVMtzTAK9o3vjmFLrE7TqE1X76iobkVc3p8h3gNzNRTwPeQGYW3CCmYCG8n5ThVkXaQzs')
self.assertEqual(xpub3, 'xpub6BD2MwdEg5PJPqiGetL9DJs7oDo6zP3XwAABX2vAQb5eLpY3QhHGUEm25V4nkQhnFMsqEVfTwtax2gKz8EFrt1PnBN6xQjE9jGmWDR6modu')
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,18 @@
import common
import unittest
from trezorlib.protobuf_json import json2pb, pb2json
import trezorlib.messages_pb2 as msg
class TestProtobufJson(unittest.TestCase):
def test_pb2json(self):
m = msg.Features()
m.device_id = '1234'
j = pb2json(m)
self.assertEqual(j, {'device_id': u'1234'} )
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,27 @@
import common
import unittest
from trezorlib.tx_api import TxApiBitcoin, TxApiTestnet
class TestTxApi(unittest.TestCase):
def test_get(self):
tx = TxApiBitcoin.get_tx('39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5')
tx = TxApiBitcoin.get_tx('54aa5680dea781f45ebb536e53dffc526d68c0eb5c00547e323b2c32382dfba3')
tx = TxApiBitcoin.get_tx('58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e')
tx = TxApiBitcoin.get_tx('6189e3febb5a21cee8b725aa1ef04ffce7e609448446d3a8d6f483c634ef5315')
tx = TxApiBitcoin.get_tx('a6e2829d089cee47e481b1a753a53081b40738cc87e38f1d9b23ab57d9ad4396')
tx = TxApiBitcoin.get_tx('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52')
tx = TxApiBitcoin.get_tx('c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb')
tx = TxApiBitcoin.get_tx('c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c')
tx = TxApiBitcoin.get_tx('d1d08ea63255af4ad16b098e9885a252632086fa6be53301521d05253ce8a73d')
tx = TxApiBitcoin.get_tx('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
tx = TxApiBitcoin.get_tx('e4bc1ae5e5007a08f2b3926fe11c66612e8f73c6b00c69c7027213b84d259be3')
tx = TxApiTestnet.get_tx('6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54')
tx = TxApiTestnet.get_tx('d6da21677d7cca5f42fbc7631d062c9ae918a0254f7c6c22de8e8cb7fd5b8236')
if __name__ == '__main__':
unittest.main()

@ -23,6 +23,7 @@ import requests
import json
from . import types_pb2 as proto_types
cache_dir = None
class TxApi(object):
@ -31,21 +32,24 @@ class TxApi(object):
self.url = url
def fetch_json(self, url, resource, resourceid):
cachefile = 'txcache/%s_%s_%s.json' % (self.network, resource, resourceid)
try: # looking into cache first
j = json.load(open(cachefile))
return j
except:
pass
global cache_dir
if cache_dir:
cache_file = '%s/%s_%s_%s.json' % (cache_dir, self.network, resource, resourceid)
try: # looking into cache first
j = json.load(open(cache_file))
return j
except:
pass
try:
r = requests.get('%s/%s/%s' % (self.url, resource, resourceid), headers={'User-agent': 'Mozilla/5.0'})
j = r.json()
except:
raise Exception('URL error: %s' % url)
try: # saving into cache
json.dump(j, open(cachefile, 'w'))
except:
pass
if cache_file:
try: # saving into cache
json.dump(j, open(cachefile, 'w'))
except:
pass
return j
def get_tx(self, txhash):
@ -91,7 +95,10 @@ class TxApiInsight(TxApi):
if joinsplit_cnt == 0:
t.extra_data =b'\x00'
else:
extra_data_len = 1 + joinsplit_cnt * 1802 + 32 + 64 # we assume cnt < 253, so we can treat varIntLen(cnt) as 1
if joinsplit_cnt >= 253:
# we assume cnt < 253, so we can treat varIntLen(cnt) as 1
raise ValueError('Too many joinsplits')
extra_data_len = 1 + joinsplit_cnt * 1802 + 32 + 64
raw = fetch_json(self.url, 'rawtx', txhash)
raw = binascii.unhexlify(raw['rawtx'])
t.extra_data = raw[-extra_data_len:]

Loading…
Cancel
Save