2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2018-04-16 17:56:07 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-04-16 17:56:07 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2018-04-16 17:56:07 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
2019-05-29 16:44:09 +00:00
|
|
|
|
2018-04-18 13:46:10 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib import lisk, messages as proto
|
2018-04-18 13:53:40 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2018-04-16 17:56:07 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from .common import TrezorTest
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
|
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.
2018-05-21 15:44:02 +00:00
|
|
|
@pytest.mark.lisk
|
2018-04-16 17:56:07 +00:00
|
|
|
class TestMsgLiskSignTx(TrezorTest):
|
|
|
|
def test_lisk_sign_tx_send(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"f48532d43e8c5abadf50bb7b82098b31eec3e67747e5328c0675203e86441899c246fa3aea6fc91043209431ce710c5aa34aa234546b85b88299d5a379bff202"
|
2018-11-06 12:29:37 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
|
|
|
parse_path("m/44'/134'/0'"),
|
|
|
|
{
|
|
|
|
"amount": "10000000",
|
|
|
|
"recipientId": "9971262264659915921L",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 0,
|
|
|
|
"fee": "10000000",
|
|
|
|
"asset": {},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
|
|
|
def test_lisk_sign_tx_send_wrong_path(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-11-06 12:29:37 +00:00
|
|
|
|
|
|
|
with self.client:
|
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(
|
|
|
|
code=proto.ButtonRequestType.UnknownDerivationPath
|
|
|
|
),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
|
|
|
signature=bytes.fromhex(
|
2018-12-13 14:49:19 +00:00
|
|
|
"cdce9eba2ea8fa75f90fbc725f0d9de6152c7189a3044ab2fe307d9ff54754856e09125d7a15376eaf4bb5451b63881821948222ccd9ffb5da4d9b1aa8bd4904"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-12-13 14:49:19 +00:00
|
|
|
parse_path("m/44'/134'/123456'/123456'/123456'/123456'/123456'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "10000000",
|
|
|
|
"recipientId": "9971262264659915921L",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 0,
|
|
|
|
"fee": "10000000",
|
|
|
|
"asset": {},
|
|
|
|
},
|
|
|
|
)
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
def test_lisk_sign_tx_send_with_data(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"4e83a651e82f2f787a71a5f44a2911dd0429ee4001b80c79fb7d174ea63ceeefdfba55aa3a9f31fa14b8325a39ad973dcd7eadbaa77b0447a9893f84b60f210e"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-11-06 12:29:37 +00:00
|
|
|
parse_path("m/44'/134'/0'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "10000000",
|
|
|
|
"recipientId": "9971262264659915921L",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 0,
|
|
|
|
"fee": "20000000",
|
|
|
|
"asset": {"data": "Test data"},
|
|
|
|
},
|
|
|
|
)
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
def test_lisk_sign_tx_second_signature(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.PublicKey),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"e27d8997d0bdbc9ab4ad928fcf140edb25a217007987447270085c0872e4178c018847d1378a949ad2aa913692f10aeec340810fd9de02da9d4461c63b6b6c06"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-11-06 12:29:37 +00:00
|
|
|
parse_path("m/44'/134'/0'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "0",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 1,
|
|
|
|
"fee": "500000000",
|
|
|
|
"asset": {
|
|
|
|
"signature": {
|
|
|
|
"publicKey": "5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
def test_lisk_sign_tx_delegate_registration(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"e9f68b9961198f4e0d33d6ae95cbd90ab243c2c1f9fcc51db54eb54cc1491db53d237131e12da9485bfbfbd02255c431d08095076f926060c434edb01cf25807"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-11-06 12:29:37 +00:00
|
|
|
parse_path("m/44'/134'/0'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "0",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 2,
|
|
|
|
"fee": "2500000000",
|
|
|
|
"asset": {"delegate": {"username": "trezor_t"}},
|
|
|
|
},
|
|
|
|
)
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
def test_lisk_sign_tx_cast_votes(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"18d7cb27276a83178427aab2abcb5ee1c8ae9e8e2d1231585dcae7a83dd7d5167eea5baca890169bc80dcaf187320cab47c2f65a20c6483fede0f059919e4106"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-11-06 12:29:37 +00:00
|
|
|
parse_path("m/44'/134'/0'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "0",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 3,
|
|
|
|
"fee": "100000000",
|
|
|
|
"asset": {
|
|
|
|
"votes": [
|
|
|
|
"+b002f58531c074c7190714523eec08c48db8c7cfc0c943097db1a2e82ed87f84",
|
|
|
|
"-ec111c8ad482445cfe83d811a7edd1f1d2765079c99d7d958cca1354740b7614",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
def test_lisk_sign_tx_multisignature(self):
|
2018-11-21 15:11:01 +00:00
|
|
|
self.setup_mnemonic_allallall()
|
2018-04-16 17:56:07 +00:00
|
|
|
|
|
|
|
with self.client:
|
2018-08-13 16:21:24 +00:00
|
|
|
self.client.set_expected_responses(
|
|
|
|
[
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
|
|
|
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
|
|
|
|
proto.LiskSignedTx(
|
2018-09-14 10:23:38 +00:00
|
|
|
signature=bytes.fromhex(
|
2018-11-21 15:11:01 +00:00
|
|
|
"b84438ae3d419d270eacd0414fc8818d8f2c721602be54c3d705cf4cb3305de44e674f6dac9aac87379cce006cc97f2f635f296a48ab6a6adf62e2c11e08e409"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
lisk.sign_tx(
|
|
|
|
self.client,
|
2018-11-06 12:29:37 +00:00
|
|
|
parse_path("m/44'/134'/0'"),
|
2018-08-13 16:21:24 +00:00
|
|
|
{
|
|
|
|
"amount": "0",
|
|
|
|
"timestamp": 57525937,
|
|
|
|
"type": 4,
|
|
|
|
"fee": "1500000000",
|
|
|
|
"asset": {
|
|
|
|
"multisignature": {
|
|
|
|
"min": 2,
|
|
|
|
"lifetime": 5,
|
|
|
|
"keysgroup": [
|
|
|
|
"+5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09",
|
|
|
|
"+922fbfdd596fa78269bbcadc67ec2a1cc15fc929a19c462169568d7a3df1a1aa",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|