mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
Passes first unit tests (against trezor-emu over transport_pipe).
WIP: Issue with console printing of protobuf messages (probably bug in protobuf for python3 itself). WIP: Disabled Bridge transport because of json_protobuf incompatibility with python3. WIP: Broken expectations of returned objects in unit tests
This commit is contained in:
parent
6ec2ff3eac
commit
64fadde3e0
@ -4,7 +4,7 @@ sys.path = ['../',] + sys.path
|
||||
from trezorlib.transport_pipe import PipeTransport
|
||||
from trezorlib.transport_hid import HidTransport
|
||||
from trezorlib.transport_socket import SocketTransportClient
|
||||
from trezorlib.transport_bridge import BridgeTransport
|
||||
#from trezorlib.transport_bridge import BridgeTransport
|
||||
|
||||
devices = HidTransport.enumerate()
|
||||
|
||||
|
@ -7,14 +7,17 @@ import unicodedata
|
||||
import json
|
||||
import getpass
|
||||
|
||||
import tools
|
||||
import mapping
|
||||
import messages_pb2 as proto
|
||||
import types_pb2 as types
|
||||
import protobuf_json
|
||||
from debuglink import DebugLink
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
from . import tools
|
||||
from . import mapping
|
||||
from . import messages_pb2 as proto
|
||||
from . import types_pb2 as types
|
||||
from .debuglink import DebugLink
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
from io import BytesIO
|
||||
unicode = lambda s, enc: BytesIO(bytes(s, enc))
|
||||
|
||||
# try:
|
||||
# from PIL import Image
|
||||
@ -44,7 +47,7 @@ def pprint(msg):
|
||||
if isinstance(msg, proto.FirmwareUpload):
|
||||
return "<%s> (%d bytes):\n" % (msg_class, msg_size)
|
||||
else:
|
||||
return "<%s> (%d bytes):\n%s" % (msg_class, msg_size, msg)
|
||||
return "<%s> (%d bytes):\n%s" % (msg_class, msg_size, '#FIXME') # msg)
|
||||
|
||||
def log(msg):
|
||||
sys.stderr.write("%s\n" % msg)
|
||||
|
@ -8,7 +8,7 @@ def button_press(yes_no):
|
||||
print("User pressed", '"y"' if yes_no else '"n"')
|
||||
|
||||
def pprint(msg):
|
||||
return "<%s> (%d bytes):\n%s" % (msg.__class__.__name__, msg.ByteSize(), msg)
|
||||
return "<%s> (%d bytes):\n%s" % (msg.__class__.__name__, msg.ByteSize(), '#FIXME') # msg))
|
||||
|
||||
class DebugLink(object):
|
||||
def __init__(self, transport, pin_func=pin_info, button_func=button_press):
|
||||
|
@ -14,7 +14,7 @@ from google.protobuf import descriptor_pb2
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
import types_pb2
|
||||
from . import types_pb2
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
|
@ -33,7 +33,7 @@ __b58base = len(__b58chars)
|
||||
def b58encode(v):
|
||||
""" encode v, which is a string of bytes, to base58."""
|
||||
|
||||
long_value = 0L
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += (256 ** i) * ord(c)
|
||||
|
||||
@ -57,7 +57,7 @@ def b58encode(v):
|
||||
|
||||
def b58decode(v, length):
|
||||
""" decode v into a string of len bytes."""
|
||||
long_value = 0L
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += __b58chars.find(c) * (__b58base ** i)
|
||||
|
||||
|
@ -66,7 +66,7 @@ class Transport(object):
|
||||
"""
|
||||
ser = msg.SerializeToString()
|
||||
header = struct.pack(">HL", mapping.get_type(msg), len(ser))
|
||||
self._write("##%s%s" % (header, ser), msg)
|
||||
self._write(b"##" + header + ser, msg)
|
||||
|
||||
def read(self):
|
||||
"""
|
||||
@ -110,14 +110,14 @@ class Transport(object):
|
||||
# Align cursor to the beginning of the header ("##")
|
||||
c = read_f.read(1)
|
||||
i = 0
|
||||
while c != '#':
|
||||
while c != b"#":
|
||||
i += 1
|
||||
if i >= 64:
|
||||
# timeout
|
||||
raise Exception("Timed out while waiting for the magic character")
|
||||
c = read_f.read(1)
|
||||
|
||||
if read_f.read(1) != "#":
|
||||
if read_f.read(1) != b"#":
|
||||
# Second character must be # to be valid header
|
||||
raise Exception("Second magic character is broken")
|
||||
|
||||
|
@ -26,10 +26,10 @@ class PipeTransport(Transport):
|
||||
raise Exception("Not connected")
|
||||
|
||||
self.write_fd = os.open(self.filename_write, os.O_RDWR)#|os.O_NONBLOCK)
|
||||
self.write_f = os.fdopen(self.write_fd, 'w+')
|
||||
self.write_f = os.fdopen(self.write_fd, 'w+b', 0)
|
||||
|
||||
self.read_fd = os.open(self.filename_read, os.O_RDWR)#|os.O_NONBLOCK)
|
||||
self.read_f = os.fdopen(self.read_fd, 'rb')
|
||||
self.read_f = os.fdopen(self.read_fd, 'rb', 0)
|
||||
|
||||
def _close(self):
|
||||
self.read_f.close()
|
||||
|
@ -1,10 +1,16 @@
|
||||
import binascii
|
||||
import urllib2
|
||||
import json
|
||||
from decimal import Decimal
|
||||
# from filecache import filecache, DAY
|
||||
from . import types_pb2 as proto_types
|
||||
|
||||
try:
|
||||
# For Python 3.0 and later
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
# Fall back to Python 2's urllib2
|
||||
from urllib2 import urlopen
|
||||
|
||||
def insight_tx(url, rawdata=False):
|
||||
if not rawdata:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user