tests: update to pytest, regenerate protobuf

pull/25/head
Pavol Rusnak 7 years ago
parent bab1303b1b
commit fe5b5c1940
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -31,6 +31,7 @@ addons:
install:
- pip3 install ed25519 pyblake2
- pip3 install flake8
- pip3 install pytest
- pip3 install ecdsa mnemonic protobuf requests
- pip3 install trezor

@ -19,13 +19,13 @@ async def get_seed(session_id: int) -> bytes:
async def compute_seed(session_id: int) -> bytes:
from trezor.messages.FailureType import Other
from trezor.messages.FailureType import ProcessError
from .request_passphrase import protect_by_passphrase
from .request_pin import protect_by_pin
from . import storage
if not storage.is_initialized():
raise wire.FailureError(Other, 'Device is not initialized')
raise wire.FailureError(ProcessError, 'Device is not initialized')
await protect_by_pin(session_id)

@ -5,7 +5,7 @@ from trezor.utils import unimport
@unimport
async def layout_apply_settings(session_id, msg):
from trezor.messages.Success import Success
from trezor.messages.FailureType import Other
from trezor.messages.FailureType import ProcessError
from trezor.ui.text import Text
from ..common.confirm import require_confirm
from ..common.request_pin import protect_by_pin
@ -15,10 +15,10 @@ async def layout_apply_settings(session_id, msg):
if msg.homescreen is not None:
raise wire.FailureError(
Other, 'ApplySettings.homescreen is not supported')
ProcessError, 'ApplySettings.homescreen is not supported')
if msg.label is None and msg.language is None and msg.use_passphrase is None:
raise wire.FailureError(Other, 'No setting provided')
raise wire.FailureError(ProcessError, 'No setting provided')
if msg.label is not None:
await require_confirm(session_id, Text(

@ -6,7 +6,7 @@ from trezor.utils import unimport
async def layout_load_device(session_id, msg):
from trezor.crypto import bip39
from trezor.messages.Success import Success
from trezor.messages.FailureType import UnexpectedMessage, Other
from trezor.messages.FailureType import UnexpectedMessage, ProcessError
from trezor.ui.text import Text
from ..common.confirm import require_confirm
from ..common import storage
@ -15,10 +15,10 @@ async def layout_load_device(session_id, msg):
raise wire.FailureError(UnexpectedMessage, 'Already initialized')
if msg.node is not None:
raise wire.FailureError(Other, 'LoadDevice.node is not supported')
raise wire.FailureError(ProcessError, 'LoadDevice.node is not supported')
if not msg.skip_checksum and not bip39.check(msg.mnemonic):
raise wire.FailureError(Other, 'Mnemonic is not valid')
raise wire.FailureError(ProcessError, 'Mnemonic is not valid')
await require_confirm(session_id, Text(
'Loading seed', ui.ICON_RESET,

@ -28,7 +28,7 @@ async def layout_reset_device(session_id, msg):
if msg.strength not in (128, 192, 256):
raise wire.FailureError(
FailureType.Other, 'Invalid strength (has to be 128, 192 or 256 bits)')
FailureType.ProcessError, 'Invalid strength (has to be 128, 192 or 256 bits)')
if storage.is_initialized():
raise wire.FailureError(

@ -3,7 +3,7 @@ from trezor.utils import unimport
from trezor.messages.wire_types import \
GetPublicKey, GetAddress, \
GetEntropy, \
SignTx, EstimateTxSize, \
SignTx, \
SignMessage, VerifyMessage, \
SignIdentity, \
CipherKeyValue
@ -33,15 +33,6 @@ def dispatch_SignTx(*args, **kwargs):
return sign_tx(*args, **kwargs)
@unimport
async def dispatch_EstimateTxSize(session_id, msg):
from trezor.messages.TxSize import TxSize
from .sign_tx.signing import estimate_tx_size
m = TxSize()
m.tx_size = estimate_tx_size(msg.inputs_count, msg.outputs_count)
return m
@unimport
def dispatch_SignMessage(*args, **kwargs):
from .sign_message import layout_sign_message
@ -71,7 +62,6 @@ def boot():
register(GetAddress, protobuf_workflow, dispatch_GetAddress)
register(GetEntropy, protobuf_workflow, dispatch_GetEntropy)
register(SignTx, protobuf_workflow, dispatch_SignTx)
register(EstimateTxSize, protobuf_workflow, dispatch_EstimateTxSize)
register(SignMessage, protobuf_workflow, dispatch_SignMessage)
register(VerifyMessage, protobuf_workflow, dispatch_VerifyMessage)
register(SignIdentity, protobuf_workflow, dispatch_SignIdentity)

@ -5,12 +5,12 @@ from trezor.utils import unimport
@unimport
async def layout_get_address(session_id, msg):
from trezor.messages.Address import Address
from trezor.messages.FailureType import Other
from trezor.messages.FailureType import ProcessError
from ..common import coins
from ..common import seed
if msg.multisig:
raise wire.FailureError(Other, 'GetAddress.multisig is unsupported')
raise wire.FailureError(ProcessError, 'GetAddress.multisig is unsupported')
address_n = msg.address_n or ()
coin_name = msg.coin_name or 'Bitcoin'

@ -173,7 +173,7 @@ async def sign_tx(tx: SignTx, root):
txo = await request_tx_output(tx_req, o)
if output_is_change(txo):
if change_out != 0:
raise SigningError(FailureType.Other,
raise SigningError(FailureType.ProcessError,
'Only one change output is valid')
change_out = txo.amount
elif txo.script_type != OutputScriptType.PAYTOOPRETURN:
@ -249,7 +249,7 @@ async def sign_tx(tx: SignTx, root):
# check the control digests
if get_tx_hash(h_first, False) != get_tx_hash(h_second, False):
raise SigningError(FailureType.Other,
raise SigningError(FailureType.ProcessError,
'Transaction has changed during signing')
# compute the signature from the tx digest
@ -321,7 +321,7 @@ async def get_prevtx_output_value(tx_req: TxRequest, prev_hash: bytes, prev_inde
write_uint32(txh, tx.lock_time)
if get_tx_hash(txh, True, True) != prev_hash:
raise SigningError(FailureType.Other,
raise SigningError(FailureType.ProcessError,
'Encountered invalid prev_hash')
return total_out

@ -0,0 +1,9 @@
# Automatically generated by pb2py
import protobuf as p
class ApplyFlags(p.MessageType):
FIELDS = {
1: ('flags', p.UVarintType, 0),
}
MESSAGE_WIRE_TYPE = 28

@ -0,0 +1,6 @@
# Automatically generated by pb2py
import protobuf as p
class BackupDevice(p.MessageType):
MESSAGE_WIRE_TYPE = 34

@ -13,4 +13,5 @@ class CoinType(p.MessageType):
9: ('xpub_magic', p.UVarintType, 0), # default=76067358
10: ('xprv_magic', p.UVarintType, 0), # default=76066276
11: ('segwit', p.BoolType, 0),
12: ('forkid', p.UVarintType, 0),
}

@ -0,0 +1,10 @@
# Automatically generated by pb2py
import protobuf as p
class EthereumMessageSignature(p.MessageType):
FIELDS = {
1: ('address', p.BytesType, 0),
2: ('signature', p.BytesType, 0),
}
MESSAGE_WIRE_TYPE = 66

@ -0,0 +1,10 @@
# Automatically generated by pb2py
import protobuf as p
class EthereumSignMessage(p.MessageType):
FIELDS = {
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('message', p.BytesType, 0), # required
}
MESSAGE_WIRE_TYPE = 64

@ -0,0 +1,11 @@
# Automatically generated by pb2py
import protobuf as p
class EthereumVerifyMessage(p.MessageType):
FIELDS = {
1: ('address', p.BytesType, 0),
2: ('signature', p.BytesType, 0),
3: ('message', p.BytesType, 0),
}
MESSAGE_WIRE_TYPE = 65

@ -3,13 +3,13 @@ from micropython import const
UnexpectedMessage = const(1)
ButtonExpected = const(2)
SyntaxError = const(3)
DataError = const(3)
ActionCancelled = const(4)
PinExpected = const(5)
PinCancelled = const(6)
PinInvalid = const(7)
InvalidSignature = const(8)
Other = const(9)
ProcessError = const(9)
NotEnoughFunds = const(10)
NotInitialized = const(11)
FirmwareError = const(99)

@ -23,5 +23,7 @@ class Features(p.MessageType):
16: ('pin_cached', p.BoolType, 0),
17: ('passphrase_cached', p.BoolType, 0),
18: ('firmware_present', p.BoolType, 0),
19: ('needs_backup', p.BoolType, 0),
20: ('flags', p.UVarintType, 0),
}
MESSAGE_WIRE_TYPE = 17

@ -3,4 +3,7 @@ import protobuf as p
class FirmwareErase(p.MessageType):
FIELDS = {
1: ('length', p.UVarintType, 0),
}
MESSAGE_WIRE_TYPE = 6

@ -29,8 +29,11 @@ ClearSession = const(24)
ApplySettings = const(25)
ButtonRequest = const(26)
ButtonAck = const(27)
ApplyFlags = const(28)
GetAddress = const(29)
Address = const(30)
SelfTest = const(32)
BackupDevice = const(34)
EntropyRequest = const(35)
EntropyAck = const(36)
SignMessage = const(38)
@ -59,6 +62,9 @@ EthereumTxAck = const(60)
GetECDHSessionKey = const(61)
ECDHSessionKey = const(62)
SetU2FCounter = const(63)
EthereumSignMessage = const(64)
EthereumVerifyMessage = const(65)
EthereumMessageSignature = const(66)
DebugLinkDecision = const(100)
DebugLinkGetState = const(101)
DebugLinkState = const(102)

@ -12,5 +12,6 @@ class RecoveryDevice(p.MessageType):
6: ('enforce_wordlist', p.BoolType, 0),
8: ('type', p.UVarintType, 0),
9: ('u2f_counter', p.UVarintType, 0),
10: ('dry_run', p.BoolType, 0),
}
MESSAGE_WIRE_TYPE = 45

@ -11,5 +11,6 @@ class ResetDevice(p.MessageType):
5: ('language', p.UnicodeType, 0), # default=u'english'
6: ('label', p.UnicodeType, 0),
7: ('u2f_counter', p.UVarintType, 0),
8: ('skip_backup', p.BoolType, 0),
}
MESSAGE_WIRE_TYPE = 14

@ -0,0 +1,9 @@
# Automatically generated by pb2py
import protobuf as p
class SelfTest(p.MessageType):
FIELDS = {
1: ('payload', p.BytesType, 0),
}
MESSAGE_WIRE_TYPE = 32

@ -7,5 +7,6 @@ class SignMessage(p.MessageType):
1: ('address_n', p.UVarintType, p.FLAG_REPEATED),
2: ('message', p.BytesType, 0), # required
3: ('coin_name', p.UnicodeType, 0), # default=u'Bitcoin'
4: ('script_type', p.UVarintType, 0), # default=0
}
MESSAGE_WIRE_TYPE = 38

@ -16,4 +16,6 @@ class Storage(p.MessageType):
9: ('imported', p.BoolType, 0),
10: ('homescreen', p.BytesType, 0),
11: ('u2f_counter', p.UVarintType, 0),
12: ('needs_backup', p.BoolType, 0),
13: ('flags', p.UVarintType, 0),
}

@ -1,70 +1,76 @@
# Automatically generated by pb2py
from micropython import const
WordRequest = const(46)
DebugLinkMemoryWrite = const(112)
Address = const(30)
ApplyFlags = const(28)
ApplySettings = const(25)
BackupDevice = const(34)
ButtonAck = const(27)
MessageSignature = const(40)
EthereumAddress = const(57)
EthereumTxAck = const(60)
Ping = const(1)
EncryptedMessage = const(50)
DebugLinkStop = const(103)
EstimateTxSize = const(43)
GetPublicKey = const(11)
GetFeatures = const(55)
GetECDHSessionKey = const(61)
PinMatrixRequest = const(18)
ClearSession = const(24)
LoadDevice = const(13)
VerifyMessage = const(39)
EthereumSignTx = const(58)
PassphraseRequest = const(41)
TxAck = const(22)
ButtonRequest = const(26)
Cancel = const(20)
ChangePin = const(4)
CipherKeyValue = const(23)
CipheredKeyValue = const(48)
ClearSession = const(24)
DebugLinkDecision = const(100)
DebugLinkFlashErase = const(113)
DebugLinkGetState = const(101)
DebugLinkLog = const(104)
FirmwareErase = const(6)
TxRequest = const(21)
EthereumGetAddress = const(56)
DebugLinkMemory = const(111)
DebugLinkMemoryRead = const(110)
DebugLinkMemoryWrite = const(112)
DebugLinkState = const(102)
DebugLinkStop = const(103)
DecryptMessage = const(51)
DecryptedMessage = const(52)
ECDHSessionKey = const(62)
EncryptMessage = const(49)
EncryptedMessage = const(50)
Entropy = const(10)
EntropyAck = const(36)
EntropyRequest = const(35)
EstimateTxSize = const(43)
EthereumAddress = const(57)
EthereumGetAddress = const(56)
EthereumMessageSignature = const(66)
EthereumSignMessage = const(64)
EthereumSignTx = const(58)
EthereumTxAck = const(60)
EthereumTxRequest = const(59)
FirmwareUpload = const(7)
SignedIdentity = const(54)
EthereumVerifyMessage = const(65)
Failure = const(3)
EntropyRequest = const(35)
ApplySettings = const(25)
DebugLinkFlashErase = const(113)
Address = const(30)
Features = const(17)
FirmwareErase = const(6)
FirmwareRequest = const(8)
FirmwareUpload = const(7)
GetAddress = const(29)
GetECDHSessionKey = const(61)
GetEntropy = const(9)
GetFeatures = const(55)
GetPublicKey = const(11)
Initialize = const(0)
LoadDevice = const(13)
MessageSignature = const(40)
PassphraseAck = const(42)
PassphraseRequest = const(41)
PinMatrixAck = const(19)
PinMatrixRequest = const(18)
Ping = const(1)
PublicKey = const(12)
RecoveryDevice = const(45)
ResetDevice = const(14)
SelfTest = const(32)
SetU2FCounter = const(63)
SignIdentity = const(53)
SignMessage = const(38)
SignTx = const(15)
DebugLinkGetState = const(101)
FirmwareRequest = const(8)
Success = const(2)
ResetDevice = const(14)
WordAck = const(47)
SignedIdentity = const(54)
SimpleSignTx = const(16)
GetAddress = const(29)
Success = const(2)
TxAck = const(22)
TxRequest = const(21)
TxSize = const(44)
PassphraseAck = const(42)
SignMessage = const(38)
DecryptedMessage = const(52)
DecryptMessage = const(51)
GetEntropy = const(9)
EntropyAck = const(36)
VerifyMessage = const(39)
WipeDevice = const(5)
CipherKeyValue = const(23)
Features = const(17)
RecoveryDevice = const(45)
SignIdentity = const(53)
DebugLinkDecision = const(100)
CipheredKeyValue = const(48)
ButtonRequest = const(26)
PublicKey = const(12)
DebugLinkMemory = const(111)
Entropy = const(10)
Cancel = const(20)
DebugLinkMemoryRead = const(110)
EncryptMessage = const(49)
ECDHSessionKey = const(62)
WordAck = const(47)
WordRequest = const(46)

@ -18,8 +18,6 @@ cd ../tests/python-trezor/tests/device_tests
error=0
PYTHON="${PYTHON:-python3}"
: '
not passing:
@ -45,7 +43,6 @@ not passing:
for i in \
test_basic.py \
test_msg_cipherkeyvalue.py \
test_msg_estimatetxsize.py \
test_msg_ethereum_getaddress.py \
test_msg_getaddress.py \
test_msg_getentropy.py \
@ -60,7 +57,7 @@ for i in \
test_zerosig.py \
; do
if $PYTHON $i >/dev/null 2>/dev/null ; then
if pytest -q $i ; then
results+=("OK $i")
else
results+=("FAIL $i")

@ -139,7 +139,7 @@ def process_module(mod, genpath, indexfile, is_upy):
msg_types = __import__('pb2', globals(), locals(), [
'messages_pb2', ]).messages_pb2.MessageType.items()
for t, cls in types.items():
for t, cls in sorted(types.items()):
# Find message type for given class
msg_id = find_msg_type(msg_types, t)

Loading…
Cancel
Save