From 77766d2d0fe3b4d51c77dd67208267a75f7d3e0a Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 10 May 2018 13:33:03 +0200 Subject: [PATCH 01/28] tests/device/eth: known/unknown token test --- .../device_tests/test_msg_ethereum_signtx.py | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py b/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py index 825848ecca..9df236d0d1 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py @@ -22,7 +22,42 @@ from trezorlib import messages as proto class TestMsgEthereumSigntx(TrezorTest): - def test_ethereum_signtx_erc20_token(self): + def test_ethereum_signtx_known_erc20_token(self): + self.setup_mnemonic_nopin_nopassphrase() + + with self.client: + self.client.set_expected_responses([ + proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), + proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), + proto.EthereumTxRequest(data_length=None), + ]) + + data = bytearray() + # method id signalizing `transfer(address _to, uint256 _value)` function + data.extend(unhexlify('a9059cbb')) + # 1st function argument (to - the receiver) + data.extend(unhexlify('000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b')) + # 2nd function argument (value - amount to be transferred) + data.extend(unhexlify('000000000000000000000000000000000000000000000000000000000bebc200')) + # 200 000 000 in dec, divisibility of ADT = 9, trezor1 displays 0.2 ADT, Trezor T 200 000 000 Wei ADT + + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( + n=[0, 0], + nonce=0, + gas_price=20, + gas_limit=20, + # ADT token address + to=b'\xd0\xd6\xd6\xc5\xfe\x4a\x67\x7d\x34\x3c\xc4\x33\x53\x6b\xb7\x17\xba\xe1\x67\xdd', + chain_id=1, + # value needs to be 0, token value is set in the contract (data) + value=0, + data=data) + + # taken from T1 might not be 100% correct but still better than nothing + assert hexlify(sig_r) == b'75cf48fa173d8ceb68af9e4fb6b78ef69e6ed5e7679ba6f8e3e91d74b2fb0f96' + assert hexlify(sig_s) == b'65de4a8c35263b2cfff3954b12146e8e568aa67a1c2461d6865e74ef75c7e190' + + def test_ethereum_signtx_unknown_erc20_token(self): self.setup_mnemonic_nopin_nopassphrase() with self.client: @@ -39,22 +74,23 @@ class TestMsgEthereumSigntx(TrezorTest): data.extend(unhexlify('000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b')) # 2nd function argument (value - amount to be transferred) data.extend(unhexlify('0000000000000000000000000000000000000000000000000000000000000123')) + # since this token is unknown trezor should display "unknown token value" sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( n=[0, 0], nonce=0, gas_price=20, gas_limit=20, - # ALTS token address - to=b'\x63\x8a\xc1\x49\xea\x8e\xf9\xa1\x28\x6c\x41\xb9\x77\x01\x7a\xa7\x35\x9e\x6c\xfa', + # unknown token address (Grzegorz Brzęczyszczykiewicz Token) + to=b'\xfc\x6b\x5d\x6a\xf8\xa1\x32\x58\xf7\xcb\xd0\xd3\x9e\x11\xb3\x5e\x01\xa3\x2f\x93', chain_id=1, # value needs to be 0, token value is set in the contract (data) value=0, data=data) # taken from T1 might not be 100% correct but still better than nothing - assert hexlify(sig_r) == b'28bf1b621be9a85d2905fa36511dfbd52ec4b67ba4ad6cb2bd08753c72b93b77' - assert hexlify(sig_s) == b'2fa605244f80a56cb438df55eb9835489288ec2c0ac0280ada2ccaccfe2b7e38' + assert hexlify(sig_r) == b'1707471fbf632e42d18144157aaf4cde101cd9aa9782ad8e30583cfc95ddeef6' + assert hexlify(sig_s) == b'3d2e52ba5904a4bf131abde3f79db826199f5d6f4d241d531d7e8a30a3b9cfd9' def test_ethereum_signtx_nodata(self): self.setup_mnemonic_nopin_nopassphrase() From d57fe3358237e285b99aa51ffcb12feb808392ca Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 14:09:39 +0200 Subject: [PATCH 02/28] tests/device/stellar: sign message --- .../test_msg_stellar_sign_message.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 trezorlib/tests/device_tests/test_msg_stellar_sign_message.py diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py new file mode 100644 index 0000000000..f754cb474a --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py @@ -0,0 +1,31 @@ +# This file is part of the TREZOR project. +# +# 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 . + +from .common import TrezorTest +from .conftest import TREZOR_VERSION +from binascii import hexlify +import pytest + + +@pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") +class TestMsgStellarSignMessage(TrezorTest): + + def test_stellar_sign_message(self): + self.setup_mnemonic_nopin_nopassphrase() + + msg = 'Hello world!' + response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) + assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' + assert hexlify(response.signature) == b'3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004' From f97815f69a6a515d0e7ae50554d6f78f1597edaf Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 15:16:26 +0200 Subject: [PATCH 03/28] vendor: trezor-common updated --- vendor/trezor-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/trezor-common b/vendor/trezor-common index 44dfb07cfa..b91db285ba 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 44dfb07cfaafffada4b2ce0d15ba1d90d17cf35e +Subproject commit b91db285ba8947d6c65a6a807fba87ebc1d43f5d From 22560128fe199cbcbc1d0aa14caa78929f9d22c2 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 15:17:13 +0200 Subject: [PATCH 04/28] stellar: StellarSignMessage.message is bytes --- trezorlib/messages/StellarSignMessage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trezorlib/messages/StellarSignMessage.py b/trezorlib/messages/StellarSignMessage.py index 190a3dd11e..069908c2fa 100644 --- a/trezorlib/messages/StellarSignMessage.py +++ b/trezorlib/messages/StellarSignMessage.py @@ -11,13 +11,13 @@ class StellarSignMessage(p.MessageType): MESSAGE_WIRE_TYPE = 204 FIELDS = { 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), - 2: ('message', p.UnicodeType, 0), + 2: ('message', p.BytesType, 0), } def __init__( self, address_n: List[int] = None, - message: str = None + message: bytes = None ) -> None: self.address_n = address_n if address_n is not None else [] self.message = message From bb74950e236b94370ca457e994e585e558c62a89 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 15:33:57 +0200 Subject: [PATCH 05/28] stellar: message is normalized before sign/verify --- trezorlib/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trezorlib/client.py b/trezorlib/client.py index 0479cf10bb..92710d87c9 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -1216,9 +1216,11 @@ class ProtocolMixin(object): @expect(proto.StellarMessageSignature) def stellar_sign_message(self, address_n, message): + message = normalize_nfc(message) return self.call(proto.StellarSignMessage(address_n=address_n, message=message)) def stellar_verify_message(self, pubkey_bytes, signature, message): + message = normalize_nfc(message) resp = self.call(proto.StellarVerifyMessage(public_key=pubkey_bytes, message=message, signature=signature)) return isinstance(resp, proto.Success) From 3ee3083e8c7f230fd2e403be2e8de439b42a54e3 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 16:52:59 +0200 Subject: [PATCH 06/28] tests/device/stellar: verify message --- .../test_msg_stellar_sign_message.py | 5 ++ .../test_msg_stellar_verify_message.py | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 trezorlib/tests/device_tests/test_msg_stellar_verify_message.py diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py index f754cb474a..29af3c2152 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py @@ -29,3 +29,8 @@ class TestMsgStellarSignMessage(TrezorTest): response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' assert hexlify(response.signature) == b'3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004' + + msg = 'LongMessage ' * 80 # but shorter than 1024 + response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) + assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' + assert hexlify(response.signature) == b'c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507' diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py new file mode 100644 index 0000000000..b43fa124e6 --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py @@ -0,0 +1,70 @@ +# This file is part of the TREZOR project. +# +# 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 . + +from .common import TrezorTest +from .conftest import TREZOR_VERSION +from binascii import unhexlify, hexlify +from trezorlib import messages as proto +from trezorlib.client import CallException +import pytest + + +# @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") +class TestMsgStellarVerifyMessage(TrezorTest): + + def test_stellar_verify_message(self): + self.setup_mnemonic_nopin_nopassphrase() + + msg = 'Hello world!' + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004') + response = self.client.stellar_verify_message(pubkey, signature, msg) + assert response is True + + msg = 'LongMessage ' * 80 # but shorter than 1024 + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507') + response = self.client.stellar_verify_message(pubkey, signature, msg) + assert response is True + + def test_stellar_verify_message_invalid(self): + msg = 'abc' + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('0000000000000000') # invalid length + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False + + # invalid signature + signature = unhexlify('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False + + # invalid pubkey + pubkey = unhexlify('00') + signature = unhexlify('00') + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False From 277296be905767e4c646486c5c6eaa2bf50dbfda Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Wed, 16 May 2018 15:04:00 +0200 Subject: [PATCH 07/28] tests/stellar: verify marked as not passing on T2 --- trezorlib/tests/device_tests/test_msg_stellar_verify_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py index b43fa124e6..c3f65ad014 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py @@ -21,7 +21,7 @@ from trezorlib.client import CallException import pytest -# @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") +@pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") class TestMsgStellarVerifyMessage(TrezorTest): def test_stellar_verify_message(self): From e656bbf0725ec7d9147d26cb5084ddff5370a16b Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Wed, 16 May 2018 16:00:08 +0200 Subject: [PATCH 08/28] stellar: xdr parse move to trezorctl; client works with messages --- trezorctl | 7 ++--- trezorlib/client.py | 6 ++--- .../test_msg_stellar_sign_transaction.py | 26 +++++++++++++++---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/trezorctl b/trezorctl index edb15fb23d..584bc01bc4 100755 --- a/trezorctl +++ b/trezorctl @@ -1013,14 +1013,15 @@ def stellar_verify_message(connect, address, message_is_b64, signatureb64, messa @cli.command(help='Sign a base64-encoded transaction envelope') @click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix") -@click.option('-n', '--network-passphrase', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'") +@click.option('-n', '--network-passphrase', default='Public Global Stellar Network ; September 2015', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'") @click.argument('b64envelope') @click.pass_obj def stellar_sign_transaction(connect, b64envelope, address, network_passphrase): client = connect() + address_n = stellar.expand_path_or_default(client, address) - # raw signature bytes - resp = client.stellar_sign_transaction(base64.b64decode(b64envelope), address_n, network_passphrase) + tx, operations = stellar.parse_transaction_bytes(base64.b64decode(b64envelope)) + resp = client.stellar_sign_transaction(tx, operations, address_n, network_passphrase) return base64.b64encode(resp.signature) diff --git a/trezorlib/client.py b/trezorlib/client.py index 92710d87c9..6881a039a6 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -1179,16 +1179,14 @@ class ProtocolMixin(object): def stellar_get_public_key(self, address_n): return self.call(proto.StellarGetPublicKey(address_n=address_n)) - def stellar_sign_transaction(self, tx_envelope, address_n, network_passphrase=None): + def stellar_sign_transaction(self, tx, operations, address_n, network_passphrase=None): # default networkPassphrase to the public network if network_passphrase is None: network_passphrase = "Public Global Stellar Network ; September 2015" - tx, operations = stellar.parse_transaction_bytes(tx_envelope) - tx.network_passphrase = network_passphrase tx.address_n = address_n - + tx.num_operations = len(operations) # Signing loop works as follows: # # 1. Start with tx (header information for the transaction) and operations (an array of operation protobuf messagess) diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py index 4b23229824..4ffe6af3d1 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py @@ -17,9 +17,11 @@ # https://www.stellar.org/laboratory/#xdr-viewer # -from base64 import b64decode, b64encode +from base64 import b64encode from .common import TrezorTest from .conftest import TREZOR_VERSION +from binascii import hexlify, unhexlify +from trezorlib import messages as proto import pytest @@ -37,15 +39,29 @@ class TestMsgStellarSignTransaction(TrezorTest): def test_sign_tx_bump_sequence_op(self): self.setup_mnemonic_nopin_nopassphrase() - xdr = b64decode("AAAAABXWSL/k028ZbPtXNf/YylTNS4Iz90PyJEnefPMBzbRpAAAAZAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAt//////////wAAAAAAAAAA") + op = proto.StellarBumpSequenceOp() + op.bump_to = 0x7fffffffffffffff + tx = self._create_msg() - response = self.client.stellar_sign_transaction(xdr, self.get_address_n(), self.get_network_passphrase()) + response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase()) assert b64encode(response.signature) == b'UAOL4ZPYIOzEgM66kBrhyNjLR66dNXtuNrmvd3m0/pc8qCSoLmYY4TybS0lHiMtb+LFZESTaxrpErMHz1sZ6DQ==' def test_sign_tx_account_merge_op(self): self.setup_mnemonic_nopin_nopassphrase() - xdr = b64decode("AAAAABXWSL/k028ZbPtXNf/YylTNS4Iz90PyJEnefPMBzbRpAAAAZAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAgAAAAAXVVkJGaxhbhDFS6eIZFR28WJICfsQBAaUXvtXKAwwuAAAAAAAAAAAQHNtGkAAABAgjoPRj4sW5o7NAXzYOqPK0uxfPbeKb4Qw48LJiCH/XUZ6YVCiZogePC0Z5ISUlozMh6YO6HoYtuLPbm7jq+eCA==") + op = proto.StellarAccountMergeOp() + op.destination_account = unhexlify('5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0') - response = self.client.stellar_sign_transaction(xdr, self.get_address_n(), self.get_network_passphrase()) + tx = self._create_msg() + + response = self.client.stellar_sign_transaction(tx, [op], self.get_address_n(), self.get_network_passphrase()) assert b64encode(response.signature) == b'gjoPRj4sW5o7NAXzYOqPK0uxfPbeKb4Qw48LJiCH/XUZ6YVCiZogePC0Z5ISUlozMh6YO6HoYtuLPbm7jq+eCA==' + + def _create_msg(self) -> proto.StellarSignTx: + tx = proto.StellarSignTx() + tx.protocol_version = 1 + tx.source_account = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + tx.fee = 100 + tx.sequence_number = 0x100000000 + tx.memo_type = 0 + return tx From 1df0cd70946a1fb13bd8316453288d62fb45de90 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 17 May 2018 17:23:25 +0200 Subject: [PATCH 09/28] travis: use newer pip that understands python_requires (should fix build on Python 3.3 because of too-new tox) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e9c11d7460..5658f9c3e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ python: install: # Optimisation: build requirements as wheels, which get cached by Travis - - pip install "pip>=7.0" wheel + - pip install "pip>=9.0" wheel - pip install "setuptools>=38" - pip install tox-travis - pip install flake8 From 9f4cc74b9a8fa5d4e503faf849428b0fb96ab0f7 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 18 May 2018 10:58:28 +0200 Subject: [PATCH 10/28] travis: set virtualenv version to restore build on py33 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5658f9c3e8..57264da624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,9 @@ python: install: # Optimisation: build requirements as wheels, which get cached by Travis - - pip install "pip>=9.0" wheel - - pip install "setuptools>=38" + - pip install "pip>=9.0" wheel # pip 9.0 understands `python_requires` constraints + - pip install "setuptools>=38" # setuptools >= 38 are capable of using prebuilt wheels + - pip install "virtualenv<16.0.0" # virtualenv 16.0.0 drops support for py33 without properly declaring it - pip install tox-travis - pip install flake8 # protobuf-related dependencies From af98a4071a9071d2cca8d1abdb7d45561f53bb3b Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 21 May 2018 17:44:02 +0200 Subject: [PATCH 11/28] device_tests: allow custom runxfail We can now selectively runxfail certain tests. This is useful for accepting PRs into trezor-core: 1. trezor-core is going to get a pytest.ini that sets xfail_strict. That means that if an `xfail`ed test actually passes, that will break the test suite. So it will be visible when we implement a feature for which tests exist. 2. To allow PRs to pass the test suite without touching python-trezor directly, we add a new pytest.ini option: run_xfail. This adds a list of markers which will ignore `xfail`. So: 2.1 First, the python-trezor PR marks the tests with the name of the feature. This commit already does that: Lisk tests are marked `@pytest.mark.lisk`, NEMs are `@pytest.mark.nem`, etc. The tests will be also marked with `xfail`, because the feature is not in core yet. 2.2 Then, the trezor-core PR implements the feature, which makes the `xfail`ed tests pass. That breaks the test suite. 2.3 To fix the test suite, the core PR also adds a `run_xfail` to `pytest.ini`: `run_xfail = lisk`. (it can take a list: `run_xfail = lisk nem stellar`) That will make the test suite behave as if the tests are not `xfail`ed. If the feature is implemented correctly, the tests will pass. 2.4 When the PR is accepted to core, the next step should be a PR to python-trezor that removes the `xfail`s. After that, we should also remove the `run_xfail` option, just to be tidy. --- trezorlib/tests/device_tests/conftest.py | 27 ++++++++++++++++--- .../device_tests/test_msg_lisk_getaddress.py | 1 + .../test_msg_lisk_getpublickey.py | 1 + .../device_tests/test_msg_lisk_signmessage.py | 1 + .../device_tests/test_msg_lisk_signtx.py | 1 + .../test_msg_lisk_verifymessage.py | 1 + .../device_tests/test_msg_nem_getaddress.py | 1 + .../test_msg_nem_signtx_mosaics.py | 1 + .../test_msg_nem_signtx_mosaics_t2.py | 1 + .../test_msg_nem_signtx_multisig.py | 1 + .../test_msg_nem_signtx_others.py | 1 + .../test_msg_nem_signtx_transfers.py | 1 + .../device_tests/test_msg_signtx_zcash.py | 7 +++-- .../test_msg_stellar_get_public_key.py | 1 + .../test_msg_stellar_sign_transaction.py | 1 + 15 files changed, 41 insertions(+), 6 deletions(-) diff --git a/trezorlib/tests/device_tests/conftest.py b/trezorlib/tests/device_tests/conftest.py index 6cb9d410a5..3e3c732f86 100644 --- a/trezorlib/tests/device_tests/conftest.py +++ b/trezorlib/tests/device_tests/conftest.py @@ -22,13 +22,32 @@ except: TREZOR_VERSION = None +def pytest_addoption(parser): + parser.addini("run_xfail", "List of markers that will run even if marked as xfail", "args", []) + + def pytest_runtest_setup(item): - ''' + """ Called for each test item (class, individual tests). - Ensures that 'skip_t2' tests are skipped on T2 - and 'skip_t1' tests are skipped on T1. - ''' + + Performs custom processing, mainly useful for trezor CI testing: + * 'skip_t2' tests are skipped on T2 and 'skip_t1' tests are skipped on T1. + * no test should have both skips at the same time + * allows to 'runxfail' tests specified by 'run_xfail' in pytest.ini + """ + if item.get_marker("skip_t1") and item.get_marker("skip_t2"): + pytest.fail("Don't skip tests for both trezors!") + if item.get_marker("skip_t2") and TREZOR_VERSION == 2: pytest.skip("Test excluded on Trezor T") if item.get_marker("skip_t1") and TREZOR_VERSION == 1: pytest.skip("Test excluded on Trezor 1") + + xfail = item.get_marker("xfail") + run_xfail = any(item.get_marker(marker) for marker in item.config.getini("run_xfail")) + if xfail and run_xfail: + # Deep hack: pytest's private _evalxfail helper determines whether the test should xfail or not. + # The helper caches its result even before this hook runs. + # Here we force-set the result to False, meaning "test does NOT xfail, run as normal" + # IOW, this is basically per-item "--runxfail" + item._evalxfail.result = False diff --git a/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py b/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py index 5ad308fe37..6479c30a44 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py @@ -21,6 +21,7 @@ import pytest from .common import TrezorTest +@pytest.mark.lisk @pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskGetaddress(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py b/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py index 1683be4efd..37c8759b44 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py @@ -21,6 +21,7 @@ import pytest from .common import TrezorTest +@pytest.mark.lisk @pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskGetPublicKey(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py b/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py index 022898eb9d..f8cca44b44 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py @@ -21,6 +21,7 @@ import pytest from .common import TrezorTest +@pytest.mark.lisk @pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskSignmessage(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_signtx.py b/trezorlib/tests/device_tests/test_msg_lisk_signtx.py index a1d36385c1..85ad777201 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_signtx.py @@ -25,6 +25,7 @@ from trezorlib import messages as proto PUBLIC_KEY = unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294') +@pytest.mark.lisk @pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskSignTx(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py b/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py index 46efbb7777..28e926ea55 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py @@ -22,6 +22,7 @@ from .common import TrezorTest from trezorlib import messages as proto +@pytest.mark.lisk @pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskVerifymessage(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_getaddress.py b/trezorlib/tests/device_tests/test_msg_nem_getaddress.py index 305be56a05..4a82127dd6 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_nem_getaddress.py @@ -18,6 +18,7 @@ from .common import * +@pytest.mark.nem @pytest.mark.xfail # to be removed when nem is merged class TestMsgNEMGetaddress(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics.py index e9f8836b95..4bb369dae0 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics.py @@ -20,6 +20,7 @@ from trezorlib import nem # assertion data from T1 +@pytest.mark.nem @pytest.mark.skip_t2 class TestMsgNEMSignTxMosaics(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py index 9619533985..6068b505d8 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py @@ -23,6 +23,7 @@ import time # assertion data from T1 +@pytest.mark.nem @pytest.mark.skip_t1 @pytest.mark.xfail # to be removed when nem is merged class TestMsgNEMSignTxMosaics(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_multisig.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_multisig.py index b41f34ad2b..bb6e75a139 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_multisig.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_multisig.py @@ -21,6 +21,7 @@ from trezorlib import nem # assertion data from T1 +@pytest.mark.nem @pytest.mark.xfail # to be removed when nem is merged class TestMsgNEMSignTxMultisig(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_others.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_others.py index 50812c1fb0..02ae2757d0 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_others.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_others.py @@ -21,6 +21,7 @@ from trezorlib import nem # assertion data from T1 +@pytest.mark.nem @pytest.mark.xfail # to be removed when nem is merged class TestMsgNEMSignTxOther(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py b/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py index a6e10baae4..456892e9a4 100644 --- a/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py +++ b/trezorlib/tests/device_tests/test_msg_nem_signtx_transfers.py @@ -22,6 +22,7 @@ from trezorlib import nem # assertion data from T1 +@pytest.mark.nem @pytest.mark.xfail # to be removed when nem is merged class TestMsgNEMSignTx(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_signtx_zcash.py b/trezorlib/tests/device_tests/test_msg_signtx_zcash.py index e4dac926e2..de78da648e 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_zcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_zcash.py @@ -28,8 +28,11 @@ TxApiZcash = coins.tx_api["Zcash"] TXHASH_93373e = unhexlify('93373e63cc626c4a7d049ad775d6511bb5eba985f142db660c9b9f955c722f5c') -@pytest.mark.skip_t1 -@pytest.mark.skip_t2 +# Zcash reset their testnet, which broke our test because it was not properly cached. +# Then when we tried to revive it, Overwinter happened and now Trezor is incapable of +# processing v3 transactions. So it's difficult to fix the test until we support v3. +@pytest.mark.zcash +@pytest.mark.xfail(reason="Zcash support is botched due to Overwinter") class TestMsgSigntxZcash(TrezorTest): def test_one_one_fee(self): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py index 85c1d83776..cd7cec2791 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_get_public_key.py @@ -19,6 +19,7 @@ from trezorlib import stellar import pytest +@pytest.mark.stellar @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") class TestMsgStellarGetPublicKey(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py index 4ffe6af3d1..dfef8509e2 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_transaction.py @@ -25,6 +25,7 @@ from trezorlib import messages as proto import pytest +@pytest.mark.stellar @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") class TestMsgStellarSignTransaction(TrezorTest): From 465c01d4f7e1dc6080e8174065cd5dbc0e80a975 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 21 May 2018 18:30:00 +0200 Subject: [PATCH 12/28] device_tests: add more currency markers missed Stellar tests, plus Ethereum, for good measure --- trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py | 2 ++ trezorlib/tests/device_tests/test_msg_ethereum_signmessage.py | 1 + trezorlib/tests/device_tests/test_msg_ethereum_signtx.py | 2 ++ trezorlib/tests/device_tests/test_msg_ethereum_verifymessage.py | 1 + trezorlib/tests/device_tests/test_msg_stellar_sign_message.py | 1 + trezorlib/tests/device_tests/test_msg_stellar_verify_message.py | 1 + 6 files changed, 8 insertions(+) diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py b/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py index b1e04f28f0..636fce9c4d 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_getaddress.py @@ -15,10 +15,12 @@ # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . +import pytest from .common import * +@pytest.mark.ethereum class TestMsgEthereumGetaddress(TrezorTest): def test_ethereum_getaddress(self): diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_signmessage.py b/trezorlib/tests/device_tests/test_msg_ethereum_signmessage.py index 24531b21c4..78d7700b0e 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_signmessage.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_signmessage.py @@ -18,6 +18,7 @@ from .common import * +@pytest.mark.ethereum @pytest.mark.skip_t2 class TestMsgEthereumSignmessage(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py b/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py index 9df236d0d1..aa3dfbca8a 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_signtx.py @@ -15,11 +15,13 @@ # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . +import pytest from .common import * from trezorlib import messages as proto +@pytest.mark.ethereum class TestMsgEthereumSigntx(TrezorTest): def test_ethereum_signtx_known_erc20_token(self): diff --git a/trezorlib/tests/device_tests/test_msg_ethereum_verifymessage.py b/trezorlib/tests/device_tests/test_msg_ethereum_verifymessage.py index 7b27d24a69..94056e3861 100644 --- a/trezorlib/tests/device_tests/test_msg_ethereum_verifymessage.py +++ b/trezorlib/tests/device_tests/test_msg_ethereum_verifymessage.py @@ -18,6 +18,7 @@ from .common import * +@pytest.mark.ethereum @pytest.mark.skip_t2 class TestMsgEthereumVerifymessage(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py index 29af3c2152..a6646eed20 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py @@ -19,6 +19,7 @@ from binascii import hexlify import pytest +@pytest.mark.stellar @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") class TestMsgStellarSignMessage(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py index c3f65ad014..30795c56b8 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py @@ -21,6 +21,7 @@ from trezorlib.client import CallException import pytest +@pytest.mark.stellar @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") class TestMsgStellarVerifyMessage(TrezorTest): From a4fe17b461169d77a064bb928fe30959c6a05c3b Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 22 May 2018 17:51:41 +0200 Subject: [PATCH 13/28] device_tests: xfail for decred. This should be investigated more though. --- trezorlib/tests/device_tests/test_msg_signtx_decred.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_decred.py b/trezorlib/tests/device_tests/test_msg_signtx_decred.py index 77b0040a5b..020a327c6e 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_decred.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_decred.py @@ -31,8 +31,7 @@ TXHASH_3f7c39 = unhexlify("3f7c395521d38387e7617565fe17628723ef6635a08537ad9c46c TXHASH_16da18 = unhexlify("16da185052740d85a630e79c140558215b64e26c500212b90e16b55d13ca06a8") -@pytest.mark.skip_t1 -@pytest.mark.skip_t2 +@pytest.mark.xfail(reason="Decred broken for 👻M👻Y👻S👻T👻E👻R👻I👻O👻U👻S reasons... 😱") class TestMsgSigntxDecred(TrezorTest): def test_send_decred(self): From 224e3c18f53f0f584cbb3e5731d3bc1588dea6b7 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 22 May 2018 19:01:34 +0200 Subject: [PATCH 14/28] device_tests: fix test_protection_levels for T1 a couple expected ButtonRequests were missing --- trezorlib/tests/device_tests/test_protection_levels.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/trezorlib/tests/device_tests/test_protection_levels.py b/trezorlib/tests/device_tests/test_protection_levels.py index c3fa7418b6..f0922d5ff6 100644 --- a/trezorlib/tests/device_tests/test_protection_levels.py +++ b/trezorlib/tests/device_tests/test_protection_levels.py @@ -129,7 +129,10 @@ class TestProtectionLevels(TrezorTest): def test_recovery_device(self): with self.client: self.client.set_mnemonic(self.mnemonic12) - self.client.set_expected_responses([proto.WordRequest()] * 24 + [proto.Success(), proto.Features()]) + self.client.set_expected_responses( + [proto.ButtonRequest()] + + [proto.WordRequest()] * 24 + + [proto.Success(), proto.Features()]) self.client.recovery_device(12, False, False, 'label', 'english') # This must fail, because device is already initialized @@ -150,7 +153,7 @@ class TestProtectionLevels(TrezorTest): def test_verify_message(self): with self.client: self.setup_mnemonic_pin_passphrase() - self.client.set_expected_responses([proto.ButtonRequest(), proto.Success()]) + self.client.set_expected_responses([proto.ButtonRequest(), proto.ButtonRequest(), proto.Success()]) self.client.verify_message( 'Bitcoin', '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e', From 013e0f6d668abc91799f2ed1e17034661ab42fb3 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 22 May 2018 19:13:59 +0200 Subject: [PATCH 15/28] device_tests: get nicer tracebacks by using pytest.raises instead of custom exception code --- .../tests/device_tests/test_msg_signtx.py | 30 ++++++++----------- .../device_tests/test_msg_signtx_bcash.py | 9 ++---- .../device_tests/test_msg_signtx_segwit.py | 13 ++++---- .../test_msg_stellar_verify_message.py | 26 ++++++---------- trezorlib/tests/device_tests/test_multisig.py | 15 +++++----- .../tests/device_tests/test_op_return.py | 14 ++++----- 6 files changed, 44 insertions(+), 63 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_signtx.py b/trezorlib/tests/device_tests/test_msg_signtx.py index 7b92325aa6..25181fe43d 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_signtx.py @@ -16,7 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . -from .common import * +from binascii import hexlify, unhexlify +import pytest + +from .common import TrezorTest from trezorlib import coins from trezorlib import messages as proto @@ -514,12 +517,9 @@ class TestMsgSigntx(TrezorTest): proto.Failure(code=proto.FailureType.NotEnoughFunds) ]) - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) - except CallException as e: - assert e.args[0] == proto.FailureType.NotEnoughFunds - else: - assert False # types.FailureType.NotEnoughFunds expected + assert exc.value.args[0] == proto.FailureType.NotEnoughFunds def test_p2sh(self): self.setup_mnemonic_nopin_nopassphrase() @@ -623,13 +623,10 @@ class TestMsgSigntx(TrezorTest): assert hexlify(serialized_tx) == b'01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000' # Now run the attack, must trigger the exception - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1, inp2], [out1, out2], debug_processor=attack_processor) - except CallException as exc: - assert exc.args[0] == proto.FailureType.ProcessError - assert exc.args[1] == 'Transaction has changed during signing' - else: - assert False # exception expected + assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[1] == 'Transaction has changed during signing' def test_attack_change_input_address(self): # This unit test attempts to modify input address after the Trezor checked @@ -701,13 +698,10 @@ class TestMsgSigntx(TrezorTest): proto.Failure(code=proto.FailureType.ProcessError), ]) # Now run the attack, must trigger the exception - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Testnet', [inp1], [out1, out2], debug_processor=attack_processor) - except CallException as exc: - assert exc.args[0] == proto.FailureType.ProcessError - assert exc.args[1] == 'Transaction has changed during signing' - else: - assert False # exception expected + assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[1] == 'Transaction has changed during signing' def test_spend_coinbase(self): # 25 TEST generated to m/1 (mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index f397d5b6ad..f54cedb456 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -222,13 +222,10 @@ class TestMsgSigntxBch(TrezorTest): proto.Failure(code=proto.FailureType.ProcessError), ]) - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Bcash', [inp1, inp2], [out1], debug_processor=attack_processor) - except CallException as exc: - assert exc.args[0] == proto.FailureType.ProcessError - assert exc.args[1] == 'Transaction has changed during signing' - else: - assert False # exception expected + assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[1] == 'Transaction has changed during signing' def test_attack_change_input(self): self.setup_mnemonic_allallall() diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py index 65136c3a3f..edfffe0195 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py @@ -15,8 +15,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . -from .common import * +from binascii import hexlify, unhexlify +import pytest +from .common import TrezorTest from trezorlib import coins from trezorlib import messages as proto from trezorlib.ckd_public import deserialize @@ -235,10 +237,7 @@ class TestMsgSigntxSegwit(TrezorTest): proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=0)), proto.Failure(code=proto.FailureType.ProcessError), ]) - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Testnet', [inp1], [out1, out2], debug_processor=attack_processor) - except CallException as exc: - assert exc.args[0] == proto.FailureType.ProcessError - assert exc.args[1] == 'Transaction has changed during signing' - else: - assert False # exception expected + assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[1] == 'Transaction has changed during signing' diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py index 30795c56b8..f7ea1aa8c0 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py @@ -13,12 +13,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . +from binascii import unhexlify +import pytest + from .common import TrezorTest from .conftest import TREZOR_VERSION -from binascii import unhexlify, hexlify from trezorlib import messages as proto from trezorlib.client import CallException -import pytest @pytest.mark.stellar @@ -44,28 +45,19 @@ class TestMsgStellarVerifyMessage(TrezorTest): msg = 'abc' pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') signature = unhexlify('0000000000000000') # invalid length - try: + with pytest.raises(CallException) as exc: self.client.stellar_verify_message(pubkey, signature, msg) - except CallException as exc: - assert exc.args[0] == proto.FailureType.DataError - else: - assert False + assert exc.value.args[0] == proto.FailureType.DataError # invalid signature signature = unhexlify('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') - try: + with pytest.raises(CallException) as exc: self.client.stellar_verify_message(pubkey, signature, msg) - except CallException as exc: - assert exc.args[0] == proto.FailureType.DataError - else: - assert False + assert exc.value.args[0] == proto.FailureType.DataError # invalid pubkey pubkey = unhexlify('00') signature = unhexlify('00') - try: + with pytest.raises(CallException) as exc: self.client.stellar_verify_message(pubkey, signature, msg) - except CallException as exc: - assert exc.args[0] == proto.FailureType.DataError - else: - assert False + assert exc.value.args[0] == proto.FailureType.DataError diff --git a/trezorlib/tests/device_tests/test_multisig.py b/trezorlib/tests/device_tests/test_multisig.py index 4316a9a71d..15d2637607 100644 --- a/trezorlib/tests/device_tests/test_multisig.py +++ b/trezorlib/tests/device_tests/test_multisig.py @@ -16,9 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . -from __future__ import print_function +from binascii import hexlify, unhexlify +import pytest -from .common import * +from .common import TrezorTest from trezorlib import messages as proto import trezorlib.ckd_public as bip32 from trezorlib.client import CallException @@ -249,10 +250,8 @@ class TestMultisig(TrezorTest): script_type=proto.OutputScriptType.PAYTOADDRESS ) - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) - except CallException as exc: - assert exc.args[0] == proto.FailureType.DataError - assert exc.args[1] == 'Pubkey not found in multisig script' - else: - assert False # exception expected + + assert exc.value.args[0] == proto.FailureType.DataError + assert exc.value.args[1] == 'Pubkey not found in multisig script' diff --git a/trezorlib/tests/device_tests/test_op_return.py b/trezorlib/tests/device_tests/test_op_return.py index e4a38bdc98..1168a128cd 100644 --- a/trezorlib/tests/device_tests/test_op_return.py +++ b/trezorlib/tests/device_tests/test_op_return.py @@ -15,8 +15,10 @@ # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . +from binascii import unhexlify, hexlify +import pytest -from .common import * +from .common import TrezorTest from trezorlib import messages as proto from trezorlib.client import CallException @@ -105,10 +107,8 @@ class TestOpReturn(TrezorTest): proto.Failure() ]) - try: + with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1], [out1]) - except CallException as exc: - assert exc.args[0] == proto.FailureType.DataError - assert exc.args[1] == 'OP_RETURN output with non-zero amount' - else: - assert False # exception expected + + assert exc.value.args[0] == proto.FailureType.DataError + assert exc.value.args[1] == 'OP_RETURN output with non-zero amount' From 2225343c52294895fd4840efe2fe698146e3249b Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 22 May 2018 19:15:19 +0200 Subject: [PATCH 16/28] device_tests: in test_multisig, T1 raises a different message expected: "Pubkey not found in multisig script" actual: "signing.c:780:Pubkey not found in multisig script" --- trezorlib/tests/device_tests/test_multisig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trezorlib/tests/device_tests/test_multisig.py b/trezorlib/tests/device_tests/test_multisig.py index 15d2637607..90c0b1693e 100644 --- a/trezorlib/tests/device_tests/test_multisig.py +++ b/trezorlib/tests/device_tests/test_multisig.py @@ -254,4 +254,4 @@ class TestMultisig(TrezorTest): self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) assert exc.value.args[0] == proto.FailureType.DataError - assert exc.value.args[1] == 'Pubkey not found in multisig script' + assert 'Pubkey not found in multisig script' in exc.value.args[1] From ce7ee8ae302ccaa1dc4b746126d6e6c46f6bed8b Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 22 May 2018 20:07:22 +0200 Subject: [PATCH 17/28] device_tests: mark decred --- trezorlib/tests/device_tests/test_msg_signtx_decred.py | 1 + 1 file changed, 1 insertion(+) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_decred.py b/trezorlib/tests/device_tests/test_msg_signtx_decred.py index 020a327c6e..e0d2ae8ce9 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_decred.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_decred.py @@ -31,6 +31,7 @@ TXHASH_3f7c39 = unhexlify("3f7c395521d38387e7617565fe17628723ef6635a08537ad9c46c TXHASH_16da18 = unhexlify("16da185052740d85a630e79c140558215b64e26c500212b90e16b55d13ca06a8") +@pytest.mark.decred @pytest.mark.xfail(reason="Decred broken for 👻M👻Y👻S👻T👻E👻R👻I👻O👻U👻S reasons... 😱") class TestMsgSigntxDecred(TrezorTest): From bc270895462152b88d5081e4e7c20faf23167811 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 23 May 2018 13:16:14 +0200 Subject: [PATCH 18/28] tests: remove lisk sign/verify --- .../device_tests/test_msg_lisk_signmessage.py | 40 ------------- .../test_msg_lisk_verifymessage.py | 56 ------------------- 2 files changed, 96 deletions(-) delete mode 100644 trezorlib/tests/device_tests/test_msg_lisk_signmessage.py delete mode 100644 trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py diff --git a/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py b/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py deleted file mode 100644 index f8cca44b44..0000000000 --- a/trezorlib/tests/device_tests/test_msg_lisk_signmessage.py +++ /dev/null @@ -1,40 +0,0 @@ -# This file is part of the TREZOR project. -# -# Copyright (C) 2016-2017 Pavol Rusnak -# -# 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 . - -from binascii import hexlify -import pytest - -from .common import TrezorTest - - -@pytest.mark.lisk -@pytest.mark.xfail # drop when trezor-core PR #90 is merged -@pytest.mark.skip_t1 -class TestMsgLiskSignmessage(TrezorTest): - - def test_sign(self): - self.setup_mnemonic_nopin_nopassphrase() - sig = self.client.lisk_sign_message([2147483692, 2147483782, 2147483648, 2147483648], 'This is an example of a signed message.') - assert sig.address == '7623396847864198749L' - assert hexlify(sig.signature) == b'af1d384cce25354b5af129662caed6f3514c6f1f6a206662d301fd56aa5549aa23c3f82009f213a7a4d9297015c2e5b06584273df7c42d78b4e531fe4d4fc80e' - - def test_sign_long(self): - self.setup_mnemonic_nopin_nopassphrase() - sig = self.client.lisk_sign_message([2147483692, 2147483782, 2147483648], 'VeryLongMessage!' * 64) - assert sig.address == '17563781916205589679L' - print(hexlify(sig.signature)) - assert hexlify(sig.signature) == b'a675152c2af34e85dbd75740681efb7d67bf910561d6c9d1e075be2f99d9bc544d62c52f6619756b0e329a2f2d82756ced53b4261a028fcee0d37d7e641ef404' diff --git a/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py b/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py deleted file mode 100644 index 28e926ea55..0000000000 --- a/trezorlib/tests/device_tests/test_msg_lisk_verifymessage.py +++ /dev/null @@ -1,56 +0,0 @@ -# This file is part of the TREZOR project. -# -# Copyright (C) 2016-2017 Pavol Rusnak -# -# 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 . - -from binascii import unhexlify -import pytest - -from .common import TrezorTest -from trezorlib import messages as proto - - -@pytest.mark.lisk -@pytest.mark.xfail # drop when trezor-core PR #90 is merged -@pytest.mark.skip_t1 -class TestMsgLiskVerifymessage(TrezorTest): - - def test_verify(self): - self.setup_mnemonic_nopin_nopassphrase() - with self.client: - self.client.set_expected_responses([ - proto.ButtonRequest(code=proto.ButtonRequestType.Other), - proto.ButtonRequest(code=proto.ButtonRequestType.Other), - proto.Success(message='Message verified') - ]) - self.client.lisk_verify_message( - unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294'), - unhexlify('af1d384cce25354b5af129662caed6f3514c6f1f6a206662d301fd56aa5549aa23c3f82009f213a7a4d9297015c2e5b06584273df7c42d78b4e531fe4d4fc80e'), - 'This is an example of a signed message.' - ) - - def test_verify_long(self): - self.setup_mnemonic_nopin_nopassphrase() - with self.client: - self.client.set_expected_responses([ - proto.ButtonRequest(code=proto.ButtonRequestType.Other), - proto.ButtonRequest(code=proto.ButtonRequestType.Other), - proto.Success(message='Message verified') - ]) - self.client.lisk_verify_message( - unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294'), - unhexlify('7b4b481f6a07a874bdd1b590cd2b933c8b571c721484d9dc303f81b22d1f3c5f55ffe0704dbfd543ff9ea3e795facda871ddb422522257d33a8fe16ab4169601'), - 'VeryLongMessage!' * 64 - ) From 70172520fb9d5c5a272a5252b8947e1ca1c0a851 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 14:04:09 +0200 Subject: [PATCH 19/28] protobuf: update messages from upstream. This drops sign/verify messages for Lisk and Stellar so we have to remove the corresponding methods. --- trezorlib/messages/Initialize.py | 5 +++- trezorlib/messages/LiskMessageSignature.py | 18 --------------- trezorlib/messages/LiskSignMessage.py | 23 ------------------- trezorlib/messages/LiskVerifyMessage.py | 21 ----------------- trezorlib/messages/MessageType.py | 6 ----- trezorlib/messages/StellarMessageSignature.py | 18 --------------- trezorlib/messages/StellarSignMessage.py | 23 ------------------- trezorlib/messages/StellarVerifyMessage.py | 21 ----------------- trezorlib/messages/TransactionType.py | 5 +++- trezorlib/messages/__init__.py | 6 ----- vendor/trezor-common | 2 +- 11 files changed, 9 insertions(+), 139 deletions(-) delete mode 100644 trezorlib/messages/LiskMessageSignature.py delete mode 100644 trezorlib/messages/LiskSignMessage.py delete mode 100644 trezorlib/messages/LiskVerifyMessage.py delete mode 100644 trezorlib/messages/StellarMessageSignature.py delete mode 100644 trezorlib/messages/StellarSignMessage.py delete mode 100644 trezorlib/messages/StellarVerifyMessage.py diff --git a/trezorlib/messages/Initialize.py b/trezorlib/messages/Initialize.py index 38e35ec73d..fa3453fca8 100644 --- a/trezorlib/messages/Initialize.py +++ b/trezorlib/messages/Initialize.py @@ -6,10 +6,13 @@ class Initialize(p.MessageType): MESSAGE_WIRE_TYPE = 0 FIELDS = { 1: ('state', p.BytesType, 0), + 2: ('skip_passphrase', p.BoolType, 0), } def __init__( self, - state: bytes = None + state: bytes = None, + skip_passphrase: bool = None ) -> None: self.state = state + self.skip_passphrase = skip_passphrase diff --git a/trezorlib/messages/LiskMessageSignature.py b/trezorlib/messages/LiskMessageSignature.py deleted file mode 100644 index b161458386..0000000000 --- a/trezorlib/messages/LiskMessageSignature.py +++ /dev/null @@ -1,18 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p - - -class LiskMessageSignature(p.MessageType): - MESSAGE_WIRE_TYPE = 119 - FIELDS = { - 1: ('address', p.UnicodeType, 0), - 2: ('signature', p.BytesType, 0), - } - - def __init__( - self, - address: str = None, - signature: bytes = None - ) -> None: - self.address = address - self.signature = signature diff --git a/trezorlib/messages/LiskSignMessage.py b/trezorlib/messages/LiskSignMessage.py deleted file mode 100644 index 4194c8a6b8..0000000000 --- a/trezorlib/messages/LiskSignMessage.py +++ /dev/null @@ -1,23 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p -if __debug__: - try: - from typing import List - except ImportError: - List = None - - -class LiskSignMessage(p.MessageType): - MESSAGE_WIRE_TYPE = 118 - FIELDS = { - 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), - 2: ('message', p.BytesType, 0), - } - - def __init__( - self, - address_n: List[int] = None, - message: bytes = None - ) -> None: - self.address_n = address_n if address_n is not None else [] - self.message = message diff --git a/trezorlib/messages/LiskVerifyMessage.py b/trezorlib/messages/LiskVerifyMessage.py deleted file mode 100644 index 235ac3b0f9..0000000000 --- a/trezorlib/messages/LiskVerifyMessage.py +++ /dev/null @@ -1,21 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p - - -class LiskVerifyMessage(p.MessageType): - MESSAGE_WIRE_TYPE = 120 - FIELDS = { - 1: ('signature', p.BytesType, 0), - 2: ('public_key', p.BytesType, 0), - 3: ('message', p.BytesType, 0), - } - - def __init__( - self, - signature: bytes = None, - public_key: bytes = None, - message: bytes = None - ) -> None: - self.signature = signature - self.public_key = public_key - self.message = message diff --git a/trezorlib/messages/MessageType.py b/trezorlib/messages/MessageType.py index 2c76d2115d..66b2787581 100644 --- a/trezorlib/messages/MessageType.py +++ b/trezorlib/messages/MessageType.py @@ -88,18 +88,12 @@ LiskGetAddress = 114 LiskAddress = 115 LiskSignTx = 116 LiskSignedTx = 117 -LiskSignMessage = 118 -LiskMessageSignature = 119 -LiskVerifyMessage = 120 LiskGetPublicKey = 121 LiskPublicKey = 122 StellarGetPublicKey = 200 StellarPublicKey = 201 StellarSignTx = 202 StellarTxOpRequest = 203 -StellarSignMessage = 204 -StellarMessageSignature = 205 -StellarVerifyMessage = 206 StellarCreateAccountOp = 210 StellarPaymentOp = 211 StellarPathPaymentOp = 212 diff --git a/trezorlib/messages/StellarMessageSignature.py b/trezorlib/messages/StellarMessageSignature.py deleted file mode 100644 index 631a04109c..0000000000 --- a/trezorlib/messages/StellarMessageSignature.py +++ /dev/null @@ -1,18 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p - - -class StellarMessageSignature(p.MessageType): - MESSAGE_WIRE_TYPE = 205 - FIELDS = { - 1: ('public_key', p.BytesType, 0), - 2: ('signature', p.BytesType, 0), - } - - def __init__( - self, - public_key: bytes = None, - signature: bytes = None - ) -> None: - self.public_key = public_key - self.signature = signature diff --git a/trezorlib/messages/StellarSignMessage.py b/trezorlib/messages/StellarSignMessage.py deleted file mode 100644 index 069908c2fa..0000000000 --- a/trezorlib/messages/StellarSignMessage.py +++ /dev/null @@ -1,23 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p -if __debug__: - try: - from typing import List - except ImportError: - List = None - - -class StellarSignMessage(p.MessageType): - MESSAGE_WIRE_TYPE = 204 - FIELDS = { - 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), - 2: ('message', p.BytesType, 0), - } - - def __init__( - self, - address_n: List[int] = None, - message: bytes = None - ) -> None: - self.address_n = address_n if address_n is not None else [] - self.message = message diff --git a/trezorlib/messages/StellarVerifyMessage.py b/trezorlib/messages/StellarVerifyMessage.py deleted file mode 100644 index 2189306d96..0000000000 --- a/trezorlib/messages/StellarVerifyMessage.py +++ /dev/null @@ -1,21 +0,0 @@ -# Automatically generated by pb2py -from .. import protobuf as p - - -class StellarVerifyMessage(p.MessageType): - MESSAGE_WIRE_TYPE = 206 - FIELDS = { - 1: ('public_key', p.BytesType, 0), - 2: ('message', p.BytesType, 0), - 3: ('signature', p.BytesType, 0), - } - - def __init__( - self, - public_key: bytes = None, - message: bytes = None, - signature: bytes = None - ) -> None: - self.public_key = public_key - self.message = message - self.signature = signature diff --git a/trezorlib/messages/TransactionType.py b/trezorlib/messages/TransactionType.py index 34f0a263ac..2d9d20b606 100644 --- a/trezorlib/messages/TransactionType.py +++ b/trezorlib/messages/TransactionType.py @@ -22,6 +22,7 @@ class TransactionType(p.MessageType): 8: ('extra_data', p.BytesType, 0), 9: ('extra_data_len', p.UVarintType, 0), 10: ('decred_expiry', p.UVarintType, 0), + 11: ('overwintered', p.BoolType, 0), } def __init__( @@ -35,7 +36,8 @@ class TransactionType(p.MessageType): outputs_cnt: int = None, extra_data: bytes = None, extra_data_len: int = None, - decred_expiry: int = None + decred_expiry: int = None, + overwintered: bool = None ) -> None: self.version = version self.inputs = inputs if inputs is not None else [] @@ -47,3 +49,4 @@ class TransactionType(p.MessageType): self.extra_data = extra_data self.extra_data_len = extra_data_len self.decred_expiry = decred_expiry + self.overwintered = overwintered diff --git a/trezorlib/messages/__init__.py b/trezorlib/messages/__init__.py index 663224076f..b1c1e8a828 100644 --- a/trezorlib/messages/__init__.py +++ b/trezorlib/messages/__init__.py @@ -96,12 +96,9 @@ from .Initialize import Initialize from .LiskAddress import LiskAddress from .LiskGetAddress import LiskGetAddress from .LiskGetPublicKey import LiskGetPublicKey -from .LiskMessageSignature import LiskMessageSignature from .LiskPublicKey import LiskPublicKey -from .LiskSignMessage import LiskSignMessage from .LiskSignTx import LiskSignTx from .LiskSignedTx import LiskSignedTx -from .LiskVerifyMessage import LiskVerifyMessage from .LoadDevice import LoadDevice from .MessageSignature import MessageSignature from .NEMAddress import NEMAddress @@ -136,16 +133,13 @@ from .StellarCreatePassiveOfferOp import StellarCreatePassiveOfferOp from .StellarGetPublicKey import StellarGetPublicKey from .StellarManageDataOp import StellarManageDataOp from .StellarManageOfferOp import StellarManageOfferOp -from .StellarMessageSignature import StellarMessageSignature from .StellarPathPaymentOp import StellarPathPaymentOp from .StellarPaymentOp import StellarPaymentOp from .StellarPublicKey import StellarPublicKey from .StellarSetOptionsOp import StellarSetOptionsOp -from .StellarSignMessage import StellarSignMessage from .StellarSignTx import StellarSignTx from .StellarSignedTx import StellarSignedTx from .StellarTxOpRequest import StellarTxOpRequest -from .StellarVerifyMessage import StellarVerifyMessage from .Success import Success from .TxAck import TxAck from .TxRequest import TxRequest diff --git a/vendor/trezor-common b/vendor/trezor-common index b91db285ba..8fc001154e 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit b91db285ba8947d6c65a6a807fba87ebc1d43f5d +Subproject commit 8fc001154e49c2c1747957c4a9a1ab92dcc86edb From 4b7926268e7f508595bf3fa43456dd3254183056 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 14:20:54 +0200 Subject: [PATCH 20/28] drop Lisk and Stellar sign/verify message functionality --- trezorctl | 51 --------------- trezorlib/client.py | 25 -------- .../test_msg_stellar_sign_message.py | 37 ----------- .../test_msg_stellar_verify_message.py | 63 ------------------- 4 files changed, 176 deletions(-) delete mode 100644 trezorlib/tests/device_tests/test_msg_stellar_sign_message.py delete mode 100644 trezorlib/tests/device_tests/test_msg_stellar_verify_message.py diff --git a/trezorctl b/trezorctl index 584bc01bc4..17bebe279b 100755 --- a/trezorctl +++ b/trezorctl @@ -891,33 +891,6 @@ def lisk_get_public_key(connect, address, show_display): return output -@cli.command(help='Sign message with Lisk address.') -@click.option('-n', '--address', required=True, help="BIP-32 path, e.g. m/44'/134'/0'/0'") -@click.argument('message') -@click.pass_obj -def lisk_sign_message(connect, address, message): - client = connect() - address_n = client.expand_path(address) - res = client.lisk_sign_message(address_n, message) - output = { - 'message': message, - 'address': res.address, - 'signature': binascii.hexlify(res.signature).decode() - } - return output - - -@cli.command(help='Verify message signed with Lisk address.') -@click.argument('pubkey') -@click.argument('signature') -@click.argument('message') -@click.pass_obj -def lisk_verify_message(connect, pubkey, signature, message): - signature = bytes.fromhex(signature) - pubkey = bytes.fromhex(pubkey) - return connect().lisk_verify_message(pubkey, signature, message) - - @cli.command(help='Sign Lisk transaction.') @click.option('-n', '--address', required=True, help="BIP-32 path to signing key, e.g. m/44'/134'/0'/0'") @click.option('-f', '--file', type=click.File('r'), default='-', help='Transaction in JSON format') @@ -987,30 +960,6 @@ def stellar_sign_message(connect, address, message): return base64.b64encode(response.signature) -@cli.command(help='Verify that a signature is valid') -@click.option('--message-is-b64/--no-message-is-b64', default=False, required=False, help="If set, the message argument will be interpreted as a base64-encoded string") -@click.argument('address') -@click.argument('signatureb64') -@click.argument('message') -@click.pass_obj -def stellar_verify_message(connect, address, message_is_b64, signatureb64, message): - if message_is_b64: - message = base64.b64decode(message) - else: - message = message.encode('utf-8') - - pubkey_bytes = stellar.address_to_public_key(address) - - client = connect() - is_verified = client.stellar_verify_message(pubkey_bytes, base64.b64decode(signatureb64), message) - - if is_verified: - return "Success: message verified" - else: - print("ERROR: invalid signature, verification failed") - sys.exit(1) - - @cli.command(help='Sign a base64-encoded transaction envelope') @click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix") @click.option('-n', '--network-passphrase', default='Public Global Stellar Network ; September 2015', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'") diff --git a/trezorlib/client.py b/trezorlib/client.py index 6881a039a6..837bbe3e10 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -640,20 +640,6 @@ class ProtocolMixin(object): n = self._convert_prime(n) return self.call(proto.LiskGetPublicKey(address_n=n, show_display=show_display)) - @expect(proto.LiskMessageSignature) - def lisk_sign_message(self, n, message): - n = self._convert_prime(n) - message = normalize_nfc(message) - return self.call(proto.LiskSignMessage(address_n=n, message=message)) - - def lisk_verify_message(self, pubkey, signature, message): - message = normalize_nfc(message) - try: - resp = self.call(proto.LiskVerifyMessage(signature=signature, public_key=pubkey, message=message)) - except CallException as e: - resp = e - return isinstance(resp, proto.Success) - @expect(proto.LiskSignedTx) def lisk_sign_tx(self, n, transaction): n = self._convert_prime(n) @@ -1212,17 +1198,6 @@ class ProtocolMixin(object): return resp - @expect(proto.StellarMessageSignature) - def stellar_sign_message(self, address_n, message): - message = normalize_nfc(message) - return self.call(proto.StellarSignMessage(address_n=address_n, message=message)) - - def stellar_verify_message(self, pubkey_bytes, signature, message): - message = normalize_nfc(message) - resp = self.call(proto.StellarVerifyMessage(public_key=pubkey_bytes, message=message, signature=signature)) - - return isinstance(resp, proto.Success) - class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient): def __init__(self, transport, *args, **kwargs): diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py deleted file mode 100644 index a6646eed20..0000000000 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py +++ /dev/null @@ -1,37 +0,0 @@ -# This file is part of the TREZOR project. -# -# 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 . - -from .common import TrezorTest -from .conftest import TREZOR_VERSION -from binascii import hexlify -import pytest - - -@pytest.mark.stellar -@pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") -class TestMsgStellarSignMessage(TrezorTest): - - def test_stellar_sign_message(self): - self.setup_mnemonic_nopin_nopassphrase() - - msg = 'Hello world!' - response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) - assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' - assert hexlify(response.signature) == b'3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004' - - msg = 'LongMessage ' * 80 # but shorter than 1024 - response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) - assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' - assert hexlify(response.signature) == b'c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507' diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py deleted file mode 100644 index f7ea1aa8c0..0000000000 --- a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py +++ /dev/null @@ -1,63 +0,0 @@ -# This file is part of the TREZOR project. -# -# 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 . - -from binascii import unhexlify -import pytest - -from .common import TrezorTest -from .conftest import TREZOR_VERSION -from trezorlib import messages as proto -from trezorlib.client import CallException - - -@pytest.mark.stellar -@pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") -class TestMsgStellarVerifyMessage(TrezorTest): - - def test_stellar_verify_message(self): - self.setup_mnemonic_nopin_nopassphrase() - - msg = 'Hello world!' - pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') - signature = unhexlify('3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004') - response = self.client.stellar_verify_message(pubkey, signature, msg) - assert response is True - - msg = 'LongMessage ' * 80 # but shorter than 1024 - pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') - signature = unhexlify('c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507') - response = self.client.stellar_verify_message(pubkey, signature, msg) - assert response is True - - def test_stellar_verify_message_invalid(self): - msg = 'abc' - pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') - signature = unhexlify('0000000000000000') # invalid length - with pytest.raises(CallException) as exc: - self.client.stellar_verify_message(pubkey, signature, msg) - assert exc.value.args[0] == proto.FailureType.DataError - - # invalid signature - signature = unhexlify('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') - with pytest.raises(CallException) as exc: - self.client.stellar_verify_message(pubkey, signature, msg) - assert exc.value.args[0] == proto.FailureType.DataError - - # invalid pubkey - pubkey = unhexlify('00') - signature = unhexlify('00') - with pytest.raises(CallException) as exc: - self.client.stellar_verify_message(pubkey, signature, msg) - assert exc.value.args[0] == proto.FailureType.DataError From f2aee59e27aa9cbf74ad1fe258c0f90b7278ad5f Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 14:21:24 +0200 Subject: [PATCH 21/28] device_tests: do not xfail Lisk tests, they are now merged --- trezorlib/tests/device_tests/test_msg_lisk_getaddress.py | 1 - trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py | 1 - trezorlib/tests/device_tests/test_msg_lisk_signtx.py | 1 - 3 files changed, 3 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py b/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py index 6479c30a44..d1e6fd4c63 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_getaddress.py @@ -22,7 +22,6 @@ from .common import TrezorTest @pytest.mark.lisk -@pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskGetaddress(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py b/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py index 37c8759b44..f14a8f8e1e 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_getpublickey.py @@ -22,7 +22,6 @@ from .common import TrezorTest @pytest.mark.lisk -@pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskGetPublicKey(TrezorTest): diff --git a/trezorlib/tests/device_tests/test_msg_lisk_signtx.py b/trezorlib/tests/device_tests/test_msg_lisk_signtx.py index 85ad777201..74d47cfe4e 100644 --- a/trezorlib/tests/device_tests/test_msg_lisk_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_lisk_signtx.py @@ -26,7 +26,6 @@ PUBLIC_KEY = unhexlify('eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b6 @pytest.mark.lisk -@pytest.mark.xfail # drop when trezor-core PR #90 is merged @pytest.mark.skip_t1 class TestMsgLiskSignTx(TrezorTest): From 7e83eb11e51a63ab31a4c3604c9ad630339de322 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 14:27:10 +0200 Subject: [PATCH 22/28] trezorctl: drop remaining stellar_sign_message command --- trezorctl | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/trezorctl b/trezorctl index 17bebe279b..7b436700d5 100755 --- a/trezorctl +++ b/trezorctl @@ -949,17 +949,6 @@ def stellar_get_address(connect, address): return stellar.address_from_public_key(response.public_key) -@cli.command(help='Sign a string with a Stellar key') -@click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix") -@click.argument('message') -@click.pass_obj -def stellar_sign_message(connect, address, message): - client = connect() - address_n = stellar.expand_path_or_default(client, address) - response = client.stellar_sign_message(address_n, message) - return base64.b64encode(response.signature) - - @cli.command(help='Sign a base64-encoded transaction envelope') @click.option('-n', '--address', required=False, help="BIP32 path. Default primary account is m/44'/148'/0'. Always use hardened paths and the m/44'/148'/ prefix") @click.option('-n', '--network-passphrase', default='Public Global Stellar Network ; September 2015', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'") From f8f0be9c86dad5ffd2bdb6c79be0ddaf9091114f Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 16:40:17 +0200 Subject: [PATCH 23/28] device_tests: fix T1 test differences in wording --- trezorlib/tests/device_tests/test_msg_signtx.py | 11 ++++++++--- trezorlib/tests/device_tests/test_msg_signtx_bcash.py | 7 ++++--- .../tests/device_tests/test_msg_signtx_segwit.py | 6 +++++- trezorlib/tests/device_tests/test_multisig.py | 2 +- trezorlib/tests/device_tests/test_op_return.py | 9 +++++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_signtx.py b/trezorlib/tests/device_tests/test_msg_signtx.py index 25181fe43d..a7d83f788a 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_signtx.py @@ -20,6 +20,7 @@ from binascii import hexlify, unhexlify import pytest from .common import TrezorTest +from .conftest import TREZOR_VERSION from trezorlib import coins from trezorlib import messages as proto @@ -625,8 +626,8 @@ class TestMsgSigntx(TrezorTest): # Now run the attack, must trigger the exception with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1, inp2], [out1, out2], debug_processor=attack_processor) - assert exc.value.args[0] == proto.FailureType.ProcessError - assert exc.value.args[1] == 'Transaction has changed during signing' + assert exc.value.args[0] in (proto.FailureType.ProcessError, proto.FailureType.DataError) + assert exc.value.args[1].endswith('Transaction has changed during signing') def test_attack_change_input_address(self): # This unit test attempts to modify input address after the Trezor checked @@ -700,8 +701,12 @@ class TestMsgSigntx(TrezorTest): # Now run the attack, must trigger the exception with pytest.raises(CallException) as exc: self.client.sign_tx('Testnet', [inp1], [out1, out2], debug_processor=attack_processor) + assert exc.value.args[0] == proto.FailureType.ProcessError - assert exc.value.args[1] == 'Transaction has changed during signing' + if TREZOR_VERSION == 1: + assert exc.value.args[1].endswith('Failed to compile input') + else: + assert exc.value.args[1].endswith('Transaction has changed during signing') def test_spend_coinbase(self): # 25 TEST generated to m/1 (mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index f54cedb456..2bb71707ae 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -219,13 +219,14 @@ class TestMsgSigntxBch(TrezorTest): proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=0)), proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=1)), - proto.Failure(code=proto.FailureType.ProcessError), + proto.Failure(), ]) with pytest.raises(CallException) as exc: self.client.sign_tx('Bcash', [inp1, inp2], [out1], debug_processor=attack_processor) - assert exc.value.args[0] == proto.FailureType.ProcessError - assert exc.value.args[1] == 'Transaction has changed during signing' + + assert exc.value.args[0] == proto.FailureType.DataError + assert exc.value.args[1].endswith('Transaction has changed during signing') def test_attack_change_input(self): self.setup_mnemonic_allallall() diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py index edfffe0195..fb274179a4 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py @@ -18,6 +18,7 @@ from binascii import hexlify, unhexlify import pytest +from .conftest import TREZOR_VERSION from .common import TrezorTest from trezorlib import coins from trezorlib import messages as proto @@ -240,4 +241,7 @@ class TestMsgSigntxSegwit(TrezorTest): with pytest.raises(CallException) as exc: self.client.sign_tx('Testnet', [inp1], [out1, out2], debug_processor=attack_processor) assert exc.value.args[0] == proto.FailureType.ProcessError - assert exc.value.args[1] == 'Transaction has changed during signing' + if TREZOR_VERSION == 1: + assert exc.value.args[1].endswith("Failed to compile input") + else: + assert exc.value.args[1].endswith('Transaction has changed during signing') diff --git a/trezorlib/tests/device_tests/test_multisig.py b/trezorlib/tests/device_tests/test_multisig.py index 90c0b1693e..115f0fd605 100644 --- a/trezorlib/tests/device_tests/test_multisig.py +++ b/trezorlib/tests/device_tests/test_multisig.py @@ -254,4 +254,4 @@ class TestMultisig(TrezorTest): self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) assert exc.value.args[0] == proto.FailureType.DataError - assert 'Pubkey not found in multisig script' in exc.value.args[1] + assert exc.value.args[1].endswith('Pubkey not found in multisig script') diff --git a/trezorlib/tests/device_tests/test_op_return.py b/trezorlib/tests/device_tests/test_op_return.py index 1168a128cd..91e370f807 100644 --- a/trezorlib/tests/device_tests/test_op_return.py +++ b/trezorlib/tests/device_tests/test_op_return.py @@ -19,6 +19,7 @@ from binascii import unhexlify, hexlify import pytest from .common import TrezorTest +from .conftest import TREZOR_VERSION from trezorlib import messages as proto from trezorlib.client import CallException @@ -110,5 +111,9 @@ class TestOpReturn(TrezorTest): with pytest.raises(CallException) as exc: self.client.sign_tx('Bitcoin', [inp1], [out1]) - assert exc.value.args[0] == proto.FailureType.DataError - assert exc.value.args[1] == 'OP_RETURN output with non-zero amount' + if TREZOR_VERSION == 1: + assert exc.value.args[0] == proto.FailureType.ProcessError + assert exc.value.args[1].endswith("Failed to compile output") + else: + assert exc.value.args[0] == proto.FailureType.DataError + assert exc.value.args[1].endswith('OP_RETURN output with non-zero amount') From 17b37034e894dd7268e252dc76219892aa4627b8 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 17:08:16 +0200 Subject: [PATCH 24/28] device_tests: fix test_msg_recoverydevice for T1 --- .../device_tests/test_msg_recoverydevice.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_recoverydevice.py b/trezorlib/tests/device_tests/test_msg_recoverydevice.py index 79eddecd0a..5244ac8e9b 100644 --- a/trezorlib/tests/device_tests/test_msg_recoverydevice.py +++ b/trezorlib/tests/device_tests/test_msg_recoverydevice.py @@ -15,10 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . +import pytest -from __future__ import print_function - -from .common import * +from .common import TrezorTest from trezorlib import messages as proto @@ -34,6 +33,11 @@ class TestMsgRecoverydevice(TrezorTest): language='english', enforce_wordlist=True)) + # click through confirmation + assert isinstance(ret, proto.ButtonRequest) + self.client.debug.press_yes() + ret = self.client.call_raw(proto.ButtonAck()) + assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time @@ -92,6 +96,11 @@ class TestMsgRecoverydevice(TrezorTest): language='english', enforce_wordlist=True)) + # click through confirmation + assert isinstance(ret, proto.ButtonRequest) + self.client.debug.press_yes() + ret = self.client.call_raw(proto.ButtonAck()) + fakes = 0 for _ in range(int(12 * 2)): assert isinstance(ret, proto.WordRequest) @@ -136,6 +145,11 @@ class TestMsgRecoverydevice(TrezorTest): language='english', enforce_wordlist=True)) + # click through confirmation + assert isinstance(ret, proto.ButtonRequest) + self.client.debug.press_yes() + ret = self.client.call_raw(proto.ButtonAck()) + assert isinstance(ret, proto.WordRequest) for _ in range(int(12 * 2)): (word, pos) = self.client.debug.read_recovery_word() @@ -154,6 +168,11 @@ class TestMsgRecoverydevice(TrezorTest): language='english', enforce_wordlist=True)) + # click through confirmation + assert isinstance(ret, proto.ButtonRequest) + self.client.debug.press_yes() + ret = self.client.call_raw(proto.ButtonAck()) + assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time From 35b9ab898d2727822af4319d298e989641106ede Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 23 May 2018 17:08:32 +0200 Subject: [PATCH 25/28] travis: also trigger trezor-mcu when running tests because now it should be ALL GREEN --- trigger-travis.sh | 64 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/trigger-travis.sh b/trigger-travis.sh index 238f34b96c..12a2ff6b24 100755 --- a/trigger-travis.sh +++ b/trigger-travis.sh @@ -2,9 +2,6 @@ # adapted from https://github.com/stephanmg/travis-dependent-builds # variables -USER=trezor -REPO=trezor-core -BRANCH=master SOURCE=trezor/python-trezor if [ "$TRAVIS_REPO_SLUG" != "$SOURCE" ]; then @@ -22,31 +19,42 @@ if [[ "$TRAVIS_JOB_NUMBER" != *.1 ]]; then exit 0; fi -MESSAGE=",\"message\": \"Triggered from upstream build of $TRAVIS_REPO_SLUG by commit "`git rev-parse --short HEAD`"\"" +function trigger_build() { + USER="$1" + REPO="$2" + BRANCH="$3" + echo "attempting to trigger build of $USER/$REPO" -# curl POST request content body -BODY="{ - \"request\": { - \"branch\":\"$BRANCH\" - $MESSAGE -}}" + MESSAGE=",\"message\": \"Triggered from upstream build of $TRAVIS_REPO_SLUG by commit "`git rev-parse --short HEAD`"\"" -echo "attempting to trigger build of $USER/$REPO" -# make a POST request with curl (note %2F could be replaced with -# / and additional curl arguments, however this works too!) -curl -s -X POST \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token ${TRAVIS_TOKEN}" \ - -d "$BODY" \ - https://api.travis-ci.org/repo/${USER}%2F${REPO}/requests \ - | tee /tmp/travis-request-output.$$.txt + # curl POST request content body + BODY="{ + \"request\": { + \"branch\":\"$BRANCH\" + $MESSAGE + }}" -if grep -q '"@type": "error"' /tmp/travis-request-output.$$.txt; then - cat /tmp/travis-request-output.$$.txt - exit 1 -elif grep -q 'access denied' /tmp/travis-request-output.$$.txt; then - cat /tmp/travis-request-output.$$.txt - exit 1 -fi + # make a POST request with curl (note %2F could be replaced with + # / and additional curl arguments, however this works too!) + curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "Travis-API-Version: 3" \ + -H "Authorization: token ${TRAVIS_TOKEN}" \ + -d "$BODY" \ + https://api.travis-ci.org/repo/${USER}%2F${REPO}/requests \ + | tee /tmp/travis-request-output.$$.txt + echo + + if grep -q '"@type": "error"' /tmp/travis-request-output.$$.txt; then + cat /tmp/travis-request-output.$$.txt + exit 1 + elif grep -q 'access denied' /tmp/travis-request-output.$$.txt; then + cat /tmp/travis-request-output.$$.txt + exit 1 + fi +} + +# trigger both core and mcu +trigger_build trezor trezor-core master +trigger_build trezor trezor-mcu master From b67322be2f40bf77d15d7c4116b37fb1da676fb6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 24 May 2018 16:39:17 +0200 Subject: [PATCH 26/28] device_tests: enable cashaddr tests (msg_getaddress, signtx_bcash) for T2 --- trezorlib/tests/device_tests/test_msg_getaddress.py | 2 -- trezorlib/tests/device_tests/test_msg_signtx_bcash.py | 1 - 2 files changed, 3 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_getaddress.py b/trezorlib/tests/device_tests/test_msg_getaddress.py index e850e0393b..69a656a282 100644 --- a/trezorlib/tests/device_tests/test_msg_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_getaddress.py @@ -43,14 +43,12 @@ class TestMsgGetaddress(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() assert self.client.get_address('Testnet', [111, 42]) == 'moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa' - @pytest.mark.skip_t2 def test_bch(self): self.setup_mnemonic_allallall() assert self.client.get_address('Bcash', self.client.expand_path("44'/145'/0'/0/0")) == 'bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv' assert self.client.get_address('Bcash', self.client.expand_path("44'/145'/0'/0/1")) == 'bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4' assert self.client.get_address('Bcash', self.client.expand_path("44'/145'/0'/1/0")) == 'bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw' - @pytest.mark.skip_t2 def test_bch_multisig(self): self.setup_mnemonic_allallall() xpubs = [] diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index 2bb71707ae..9399be5de9 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -24,7 +24,6 @@ from trezorlib.client import CallException TxApiBcash = coins.tx_api['Bcash'] -@pytest.mark.skip_t2 class TestMsgSigntxBch(TrezorTest): def test_send_bch_change(self): From bb5e49e4528b359bbd61a4149db58620362cd05a Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 24 May 2018 17:02:11 +0200 Subject: [PATCH 27/28] device_tests: fix failed test --- trezorlib/tests/device_tests/test_msg_signtx_bcash.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index 9399be5de9..4b280deb6c 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -224,9 +224,10 @@ class TestMsgSigntxBch(TrezorTest): with pytest.raises(CallException) as exc: self.client.sign_tx('Bcash', [inp1, inp2], [out1], debug_processor=attack_processor) - assert exc.value.args[0] == proto.FailureType.DataError + assert exc.value.args[0] in (proto.FailureType.ProcessError, proto.FailureType.DataError) assert exc.value.args[1].endswith('Transaction has changed during signing') + def test_attack_change_input(self): self.setup_mnemonic_allallall() self.client.set_tx_api(TxApiBcash) From e2962ef9f714152f8f5930a03d7959c6dfe8b70b Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 24 May 2018 17:07:17 +0200 Subject: [PATCH 28/28] fix typo --- trezorlib/tests/device_tests/test_msg_signtx_bcash.py | 1 - 1 file changed, 1 deletion(-) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index 4b280deb6c..e2bb949781 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -227,7 +227,6 @@ class TestMsgSigntxBch(TrezorTest): assert exc.value.args[0] in (proto.FailureType.ProcessError, proto.FailureType.DataError) assert exc.value.args[1].endswith('Transaction has changed during signing') - def test_attack_change_input(self): self.setup_mnemonic_allallall() self.client.set_tx_api(TxApiBcash)