1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-15 17:12:04 +00:00

tests: convert from self.client to the client fixture

This commit is contained in:
matejcik 2019-08-27 16:58:59 +02:00
parent eee02dd3f8
commit e0f55be7a6
81 changed files with 1708 additions and 2034 deletions

View File

@ -88,6 +88,7 @@ def client(request):
label="test", label="test",
language="english", language="english",
) )
client.clear_session()
if setup_params["passphrase"] and client.features.model != "1": if setup_params["passphrase"] and client.features.model != "1":
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST) apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)

View File

@ -14,25 +14,28 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import device, messages from trezorlib import device, messages
from .common import TrezorTest from .common import TrezorTest
class TestBasic(TrezorTest): class TestBasic(TrezorTest):
def test_features(self): @pytest.mark.setup_client(uninitialized=True)
f0 = self.client.features def test_features(self, client):
f1 = self.client.call(messages.Initialize()) f0 = client.features
f1 = client.call(messages.Initialize())
assert f0 == f1 assert f0 == f1
def test_ping(self): def test_ping(self, client):
ping = self.client.call(messages.Ping(message="ahoj!")) ping = client.call(messages.Ping(message="ahoj!"))
assert ping == messages.Success(message="ahoj!") assert ping == messages.Success(message="ahoj!")
def test_device_id_same(self): def test_device_id_same(self, client):
id1 = self.client.get_device_id() id1 = client.get_device_id()
self.client.init_device() client.init_device()
id2 = self.client.get_device_id() id2 = client.get_device_id()
# ID must be at least 12 characters # ID must be at least 12 characters
assert len(id1) >= 12 assert len(id1) >= 12
@ -40,10 +43,10 @@ class TestBasic(TrezorTest):
# Every resulf of UUID must be the same # Every resulf of UUID must be the same
assert id1 == id2 assert id1 == id2
def test_device_id_different(self): def test_device_id_different(self, client):
id1 = self.client.get_device_id() id1 = client.get_device_id()
device.wipe(self.client) device.wipe(client)
id2 = self.client.get_device_id() id2 = client.get_device_id()
# Device ID must be fresh after every reset # Device ID must be fresh after every reset
assert id1 != id2 assert id1 != id2

View File

@ -26,45 +26,39 @@ from .common import TrezorTest
@pytest.mark.flaky(max_runs=5) @pytest.mark.flaky(max_runs=5)
class TestBip32Speed(TrezorTest): class TestBip32Speed(TrezorTest):
def test_public_ckd(self): def test_public_ckd(self, client):
self.setup_mnemonic_nopin_nopassphrase() btc.get_address(client, "Bitcoin", []) # to compute root node via BIP39
btc.get_address(self.client, "Bitcoin", []) # to compute root node via BIP39
for depth in range(8): for depth in range(8):
start = time.time() start = time.time()
btc.get_address(self.client, "Bitcoin", range(depth)) btc.get_address(client, "Bitcoin", range(depth))
delay = time.time() - start delay = time.time() - start
expected = (depth + 1) * 0.26 expected = (depth + 1) * 0.26
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
assert delay <= expected assert delay <= expected
def test_private_ckd(self): def test_private_ckd(self, client):
self.setup_mnemonic_nopin_nopassphrase() btc.get_address(client, "Bitcoin", []) # to compute root node via BIP39
btc.get_address(self.client, "Bitcoin", []) # to compute root node via BIP39
for depth in range(8): for depth in range(8):
start = time.time() start = time.time()
address_n = [H_(-i) for i in range(-depth, 0)] address_n = [H_(-i) for i in range(-depth, 0)]
btc.get_address(self.client, "Bitcoin", address_n) btc.get_address(client, "Bitcoin", address_n)
delay = time.time() - start delay = time.time() - start
expected = (depth + 1) * 0.26 expected = (depth + 1) * 0.26
print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay) print("DEPTH", depth, "EXPECTED DELAY", expected, "REAL DELAY", delay)
assert delay <= expected assert delay <= expected
@pytest.mark.skip_t2 @pytest.mark.skip_t2
def test_cache(self): def test_cache(self, client):
self.setup_mnemonic_nopin_nopassphrase()
start = time.time() start = time.time()
for x in range(10): for x in range(10):
btc.get_address(self.client, "Bitcoin", [x, 2, 3, 4, 5, 6, 7, 8]) btc.get_address(client, "Bitcoin", [x, 2, 3, 4, 5, 6, 7, 8])
nocache_time = time.time() - start nocache_time = time.time() - start
start = time.time() start = time.time()
for x in range(10): for x in range(10):
btc.get_address(self.client, "Bitcoin", [1, 2, 3, 4, 5, 6, 7, x]) btc.get_address(client, "Bitcoin", [1, 2, 3, 4, 5, 6, 7, x])
cache_time = time.time() - start cache_time = time.time() - start
print("NOCACHE TIME", nocache_time) print("NOCACHE TIME", nocache_time)

View File

@ -26,14 +26,12 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestCosi(TrezorTest): class TestCosi(TrezorTest):
def test_cosi_commit(self): def test_cosi_commit(self, client):
self.setup_mnemonic_pin_passphrase()
digest = sha256(b"this is a message").digest() digest = sha256(b"this is a message").digest()
c0 = cosi.commit(self.client, parse_path("10018'/0'"), digest) c0 = cosi.commit(client, parse_path("10018'/0'"), digest)
c1 = cosi.commit(self.client, parse_path("10018'/1'"), digest) c1 = cosi.commit(client, parse_path("10018'/1'"), digest)
c2 = cosi.commit(self.client, parse_path("10018'/2'"), digest) c2 = cosi.commit(client, parse_path("10018'/2'"), digest)
assert c0.pubkey != c1.pubkey assert c0.pubkey != c1.pubkey
assert c0.pubkey != c2.pubkey assert c0.pubkey != c2.pubkey
@ -45,9 +43,9 @@ class TestCosi(TrezorTest):
digestb = sha256(b"this is a different message").digest() digestb = sha256(b"this is a different message").digest()
c0b = cosi.commit(self.client, parse_path("10018'/0'"), digestb) c0b = cosi.commit(client, parse_path("10018'/0'"), digestb)
c1b = cosi.commit(self.client, parse_path("10018'/1'"), digestb) c1b = cosi.commit(client, parse_path("10018'/1'"), digestb)
c2b = cosi.commit(self.client, parse_path("10018'/2'"), digestb) c2b = cosi.commit(client, parse_path("10018'/2'"), digestb)
assert c0.pubkey == c0b.pubkey assert c0.pubkey == c0b.pubkey
assert c1.pubkey == c1b.pubkey assert c1.pubkey == c1b.pubkey
@ -57,22 +55,20 @@ class TestCosi(TrezorTest):
assert c1.commitment != c1b.commitment assert c1.commitment != c1b.commitment
assert c2.commitment != c2b.commitment assert c2.commitment != c2b.commitment
def test_cosi_sign(self): def test_cosi_sign(self, client):
self.setup_mnemonic_pin_passphrase()
digest = sha256(b"this is a message").digest() digest = sha256(b"this is a message").digest()
c0 = cosi.commit(self.client, parse_path("10018'/0'"), digest) c0 = cosi.commit(client, parse_path("10018'/0'"), digest)
c1 = cosi.commit(self.client, parse_path("10018'/1'"), digest) c1 = cosi.commit(client, parse_path("10018'/1'"), digest)
c2 = cosi.commit(self.client, parse_path("10018'/2'"), digest) c2 = cosi.commit(client, parse_path("10018'/2'"), digest)
global_pk = cosi.combine_keys([c0.pubkey, c1.pubkey, c2.pubkey]) global_pk = cosi.combine_keys([c0.pubkey, c1.pubkey, c2.pubkey])
global_R = cosi.combine_keys([c0.commitment, c1.commitment, c2.commitment]) global_R = cosi.combine_keys([c0.commitment, c1.commitment, c2.commitment])
# fmt: off # fmt: off
sig0 = cosi.sign(self.client, parse_path("10018'/0'"), digest, global_R, global_pk) sig0 = cosi.sign(client, parse_path("10018'/0'"), digest, global_R, global_pk)
sig1 = cosi.sign(self.client, parse_path("10018'/1'"), digest, global_R, global_pk) sig1 = cosi.sign(client, parse_path("10018'/1'"), digest, global_R, global_pk)
sig2 = cosi.sign(self.client, parse_path("10018'/2'"), digest, global_R, global_pk) sig2 = cosi.sign(client, parse_path("10018'/2'"), digest, global_R, global_pk)
# fmt: on # fmt: on
sig = cosi.combine_sig( sig = cosi.combine_sig(
@ -81,11 +77,9 @@ class TestCosi(TrezorTest):
cosi.verify(sig, digest, global_pk) cosi.verify(sig, digest, global_pk)
def test_cosi_compat(self): def test_cosi_compat(self, client):
self.setup_mnemonic_pin_passphrase()
digest = sha256(b"this is not a pipe").digest() digest = sha256(b"this is not a pipe").digest()
remote_commit = cosi.commit(self.client, parse_path("10018'/0'"), digest) remote_commit = cosi.commit(client, parse_path("10018'/0'"), digest)
local_privkey = sha256(b"private key").digest()[:32] local_privkey = sha256(b"private key").digest()[:32]
local_pubkey = cosi.pubkey_from_privkey(local_privkey) local_pubkey = cosi.pubkey_from_privkey(local_privkey)
@ -95,7 +89,7 @@ class TestCosi(TrezorTest):
global_R = cosi.combine_keys([remote_commit.commitment, local_commitment]) global_R = cosi.combine_keys([remote_commit.commitment, local_commitment])
remote_sig = cosi.sign( remote_sig = cosi.sign(
self.client, parse_path("10018'/0'"), digest, global_R, global_pk client, parse_path("10018'/0'"), digest, global_R, global_pk
) )
local_sig = cosi.sign_with_privkey( local_sig = cosi.sign_with_privkey(
digest, local_privkey, global_pk, local_nonce, global_R digest, local_privkey, global_pk, local_nonce, global_R

View File

@ -16,33 +16,38 @@
import pytest import pytest
from trezorlib import messages as proto from trezorlib import debuglink, messages
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestDebuglink(TrezorTest): class TestDebuglink(TrezorTest):
def test_layout(self): def test_layout(self, client):
layout = self.client.debug.state().layout layout = client.debug.state().layout
assert len(layout) == 1024 assert len(layout) == 1024
def test_mnemonic(self): @pytest.mark.setup_client(uninitialized=True)
self.setup_mnemonic_nopin_nopassphrase(lock=False) def test_mnemonic(self, client):
mnemonic = self.client.debug.state().mnemonic_secret debuglink.load_device_by_mnemonic(
client,
mnemonic=MNEMONIC12,
pin="",
passphrase_protection=False,
label="test",
)
mnemonic = client.debug.state().mnemonic_secret
assert mnemonic == self.mnemonic12.encode() assert mnemonic == self.mnemonic12.encode()
def test_pin(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin="1234", passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_pin(self, client):
resp = client.call_raw(messages.Ping(message="test", pin_protection=True))
assert isinstance(resp, messages.PinMatrixRequest)
# Manually trigger PinMatrixRequest pin, matrix = client.debug.read_pin()
resp = self.client.call_raw(proto.Ping(message="test", pin_protection=True))
assert isinstance(resp, proto.PinMatrixRequest)
pin, matrix = self.client.debug.read_pin()
assert pin == "1234" assert pin == "1234"
assert matrix != "" assert matrix != ""
pin_encoded = self.client.debug.read_pin_encoded() pin_encoded = client.debug.read_pin_encoded()
resp = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))
assert isinstance(resp, proto.Success) assert isinstance(resp, messages.Success)

View File

@ -32,110 +32,99 @@ else:
EXPECTED_RESPONSES = EXPECTED_RESPONSES_NOPIN EXPECTED_RESPONSES = EXPECTED_RESPONSES_NOPIN
@pytest.mark.setup_client(pin=True)
class TestMsgApplysettings(TrezorTest): class TestMsgApplysettings(TrezorTest):
def test_apply_settings(self): def test_apply_settings(self, client):
self.setup_mnemonic_pin_passphrase() assert client.features.label == "test"
assert self.client.features.label == "test"
with self.client: with client:
self.client.set_expected_responses(EXPECTED_RESPONSES) client.set_expected_responses(EXPECTED_RESPONSES)
device.apply_settings(self.client, label="new label") device.apply_settings(client, label="new label")
assert self.client.features.label == "new label" assert client.features.label == "new label"
@pytest.mark.skip_t2 @pytest.mark.skip_t2
def test_invalid_language(self): def test_invalid_language(self, client):
self.setup_mnemonic_pin_passphrase() assert client.features.language == "english"
assert self.client.features.language == "english"
with self.client: with client:
self.client.set_expected_responses(EXPECTED_RESPONSES) client.set_expected_responses(EXPECTED_RESPONSES)
device.apply_settings(self.client, language="nonexistent") device.apply_settings(client, language="nonexistent")
assert self.client.features.language == "english" assert client.features.language == "english"
def test_apply_settings_passphrase(self): @pytest.mark.setup_client(pin=True, passphrase=False)
self.setup_mnemonic_pin_nopassphrase() def test_apply_settings_passphrase(self, client):
assert client.features.passphrase_protection is False
assert self.client.features.passphrase_protection is False with client:
client.set_expected_responses(EXPECTED_RESPONSES)
device.apply_settings(client, use_passphrase=True)
with self.client: assert client.features.passphrase_protection is True
self.client.set_expected_responses(EXPECTED_RESPONSES)
device.apply_settings(self.client, use_passphrase=True)
assert self.client.features.passphrase_protection is True with client:
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
device.apply_settings(client, use_passphrase=False)
with self.client: assert client.features.passphrase_protection is False
self.client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
device.apply_settings(self.client, use_passphrase=False)
assert self.client.features.passphrase_protection is False with client:
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
device.apply_settings(client, use_passphrase=True)
with self.client: assert client.features.passphrase_protection is True
self.client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
device.apply_settings(self.client, use_passphrase=True)
assert self.client.features.passphrase_protection is True
@pytest.mark.skip_t2 @pytest.mark.skip_t2
def test_apply_homescreen(self): def test_apply_homescreen(self, client):
self.setup_mnemonic_pin_passphrase()
img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x04\x88\x02\x00\x00\x00\x02\x91\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x90@\x00\x11@\x00\x00\x00\x00\x00\x00\x08\x00\x10\x92\x12\x04\x00\x00\x05\x12D\x00\x00\x00\x00\x00 \x00\x00\x08\x00Q\x00\x00\x02\xc0\x00\x00\x00\x00\x00\x00\x00\x10\x02 \x01\x04J\x00)$\x00\x00\x00\x00\x80\x00\x00\x00\x00\x08\x10\xa1\x00\x00\x02\x81 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\tP\x00\x00\x00\x00\x00\x00 \x00\x00\xa0\x00\xa0R \x12\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x08\x00\tP\x00\x00\x00\x00 \x00\x04 \x00\x80\x02\x00@\x02T\xc2 \x00\x00\x00\x00\x00\x00\x00\x10@\x00)\t@\n\xa0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x80@\x14\xa9H\x04\x00\x00\x88@\x00\x00\x00\x00\x00\x02\x02$\x00\x15B@\x00\nP\x00\x00\x00\x00\x00\x80\x00\x00\x91\x01UP\x00\x00 \x02\x00\x00\x00\x00\x00\x00\x02\x08@ Z\xa5 \x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\xa1%\x14*\xa0\x00\x00\x02\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00@\xaa\x91 \x00\x05E\x80\x00\x00\x00\x00\x00\x02*T\x05-D\x00\x00\x05 @\x00\x00\x00\x00\x00%@\x80\x11V\xa0\x88\x00\x05@\xb0\x00\x00\x00\x00\x00\x818$\x04\xabD \x00\x06\xa1T\x00\x00\x00\x00\x02\x03\xb8\x01R\xd5\x01\x00\x00\x05AP\x00\x00\x00\x00\x08\xadT\x00\x05j\xa4@\x00\x87ah\x00\x00\x00\x00\x02\x8d\xb8\x08\x00.\x01\x00\x00\x02\xa5\xa8\x10\x00\x00\x00*\xc1\xec \n\xaa\x88 \x02@\xf6\xd0\x02\x00\x00\x00\x0bB\xb6\x14@U"\x80\x00\x01{`\x00\x00\x00\x00M\xa3\xf8 \x15*\x00\x00\x00\x10n\xc0\x04\x00\x00\x02\x06\xc2\xa8)\x00\x96\x84\x80\x00\x00\x1b\x00\x00\x80@\x10\x87\xa7\xf0\x84\x10\xaa\x10\x00\x00D\x00\x00\x02 \x00\x8a\x06\xfa\xe0P\n-\x02@\x00\x12\x00\x00\x00\x00\x10@\x83\xdf\xa0\x00\x08\xaa@\x00\x00\x01H\x00\x05H\x04\x12\x01\xf7\x81P\x02T\t\x00\x00\x00 \x00\x00\x84\x10\x00\x00z\x00@)* \x00\x00\x01\n\xa0\x02 \x05\n\x00\x00\x05\x10\x84\xa8\x84\x80\x00\x00@\x14\x00\x92\x10\x80\x00\x04\x11@\tT\x00\x00\x00\x00\n@\x00\x08\x84@$\x00H\x00\x12Q\x02\x00\x00\x00\x00\x90\x02A\x12\xa8\n\xaa\x92\x10\x04\xa8\x10@\x00\x00\x04\x04\x00\x04I\x00\x04\x14H\x80"R\x01\x00\x00\x00!@\x00\x00$\xa0EB\x80\x08\x95hH\x00\x00\x00\x84\x10 \x05Z\x00\x00(\x00\x02\x00\xa1\x01\x00\x00\x04\x00@\x82\x00\xadH*\x92P\x00\xaaP\x00\x00\x00\x00\x11\x02\x01*\xad\x01\x00\x01\x01"\x11D\x08\x00\x00\x10\x80 \x00\x81W\x80J\x94\x04\x08\xa5 !\x00\x00\x00\x02\x00B*\xae\xa1\x00\x80\x10\x01\x08\xa4\x00\x00\x00\x00\x00\x84\x00\t[@"HA\x04E\x00\x84\x00\x00\x00\x10\x00\x01J\xd5\x82\x90\x02\x00!\x02\xa2\x00\x00\x00\x00\x00\x00\x00\x05~\xa0\x00 \x10\n)\x00\x11\x00\x00\x00\x00\x00\x00!U\x80\xa8\x88\x82\x80\x01\x00\x00\x00\x00\x00\x00H@\x11\xaa\xc0\x82\x00 *\n\x00\x00\x00\x00\x00\x00\x00\x00\n\xabb@ \x04\x00! \x84\x00\x00\x00\x00\x02@\xa5\x15A$\x04\x81(\n\x00\x00\x00\x00\x00\x00 \x01\x10\x02\xe0\x91\x02\x00\x00\x04\x00\x00\x00\x00\x00\x00\x01 \xa9\tQH@\x91 P\x00\x00\x00\x00\x00\x00\x08\x00\x00\xa0T\xa5\x00@\x80\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00 T\xa0\t\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00@\x02\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x10\x00\x00\x10\x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00@\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x08@\x10\x00\x00\x00\x00' img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x04\x88\x02\x00\x00\x00\x02\x91\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x90@\x00\x11@\x00\x00\x00\x00\x00\x00\x08\x00\x10\x92\x12\x04\x00\x00\x05\x12D\x00\x00\x00\x00\x00 \x00\x00\x08\x00Q\x00\x00\x02\xc0\x00\x00\x00\x00\x00\x00\x00\x10\x02 \x01\x04J\x00)$\x00\x00\x00\x00\x80\x00\x00\x00\x00\x08\x10\xa1\x00\x00\x02\x81 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\tP\x00\x00\x00\x00\x00\x00 \x00\x00\xa0\x00\xa0R \x12\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x08\x00\tP\x00\x00\x00\x00 \x00\x04 \x00\x80\x02\x00@\x02T\xc2 \x00\x00\x00\x00\x00\x00\x00\x10@\x00)\t@\n\xa0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x80@\x14\xa9H\x04\x00\x00\x88@\x00\x00\x00\x00\x00\x02\x02$\x00\x15B@\x00\nP\x00\x00\x00\x00\x00\x80\x00\x00\x91\x01UP\x00\x00 \x02\x00\x00\x00\x00\x00\x00\x02\x08@ Z\xa5 \x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\xa1%\x14*\xa0\x00\x00\x02\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00@\xaa\x91 \x00\x05E\x80\x00\x00\x00\x00\x00\x02*T\x05-D\x00\x00\x05 @\x00\x00\x00\x00\x00%@\x80\x11V\xa0\x88\x00\x05@\xb0\x00\x00\x00\x00\x00\x818$\x04\xabD \x00\x06\xa1T\x00\x00\x00\x00\x02\x03\xb8\x01R\xd5\x01\x00\x00\x05AP\x00\x00\x00\x00\x08\xadT\x00\x05j\xa4@\x00\x87ah\x00\x00\x00\x00\x02\x8d\xb8\x08\x00.\x01\x00\x00\x02\xa5\xa8\x10\x00\x00\x00*\xc1\xec \n\xaa\x88 \x02@\xf6\xd0\x02\x00\x00\x00\x0bB\xb6\x14@U"\x80\x00\x01{`\x00\x00\x00\x00M\xa3\xf8 \x15*\x00\x00\x00\x10n\xc0\x04\x00\x00\x02\x06\xc2\xa8)\x00\x96\x84\x80\x00\x00\x1b\x00\x00\x80@\x10\x87\xa7\xf0\x84\x10\xaa\x10\x00\x00D\x00\x00\x02 \x00\x8a\x06\xfa\xe0P\n-\x02@\x00\x12\x00\x00\x00\x00\x10@\x83\xdf\xa0\x00\x08\xaa@\x00\x00\x01H\x00\x05H\x04\x12\x01\xf7\x81P\x02T\t\x00\x00\x00 \x00\x00\x84\x10\x00\x00z\x00@)* \x00\x00\x01\n\xa0\x02 \x05\n\x00\x00\x05\x10\x84\xa8\x84\x80\x00\x00@\x14\x00\x92\x10\x80\x00\x04\x11@\tT\x00\x00\x00\x00\n@\x00\x08\x84@$\x00H\x00\x12Q\x02\x00\x00\x00\x00\x90\x02A\x12\xa8\n\xaa\x92\x10\x04\xa8\x10@\x00\x00\x04\x04\x00\x04I\x00\x04\x14H\x80"R\x01\x00\x00\x00!@\x00\x00$\xa0EB\x80\x08\x95hH\x00\x00\x00\x84\x10 \x05Z\x00\x00(\x00\x02\x00\xa1\x01\x00\x00\x04\x00@\x82\x00\xadH*\x92P\x00\xaaP\x00\x00\x00\x00\x11\x02\x01*\xad\x01\x00\x01\x01"\x11D\x08\x00\x00\x10\x80 \x00\x81W\x80J\x94\x04\x08\xa5 !\x00\x00\x00\x02\x00B*\xae\xa1\x00\x80\x10\x01\x08\xa4\x00\x00\x00\x00\x00\x84\x00\t[@"HA\x04E\x00\x84\x00\x00\x00\x10\x00\x01J\xd5\x82\x90\x02\x00!\x02\xa2\x00\x00\x00\x00\x00\x00\x00\x05~\xa0\x00 \x10\n)\x00\x11\x00\x00\x00\x00\x00\x00!U\x80\xa8\x88\x82\x80\x01\x00\x00\x00\x00\x00\x00H@\x11\xaa\xc0\x82\x00 *\n\x00\x00\x00\x00\x00\x00\x00\x00\n\xabb@ \x04\x00! \x84\x00\x00\x00\x00\x02@\xa5\x15A$\x04\x81(\n\x00\x00\x00\x00\x00\x00 \x01\x10\x02\xe0\x91\x02\x00\x00\x04\x00\x00\x00\x00\x00\x00\x01 \xa9\tQH@\x91 P\x00\x00\x00\x00\x00\x00\x08\x00\x00\xa0T\xa5\x00@\x80\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00 T\xa0\t\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00@\x02\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x10\x00\x00\x10\x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00@\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x08@\x10\x00\x00\x00\x00'
with self.client: with client:
self.client.set_expected_responses(EXPECTED_RESPONSES) client.set_expected_responses(EXPECTED_RESPONSES)
device.apply_settings(self.client, homescreen=img) device.apply_settings(client, homescreen=img)
@pytest.mark.skip_t2 @pytest.mark.skip_t2
def test_apply_auto_lock_delay(self): def test_apply_auto_lock_delay(self, client):
self.setup_mnemonic_pin_passphrase() with client:
client.set_expected_responses(EXPECTED_RESPONSES_PIN)
with self.client: device.apply_settings(client, auto_lock_delay_ms=int(10e3)) # 10 secs
self.client.set_expected_responses(EXPECTED_RESPONSES_PIN)
device.apply_settings(self.client, auto_lock_delay_ms=int(10e3)) # 10 secs
time.sleep(0.1) # sleep less than auto-lock delay time.sleep(0.1) # sleep less than auto-lock delay
with self.client: with client:
# No PIN protection is required. # No PIN protection is required.
self.client.set_expected_responses([proto.Success()]) client.set_expected_responses([proto.Success()])
self.client.ping(msg="", pin_protection=True) client.ping(msg="", pin_protection=True)
time.sleep(10.1) # sleep more than auto-lock delay time.sleep(10.1) # sleep more than auto-lock delay
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
[proto.PinMatrixRequest(), proto.Success()] client.ping(msg="", pin_protection=True)
)
self.client.ping(msg="", pin_protection=True)
@pytest.mark.skip_t2 @pytest.mark.skip_t2
def test_apply_minimal_auto_lock_delay(self): def test_apply_minimal_auto_lock_delay(self, client):
""" """
Verify that the delay is not below the minimal auto-lock delay (10 secs) Verify that the delay is not below the minimal auto-lock delay (10 secs)
otherwise the device may auto-lock before any user interaction. otherwise the device may auto-lock before any user interaction.
""" """
self.setup_mnemonic_pin_passphrase()
with self.client: with client:
self.client.set_expected_responses(EXPECTED_RESPONSES_PIN) client.set_expected_responses(EXPECTED_RESPONSES_PIN)
# Note: the actual delay will be 10 secs (see above). # Note: the actual delay will be 10 secs (see above).
device.apply_settings(self.client, auto_lock_delay_ms=int(1e3)) device.apply_settings(client, auto_lock_delay_ms=int(1e3))
time.sleep(0.1) # sleep less than auto-lock delay time.sleep(0.1) # sleep less than auto-lock delay
with self.client: with client:
# No PIN protection is required. # No PIN protection is required.
self.client.set_expected_responses([proto.Success()]) client.set_expected_responses([proto.Success()])
self.client.ping(msg="", pin_protection=True) client.ping(msg="", pin_protection=True)
time.sleep(2) # sleep less than the minimal auto-lock delay time.sleep(2) # sleep less than the minimal auto-lock delay
with self.client: with client:
# No PIN protection is required. # No PIN protection is required.
self.client.set_expected_responses([proto.Success()]) client.set_expected_responses([proto.Success()])
self.client.ping(msg="", pin_protection=True) client.ping(msg="", pin_protection=True)
time.sleep(10.1) # sleep more than the minimal auto-lock delay time.sleep(10.1) # sleep more than the minimal auto-lock delay
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
[proto.PinMatrixRequest(), proto.Success()] client.ping(msg="", pin_protection=True)
)
self.client.ping(msg="", pin_protection=True)

View File

@ -18,202 +18,202 @@ import pytest
from trezorlib import messages as proto from trezorlib import messages as proto
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgChangepin(TrezorTest): class TestMsgChangepin(TrezorTest):
def test_set_pin(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_set_pin(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is False assert features.pin_protection is False
# Check that there's no PIN protection # Check that there's no PIN protection
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Let's set new PIN # Let's set new PIN
ret = self.client.call_raw(proto.ChangePin()) ret = client.call_raw(proto.ChangePin())
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
# Press button # Press button
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Send the PIN for first time # Send the PIN for first time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for second time # Send the PIN for second time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now we're done # Now we're done
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check that there's PIN protection now # Check that there's PIN protection now
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
# Check that the PIN is correct # Check that the PIN is correct
self.check_pin(self.pin6) self.check_pin(client, self.pin6)
def test_change_pin(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_change_pin(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
# Check that there's PIN protection # Check that there's PIN protection
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
self.client.call_raw(proto.Cancel()) client.call_raw(proto.Cancel())
# Check current PIN value # Check current PIN value
self.check_pin(self.pin4) self.check_pin(client, self.pin4)
# Let's change PIN # Let's change PIN
ret = self.client.call_raw(proto.ChangePin()) ret = client.call_raw(proto.ChangePin())
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
# Press button # Press button
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Send current PIN # Send current PIN
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.read_pin_encoded() pin_encoded = client.debug.read_pin_encoded()
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send new PIN for first time # Send new PIN for first time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for second time # Send the PIN for second time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now we're done # Now we're done
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check that there's still PIN protection now # Check that there's still PIN protection now
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
# Check that the PIN is correct # Check that the PIN is correct
self.check_pin(self.pin6) self.check_pin(client, self.pin6)
def test_remove_pin(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_remove_pin(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
# Check that there's PIN protection # Check that there's PIN protection
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
self.client.call_raw(proto.Cancel()) client.call_raw(proto.Cancel())
# Let's remove PIN # Let's remove PIN
ret = self.client.call_raw(proto.ChangePin(remove=True)) ret = client.call_raw(proto.ChangePin(remove=True))
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
# Press button # Press button
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Send current PIN # Send current PIN
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.read_pin_encoded() pin_encoded = client.debug.read_pin_encoded()
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now we're done # Now we're done
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check that there's no PIN protection now # Check that there's no PIN protection now
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is False assert features.pin_protection is False
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
def test_set_failed(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_set_failed(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is False assert features.pin_protection is False
# Check that there's no PIN protection # Check that there's no PIN protection
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Let's set new PIN # Let's set new PIN
ret = self.client.call_raw(proto.ChangePin()) ret = client.call_raw(proto.ChangePin())
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
# Press button # Press button
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Send the PIN for first time # Send the PIN for first time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for second time, but with typo # Send the PIN for second time, but with typo
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin4) pin_encoded = client.debug.encode_pin(self.pin4)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now it should fail, because pins are different # Now it should fail, because pins are different
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
# Check that there's still no PIN protection now # Check that there's still no PIN protection now
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is False assert features.pin_protection is False
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
def test_set_failed_2(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_set_failed_2(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
# Let's set new PIN # Let's set new PIN
ret = self.client.call_raw(proto.ChangePin()) ret = client.call_raw(proto.ChangePin())
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
# Press button # Press button
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Send current PIN # Send current PIN
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.read_pin_encoded() pin_encoded = client.debug.read_pin_encoded()
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for first time # Send the PIN for first time
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for second time, but with typo # Send the PIN for second time, but with typo
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6 + "3") pin_encoded = client.debug.encode_pin(self.pin6 + "3")
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now it should fail, because pins are different # Now it should fail, because pins are different
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
# Check that there's still old PIN protection # Check that there's still old PIN protection
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.pin_protection is True assert features.pin_protection is True
self.check_pin(self.pin4) self.check_pin(client, self.pin4)
def check_pin(self, pin): def check_pin(self, client, pin):
self.client.clear_session() client.clear_session()
ret = self.client.call_raw(proto.Ping(pin_protection=True)) ret = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(pin) pin_encoded = client.debug.encode_pin(pin)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)

View File

@ -18,16 +18,14 @@ import pytest
from trezorlib import misc from trezorlib import misc
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgCipherkeyvalue(TrezorTest): class TestMsgCipherkeyvalue(TrezorTest):
def test_encrypt(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_encrypt(self, client):
# different ask values
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
b"testing message!", b"testing message!",
@ -37,7 +35,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res.hex() == "676faf8f13272af601776bc31bc14e8f" assert res.hex() == "676faf8f13272af601776bc31bc14e8f"
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
b"testing message!", b"testing message!",
@ -47,7 +45,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res.hex() == "5aa0fbcb9d7fa669880745479d80c622" assert res.hex() == "5aa0fbcb9d7fa669880745479d80c622"
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
b"testing message!", b"testing message!",
@ -57,7 +55,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res.hex() == "958d4f63269b61044aaedc900c8d6208" assert res.hex() == "958d4f63269b61044aaedc900c8d6208"
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
b"testing message!", b"testing message!",
@ -68,7 +66,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different key # different key
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test2", b"test2",
b"testing message!", b"testing message!",
@ -79,7 +77,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different message # different message
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
b"testing message! it is different", b"testing message! it is different",
@ -93,7 +91,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different path # different path
res = misc.encrypt_keyvalue( res = misc.encrypt_keyvalue(
self.client, client,
[0, 1, 3], [0, 1, 3],
b"test", b"test",
b"testing message!", b"testing message!",
@ -102,12 +100,10 @@ class TestMsgCipherkeyvalue(TrezorTest):
) )
assert res.hex() == "b4811a9d492f5355a5186ddbfccaae7b" assert res.hex() == "b4811a9d492f5355a5186ddbfccaae7b"
def test_decrypt(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_decrypt(self, client):
# different ask values
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
bytes.fromhex("676faf8f13272af601776bc31bc14e8f"), bytes.fromhex("676faf8f13272af601776bc31bc14e8f"),
@ -117,7 +113,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res == b"testing message!" assert res == b"testing message!"
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
bytes.fromhex("5aa0fbcb9d7fa669880745479d80c622"), bytes.fromhex("5aa0fbcb9d7fa669880745479d80c622"),
@ -127,7 +123,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res == b"testing message!" assert res == b"testing message!"
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
bytes.fromhex("958d4f63269b61044aaedc900c8d6208"), bytes.fromhex("958d4f63269b61044aaedc900c8d6208"),
@ -137,7 +133,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
assert res == b"testing message!" assert res == b"testing message!"
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
bytes.fromhex("e0cf0eb0425947000eb546cc3994bc6c"), bytes.fromhex("e0cf0eb0425947000eb546cc3994bc6c"),
@ -148,7 +144,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different key # different key
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test2", b"test2",
bytes.fromhex("de247a6aa6be77a134bb3f3f925f13af"), bytes.fromhex("de247a6aa6be77a134bb3f3f925f13af"),
@ -159,7 +155,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different message # different message
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 2], [0, 1, 2],
b"test", b"test",
bytes.fromhex( bytes.fromhex(
@ -172,7 +168,7 @@ class TestMsgCipherkeyvalue(TrezorTest):
# different path # different path
res = misc.decrypt_keyvalue( res = misc.decrypt_keyvalue(
self.client, client,
[0, 1, 3], [0, 1, 3],
b"test", b"test",
bytes.fromhex("b4811a9d492f5355a5186ddbfccaae7b"), bytes.fromhex("b4811a9d492f5355a5186ddbfccaae7b"),
@ -181,12 +177,10 @@ class TestMsgCipherkeyvalue(TrezorTest):
) )
assert res == b"testing message!" assert res == b"testing message!"
def test_encrypt_badlen(self): def test_encrypt_badlen(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(Exception): with pytest.raises(Exception):
misc.encrypt_keyvalue(self.client, [0, 1, 2], b"test", b"testing") misc.encrypt_keyvalue(client, [0, 1, 2], b"test", b"testing")
def test_decrypt_badlen(self): def test_decrypt_badlen(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(Exception): with pytest.raises(Exception):
misc.decrypt_keyvalue(self.client, [0, 1, 2], b"test", b"testing") misc.decrypt_keyvalue(client, [0, 1, 2], b"test", b"testing")

View File

@ -23,11 +23,10 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgClearsession(TrezorTest): class TestMsgClearsession(TrezorTest):
def test_clearsession(self): @pytest.mark.setup_client(pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_clearsession(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -35,7 +34,7 @@ class TestMsgClearsession(TrezorTest):
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,
@ -43,15 +42,15 @@ class TestMsgClearsession(TrezorTest):
) )
assert res == "random data" assert res == "random data"
with self.client: with client:
# pin and passphrase are cached # pin and passphrase are cached
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,
@ -59,11 +58,11 @@ class TestMsgClearsession(TrezorTest):
) )
assert res == "random data" assert res == "random data"
self.client.clear_session() client.clear_session()
# session cache is cleared # session cache is cleared
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -71,7 +70,7 @@ class TestMsgClearsession(TrezorTest):
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,
@ -79,15 +78,15 @@ class TestMsgClearsession(TrezorTest):
) )
assert res == "random data" assert res == "random data"
with self.client: with client:
# pin and passphrase are cached # pin and passphrase are cached
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,

View File

@ -19,16 +19,16 @@ import pytest
from trezorlib.eos import get_public_key from trezorlib.eos import get_public_key
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.eos @pytest.mark.eos
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgEosGetpublickey(TrezorTest): class TestMsgEosGetpublickey(TrezorTest):
def test_eos_get_public_key(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_eos_get_public_key(self, client):
public_key = get_public_key(self.client, parse_path("m/44'/194'/0'/0/0")) public_key = get_public_key(client, parse_path("m/44'/194'/0'/0/0"))
assert ( assert (
public_key.wif_public_key public_key.wif_public_key
== "EOS4u6Sfnzj4Sh2pEQnkXyZQJqH3PkKjGByDCbsqqmyq6PttM9KyB" == "EOS4u6Sfnzj4Sh2pEQnkXyZQJqH3PkKjGByDCbsqqmyq6PttM9KyB"
@ -37,7 +37,7 @@ class TestMsgEosGetpublickey(TrezorTest):
public_key.raw_public_key.hex() public_key.raw_public_key.hex()
== "02015fabe197c955036bab25f4e7c16558f9f672f9f625314ab1ec8f64f7b1198e" == "02015fabe197c955036bab25f4e7c16558f9f672f9f625314ab1ec8f64f7b1198e"
) )
public_key = get_public_key(self.client, parse_path("m/44'/194'/0'/0/1")) public_key = get_public_key(client, parse_path("m/44'/194'/0'/0/1"))
assert ( assert (
public_key.wif_public_key public_key.wif_public_key
== "EOS5d1VP15RKxT4dSakWu2TFuEgnmaGC2ckfSvQwND7pZC1tXkfLP" == "EOS5d1VP15RKxT4dSakWu2TFuEgnmaGC2ckfSvQwND7pZC1tXkfLP"
@ -46,7 +46,7 @@ class TestMsgEosGetpublickey(TrezorTest):
public_key.raw_public_key.hex() public_key.raw_public_key.hex()
== "02608bc2c431521dee0b9d5f2fe34053e15fc3b20d2895e0abda857b9ed8e77a78" == "02608bc2c431521dee0b9d5f2fe34053e15fc3b20d2895e0abda857b9ed8e77a78"
) )
public_key = get_public_key(self.client, parse_path("m/44'/194'/1'/0/0")) public_key = get_public_key(client, parse_path("m/44'/194'/1'/0/0"))
assert ( assert (
public_key.wif_public_key public_key.wif_public_key
== "EOS7UuNeTf13nfcG85rDB7AHGugZi4C4wJ4ft12QRotqNfxdV2NvP" == "EOS7UuNeTf13nfcG85rDB7AHGugZi4C4wJ4ft12QRotqNfxdV2NvP"

View File

@ -21,7 +21,7 @@ from trezorlib import eos
from trezorlib.messages import EosSignedTx from trezorlib.messages import EosSignedTx
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
CHAIN_ID = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f" CHAIN_ID = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
ADDRESS_N = parse_path("m/44'/194'/0'/0/0") ADDRESS_N = parse_path("m/44'/194'/0'/0/0")
@ -30,22 +30,23 @@ ADDRESS_N = parse_path("m/44'/194'/0'/0/0")
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.eos @pytest.mark.eos
@pytest.mark.skip_t1 @pytest.mark.skip_t1
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
class TestMsgEosSignTx(TrezorTest): class TestMsgEosSignTx(TrezorTest):
def input_flow(self, pages): @pytest.mark.setup_client(uninitialized=True)
def input_flow(self, debug, pages):
# confirm number of actions # confirm number of actions
yield yield
self.client.debug.press_yes() debug.press_yes()
# swipe through pages # swipe through pages
yield yield
for _ in range(pages - 1): for _ in range(pages - 1):
self.client.debug.swipe_down() debug.swipe_down()
# confirm last page # confirm last page
self.client.debug.press_yes() debug.press_yes()
def test_eos_signtx_transfer_token(self): def test_eos_signtx_transfer_token(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -72,17 +73,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=3)) client.set_input_flow(self.input_flow(client.debug, pages=3))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JveDuew7oyKjgLmApra3NmKArx3QH6HVmatgkLYeUYWv7aGaoQPFyjBwAdcxuo2Skq9wRgsizos92h9iq9i5JbeHh7zNuo" == "SIG_K1_JveDuew7oyKjgLmApra3NmKArx3QH6HVmatgkLYeUYWv7aGaoQPFyjBwAdcxuo2Skq9wRgsizos92h9iq9i5JbeHh7zNuo"
) )
def test_eos_signtx_buyram(self): def test_eos_signtx_buyram(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -108,17 +108,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_K4gU5S9g7rS6MojaPwWppEBCBbPrJm1pyJtVR9mts1sBq5xyN7nJv3FGnrBR7ByjanboCtK4ogY35sNPFX1F5qoZW7BkF9" == "SIG_K1_K4gU5S9g7rS6MojaPwWppEBCBbPrJm1pyJtVR9mts1sBq5xyN7nJv3FGnrBR7ByjanboCtK4ogY35sNPFX1F5qoZW7BkF9"
) )
def test_eos_signtx_buyrambytes(self): def test_eos_signtx_buyrambytes(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -144,17 +143,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_K618wK9f27YxHoPG9hoUCsazZXzxumBj3V9MqcTUh9yCocvP1uFZQAmGmZLhsAtuC2TRR4gtqbeQj57FniYd5i4faQCb6t" == "SIG_K1_K618wK9f27YxHoPG9hoUCsazZXzxumBj3V9MqcTUh9yCocvP1uFZQAmGmZLhsAtuC2TRR4gtqbeQj57FniYd5i4faQCb6t"
) )
def test_eos_signtx_sellram(self): def test_eos_signtx_sellram(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -176,17 +174,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JusrCS7H5DR53qke7edoWvJuLiQS2VQ84CsN5NWmWYVa7wmJVjh3Hcg5hH42zF8KjAmmvHtaJZ3wkortTW9eds1eoiKsrj" == "SIG_K1_JusrCS7H5DR53qke7edoWvJuLiQS2VQ84CsN5NWmWYVa7wmJVjh3Hcg5hH42zF8KjAmmvHtaJZ3wkortTW9eds1eoiKsrj"
) )
def test_eos_signtx_delegate(self): def test_eos_signtx_delegate(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -214,17 +211,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=3)) client.set_input_flow(self.input_flow(client.debug, pages=3))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_Juju8Wjzyn38nuvgS1KT3koKQLHxMMfqVHrp5jMjv4QLU2pUG6EbiJD7D1EHE6xP8DRuwFLVUNR38nTyUKC1Eiz33WocUE" == "SIG_K1_Juju8Wjzyn38nuvgS1KT3koKQLHxMMfqVHrp5jMjv4QLU2pUG6EbiJD7D1EHE6xP8DRuwFLVUNR38nTyUKC1Eiz33WocUE"
) )
def test_eos_signtx_undelegate(self): def test_eos_signtx_undelegate(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -251,17 +247,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_K3XXUzCUkT2HEdrJTz1CdDDKZbLMShmyEjknQozGhy4F21yUetr1nEe2vUgmGebk2nyYe49R5nkA155J5yFBBaLsTcSdBL" == "SIG_K1_K3XXUzCUkT2HEdrJTz1CdDDKZbLMShmyEjknQozGhy4F21yUetr1nEe2vUgmGebk2nyYe49R5nkA155J5yFBBaLsTcSdBL"
) )
def test_eos_signtx_refund(self): def test_eos_signtx_refund(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -283,17 +278,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=0)) client.set_input_flow(self.input_flow(client.debug, pages=0))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JwWZSSKQZL1hCdMmwEAKjs3r15kau5gaBrQczKy65QANANzovV6U4XbVUZQkZzaQrNGYAtgxrU1WJ1smWgXZNqtKVQUZqc" == "SIG_K1_JwWZSSKQZL1hCdMmwEAKjs3r15kau5gaBrQczKy65QANANzovV6U4XbVUZQkZzaQrNGYAtgxrU1WJ1smWgXZNqtKVQUZqc"
) )
def test_eos_signtx_linkauth(self): def test_eos_signtx_linkauth(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -320,17 +314,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_Kgs3JdLNqTyGz7uyNiuYLK8sy5qhVQWozrBY7bJWKsjrWAxNyDQUKqHsHmTom5rGY21vYdXmCpi4msU6XeMgWvi4bsBxTx" == "SIG_K1_Kgs3JdLNqTyGz7uyNiuYLK8sy5qhVQWozrBY7bJWKsjrWAxNyDQUKqHsHmTom5rGY21vYdXmCpi4msU6XeMgWvi4bsBxTx"
) )
def test_eos_signtx_unlinkauth(self): def test_eos_signtx_unlinkauth(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -356,17 +349,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_K1ioB5KMRC2mmTwYsGwsFU51ENp1XdSBUrb4bxUCLYhoq7Y733WaLZ4Soq9fdrkaJS8uJ3R7Z1ZjyEKRHU8HU4s4MA86zB" == "SIG_K1_K1ioB5KMRC2mmTwYsGwsFU51ENp1XdSBUrb4bxUCLYhoq7Y733WaLZ4Soq9fdrkaJS8uJ3R7Z1ZjyEKRHU8HU4s4MA86zB"
) )
def test_eos_signtx_updateauth(self): def test_eos_signtx_updateauth(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -415,17 +407,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=8)) client.set_input_flow(self.input_flow(client.debug, pages=8))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JuNuwmJm7nLfpxbCqXZMxZoU56TzBh8F5PH7ZyPvQMti6QxJbErDGbKCAaHhoRxwWKzv5kj6kX3WyWys6jAzVe9pDhXB1k" == "SIG_K1_JuNuwmJm7nLfpxbCqXZMxZoU56TzBh8F5PH7ZyPvQMti6QxJbErDGbKCAaHhoRxwWKzv5kj6kX3WyWys6jAzVe9pDhXB1k"
) )
def test_eos_signtx_deleteauth(self): def test_eos_signtx_deleteauth(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -447,17 +438,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=0)) client.set_input_flow(self.input_flow(client.debug, pages=0))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_KjPTp8jCtgBKQWqsndhrH4pdCGiks76Q1qBt9e8MtexW6FQg3FzfVFKDU4SvyVDyFs3worn6RyW6WYavw76ACNqcqkCYjf" == "SIG_K1_KjPTp8jCtgBKQWqsndhrH4pdCGiks76Q1qBt9e8MtexW6FQg3FzfVFKDU4SvyVDyFs3worn6RyW6WYavw76ACNqcqkCYjf"
) )
def test_eos_signtx_vote(self): def test_eos_signtx_vote(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -513,17 +503,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=6)) client.set_input_flow(self.input_flow(client.debug, pages=6))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JxgVhc6ExoTHee3Djrciwmmf2Xck7NLgvAtC2gfgV4Wj2AqMXEb6aKMhpUcTV59VTR1DdnPF1XbiCcJViJiU3zsk1kQz89" == "SIG_K1_JxgVhc6ExoTHee3Djrciwmmf2Xck7NLgvAtC2gfgV4Wj2AqMXEb6aKMhpUcTV59VTR1DdnPF1XbiCcJViJiU3zsk1kQz89"
) )
def test_eos_signtx_vote_proxy(self): def test_eos_signtx_vote_proxy(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -545,17 +534,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=0)) client.set_input_flow(self.input_flow(client.debug, pages=0))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_KjJzcDg9MT8XbLeP1fgQjdmdE6oNQQisMwbXikqrEZYmJe6GCYg89Wr2donYV6zRfg9h7dJKQDCHugdtsxjtmEdqLtPv25" == "SIG_K1_KjJzcDg9MT8XbLeP1fgQjdmdE6oNQQisMwbXikqrEZYmJe6GCYg89Wr2donYV6zRfg9h7dJKQDCHugdtsxjtmEdqLtPv25"
) )
def test_eos_signtx_unknown(self): def test_eos_signtx_unknown(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -577,17 +565,16 @@ class TestMsgEosSignTx(TrezorTest):
"transaction_extensions": [], "transaction_extensions": [],
} }
with self.client: with client:
self.client.set_input_flow(self.input_flow(pages=2)) client.set_input_flow(self.input_flow(client.debug, pages=2))
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_JvoJtrHpQJjHAZzEBhiQm75iimYabcAVNDvz8mkempLh6avSJgnXm5JzCCUEBjDtW3syByfXknmgr93Sw3P9RNLnwySmv6" == "SIG_K1_JvoJtrHpQJjHAZzEBhiQm75iimYabcAVNDvz8mkempLh6avSJgnXm5JzCCUEBjDtW3syByfXknmgr93Sw3P9RNLnwySmv6"
) )
def test_eos_signtx_newaccount(self): def test_eos_signtx_newaccount(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-07-14T10:43:28", "expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439, "ref_block_num": 6439,
@ -663,42 +650,41 @@ class TestMsgEosSignTx(TrezorTest):
def input_flow(): def input_flow():
# confirm number of actions # confirm number of actions
yield yield
self.client.debug.press_yes() client.debug.press_yes()
# swipe through new account # swipe through new account
yield yield
for _ in range(5): for _ in range(5):
self.client.debug.swipe_down() client.debug.swipe_down()
# confirm new account # confirm new account
self.client.debug.press_yes() client.debug.press_yes()
# swipe through buyrambytes # swipe through buyrambytes
yield yield
self.client.debug.swipe_down() client.debug.swipe_down()
# confirm buyrambytes # confirm buyrambytes
self.client.debug.press_yes() client.debug.press_yes()
# swipe through delegatebw # swipe through delegatebw
yield yield
for _ in range(2): for _ in range(2):
self.client.debug.swipe_down() client.debug.swipe_down()
# confirm delegatebw # confirm delegatebw
self.client.debug.press_yes() client.debug.press_yes()
with self.client: with client:
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature
== "SIG_K1_KhjdS1gKUHR4jKbN3YSdNbPbEqnUVM1Nt6ybdzEAwsUtfbCRJDwpQwPRuEau48CyvhYC5fKo5BiWMPQJbQPrg5ErHThieU" == "SIG_K1_KhjdS1gKUHR4jKbN3YSdNbPbEqnUVM1Nt6ybdzEAwsUtfbCRJDwpQwPRuEau48CyvhYC5fKo5BiWMPQJbQPrg5ErHThieU"
) )
def test_eos_signtx_setcontract(self): def test_eos_signtx_setcontract(self, client):
self.setup_mnemonic_nopin_nopassphrase()
transaction = { transaction = {
"expiration": "2018-06-19T13:29:53", "expiration": "2018-06-19T13:29:53",
"ref_block_num": 30587, "ref_block_num": 30587,
@ -732,25 +718,25 @@ class TestMsgEosSignTx(TrezorTest):
def input_flow(): def input_flow():
# confirm number of actions # confirm number of actions
yield yield
self.client.debug.press_yes() client.debug.press_yes()
# swipe through setcode # swipe through setcode
yield yield
self.client.debug.swipe_down() client.debug.swipe_down()
# confirm setcode # confirm setcode
self.client.debug.press_yes() client.debug.press_yes()
# swipe through setabi # swipe through setabi
yield yield
self.client.debug.swipe_down() client.debug.swipe_down()
# confirm setabi # confirm setabi
self.client.debug.press_yes() client.debug.press_yes()
with self.client: with client:
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
resp = eos.sign_tx(self.client, ADDRESS_N, transaction, CHAIN_ID) resp = eos.sign_tx(client, ADDRESS_N, transaction, CHAIN_ID)
assert isinstance(resp, EosSignedTx) assert isinstance(resp, EosSignedTx)
assert ( assert (
resp.signature resp.signature

View File

@ -19,40 +19,40 @@ import pytest
from trezorlib import ethereum from trezorlib import ethereum
from trezorlib.tools import H_ from trezorlib.tools import H_
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.ethereum @pytest.mark.ethereum
class TestMsgEthereumGetaddress(TrezorTest): class TestMsgEthereumGetaddress(TrezorTest):
def test_ethereum_getaddress(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_getaddress(self, client):
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60)]) ethereum.get_address(client, [H_(44), H_(60)])
== "0xE025dfbE2C53638E547C6487DED34Add7b8Aafc1" == "0xE025dfbE2C53638E547C6487DED34Add7b8Aafc1"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 1]) ethereum.get_address(client, [H_(44), H_(60), 1])
== "0xeD46C856D0c79661cF7d40FFE0C0C5077c00E898" == "0xeD46C856D0c79661cF7d40FFE0C0C5077c00E898"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 0, H_(1)]) ethereum.get_address(client, [H_(44), H_(60), 0, H_(1)])
== "0x6682Fa7F3eC58581b1e576268b5463B4b5c93839" == "0x6682Fa7F3eC58581b1e576268b5463B4b5c93839"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), H_(9), 0]) ethereum.get_address(client, [H_(44), H_(60), H_(9), 0])
== "0xFb3BE0F9717fF5fCF3C58EB49a9Ed67F1BD89D4E" == "0xFb3BE0F9717fF5fCF3C58EB49a9Ed67F1BD89D4E"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 0, 9999999]) ethereum.get_address(client, [H_(44), H_(60), 0, 9999999])
== "0x6b909b50d88c9A8E02453A87b3662E3e7a5E0CF1" == "0x6b909b50d88c9A8E02453A87b3662E3e7a5E0CF1"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999]) ethereum.get_address(client, [H_(44), H_(6060), 0, 9999999])
== "0x98b8e926bd224764De2A0E4f4CBe1521474050AF" == "0x98b8e926bd224764De2A0E4f4CBe1521474050AF"
) )
# Wanchain SLIP44 id # Wanchain SLIP44 id
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(5718350), H_(0)]) ethereum.get_address(client, [H_(44), H_(5718350), H_(0)])
== "0x4d643B1b556E14A27143a38bcE61230FFf5AFca8" == "0x4d643B1b556E14A27143a38bcE61230FFf5AFca8"
) )

View File

@ -19,15 +19,15 @@ import pytest
from trezorlib import ethereum from trezorlib import ethereum
from trezorlib.tools import H_ from trezorlib.tools import H_
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.ethereum @pytest.mark.ethereum
class TestMsgEthereumGetPublicKey(TrezorTest): class TestMsgEthereumGetPublicKey(TrezorTest):
def test_ethereum_getpublickey(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_getpublickey(self, client):
res = ethereum.get_public_node(self.client, [H_(44), H_(60), H_(0)]) res = ethereum.get_public_node(client, [H_(44), H_(60), H_(0)])
assert res.node.depth == 3 assert res.node.depth == 3
assert res.node.fingerprint == 0xC10CFFDA assert res.node.fingerprint == 0xC10CFFDA
assert res.node.child_num == 0x80000000 assert res.node.child_num == 0x80000000

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import ethereum from trezorlib import ethereum
from trezorlib.tools import H_ from trezorlib.tools import H_
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@ -63,9 +63,9 @@ class TestMsgEthereumSignmessage(TrezorTest):
), ),
] ]
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
for msg, sig in self.VECTORS: for msg, sig in self.VECTORS:
res = ethereum.sign_message(self.client, self.PATH, msg) res = ethereum.sign_message(client, self.PATH, msg)
assert res.address == self.ADDRESS assert res.address == self.ADDRESS
assert res.signature.hex() == sig assert res.signature.hex() == sig

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import ethereum, messages as proto from trezorlib import ethereum, messages as proto
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef" TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
@ -27,11 +27,10 @@ TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.ethereum @pytest.mark.ethereum
class TestMsgEthereumSigntx(TrezorTest): class TestMsgEthereumSigntx(TrezorTest):
def test_ethereum_signtx_known_erc20_token(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_known_erc20_token(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -57,7 +56,7 @@ class TestMsgEthereumSigntx(TrezorTest):
# 200 000 000 in dec, divisibility of ADT = 9, trezor1 displays 0.2 ADT, Trezor T 200 000 000 Wei ADT # 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 = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=0, nonce=0,
gas_price=20, gas_price=20,
@ -80,11 +79,10 @@ class TestMsgEthereumSigntx(TrezorTest):
== "7001bfe3ba357e4a9f9e0d3a3f8a8962257615a4cf215db93e48b98999fc51b7" == "7001bfe3ba357e4a9f9e0d3a3f8a8962257615a4cf215db93e48b98999fc51b7"
) )
def test_ethereum_signtx_wanchain(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_wanchain(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -92,7 +90,7 @@ class TestMsgEthereumSigntx(TrezorTest):
] ]
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/5718350'/0'/0/0"), n=parse_path("44'/5718350'/0'/0/0"),
nonce=0, nonce=0,
gas_price=20, gas_price=20,
@ -115,11 +113,10 @@ class TestMsgEthereumSigntx(TrezorTest):
== "326e0d600dd1b7ee606eb531b998a6a3b3293d4995fb8cfe0677962e8a43cff6" == "326e0d600dd1b7ee606eb531b998a6a3b3293d4995fb8cfe0677962e8a43cff6"
) )
def test_ethereum_signtx_unknown_erc20_token(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_unknown_erc20_token(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -145,7 +142,7 @@ class TestMsgEthereumSigntx(TrezorTest):
# since this token is unknown trezor should display "unknown token value" # since this token is unknown trezor should display "unknown token value"
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/1"), n=parse_path("44'/60'/0'/0/1"),
nonce=0, nonce=0,
gas_price=20, gas_price=20,
@ -168,11 +165,10 @@ class TestMsgEthereumSigntx(TrezorTest):
== "633a74429eb6d3aeec4ed797542236a85daab3cab15e37736b87a45697541d7a" == "633a74429eb6d3aeec4ed797542236a85daab3cab15e37736b87a45697541d7a"
) )
def test_ethereum_signtx_nodata(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_nodata(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -181,7 +177,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/100"), n=parse_path("44'/60'/0'/0/100"),
nonce=0, nonce=0,
gas_price=20, gas_price=20,
@ -200,8 +196,8 @@ class TestMsgEthereumSigntx(TrezorTest):
== "428d35f0dca963b5196b63e7aa5e0405d8bff77d6aee1202183f1f68dacb4483" == "428d35f0dca963b5196b63e7aa5e0405d8bff77d6aee1202183f1f68dacb4483"
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -210,7 +206,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/100"), n=parse_path("44'/60'/0'/0/100"),
nonce=123456, nonce=123456,
gas_price=20000, gas_price=20000,
@ -228,11 +224,10 @@ class TestMsgEthereumSigntx(TrezorTest):
== "48b3ef1b2502febdf35e9ff4df0ba1fda62f042fad639eb4852a297fc9872ebd" == "48b3ef1b2502febdf35e9ff4df0ba1fda62f042fad639eb4852a297fc9872ebd"
) )
def test_ethereum_signtx_data(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_data(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -242,7 +237,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=0, nonce=0,
gas_price=20, gas_price=20,
@ -261,8 +256,8 @@ class TestMsgEthereumSigntx(TrezorTest):
== "763912b8801f76cbea7792d98123a245514beeab2f3afebb4bab637888e8393a" == "763912b8801f76cbea7792d98123a245514beeab2f3afebb4bab637888e8393a"
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -281,7 +276,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=123456, nonce=123456,
gas_price=20000, gas_price=20000,
@ -300,11 +295,10 @@ class TestMsgEthereumSigntx(TrezorTest):
== "60a77558f28d483d476f9507cd8a6a4bb47b86611aaff95fd5499b9ee9ebe7ee" == "60a77558f28d483d476f9507cd8a6a4bb47b86611aaff95fd5499b9ee9ebe7ee"
) )
def test_ethereum_signtx_message(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ethereum_signtx_message(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -323,7 +317,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=0, nonce=0,
gas_price=20000, gas_price=20000,
@ -342,13 +336,11 @@ class TestMsgEthereumSigntx(TrezorTest):
== "7b34b5d8a43771d493cd9fa0c7b27a9563e2a31799fb9f0c2809539a848b9f47" == "7b34b5d8a43771d493cd9fa0c7b27a9563e2a31799fb9f0c2809539a848b9f47"
) )
def test_ethereum_signtx_newcontract(self): def test_ethereum_signtx_newcontract(self, client):
self.setup_mnemonic_allallall()
# contract creation without data should fail. # contract creation without data should fail.
with pytest.raises(Exception): with pytest.raises(Exception):
ethereum.sign_tx( ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=123456, nonce=123456,
gas_price=20000, gas_price=20000,
@ -357,8 +349,8 @@ class TestMsgEthereumSigntx(TrezorTest):
value=12345678901234567890, value=12345678901234567890,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
@ -377,7 +369,7 @@ class TestMsgEthereumSigntx(TrezorTest):
) )
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=0, nonce=0,
gas_price=20000, gas_price=20000,
@ -396,11 +388,12 @@ class TestMsgEthereumSigntx(TrezorTest):
== "18742403f75a05e7fa9868c30b36f1e55628de02d01c03084c1ff6775a13137c" == "18742403f75a05e7fa9868c30b36f1e55628de02d01c03084c1ff6775a13137c"
) )
def test_ethereum_sanity_checks(self): @pytest.mark.setup_client(uninitialized=True)
def test_ethereum_sanity_checks(self, client):
# gas overflow # gas overflow
with pytest.raises(Exception): with pytest.raises(Exception):
ethereum.sign_tx( ethereum.sign_tx(
self.client, client,
n=parse_path("44'/60'/0'/0/0"), n=parse_path("44'/60'/0'/0/0"),
nonce=123456, nonce=123456,
gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
@ -412,7 +405,7 @@ class TestMsgEthereumSigntx(TrezorTest):
# no gas price # no gas price
with pytest.raises(Exception): with pytest.raises(Exception):
ethereum.sign_tx( ethereum.sign_tx(
self.client, client,
n=[0, 0], n=[0, 0],
nonce=123456, nonce=123456,
gas_limit=10000, gas_limit=10000,
@ -423,7 +416,7 @@ class TestMsgEthereumSigntx(TrezorTest):
# no gas limit # no gas limit
with pytest.raises(Exception): with pytest.raises(Exception):
ethereum.sign_tx( ethereum.sign_tx(
self.client, client,
n=[0, 0], n=[0, 0],
nonce=123456, nonce=123456,
gas_price=10000, gas_price=10000,
@ -434,7 +427,7 @@ class TestMsgEthereumSigntx(TrezorTest):
# no nonce # no nonce
with pytest.raises(Exception): with pytest.raises(Exception):
ethereum.sign_tx( ethereum.sign_tx(
self.client, client,
n=[0, 0], n=[0, 0],
gas_price=10000, gas_price=10000,
gas_limit=123456, gas_limit=123456,

View File

@ -25,9 +25,7 @@ from .common import TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.ethereum @pytest.mark.ethereum
class TestMsgEthereumSigntxChainId(TrezorTest): class TestMsgEthereumSigntxChainId(TrezorTest):
def test_ethereum_signtx_eip155(self): def test_ethereum_signtx_eip155(self, client):
# chain_id, nonce, sig_v, sig_r, sig_s, value, gas_limit, data
VECTORS = [ VECTORS = [
( (
3, 3,
@ -201,11 +199,9 @@ class TestMsgEthereumSigntxChainId(TrezorTest):
), ),
] ]
self.setup_mnemonic_allallall()
for ci, n, sv, sr, ss, v, gl, d in VECTORS: for ci, n, sv, sr, ss, v, gl, d in VECTORS:
sig_v, sig_r, sig_s = ethereum.sign_tx( sig_v, sig_r, sig_s = ethereum.sign_tx(
self.client, client,
n=[H_(44), H_(60), H_(0), 0, 0], n=[H_(44), H_(60), H_(0), 0, 0],
nonce=n, nonce=n,
gas_price=20000000000, gas_price=20000000000,

View File

@ -61,18 +61,14 @@ class TestMsgEthereumVerifymessage(TrezorTest):
), ),
] ]
def test_verify(self): def test_verify(self, client):
self.setup_mnemonic_nopin_nopassphrase()
for msg, sig in self.VECTORS: for msg, sig in self.VECTORS:
res = ethereum.verify_message( res = ethereum.verify_message(client, self.ADDRESS, bytes.fromhex(sig), msg)
self.client, self.ADDRESS, bytes.fromhex(sig), msg
)
assert res is True assert res is True
def test_verify_invalid(self): def test_verify_invalid(self, client):
self.setup_mnemonic_nopin_nopassphrase()
signature = bytes.fromhex(self.VECTORS[0][1]) signature = bytes.fromhex(self.VECTORS[0][1])
res = ethereum.verify_message( res = ethereum.verify_message(
self.client, self.ADDRESS, signature, "another message" client, self.ADDRESS, signature, "another message"
) )
assert res is False assert res is False

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import btc, ckd_public as bip32, messages as proto from trezorlib import btc, ckd_public as bip32, messages as proto
from trezorlib.tools import H_, CallException, parse_path from trezorlib.tools import H_, CallException, parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]): def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]):
@ -32,111 +32,107 @@ def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]):
class TestMsgGetaddress(TrezorTest): class TestMsgGetaddress(TrezorTest):
def test_btc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_btc(self, client):
assert ( assert (
btc.get_address(self.client, "Bitcoin", []) btc.get_address(client, "Bitcoin", [])
== "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK" == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [1]) btc.get_address(client, "Bitcoin", [1])
== "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [0, H_(1)]) btc.get_address(client, "Bitcoin", [0, H_(1)])
== "1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs" == "1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [H_(9), 0]) btc.get_address(client, "Bitcoin", [H_(9), 0])
== "1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P" == "1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [0, 9999999]) btc.get_address(client, "Bitcoin", [0, 9999999])
== "1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV" == "1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV"
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_ltc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ltc(self, client):
assert ( assert (
btc.get_address(self.client, "Litecoin", []) btc.get_address(client, "Litecoin", [])
== "LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK" == "LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK"
) )
assert ( assert (
btc.get_address(self.client, "Litecoin", [1]) btc.get_address(client, "Litecoin", [1])
== "LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE" == "LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE"
) )
assert ( assert (
btc.get_address(self.client, "Litecoin", [0, H_(1)]) btc.get_address(client, "Litecoin", [0, H_(1)])
== "LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6" == "LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6"
) )
assert ( assert (
btc.get_address(self.client, "Litecoin", [H_(9), 0]) btc.get_address(client, "Litecoin", [H_(9), 0])
== "LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX" == "LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX"
) )
assert ( assert (
btc.get_address(self.client, "Litecoin", [0, 9999999]) btc.get_address(client, "Litecoin", [0, 9999999])
== "Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S" == "Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S"
) )
def test_tbtc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_tbtc(self, client):
assert ( assert (
btc.get_address(self.client, "Testnet", [111, 42]) btc.get_address(client, "Testnet", [111, 42])
== "moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa" == "moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa"
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_bch(self): def test_bch(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address(self.client, "Bcash", parse_path("44'/145'/0'/0/0")) btc.get_address(client, "Bcash", parse_path("44'/145'/0'/0/0"))
== "bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv" == "bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv"
) )
assert ( assert (
btc.get_address(self.client, "Bcash", parse_path("44'/145'/0'/0/1")) btc.get_address(client, "Bcash", parse_path("44'/145'/0'/0/1"))
== "bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4" == "bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4"
) )
assert ( assert (
btc.get_address(self.client, "Bcash", parse_path("44'/145'/0'/1/0")) btc.get_address(client, "Bcash", parse_path("44'/145'/0'/1/0"))
== "bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw" == "bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw"
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_grs(self): def test_grs(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address(self.client, "Groestlcoin", parse_path("44'/17'/0'/0/0")) btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/0/0"))
== "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM" == "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM"
) )
assert ( assert (
btc.get_address(self.client, "Groestlcoin", parse_path("44'/17'/0'/1/0")) btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/1/0"))
== "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN" == "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN"
) )
assert ( assert (
btc.get_address(self.client, "Groestlcoin", parse_path("44'/17'/0'/1/1")) btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/1/1"))
== "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di" == "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di"
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_elements(self): def test_elements(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address(self.client, "Elements", parse_path("m/44'/1'/0'/0/0")) btc.get_address(client, "Elements", parse_path("m/44'/1'/0'/0/0"))
== "2dpWh6jbhAowNsQ5agtFzi7j6nKscj6UnEr" == "2dpWh6jbhAowNsQ5agtFzi7j6nKscj6UnEr"
) )
def test_multisig(self): def test_multisig(self, client):
self.setup_mnemonic_allallall()
xpubs = [] xpubs = []
for n in range(1, 4): for n in range(1, 4):
node = btc.get_public_node(self.client, parse_path("44'/0'/%d'" % n)) node = btc.get_public_node(client, parse_path("44'/0'/%d'" % n))
xpubs.append(node.xpub) xpubs.append(node.xpub)
for nr in range(1, 4): for nr in range(1, 4):
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Bitcoin", "Bitcoin",
parse_path("44'/0'/%d'/0/0" % nr), parse_path("44'/0'/%d'/0/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -146,7 +142,7 @@ class TestMsgGetaddress(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Bitcoin", "Bitcoin",
parse_path("44'/0'/%d'/1/0" % nr), parse_path("44'/0'/%d'/1/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -155,19 +151,18 @@ class TestMsgGetaddress(TrezorTest):
== "36gP3KVx1ooStZ9quZDXbAF3GCr42b2zzd" == "36gP3KVx1ooStZ9quZDXbAF3GCr42b2zzd"
) )
def test_multisig_missing(self): def test_multisig_missing(self, client):
self.setup_mnemonic_allallall()
xpubs = [] xpubs = []
for n in range(1, 4): for n in range(1, 4):
# shift account numbers by 10 to create valid multisig, # shift account numbers by 10 to create valid multisig,
# but not containing the keys used below # but not containing the keys used below
n = n + 10 n = n + 10
node = btc.get_public_node(self.client, parse_path("44'/0'/%d'" % n)) node = btc.get_public_node(client, parse_path("44'/0'/%d'" % n))
xpubs.append(node.xpub) xpubs.append(node.xpub)
for nr in range(1, 4): for nr in range(1, 4):
with pytest.raises(CallException): with pytest.raises(CallException):
btc.get_address( btc.get_address(
self.client, client,
"Bitcoin", "Bitcoin",
parse_path("44'/0'/%d'/0/0" % nr), parse_path("44'/0'/%d'/0/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -175,7 +170,7 @@ class TestMsgGetaddress(TrezorTest):
) )
with pytest.raises(CallException): with pytest.raises(CallException):
btc.get_address( btc.get_address(
self.client, client,
"Bitcoin", "Bitcoin",
parse_path("44'/0'/%d'/1/0" % nr), parse_path("44'/0'/%d'/1/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -183,17 +178,16 @@ class TestMsgGetaddress(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_bch_multisig(self): def test_bch_multisig(self, client):
self.setup_mnemonic_allallall()
xpubs = [] xpubs = []
for n in range(1, 4): for n in range(1, 4):
node = btc.get_public_node(self.client, parse_path("44'/145'/%d'" % n)) node = btc.get_public_node(client, parse_path("44'/145'/%d'" % n))
xpubs.append(node.xpub) xpubs.append(node.xpub)
for nr in range(1, 4): for nr in range(1, 4):
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Bcash", "Bcash",
parse_path("44'/145'/%d'/0/0" % nr), parse_path("44'/145'/%d'/0/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -203,7 +197,7 @@ class TestMsgGetaddress(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Bcash", "Bcash",
parse_path("44'/145'/%d'/1/0" % nr), parse_path("44'/145'/%d'/1/0" % nr),
show_display=(nr == 1), show_display=(nr == 1),
@ -212,17 +206,16 @@ class TestMsgGetaddress(TrezorTest):
== "bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a" == "bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a"
) )
def test_public_ckd(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_public_ckd(self, client):
node = btc.get_public_node(client, []).node
node = btc.get_public_node(self.client, []).node node_sub1 = btc.get_public_node(client, [1]).node
node_sub1 = btc.get_public_node(self.client, [1]).node
node_sub2 = bip32.public_ckd(node, [1]) node_sub2 = bip32.public_ckd(node, [1])
assert node_sub1.chain_code == node_sub2.chain_code assert node_sub1.chain_code == node_sub2.chain_code
assert node_sub1.public_key == node_sub2.public_key assert node_sub1.public_key == node_sub2.public_key
address1 = btc.get_address(self.client, "Bitcoin", [1]) address1 = btc.get_address(client, "Bitcoin", [1])
address2 = bip32.get_address(node_sub2, 0) address2 = bip32.get_address(node_sub2, 0)
assert address2 == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" assert address2 == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb"

View File

@ -23,11 +23,10 @@ from .common import TrezorTest
class TestMsgGetaddressSegwit(TrezorTest): class TestMsgGetaddressSegwit(TrezorTest):
def test_show_segwit(self): def test_show_segwit(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("49'/1'/0'/1/0"), parse_path("49'/1'/0'/1/0"),
True, True,
@ -38,7 +37,7 @@ class TestMsgGetaddressSegwit(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("49'/1'/0'/0/0"), parse_path("49'/1'/0'/0/0"),
False, False,
@ -49,7 +48,7 @@ class TestMsgGetaddressSegwit(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("44'/1'/0'/0/0"), parse_path("44'/1'/0'/0/0"),
False, False,
@ -60,7 +59,7 @@ class TestMsgGetaddressSegwit(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("44'/1'/0'/0/0"), parse_path("44'/1'/0'/0/0"),
False, False,
@ -71,11 +70,10 @@ class TestMsgGetaddressSegwit(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_show_segwit_altcoin(self): def test_show_segwit_altcoin(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Groestlcoin Testnet", "Groestlcoin Testnet",
parse_path("49'/1'/0'/0/0"), parse_path("49'/1'/0'/0/0"),
False, False,
@ -86,7 +84,7 @@ class TestMsgGetaddressSegwit(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Elements", "Elements",
parse_path("m/49'/1'/0'/0/0"), parse_path("m/49'/1'/0'/0/0"),
False, False,
@ -96,10 +94,9 @@ class TestMsgGetaddressSegwit(TrezorTest):
== "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z" == "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z"
) )
def test_show_multisig_3(self): def test_show_multisig_3(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % i)).node btc.get_public_node(client, parse_path("999'/1'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
@ -114,7 +111,7 @@ class TestMsgGetaddressSegwit(TrezorTest):
for i in [1, 2, 3]: for i in [1, 2, 3]:
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("999'/1'/%d'/2/0" % i), parse_path("999'/1'/%d'/2/0" % i),
False, False,

View File

@ -23,11 +23,10 @@ from .common import TrezorTest
class TestMsgGetaddressSegwitNative(TrezorTest): class TestMsgGetaddressSegwitNative(TrezorTest):
def test_show_segwit(self): def test_show_segwit(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("49'/1'/0'/0/0"), parse_path("49'/1'/0'/0/0"),
True, True,
@ -38,7 +37,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("49'/1'/0'/1/0"), parse_path("49'/1'/0'/1/0"),
False, False,
@ -49,7 +48,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("44'/1'/0'/0/0"), parse_path("44'/1'/0'/0/0"),
False, False,
@ -60,7 +59,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("44'/1'/0'/0/0"), parse_path("44'/1'/0'/0/0"),
False, False,
@ -71,11 +70,10 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_show_segwit_altcoin(self): def test_show_segwit_altcoin(self, client):
self.setup_mnemonic_allallall()
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Groestlcoin", "Groestlcoin",
parse_path("84'/17'/0'/0/0"), parse_path("84'/17'/0'/0/0"),
False, False,
@ -86,7 +84,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Elements", "Elements",
parse_path("84'/1'/0'/0/0"), parse_path("84'/1'/0'/0/0"),
False, False,
@ -96,10 +94,9 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
== "ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v" == "ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v"
) )
def test_show_multisig_3(self): def test_show_multisig_3(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index)).node btc.get_public_node(client, parse_path("999'/1'/%d'" % index)).node
for index in range(1, 4) for index in range(1, 4)
] ]
multisig1 = proto.MultisigRedeemScriptType( multisig1 = proto.MultisigRedeemScriptType(
@ -111,7 +108,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
for i in [1, 2, 3]: for i in [1, 2, 3]:
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("999'/1'/%d'/2/1" % i), parse_path("999'/1'/%d'/2/1" % i),
False, False,
@ -122,7 +119,7 @@ class TestMsgGetaddressSegwitNative(TrezorTest):
) )
assert ( assert (
btc.get_address( btc.get_address(
self.client, client,
"Testnet", "Testnet",
parse_path("999'/1'/%d'/2/0" % i), parse_path("999'/1'/%d'/2/0" % i),
False, False,

View File

@ -14,30 +14,31 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import btc, ckd_public as bip32, messages as proto from trezorlib import btc, ckd_public as bip32, messages as proto
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgGetaddressShow(TrezorTest): class TestMsgGetaddressShow(TrezorTest):
def test_show(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_show(self, client):
assert ( assert (
btc.get_address(self.client, "Bitcoin", [1], show_display=True) btc.get_address(client, "Bitcoin", [1], show_display=True)
== "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [2], show_display=True) btc.get_address(client, "Bitcoin", [2], show_display=True)
== "15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG" == "15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG"
) )
assert ( assert (
btc.get_address(self.client, "Bitcoin", [3], show_display=True) btc.get_address(client, "Bitcoin", [3], show_display=True)
== "1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5" == "1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5"
) )
def test_show_multisig_3(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_show_multisig_3(self, client):
node = bip32.deserialize( node = bip32.deserialize(
"xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
@ -54,14 +55,13 @@ class TestMsgGetaddressShow(TrezorTest):
for i in [1, 2, 3]: for i in [1, 2, 3]:
assert ( assert (
btc.get_address( btc.get_address(
self.client, "Bitcoin", [i], show_display=True, multisig=multisig client, "Bitcoin", [i], show_display=True, multisig=multisig
) )
== "3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz" == "3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz"
) )
def test_show_multisig_15(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_show_multisig_15(self, client):
node = bip32.deserialize( node = bip32.deserialize(
"xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
@ -77,7 +77,7 @@ class TestMsgGetaddressShow(TrezorTest):
for i in range(15): for i in range(15):
assert ( assert (
btc.get_address( btc.get_address(
self.client, "Bitcoin", [i], show_display=True, multisig=multisig client, "Bitcoin", [i], show_display=True, multisig=multisig
) )
== "3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU" == "3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU"
) )

View File

@ -14,16 +14,16 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import messages as proto, misc from trezorlib import messages as proto, misc
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgGetECDHSessionKey(TrezorTest): class TestMsgGetECDHSessionKey(TrezorTest):
def test_ecdh(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ecdh(self, client):
# URI : gpg://Satoshi Nakamoto <satoshi@bitcoin.org>
identity = proto.IdentityType( identity = proto.IdentityType(
proto="gpg", proto="gpg",
user="", user="",
@ -37,7 +37,7 @@ class TestMsgGetECDHSessionKey(TrezorTest):
"0407f2c6e5becf3213c1d07df0cfbe8e39f70a8c643df7575e5c56859ec52c45ca950499c019719dae0fda04248d851e52cf9d66eeb211d89a77be40de22b6c89d" "0407f2c6e5becf3213c1d07df0cfbe8e39f70a8c643df7575e5c56859ec52c45ca950499c019719dae0fda04248d851e52cf9d66eeb211d89a77be40de22b6c89d"
) )
result = misc.get_ecdh_session_key( result = misc.get_ecdh_session_key(
self.client, client,
identity=identity, identity=identity,
peer_public_key=peer_public_key, peer_public_key=peer_public_key,
ecdsa_curve_name="secp256k1", ecdsa_curve_name="secp256k1",
@ -51,7 +51,7 @@ class TestMsgGetECDHSessionKey(TrezorTest):
"04811a6c2bd2a547d0dd84747297fec47719e7c3f9b0024f027c2b237be99aac39a9230acbd163d0cb1524a0f5ea4bfed6058cec6f18368f72a12aa0c4d083ff64" "04811a6c2bd2a547d0dd84747297fec47719e7c3f9b0024f027c2b237be99aac39a9230acbd163d0cb1524a0f5ea4bfed6058cec6f18368f72a12aa0c4d083ff64"
) )
result = misc.get_ecdh_session_key( result = misc.get_ecdh_session_key(
self.client, client,
identity=identity, identity=identity,
peer_public_key=peer_public_key, peer_public_key=peer_public_key,
ecdsa_curve_name="nist256p1", ecdsa_curve_name="nist256p1",
@ -65,7 +65,7 @@ class TestMsgGetECDHSessionKey(TrezorTest):
"40a8cf4b6a64c4314e80f15a8ea55812bd735fbb365936a48b2d78807b575fa17a" "40a8cf4b6a64c4314e80f15a8ea55812bd735fbb365936a48b2d78807b575fa17a"
) )
result = misc.get_ecdh_session_key( result = misc.get_ecdh_session_key(
self.client, client,
identity=identity, identity=identity,
peer_public_key=peer_public_key, peer_public_key=peer_public_key,
ecdsa_curve_name="curve25519", ecdsa_curve_name="curve25519",

View File

@ -19,131 +19,117 @@ import pytest
from trezorlib import btc, ckd_public as bip32, messages as proto from trezorlib import btc, ckd_public as bip32, messages as proto
from trezorlib.tools import H_ from trezorlib.tools import H_
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgGetpublickey(TrezorTest): class TestMsgGetpublickey(TrezorTest):
def test_btc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_btc(self, client):
assert ( assert (
bip32.serialize(btc.get_public_node(self.client, []).node, 0x0488B21E) bip32.serialize(btc.get_public_node(client, []).node, 0x0488B21E)
== "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
assert ( assert (
btc.get_public_node(self.client, [], coin_name="Bitcoin").xpub btc.get_public_node(client, [], coin_name="Bitcoin").xpub
== "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
assert ( assert (
bip32.serialize(btc.get_public_node(self.client, [1]).node, 0x0488B21E) bip32.serialize(btc.get_public_node(client, [1]).node, 0x0488B21E)
== "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N" == "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N"
) )
assert ( assert (
btc.get_public_node(self.client, [1], coin_name="Bitcoin").xpub btc.get_public_node(client, [1], coin_name="Bitcoin").xpub
== "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N" == "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [0, H_(1)]).node, 0x0488B21E)
btc.get_public_node(self.client, [0, H_(1)]).node, 0x0488B21E
)
== "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v" == "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v"
) )
assert ( assert (
btc.get_public_node(self.client, [0, H_(1)], coin_name="Bitcoin").xpub btc.get_public_node(client, [0, H_(1)], coin_name="Bitcoin").xpub
== "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v" == "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [H_(9), 0]).node, 0x0488B21E)
btc.get_public_node(self.client, [H_(9), 0]).node, 0x0488B21E
)
== "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv" == "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv"
) )
assert ( assert (
btc.get_public_node(self.client, [H_(9), 0], coin_name="Bitcoin").xpub btc.get_public_node(client, [H_(9), 0], coin_name="Bitcoin").xpub
== "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv" == "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [0, 9999999]).node, 0x0488B21E)
btc.get_public_node(self.client, [0, 9999999]).node, 0x0488B21E
)
== "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r" == "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r"
) )
assert ( assert (
btc.get_public_node(self.client, [0, 9999999], coin_name="Bitcoin").xpub btc.get_public_node(client, [0, 9999999], coin_name="Bitcoin").xpub
== "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r" == "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r"
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_ltc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ltc(self, client):
assert ( assert (
bip32.serialize(btc.get_public_node(self.client, []).node, 0x019DA462) bip32.serialize(btc.get_public_node(client, []).node, 0x019DA462)
== "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp" == "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp"
) )
assert ( assert (
btc.get_public_node(self.client, [], coin_name="Litecoin").xpub btc.get_public_node(client, [], coin_name="Litecoin").xpub
== "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp" == "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp"
) )
assert ( assert (
bip32.serialize(btc.get_public_node(self.client, [1]).node, 0x019DA462) bip32.serialize(btc.get_public_node(client, [1]).node, 0x019DA462)
== "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C" == "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C"
) )
assert ( assert (
btc.get_public_node(self.client, [1], coin_name="Litecoin").xpub btc.get_public_node(client, [1], coin_name="Litecoin").xpub
== "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C" == "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [0, H_(1)]).node, 0x019DA462)
btc.get_public_node(self.client, [0, H_(1)]).node, 0x019DA462
)
== "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT" == "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT"
) )
assert ( assert (
btc.get_public_node(self.client, [0, H_(1)], coin_name="Litecoin").xpub btc.get_public_node(client, [0, H_(1)], coin_name="Litecoin").xpub
== "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT" == "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [H_(9), 0]).node, 0x019DA462)
btc.get_public_node(self.client, [H_(9), 0]).node, 0x019DA462
)
== "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu" == "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu"
) )
assert ( assert (
btc.get_public_node(self.client, [H_(9), 0], coin_name="Litecoin").xpub btc.get_public_node(client, [H_(9), 0], coin_name="Litecoin").xpub
== "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu" == "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu"
) )
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [0, 9999999]).node, 0x019DA462)
btc.get_public_node(self.client, [0, 9999999]).node, 0x019DA462
)
== "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n" == "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n"
) )
assert ( assert (
btc.get_public_node(self.client, [0, 9999999], coin_name="Litecoin").xpub btc.get_public_node(client, [0, 9999999], coin_name="Litecoin").xpub
== "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n" == "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n"
) )
def test_tbtc(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_tbtc(self, client):
assert ( assert (
bip32.serialize( bip32.serialize(btc.get_public_node(client, [111, 42]).node, 0x043587CF)
btc.get_public_node(self.client, [111, 42]).node, 0x043587CF
)
== "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz" == "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz"
) )
assert ( assert (
btc.get_public_node(self.client, [111, 42], coin_name="Testnet").xpub btc.get_public_node(client, [111, 42], coin_name="Testnet").xpub
== "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz" == "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz"
) )
def test_script_type(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_script_type(self, client):
assert ( assert (
btc.get_public_node(self.client, [], coin_name="Bitcoin").xpub btc.get_public_node(client, [], coin_name="Bitcoin").xpub
== "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, client,
[], [],
coin_name="Bitcoin", coin_name="Bitcoin",
script_type=proto.InputScriptType.SPENDADDRESS, script_type=proto.InputScriptType.SPENDADDRESS,
@ -152,7 +138,7 @@ class TestMsgGetpublickey(TrezorTest):
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, client,
[], [],
coin_name="Bitcoin", coin_name="Bitcoin",
script_type=proto.InputScriptType.SPENDP2SHWITNESS, script_type=proto.InputScriptType.SPENDP2SHWITNESS,
@ -161,7 +147,7 @@ class TestMsgGetpublickey(TrezorTest):
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, client,
[], [],
coin_name="Bitcoin", coin_name="Bitcoin",
script_type=proto.InputScriptType.SPENDWITNESS, script_type=proto.InputScriptType.SPENDWITNESS,

View File

@ -19,66 +19,66 @@ import pytest
from trezorlib import btc from trezorlib import btc
from trezorlib.tools import H_, CallException from trezorlib.tools import H_, CallException
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgGetpublickeyCurve(TrezorTest): class TestMsgGetpublickeyCurve(TrezorTest):
def test_default_curve(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_default_curve(self, client):
assert ( assert (
btc.get_public_node(self.client, [H_(111), 42]).node.public_key.hex() btc.get_public_node(client, [H_(111), 42]).node.public_key.hex()
== "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc" == "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc"
) )
assert ( assert (
btc.get_public_node(self.client, [H_(111), H_(42)]).node.public_key.hex() btc.get_public_node(client, [H_(111), H_(42)]).node.public_key.hex()
== "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220" == "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220"
) )
def test_secp256k1_curve(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_secp256k1_curve(self, client):
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), 42], ecdsa_curve_name="secp256k1" client, [H_(111), 42], ecdsa_curve_name="secp256k1"
).node.public_key.hex() ).node.public_key.hex()
== "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc" == "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc"
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), H_(42)], ecdsa_curve_name="secp256k1" client, [H_(111), H_(42)], ecdsa_curve_name="secp256k1"
).node.public_key.hex() ).node.public_key.hex()
== "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220" == "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220"
) )
def test_nist256p1_curve(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nist256p1_curve(self, client):
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), 42], ecdsa_curve_name="nist256p1" client, [H_(111), 42], ecdsa_curve_name="nist256p1"
).node.public_key.hex() ).node.public_key.hex()
== "02a9ce59b32bd64a70bc52aca96e5d09af65c6b9593ba2a60af8fccfe1437f2129" == "02a9ce59b32bd64a70bc52aca96e5d09af65c6b9593ba2a60af8fccfe1437f2129"
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), H_(42)], ecdsa_curve_name="nist256p1" client, [H_(111), H_(42)], ecdsa_curve_name="nist256p1"
).node.public_key.hex() ).node.public_key.hex()
== "026fe35d8afed67dbf0561a1d32922e8ad0cd0d86effbc82be970cbed7d9bab2c2" == "026fe35d8afed67dbf0561a1d32922e8ad0cd0d86effbc82be970cbed7d9bab2c2"
) )
def test_ed25519_curve(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_ed25519_curve(self, client):
# ed25519 curve does not support public derivation, so test only private derivation paths # ed25519 curve does not support public derivation, so test only private derivation paths
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), H_(42)], ecdsa_curve_name="ed25519" client, [H_(111), H_(42)], ecdsa_curve_name="ed25519"
).node.public_key.hex() ).node.public_key.hex()
== "0069a14b478e508eab6e93303f4e6f5c50b8136627830f2ed5c3a835fc6c0ea2b7" == "0069a14b478e508eab6e93303f4e6f5c50b8136627830f2ed5c3a835fc6c0ea2b7"
) )
assert ( assert (
btc.get_public_node( btc.get_public_node(
self.client, [H_(111), H_(65535)], ecdsa_curve_name="ed25519" client, [H_(111), H_(65535)], ecdsa_curve_name="ed25519"
).node.public_key.hex() ).node.public_key.hex()
== "00514f73a05184458611b14c348fee4fd988d36cf3aee7207737861bac611de991" == "00514f73a05184458611b14c348fee4fd988d36cf3aee7207737861bac611de991"
) )
# test failure when using public derivation # test failure when using public derivation
with pytest.raises(CallException): with pytest.raises(CallException):
btc.get_public_node(self.client, [H_(111), 42], ecdsa_curve_name="ed25519") btc.get_public_node(client, [H_(111), 42], ecdsa_curve_name="ed25519")

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import lisk from trezorlib import lisk
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
LISK_PATH = parse_path("m/44h/134h/0h/1h") LISK_PATH = parse_path("m/44h/134h/0h/1h")
@ -27,12 +27,12 @@ LISK_PATH = parse_path("m/44h/134h/0h/1h")
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.lisk @pytest.mark.lisk
class TestMsgLiskGetaddress(TrezorTest): class TestMsgLiskGetaddress(TrezorTest):
def test_lisk_getaddress(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_lisk_getaddress(self, client):
assert lisk.get_address(self.client, LISK_PATH[:2]) == "1431530009238518937L" assert lisk.get_address(client, LISK_PATH[:2]) == "1431530009238518937L"
assert lisk.get_address(self.client, LISK_PATH[:3]) == "17563781916205589679L" assert lisk.get_address(client, LISK_PATH[:3]) == "17563781916205589679L"
assert lisk.get_address(self.client, LISK_PATH) == "1874186517773691964L" assert lisk.get_address(client, LISK_PATH) == "1874186517773691964L"
assert ( assert (
lisk.get_address(self.client, parse_path("m/44h/134h/999h/999h")) lisk.get_address(client, parse_path("m/44h/134h/999h/999h"))
== "16295203558710684671L" == "16295203558710684671L"
) )

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import lisk from trezorlib import lisk
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
LISK_PATH = parse_path("m/44h/134h/0h/0h") LISK_PATH = parse_path("m/44h/134h/0h/0h")
@ -27,9 +27,9 @@ LISK_PATH = parse_path("m/44h/134h/0h/0h")
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.lisk @pytest.mark.lisk
class TestMsgLiskGetPublicKey(TrezorTest): class TestMsgLiskGetPublicKey(TrezorTest):
def test_lisk_get_public_key(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_lisk_get_public_key(self, client):
sig = lisk.get_public_key(self.client, LISK_PATH) sig = lisk.get_public_key(client, LISK_PATH)
assert ( assert (
sig.public_key.hex() sig.public_key.hex()
== "eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294" == "eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294"

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import lisk from trezorlib import lisk
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
LISK_PATH = parse_path("m/44h/134h/0h/0h") LISK_PATH = parse_path("m/44h/134h/0h/0h")
@ -27,10 +27,10 @@ LISK_PATH = parse_path("m/44h/134h/0h/0h")
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.lisk @pytest.mark.lisk
class TestMsgLiskSignmessage(TrezorTest): class TestMsgLiskSignmessage(TrezorTest):
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
sig = lisk.sign_message( sig = lisk.sign_message(
self.client, LISK_PATH, "This is an example of a signed message." client, LISK_PATH, "This is an example of a signed message."
) )
assert ( assert (
sig.public_key.hex() sig.public_key.hex()
@ -41,9 +41,9 @@ class TestMsgLiskSignmessage(TrezorTest):
== "7858ae7cd52ea6d4b17e800ca60144423db5560bfd618b663ffbf26ab66758563df45cbffae8463db22dc285dd94309083b8c807776085b97d05374d79867d05" == "7858ae7cd52ea6d4b17e800ca60144423db5560bfd618b663ffbf26ab66758563df45cbffae8463db22dc285dd94309083b8c807776085b97d05374d79867d05"
) )
def test_sign_long(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_long(self, client):
sig = lisk.sign_message(self.client, LISK_PATH, "VeryLongMessage!" * 64) sig = lisk.sign_message(client, LISK_PATH, "VeryLongMessage!" * 64)
assert ( assert (
sig.public_key.hex() sig.public_key.hex()
== "eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294" == "eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294"

View File

@ -25,11 +25,9 @@ from .common import TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.lisk @pytest.mark.lisk
class TestMsgLiskSignTx(TrezorTest): class TestMsgLiskSignTx(TrezorTest):
def test_lisk_sign_tx_send(self): def test_lisk_sign_tx_send(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -42,7 +40,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "10000000", "amount": "10000000",
@ -55,11 +53,9 @@ class TestMsgLiskSignTx(TrezorTest):
) )
@pytest.mark.skip_t1 @pytest.mark.skip_t1
def test_lisk_sign_tx_send_wrong_path(self): def test_lisk_sign_tx_send_wrong_path(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest( proto.ButtonRequest(
code=proto.ButtonRequestType.UnknownDerivationPath code=proto.ButtonRequestType.UnknownDerivationPath
@ -75,7 +71,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/123456'/123456'/123456'/123456'/123456'"), parse_path("m/44'/134'/123456'/123456'/123456'/123456'/123456'"),
{ {
"amount": "10000000", "amount": "10000000",
@ -87,11 +83,9 @@ class TestMsgLiskSignTx(TrezorTest):
}, },
) )
def test_lisk_sign_tx_send_with_data(self): def test_lisk_sign_tx_send_with_data(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -104,7 +98,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "10000000", "amount": "10000000",
@ -116,11 +110,9 @@ class TestMsgLiskSignTx(TrezorTest):
}, },
) )
def test_lisk_sign_tx_second_signature(self): def test_lisk_sign_tx_second_signature(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.PublicKey), proto.ButtonRequest(code=proto.ButtonRequestType.PublicKey),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -133,7 +125,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "0", "amount": "0",
@ -148,11 +140,9 @@ class TestMsgLiskSignTx(TrezorTest):
}, },
) )
def test_lisk_sign_tx_delegate_registration(self): def test_lisk_sign_tx_delegate_registration(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -165,7 +155,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "0", "amount": "0",
@ -176,11 +166,9 @@ class TestMsgLiskSignTx(TrezorTest):
}, },
) )
def test_lisk_sign_tx_cast_votes(self): def test_lisk_sign_tx_cast_votes(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -193,7 +181,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "0", "amount": "0",
@ -209,11 +197,9 @@ class TestMsgLiskSignTx(TrezorTest):
}, },
) )
def test_lisk_sign_tx_multisignature(self): def test_lisk_sign_tx_multisignature(self, client):
self.setup_mnemonic_allallall() with client:
client.set_expected_responses(
with self.client:
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -226,7 +212,7 @@ class TestMsgLiskSignTx(TrezorTest):
) )
lisk.sign_tx( lisk.sign_tx(
self.client, client,
parse_path("m/44'/134'/0'"), parse_path("m/44'/134'/0'"),
{ {
"amount": "0", "amount": "0",

View File

@ -24,10 +24,9 @@ from .common import TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.lisk @pytest.mark.lisk
class TestMsgLiskVerifymessage(TrezorTest): class TestMsgLiskVerifymessage(TrezorTest):
def test_verify(self): def test_verify(self, client):
self.setup_mnemonic_nopin_nopassphrase() with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.Other), proto.ButtonRequest(code=proto.ButtonRequestType.Other),
proto.ButtonRequest(code=proto.ButtonRequestType.Other), proto.ButtonRequest(code=proto.ButtonRequestType.Other),
@ -35,7 +34,7 @@ class TestMsgLiskVerifymessage(TrezorTest):
] ]
) )
lisk.verify_message( lisk.verify_message(
self.client, client,
bytes.fromhex( bytes.fromhex(
"eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294" "eb56d7bbb5e8ea9269405f7a8527fe126023d1db2c973cfac6f760b60ae27294"
), ),
@ -45,10 +44,9 @@ class TestMsgLiskVerifymessage(TrezorTest):
"This is an example of a signed message.", "This is an example of a signed message.",
) )
def test_verify_long(self): def test_verify_long(self, client):
self.setup_mnemonic_nopin_nopassphrase() with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.Other), proto.ButtonRequest(code=proto.ButtonRequestType.Other),
proto.ButtonRequest(code=proto.ButtonRequestType.Other), proto.ButtonRequest(code=proto.ButtonRequestType.Other),
@ -56,7 +54,7 @@ class TestMsgLiskVerifymessage(TrezorTest):
] ]
) )
lisk.verify_message( lisk.verify_message(
self.client, client,
bytes.fromhex( bytes.fromhex(
"8bca6b65a1a877767b746ea0b3c4310d404aa113df99c1b554e1802d70185ab5" "8bca6b65a1a877767b746ea0b3c4310d404aa113df99c1b554e1802d70185ab5"
), ),

View File

@ -18,33 +18,46 @@ import pytest
from trezorlib import btc, debuglink, device from trezorlib import btc, debuglink, device
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
@pytest.mark.setup_client(uninitialized=True)
class TestDeviceLoad(TrezorTest): class TestDeviceLoad(TrezorTest):
def test_load_device_1(self): def test_load_device_1(self, client):
self.setup_mnemonic_nopin_nopassphrase(lock=False) debuglink.load_device_by_mnemonic(
state = self.client.debug.state() client,
assert state.mnemonic_secret == self.mnemonic12.encode() mnemonic=MNEMONIC12,
pin="",
passphrase_protection=False,
label="test",
)
state = client.debug.state()
assert state.mnemonic_secret == MNEMONIC12.encode()
assert state.pin is None assert state.pin is None
assert state.passphrase_protection is False assert state.passphrase_protection is False
address = btc.get_address(self.client, "Bitcoin", []) address = btc.get_address(client, "Bitcoin", [])
assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK" assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
def test_load_device_2(self): def test_load_device_2(self, client):
self.setup_mnemonic_pin_passphrase(lock=False) debuglink.load_device_by_mnemonic(
self.client.set_passphrase("passphrase") client,
state = self.client.debug.state() mnemonic=MNEMONIC12,
assert state.mnemonic_secret == self.mnemonic12.encode() pin="1234",
assert state.pin == self.pin4 passphrase_protection=True,
label="test",
)
client.set_passphrase("passphrase")
state = client.debug.state()
assert state.mnemonic_secret == MNEMONIC12.encode()
assert state.pin == "1234"
assert state.passphrase_protection is True assert state.passphrase_protection is True
address = btc.get_address(self.client, "Bitcoin", []) address = btc.get_address(client, "Bitcoin", [])
assert address == "15fiTDFwZd2kauHYYseifGi9daH2wniDHH" assert address == "15fiTDFwZd2kauHYYseifGi9daH2wniDHH"
def test_load_device_utf(self): def test_load_device_utf(self, client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
words_nfkc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfkc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
@ -63,9 +76,9 @@ class TestDeviceLoad(TrezorTest):
u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko" u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko"
) )
device.wipe(self.client) device.wipe(client)
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
mnemonic=words_nfkd, mnemonic=words_nfkd,
pin="", pin="",
passphrase_protection=True, passphrase_protection=True,
@ -73,12 +86,12 @@ class TestDeviceLoad(TrezorTest):
language="english", language="english",
skip_checksum=True, skip_checksum=True,
) )
self.client.set_passphrase(passphrase_nfkd) client.set_passphrase(passphrase_nfkd)
address_nfkd = btc.get_address(self.client, "Bitcoin", []) address_nfkd = btc.get_address(client, "Bitcoin", [])
device.wipe(self.client) device.wipe(client)
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
mnemonic=words_nfc, mnemonic=words_nfc,
pin="", pin="",
passphrase_protection=True, passphrase_protection=True,
@ -86,12 +99,12 @@ class TestDeviceLoad(TrezorTest):
language="english", language="english",
skip_checksum=True, skip_checksum=True,
) )
self.client.set_passphrase(passphrase_nfc) client.set_passphrase(passphrase_nfc)
address_nfc = btc.get_address(self.client, "Bitcoin", []) address_nfc = btc.get_address(client, "Bitcoin", [])
device.wipe(self.client) device.wipe(client)
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
mnemonic=words_nfkc, mnemonic=words_nfkc,
pin="", pin="",
passphrase_protection=True, passphrase_protection=True,
@ -99,12 +112,12 @@ class TestDeviceLoad(TrezorTest):
language="english", language="english",
skip_checksum=True, skip_checksum=True,
) )
self.client.set_passphrase(passphrase_nfkc) client.set_passphrase(passphrase_nfkc)
address_nfkc = btc.get_address(self.client, "Bitcoin", []) address_nfkc = btc.get_address(client, "Bitcoin", [])
device.wipe(self.client) device.wipe(client)
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
mnemonic=words_nfd, mnemonic=words_nfd,
pin="", pin="",
passphrase_protection=True, passphrase_protection=True,
@ -112,8 +125,8 @@ class TestDeviceLoad(TrezorTest):
language="english", language="english",
skip_checksum=True, skip_checksum=True,
) )
self.client.set_passphrase(passphrase_nfd) client.set_passphrase(passphrase_nfd)
address_nfd = btc.get_address(self.client, "Bitcoin", []) address_nfd = btc.get_address(client, "Bitcoin", [])
assert address_nfkd == address_nfc assert address_nfkd == address_nfc
assert address_nfkd == address_nfkc assert address_nfkd == address_nfkc

View File

@ -23,9 +23,10 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestDeviceLoadXprv(TrezorTest): class TestDeviceLoadXprv(TrezorTest):
def test_load_device_xprv_1(self): @pytest.mark.setup_client(uninitialized=True)
def test_load_device_xprv_1(self, client):
debuglink.load_device_by_xprv( debuglink.load_device_by_xprv(
self.client, client,
xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73", xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73",
pin="", pin="",
passphrase_protection=False, passphrase_protection=False,
@ -33,15 +34,16 @@ class TestDeviceLoadXprv(TrezorTest):
language="english", language="english",
) )
passphrase_protection = self.client.debug.read_passphrase_protection() passphrase_protection = client.debug.read_passphrase_protection()
assert passphrase_protection is False assert passphrase_protection is False
address = btc.get_address(self.client, "Bitcoin", []) address = btc.get_address(client, "Bitcoin", [])
assert address == "128RdrAkJDmqasgvfRf6MC5VcX4HKqH4mR" assert address == "128RdrAkJDmqasgvfRf6MC5VcX4HKqH4mR"
def test_load_device_xprv_2(self): @pytest.mark.setup_client(uninitialized=True)
def test_load_device_xprv_2(self, client):
debuglink.load_device_by_xprv( debuglink.load_device_by_xprv(
self.client, client,
xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73", xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73",
pin="", pin="",
passphrase_protection=True, passphrase_protection=True,
@ -49,10 +51,10 @@ class TestDeviceLoadXprv(TrezorTest):
language="english", language="english",
) )
self.client.set_passphrase("passphrase") client.set_passphrase("passphrase")
passphrase_protection = self.client.debug.read_passphrase_protection() passphrase_protection = client.debug.read_passphrase_protection()
assert passphrase_protection is True assert passphrase_protection is True
address = btc.get_address(self.client, "Bitcoin", []) address = btc.get_address(client, "Bitcoin", [])
assert address == "1CHUbFa4wTTPYgkYaw2LHSd5D4qJjMU8ri" assert address == "1CHUbFa4wTTPYgkYaw2LHSd5D4qJjMU8ri"

View File

@ -19,24 +19,24 @@ import pytest
from trezorlib import monero from trezorlib import monero
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.monero @pytest.mark.monero
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgMoneroGetaddress(TrezorTest): class TestMsgMoneroGetaddress(TrezorTest):
def test_monero_getaddress(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_monero_getaddress(self, client):
assert ( assert (
monero.get_address(self.client, parse_path("m/44h/128h/0h")) monero.get_address(client, parse_path("m/44h/128h/0h"))
== b"4Ahp23WfMrMFK3wYL2hLWQFGt87ZTeRkufS6JoQZu6MEFDokAQeGWmu9MA3GFq1yVLSJQbKJqVAn9F9DLYGpRzRAEXqAXKM" == b"4Ahp23WfMrMFK3wYL2hLWQFGt87ZTeRkufS6JoQZu6MEFDokAQeGWmu9MA3GFq1yVLSJQbKJqVAn9F9DLYGpRzRAEXqAXKM"
) )
assert ( assert (
monero.get_address(self.client, parse_path("m/44h/128h/1h")) monero.get_address(client, parse_path("m/44h/128h/1h"))
== b"44iAazhoAkv5a5RqLNVyh82a1n3ceNggmN4Ho7bUBJ14WkEVR8uFTe9f7v5rNnJ2kEbVXxfXiRzsD5Jtc6NvBi4D6WNHPie" == b"44iAazhoAkv5a5RqLNVyh82a1n3ceNggmN4Ho7bUBJ14WkEVR8uFTe9f7v5rNnJ2kEbVXxfXiRzsD5Jtc6NvBi4D6WNHPie"
) )
assert ( assert (
monero.get_address(self.client, parse_path("m/44h/128h/2h")) monero.get_address(client, parse_path("m/44h/128h/2h"))
== b"47ejhmbZ4wHUhXaqA4b7PN667oPMkokf4ZkNdWrMSPy9TNaLVr7vLqVUQHh2MnmaAEiyrvLsX8xUf99q3j1iAeMV8YvSFcH" == b"47ejhmbZ4wHUhXaqA4b7PN667oPMkokf4ZkNdWrMSPy9TNaLVr7vLqVUQHh2MnmaAEiyrvLsX8xUf99q3j1iAeMV8YvSFcH"
) )

View File

@ -19,16 +19,16 @@ import pytest
from trezorlib import monero from trezorlib import monero
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.monero @pytest.mark.monero
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgMoneroGetwatchkey(TrezorTest): class TestMsgMoneroGetwatchkey(TrezorTest):
def test_monero_getwatchkey(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_monero_getwatchkey(self, client):
res = monero.get_watch_key(self.client, parse_path("m/44h/128h/0h")) res = monero.get_watch_key(client, parse_path("m/44h/128h/0h"))
assert ( assert (
res.address res.address
== b"4Ahp23WfMrMFK3wYL2hLWQFGt87ZTeRkufS6JoQZu6MEFDokAQeGWmu9MA3GFq1yVLSJQbKJqVAn9F9DLYGpRzRAEXqAXKM" == b"4Ahp23WfMrMFK3wYL2hLWQFGt87ZTeRkufS6JoQZu6MEFDokAQeGWmu9MA3GFq1yVLSJQbKJqVAn9F9DLYGpRzRAEXqAXKM"
@ -37,7 +37,7 @@ class TestMsgMoneroGetwatchkey(TrezorTest):
res.watch_key.hex() res.watch_key.hex()
== "8722520a581e2a50cc1adab4a1692401effd37b0d63b9d9b60fd7f34ea2b950e" == "8722520a581e2a50cc1adab4a1692401effd37b0d63b9d9b60fd7f34ea2b950e"
) )
res = monero.get_watch_key(self.client, parse_path("m/44h/128h/1h")) res = monero.get_watch_key(client, parse_path("m/44h/128h/1h"))
assert ( assert (
res.address res.address
== b"44iAazhoAkv5a5RqLNVyh82a1n3ceNggmN4Ho7bUBJ14WkEVR8uFTe9f7v5rNnJ2kEbVXxfXiRzsD5Jtc6NvBi4D6WNHPie" == b"44iAazhoAkv5a5RqLNVyh82a1n3ceNggmN4Ho7bUBJ14WkEVR8uFTe9f7v5rNnJ2kEbVXxfXiRzsD5Jtc6NvBi4D6WNHPie"
@ -46,7 +46,7 @@ class TestMsgMoneroGetwatchkey(TrezorTest):
res.watch_key.hex() res.watch_key.hex()
== "1f70b7d9e86c11b7a5bee883b75c43d6be189c8f812726ea1ecd94b06bb7db04" == "1f70b7d9e86c11b7a5bee883b75c43d6be189c8f812726ea1ecd94b06bb7db04"
) )
res = monero.get_watch_key(self.client, parse_path("m/44h/128h/2h")) res = monero.get_watch_key(client, parse_path("m/44h/128h/2h"))
assert ( assert (
res.address res.address
== b"47ejhmbZ4wHUhXaqA4b7PN667oPMkokf4ZkNdWrMSPy9TNaLVr7vLqVUQHh2MnmaAEiyrvLsX8xUf99q3j1iAeMV8YvSFcH" == b"47ejhmbZ4wHUhXaqA4b7PN667oPMkokf4ZkNdWrMSPy9TNaLVr7vLqVUQHh2MnmaAEiyrvLsX8xUf99q3j1iAeMV8YvSFcH"

View File

@ -19,19 +19,19 @@ import pytest
from trezorlib import nem from trezorlib import nem
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.nem @pytest.mark.nem
class TestMsgNEMGetaddress(TrezorTest): class TestMsgNEMGetaddress(TrezorTest):
def test_nem_getaddress(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_getaddress(self, client):
assert ( assert (
nem.get_address(self.client, parse_path("m/44'/1'/0'/0'/0'"), 0x68) nem.get_address(client, parse_path("m/44'/1'/0'/0'/0'"), 0x68)
== "NB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQGHUBWQN" == "NB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQGHUBWQN"
) )
assert ( assert (
nem.get_address(self.client, parse_path("m/44'/1'/0'/0'/0'"), 0x98) nem.get_address(client, parse_path("m/44'/1'/0'/0'/0'"), 0x98)
== "TB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQHSBNBMF" == "TB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQHSBNBMF"
) )

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import nem from trezorlib import nem
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
# assertion data from T1 # assertion data from T1
@ -27,11 +27,10 @@ from .common import TrezorTest
@pytest.mark.nem @pytest.mark.nem
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgNEMSignTxMosaics(TrezorTest): class TestMsgNEMSignTxMosaics(TrezorTest):
def test_nem_signtx_mosaic_supply_change(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_supply_change(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -57,11 +56,10 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "928b03c4a69fff35ecf0912066ea705895b3028fad141197d7ea2b56f1eef2a2516455e6f35d318f6fa39e2bb40492ac4ae603260790f7ebc7ea69feb4ca4c0a" == "928b03c4a69fff35ecf0912066ea705895b3028fad141197d7ea2b56f1eef2a2516455e6f35d318f6fa39e2bb40492ac4ae603260790f7ebc7ea69feb4ca4c0a"
) )
def test_nem_signtx_mosaic_creation(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -90,11 +88,10 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "537adf4fd9bd5b46e204b2db0a435257a951ed26008305e0aa9e1201dafa4c306d7601a8dbacabf36b5137724386124958d53202015ab31fb3d0849dfed2df0e" == "537adf4fd9bd5b46e204b2db0a435257a951ed26008305e0aa9e1201dafa4c306d7601a8dbacabf36b5137724386124958d53202015ab31fb3d0849dfed2df0e"
) )
def test_nem_signtx_mosaic_creation_properties(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation_properties(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -128,11 +125,10 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "f17c859710060f2ea9a0ab740ef427431cf36bdc7d263570ca282bd66032e9f5737a921be9839429732e663be2bb74ccc16f34f5157ff2ef00a65796b54e800e" == "f17c859710060f2ea9a0ab740ef427431cf36bdc7d263570ca282bd66032e9f5737a921be9839429732e663be2bb74ccc16f34f5157ff2ef00a65796b54e800e"
) )
def test_nem_signtx_mosaic_creation_levy(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation_levy(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,

View File

@ -21,7 +21,7 @@ from trezorlib import messages as proto, nem
from trezorlib.messages import ButtonRequestType as B from trezorlib.messages import ButtonRequestType as B
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
# assertion data from T1 # assertion data from T1
@ -29,12 +29,11 @@ from .common import TrezorTest
@pytest.mark.nem @pytest.mark.nem
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgNEMSignTxMosaics(TrezorTest): class TestMsgNEMSignTxMosaics(TrezorTest):
def test_nem_signtx_mosaic_supply_change(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_supply_change(self, client):
with client:
with self.client:
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -60,9 +59,8 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "928b03c4a69fff35ecf0912066ea705895b3028fad141197d7ea2b56f1eef2a2516455e6f35d318f6fa39e2bb40492ac4ae603260790f7ebc7ea69feb4ca4c0a" == "928b03c4a69fff35ecf0912066ea705895b3028fad141197d7ea2b56f1eef2a2516455e6f35d318f6fa39e2bb40492ac4ae603260790f7ebc7ea69feb4ca4c0a"
) )
def test_nem_signtx_mosaic_creation(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation(self, client):
test_suite = { test_suite = {
"timeStamp": 74649215, "timeStamp": 74649215,
"fee": 2000000, "fee": 2000000,
@ -81,7 +79,7 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
} }
# not using client.nem_sign_tx() because of swiping # not using client.nem_sign_tx() because of swiping
tx = self._nem_sign(2, test_suite) tx = self._nem_sign(client, 2, test_suite)
assert ( assert (
tx.data.hex() tx.data.hex()
== "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f7404c100000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000030160000000d000000696e697469616c537570706c7901000000301a0000000d000000737570706c794d757461626c650500000066616c7365190000000c0000007472616e7366657261626c650500000066616c7365000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000" == "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f7404c100000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000030160000000d000000696e697469616c537570706c7901000000301a0000000d000000737570706c794d757461626c650500000066616c7365190000000c0000007472616e7366657261626c650500000066616c7365000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000"
@ -91,9 +89,8 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "537adf4fd9bd5b46e204b2db0a435257a951ed26008305e0aa9e1201dafa4c306d7601a8dbacabf36b5137724386124958d53202015ab31fb3d0849dfed2df0e" == "537adf4fd9bd5b46e204b2db0a435257a951ed26008305e0aa9e1201dafa4c306d7601a8dbacabf36b5137724386124958d53202015ab31fb3d0849dfed2df0e"
) )
def test_nem_signtx_mosaic_creation_properties(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation_properties(self, client):
test_suite = { test_suite = {
"timeStamp": 74649215, "timeStamp": 74649215,
"fee": 2000000, "fee": 2000000,
@ -117,7 +114,7 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
} }
# not using client.nem_sign_tx() because of swiping # not using client.nem_sign_tx() because of swiping
tx = self._nem_sign(2, test_suite) tx = self._nem_sign(client, 2, test_suite)
assert ( assert (
tx.data.hex() tx.data.hex()
== "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f7404c200000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000034180000000d000000696e697469616c537570706c79030000003230301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c650400000074727565000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000" == "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f7404c200000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000034180000000d000000696e697469616c537570706c79030000003230301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c650400000074727565000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000"
@ -127,9 +124,8 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "f17c859710060f2ea9a0ab740ef427431cf36bdc7d263570ca282bd66032e9f5737a921be9839429732e663be2bb74ccc16f34f5157ff2ef00a65796b54e800e" == "f17c859710060f2ea9a0ab740ef427431cf36bdc7d263570ca282bd66032e9f5737a921be9839429732e663be2bb74ccc16f34f5157ff2ef00a65796b54e800e"
) )
def test_nem_signtx_mosaic_creation_levy(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_mosaic_creation_levy(self, client):
test_suite = { test_suite = {
"timeStamp": 74649215, "timeStamp": 74649215,
"fee": 2000000, "fee": 2000000,
@ -157,7 +153,7 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
"creationFee": 1500, "creationFee": 1500,
} }
tx = self._nem_sign(6, test_suite) tx = self._nem_sign(client, 6, test_suite)
assert ( assert (
tx.data.hex() tx.data.hex()
== "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f74041801000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000034180000000d000000696e697469616c537570706c79030000003230301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c65040000007472756556000000010000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324a1a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f7361696302000000000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000" == "01400000010000987f0e730420000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b406208480841e0000000000ff5f74041801000020000000edfd32f6e760648c032f9acb4b30d514265f6a5b5f8a7154f2618922b40620841a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f73616963050000006c6f72656d04000000150000000c00000064697669736962696c6974790100000034180000000d000000696e697469616c537570706c79030000003230301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c65040000007472756556000000010000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324a1a0000000600000068656c6c6f6d0c00000048656c6c6f206d6f7361696302000000000000002800000054414c49434532474d4133344358484437584c4a513533364e4d35554e4b5148544f524e4e54324adc05000000000000"
@ -167,33 +163,33 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
== "b87aac1ddf146d35e6a7f3451f57e2fe504ac559031e010a51261257c37bd50fcfa7b2939dd7a3203b54c4807d458475182f5d3dc135ec0d1d4a9cd42159fd0a" == "b87aac1ddf146d35e6a7f3451f57e2fe504ac559031e010a51261257c37bd50fcfa7b2939dd7a3203b54c4807d458475182f5d3dc135ec0d1d4a9cd42159fd0a"
) )
def _nem_sign(self, num_of_swipes, test_suite): def _nem_sign(self, client, num_of_swipes, test_suite):
n = parse_path("m/44'/1'/0'/0'/0'") n = parse_path("m/44'/1'/0'/0'/0'")
def input_flow(): def input_flow():
# Confirm Action # Confirm Action
btn_code = yield btn_code = yield
assert btn_code == B.ConfirmOutput assert btn_code == B.ConfirmOutput
self.client.debug.press_yes() client.debug.press_yes()
# Swipe and confirm # Swipe and confirm
yield yield
for _ in range(num_of_swipes): for _ in range(num_of_swipes):
self.client.debug.swipe_down() client.debug.swipe_down()
self.client.debug.press_yes() client.debug.press_yes()
# Confirm Action # Confirm Action
btn_code = yield btn_code = yield
assert btn_code == B.ConfirmOutput assert btn_code == B.ConfirmOutput
self.client.debug.press_yes() client.debug.press_yes()
# Sign Tx # Sign Tx
btn_code = yield btn_code = yield
assert btn_code == B.SignTx assert btn_code == B.SignTx
self.client.debug.press_yes() client.debug.press_yes()
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=B.ConfirmOutput), proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.ConfirmOutput), proto.ButtonRequest(code=B.ConfirmOutput),
@ -202,5 +198,5 @@ class TestMsgNEMSignTxMosaics(TrezorTest):
proto.NEMSignedTx(), proto.NEMSignedTx(),
] ]
) )
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
return nem.sign_tx(self.client, n, test_suite) return nem.sign_tx(client, n, test_suite)

View File

@ -19,18 +19,17 @@ import pytest
from trezorlib import nem from trezorlib import nem
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
# assertion data from T1 # assertion data from T1
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.nem @pytest.mark.nem
class TestMsgNEMSignTxMultisig(TrezorTest): class TestMsgNEMSignTxMultisig(TrezorTest):
def test_nem_signtx_aggregate_modification(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_aggregate_modification(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -57,11 +56,10 @@ class TestMsgNEMSignTxMultisig(TrezorTest):
== "1200e552d8732ce3eae96719731194abfc5a09d98f61bb35684f4eeaeff15b1bdf326ee7b1bbbe89d3f68c8e07ad3daf72e4c7f031094ad2236b97918ad98601" == "1200e552d8732ce3eae96719731194abfc5a09d98f61bb35684f4eeaeff15b1bdf326ee7b1bbbe89d3f68c8e07ad3daf72e4c7f031094ad2236b97918ad98601"
) )
def test_nem_signtx_multisig(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_multisig(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 1, "timeStamp": 1,
@ -96,7 +94,7 @@ class TestMsgNEMSignTxMultisig(TrezorTest):
) )
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -129,11 +127,10 @@ class TestMsgNEMSignTxMultisig(TrezorTest):
== "c915ca3332380925f4050301cdc62269cf29437ac5955321b18da34e570c7fdbb1aec2940a2a553a2a5c90950a4db3c8d3ef899c1a108582e0657f66fbbb0b04" == "c915ca3332380925f4050301cdc62269cf29437ac5955321b18da34e570c7fdbb1aec2940a2a553a2a5c90950a4db3c8d3ef899c1a108582e0657f66fbbb0b04"
) )
def test_nem_signtx_multisig_signer(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_multisig_signer(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 333, "timeStamp": 333,
@ -168,7 +165,7 @@ class TestMsgNEMSignTxMultisig(TrezorTest):
) )
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 900000, "timeStamp": 900000,

View File

@ -19,19 +19,18 @@ import pytest
from trezorlib import nem from trezorlib import nem
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
# assertion data from T1 # assertion data from T1
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.nem @pytest.mark.nem
class TestMsgNEMSignTxOther(TrezorTest): class TestMsgNEMSignTxOther(TrezorTest):
def test_nem_signtx_importance_transfer(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_importance_transfer(self, client):
with client:
with self.client:
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 12349215, "timeStamp": 12349215,
@ -56,12 +55,10 @@ class TestMsgNEMSignTxOther(TrezorTest):
== "b6d9434ec5df80e65e6e45d7f0f3c579b4adfe8567c42d981b06e8ac368b1aad2b24eebecd5efd41f4497051fca8ea8a5e77636a79afc46ee1a8e0fe9e3ba90b" == "b6d9434ec5df80e65e6e45d7f0f3c579b4adfe8567c42d981b06e8ac368b1aad2b24eebecd5efd41f4497051fca8ea8a5e77636a79afc46ee1a8e0fe9e3ba90b"
) )
def test_nem_signtx_provision_namespace(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_provision_namespace(self, client):
self.setup_mnemonic_nopin_nopassphrase()
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,

View File

@ -19,18 +19,17 @@ import pytest
from trezorlib import messages as proto, nem from trezorlib import messages as proto, nem
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
# assertion data from T1 # assertion data from T1
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.nem @pytest.mark.nem
class TestMsgNEMSignTx(TrezorTest): class TestMsgNEMSignTx(TrezorTest):
def test_nem_signtx_simple(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
# tx hash: 209368053ac61969b6838ceb7e31badeb622ed6aa42d6c58365c42ad1a11e19d def test_nem_signtx_simple(self, client):
self.setup_mnemonic_nopin_nopassphrase() with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
# Confirm transfer and network fee # Confirm transfer and network fee
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -43,7 +42,7 @@ class TestMsgNEMSignTx(TrezorTest):
) )
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -69,11 +68,10 @@ class TestMsgNEMSignTx(TrezorTest):
== "9cda2045324d05c791a4fc312ecceb62954e7740482f8df8928560d63cf273dea595023640179f112de755c79717757ef76962175378d6d87360ddb3f3e5f70f" == "9cda2045324d05c791a4fc312ecceb62954e7740482f8df8928560d63cf273dea595023640179f112de755c79717757ef76962175378d6d87360ddb3f3e5f70f"
) )
def test_nem_signtx_encrypted_payload(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_encrypted_payload(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
# Confirm transfer and network fee # Confirm transfer and network fee
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
@ -86,7 +84,7 @@ class TestMsgNEMSignTx(TrezorTest):
) )
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 74649215, "timeStamp": 74649215,
@ -115,11 +113,10 @@ class TestMsgNEMSignTx(TrezorTest):
# because IV and salt are random (therefore the encrypted payload as well) those data can't be asserted # because IV and salt are random (therefore the encrypted payload as well) those data can't be asserted
assert len(tx.signature) == 64 assert len(tx.signature) == 64
def test_nem_signtx_xem_as_mosaic(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_xem_as_mosaic(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 76809215, "timeStamp": 76809215,
@ -149,11 +146,10 @@ class TestMsgNEMSignTx(TrezorTest):
== "7b25a84b65adb489ea55739f1ca2d83a0ae069c3c58d0ea075fc30bfe8f649519199ad2324ca229c6c3214191469f95326e99712124592cae7cd3a092c93ac0c" == "7b25a84b65adb489ea55739f1ca2d83a0ae069c3c58d0ea075fc30bfe8f649519199ad2324ca229c6c3214191469f95326e99712124592cae7cd3a092c93ac0c"
) )
def test_nem_signtx_unknown_mosaic(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_unknown_mosaic(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 76809215, "timeStamp": 76809215,
@ -183,12 +179,10 @@ class TestMsgNEMSignTx(TrezorTest):
== "2f0280420eceb41ef9e5d94fa44ddda9cdc70b8f423ae18af577f6d85df64bb4aaf40cf24fc6eef47c63b0963611f8682348cecdc49a9b64eafcbe7afcb49102" == "2f0280420eceb41ef9e5d94fa44ddda9cdc70b8f423ae18af577f6d85df64bb4aaf40cf24fc6eef47c63b0963611f8682348cecdc49a9b64eafcbe7afcb49102"
) )
def test_nem_signtx_known_mosaic(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_known_mosaic(self, client):
self.setup_mnemonic_nopin_nopassphrase()
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 76809215, "timeStamp": 76809215,
@ -218,12 +212,10 @@ class TestMsgNEMSignTx(TrezorTest):
== "e7f14ef8c39727bfd257e109cd5acac31542f2e41f2e5deb258fc1db602b690eb1cabca41a627fe2adc51f3193db85c76b41c80bb60161eb8738ebf20b507104" == "e7f14ef8c39727bfd257e109cd5acac31542f2e41f2e5deb258fc1db602b690eb1cabca41a627fe2adc51f3193db85c76b41c80bb60161eb8738ebf20b507104"
) )
def test_nem_signtx_known_mosaic_with_levy(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_known_mosaic_with_levy(self, client):
self.setup_mnemonic_nopin_nopassphrase()
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 76809215, "timeStamp": 76809215,
@ -253,11 +245,10 @@ class TestMsgNEMSignTx(TrezorTest):
== "d3222dd7b83d66bda0539827ac6f909d06e40350b5e5e893d6fa762f954e9bf7da61022ef04950e7b6dfa88a2278f2f8a1b21df2bc3af22b388cb3a90bf76f07" == "d3222dd7b83d66bda0539827ac6f909d06e40350b5e5e893d6fa762f954e9bf7da61022ef04950e7b6dfa88a2278f2f8a1b21df2bc3af22b388cb3a90bf76f07"
) )
def test_nem_signtx_multiple_mosaics(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_nem_signtx_multiple_mosaics(self, client):
tx = nem.sign_tx( tx = nem.sign_tx(
self.client, client,
parse_path("m/44'/1'/0'/0'/0'"), parse_path("m/44'/1'/0'/0'/0'"),
{ {
"timeStamp": 76809215, "timeStamp": 76809215,

View File

@ -23,43 +23,37 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgPing(TrezorTest): class TestMsgPing(TrezorTest):
def test_ping(self): @pytest.mark.setup_client(pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_ping(self, client):
with client:
with self.client: client.set_expected_responses([proto.Success()])
self.client.set_expected_responses([proto.Success()]) res = client.ping("random data")
res = self.client.ping("random data")
assert res == "random data" assert res == "random data"
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping("random data", button_protection=True) res = client.ping("random data", button_protection=True)
assert res == "random data" assert res == "random data"
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
[proto.PinMatrixRequest(), proto.Success()] res = client.ping("random data", pin_protection=True)
)
res = self.client.ping("random data", pin_protection=True)
assert res == "random data" assert res == "random data"
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses([proto.PassphraseRequest(), proto.Success()])
[proto.PassphraseRequest(), proto.Success()] res = client.ping("random data", passphrase_protection=True)
)
res = self.client.ping("random data", passphrase_protection=True)
assert res == "random data" assert res == "random data"
def test_ping_caching(self): @pytest.mark.setup_client(pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_ping_caching(self, client):
with client:
with self.client: client.set_expected_responses(
self.client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -67,7 +61,7 @@ class TestMsgPing(TrezorTest):
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,
@ -75,15 +69,15 @@ class TestMsgPing(TrezorTest):
) )
assert res == "random data" assert res == "random data"
with self.client: with client:
# pin and passphrase are cached # pin and passphrase are cached
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall), proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
proto.Success(), proto.Success(),
] ]
) )
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=True, button_protection=True,
pin_protection=True, pin_protection=True,

View File

@ -23,9 +23,10 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgRecoverydevice(TrezorTest): class TestMsgRecoverydevice(TrezorTest):
def test_pin_passphrase(self): @pytest.mark.setup_client(uninitialized=True)
def test_pin_passphrase(self, client):
mnemonic = self.mnemonic12.split(" ") mnemonic = self.mnemonic12.split(" ")
ret = self.client.call_raw( ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
word_count=12, word_count=12,
passphrase_protection=True, passphrase_protection=True,
@ -38,30 +39,30 @@ class TestMsgRecoverydevice(TrezorTest):
# click through confirmation # click through confirmation
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for second time # Enter PIN for second time
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
fakes = 0 fakes = 0
for _ in range(int(12 * 2)): for _ in range(int(12 * 2)):
assert isinstance(ret, proto.WordRequest) assert isinstance(ret, proto.WordRequest)
(word, pos) = self.client.debug.read_recovery_word() (word, pos) = client.debug.read_recovery_word()
if pos != 0: if pos != 0:
ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1]))
mnemonic[pos - 1] = None mnemonic[pos - 1] = None
else: else:
ret = self.client.call_raw(proto.WordAck(word=word)) ret = client.call_raw(proto.WordAck(word=word))
fakes += 1 fakes += 1
print(mnemonic) print(mnemonic)
@ -74,20 +75,21 @@ class TestMsgRecoverydevice(TrezorTest):
assert mnemonic == [None] * 12 assert mnemonic == [None] * 12
# Mnemonic is the same # Mnemonic is the same
self.client.init_device() client.init_device()
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode() assert client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
assert self.client.features.pin_protection is True assert client.features.pin_protection is True
assert self.client.features.passphrase_protection is True assert client.features.passphrase_protection is True
# Do passphrase-protected action, PassphraseRequest should be raised # Do passphrase-protected action, PassphraseRequest should be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) resp = client.call_raw(proto.Ping(passphrase_protection=True))
assert isinstance(resp, proto.PassphraseRequest) assert isinstance(resp, proto.PassphraseRequest)
self.client.call_raw(proto.Cancel()) client.call_raw(proto.Cancel())
def test_nopin_nopassphrase(self): @pytest.mark.setup_client(uninitialized=True)
def test_nopin_nopassphrase(self, client):
mnemonic = self.mnemonic12.split(" ") mnemonic = self.mnemonic12.split(" ")
ret = self.client.call_raw( ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
word_count=12, word_count=12,
passphrase_protection=False, passphrase_protection=False,
@ -100,19 +102,19 @@ class TestMsgRecoverydevice(TrezorTest):
# click through confirmation # click through confirmation
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
fakes = 0 fakes = 0
for _ in range(int(12 * 2)): for _ in range(int(12 * 2)):
assert isinstance(ret, proto.WordRequest) assert isinstance(ret, proto.WordRequest)
(word, pos) = self.client.debug.read_recovery_word() (word, pos) = client.debug.read_recovery_word()
if pos != 0: if pos != 0:
ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1]))
mnemonic[pos - 1] = None mnemonic[pos - 1] = None
else: else:
ret = self.client.call_raw(proto.WordAck(word=word)) ret = client.call_raw(proto.WordAck(word=word))
fakes += 1 fakes += 1
print(mnemonic) print(mnemonic)
@ -125,22 +127,23 @@ class TestMsgRecoverydevice(TrezorTest):
assert mnemonic == [None] * 12 assert mnemonic == [None] * 12
# Mnemonic is the same # Mnemonic is the same
self.client.init_device() client.init_device()
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode() assert client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
assert self.client.features.pin_protection is False assert client.features.pin_protection is False
assert self.client.features.passphrase_protection is False assert client.features.passphrase_protection is False
# Do passphrase-protected action, PassphraseRequest should NOT be raised # Do passphrase-protected action, PassphraseRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) resp = client.call_raw(proto.Ping(passphrase_protection=True))
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
# Do PIN-protected action, PinRequest should NOT be raised # Do PIN-protected action, PinRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(pin_protection=True)) resp = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
def test_word_fail(self): @pytest.mark.setup_client(uninitialized=True)
ret = self.client.call_raw( def test_word_fail(self, client):
ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
word_count=12, word_count=12,
passphrase_protection=False, passphrase_protection=False,
@ -153,21 +156,22 @@ class TestMsgRecoverydevice(TrezorTest):
# click through confirmation # click through confirmation
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.WordRequest) assert isinstance(ret, proto.WordRequest)
for _ in range(int(12 * 2)): for _ in range(int(12 * 2)):
(word, pos) = self.client.debug.read_recovery_word() (word, pos) = client.debug.read_recovery_word()
if pos != 0: if pos != 0:
ret = self.client.call_raw(proto.WordAck(word="kwyjibo")) ret = client.call_raw(proto.WordAck(word="kwyjibo"))
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
break break
else: else:
self.client.call_raw(proto.WordAck(word=word)) client.call_raw(proto.WordAck(word=word))
def test_pin_fail(self): @pytest.mark.setup_client(uninitialized=True)
ret = self.client.call_raw( def test_pin_fail(self, client):
ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
word_count=12, word_count=12,
passphrase_protection=True, passphrase_protection=True,
@ -180,32 +184,25 @@ class TestMsgRecoverydevice(TrezorTest):
# click through confirmation # click through confirmation
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time
pin_encoded = self.client.debug.encode_pin(self.pin4) pin_encoded = client.debug.encode_pin(self.pin4)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for second time, but different one # Enter PIN for second time, but different one
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Failure should be raised # Failure should be raised
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
def test_already_initialized(self): def test_already_initialized(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
device.recover( device.recover(
self.client, client, 12, False, False, "label", "english", client.mnemonic_callback
12,
False,
False,
"label",
"english",
self.client.mnemonic_callback,
) )

View File

@ -18,13 +18,13 @@ import pytest
from trezorlib import messages as proto from trezorlib import messages as proto
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgRecoverydeviceDryrun(TrezorTest): class TestMsgRecoverydeviceDryrun(TrezorTest):
def recovery_loop(self, mnemonic, result): def recovery_loop(self, client, mnemonic, result):
ret = self.client.call_raw( ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
word_count=12, word_count=12,
passphrase_protection=False, passphrase_protection=False,
@ -39,34 +39,31 @@ class TestMsgRecoverydeviceDryrun(TrezorTest):
fakes = 0 fakes = 0
for _ in range(int(12 * 2)): for _ in range(int(12 * 2)):
assert isinstance(ret, proto.WordRequest) assert isinstance(ret, proto.WordRequest)
(word, pos) = self.client.debug.read_recovery_word() (word, pos) = client.debug.read_recovery_word()
if pos != 0: if pos != 0:
ret = self.client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1]))
mnemonic[pos - 1] = None mnemonic[pos - 1] = None
else: else:
ret = self.client.call_raw(proto.WordAck(word=word)) ret = client.call_raw(proto.WordAck(word=word))
fakes += 1 fakes += 1
print(mnemonic) print(mnemonic)
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, result) assert isinstance(ret, result)
def test_correct_notsame(self): def test_correct_notsame(self, client):
self.setup_mnemonic_nopin_nopassphrase() mnemonic = MNEMONIC12.split(" ")
self.recovery_loop(client, mnemonic, proto.Failure)
def test_correct_same(self, client):
mnemonic = ["all"] * 12 mnemonic = ["all"] * 12
self.recovery_loop(mnemonic, proto.Failure) self.recovery_loop(client, mnemonic, proto.Success)
def test_correct_same(self): def test_incorrect(self, client):
self.setup_mnemonic_nopin_nopassphrase()
mnemonic = self.mnemonic12.split(" ")
self.recovery_loop(mnemonic, proto.Success)
def test_incorrect(self):
self.setup_mnemonic_nopin_nopassphrase()
mnemonic = ["stick"] * 12 mnemonic = ["stick"] * 12
self.recovery_loop(mnemonic, proto.Failure) self.recovery_loop(client, mnemonic, proto.Failure)

View File

@ -69,6 +69,7 @@ def enter_all_shares(debug, shares):
debug.press_yes() debug.press_yes()
@pytest.mark.setup_client(uninitialized=True)
@pytest.mark.parametrize("shares, secret", VECTORS) @pytest.mark.parametrize("shares, secret", VECTORS)
def test_secret(client, shares, secret): def test_secret(client, shares, secret):
debug = client.debug debug = client.debug

View File

@ -24,9 +24,10 @@ from .common import TrezorTest
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgRecoverydeviceT2(TrezorTest): class TestMsgRecoverydeviceT2(TrezorTest):
def test_pin_passphrase(self): @pytest.mark.setup_client(uninitialized=True)
def test_pin_passphrase(self, client):
mnemonic = self.mnemonic12.split(" ") mnemonic = self.mnemonic12.split(" ")
ret = self.client.call_raw( ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
passphrase_protection=True, passphrase_protection=True,
pin_protection=True, pin_protection=True,
@ -37,61 +38,62 @@ class TestMsgRecoverydeviceT2(TrezorTest):
# Confirm Recovery # Confirm Recovery
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter PIN for first time # Enter PIN for first time
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other) assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other)
self.client.debug.input("654") client.debug.input("654")
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter PIN for second time # Enter PIN for second time
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other) assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other)
self.client.debug.input("654") client.debug.input("654")
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Homescreen # Homescreen
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter word count # Enter word count
assert ret == proto.ButtonRequest( assert ret == proto.ButtonRequest(
code=proto.ButtonRequestType.MnemonicWordCount code=proto.ButtonRequestType.MnemonicWordCount
) )
self.client.debug.input(str(len(mnemonic))) client.debug.input(str(len(mnemonic)))
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Homescreen # Homescreen
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter mnemonic words # Enter mnemonic words
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput) assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput)
self.client.transport.write(proto.ButtonAck()) client.transport.write(proto.ButtonAck())
for word in mnemonic: for word in mnemonic:
self.client.debug.input(word) client.debug.input(word)
ret = self.client.transport.read() ret = client.transport.read()
# Confirm success # Confirm success
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Workflow succesfully ended # Workflow succesfully ended
assert ret == proto.Success(message="Device recovered") assert ret == proto.Success(message="Device recovered")
# Mnemonic is the same # Mnemonic is the same
self.client.init_device() client.init_device()
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode() assert client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
assert self.client.features.pin_protection is True assert client.features.pin_protection is True
assert self.client.features.passphrase_protection is True assert client.features.passphrase_protection is True
def test_nopin_nopassphrase(self): @pytest.mark.setup_client(uninitialized=True)
def test_nopin_nopassphrase(self, client):
mnemonic = self.mnemonic12.split(" ") mnemonic = self.mnemonic12.split(" ")
ret = self.client.call_raw( ret = client.call_raw(
proto.RecoveryDevice( proto.RecoveryDevice(
passphrase_protection=False, passphrase_protection=False,
pin_protection=False, pin_protection=False,
@ -102,57 +104,50 @@ class TestMsgRecoverydeviceT2(TrezorTest):
# Confirm Recovery # Confirm Recovery
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Homescreen # Homescreen
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter word count # Enter word count
assert ret == proto.ButtonRequest( assert ret == proto.ButtonRequest(
code=proto.ButtonRequestType.MnemonicWordCount code=proto.ButtonRequestType.MnemonicWordCount
) )
self.client.debug.input(str(len(mnemonic))) client.debug.input(str(len(mnemonic)))
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Homescreen # Homescreen
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter mnemonic words # Enter mnemonic words
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput) assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput)
self.client.transport.write(proto.ButtonAck()) client.transport.write(proto.ButtonAck())
for word in mnemonic: for word in mnemonic:
self.client.debug.input(word) client.debug.input(word)
ret = self.client.transport.read() ret = client.transport.read()
# Confirm success # Confirm success
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Workflow succesfully ended # Workflow succesfully ended
assert ret == proto.Success(message="Device recovered") assert ret == proto.Success(message="Device recovered")
# Mnemonic is the same # Mnemonic is the same
self.client.init_device() client.init_device()
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode() assert client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
assert self.client.features.pin_protection is False assert client.features.pin_protection is False
assert self.client.features.passphrase_protection is False assert client.features.passphrase_protection is False
def test_already_initialized(self): def test_already_initialized(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
device.recover( device.recover(
self.client, client, 12, False, False, "label", "english", client.mnemonic_callback
12,
False,
False,
"label",
"english",
self.client.mnemonic_callback,
) )

View File

@ -24,13 +24,13 @@ from .common import TrezorTest, generate_entropy
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgResetDevice(TrezorTest): class TestMsgResetDevice(TrezorTest):
def test_reset_device(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device(self, client):
# No PIN, no passphrase # No PIN, no passphrase
external_entropy = b"zlutoucky kun upel divoke ody" * 2 external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128 strength = 128
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=strength, strength=strength,
@ -42,13 +42,13 @@ class TestMsgResetDevice(TrezorTest):
) )
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_reset_entropy() internal_entropy = client.debug.read_reset_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) ret = client.call_raw(proto.EntropyAck(entropy=external_entropy))
# Generate mnemonic locally # Generate mnemonic locally
entropy = generate_entropy(strength, internal_entropy, external_entropy) entropy = generate_entropy(strength, internal_entropy, external_entropy)
@ -57,9 +57,9 @@ class TestMsgResetDevice(TrezorTest):
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
self.client.call_raw(proto.ButtonAck()) client.call_raw(proto.ButtonAck())
mnemonic = " ".join(mnemonic) mnemonic = " ".join(mnemonic)
@ -69,9 +69,9 @@ class TestMsgResetDevice(TrezorTest):
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
resp = self.client.call_raw(proto.ButtonAck()) resp = client.call_raw(proto.ButtonAck())
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
@ -81,25 +81,26 @@ class TestMsgResetDevice(TrezorTest):
assert mnemonic == expected_mnemonic assert mnemonic == expected_mnemonic
# Check if device is properly initialized # Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize()) resp = client.call_raw(proto.Initialize())
assert resp.initialized is True assert resp.initialized is True
assert resp.needs_backup is False assert resp.needs_backup is False
assert resp.pin_protection is False assert resp.pin_protection is False
assert resp.passphrase_protection is False assert resp.passphrase_protection is False
# Do passphrase-protected action, PassphraseRequest should NOT be raised # Do passphrase-protected action, PassphraseRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) resp = client.call_raw(proto.Ping(passphrase_protection=True))
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
# Do PIN-protected action, PinRequest should NOT be raised # Do PIN-protected action, PinRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(pin_protection=True)) resp = client.call_raw(proto.Ping(pin_protection=True))
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
def test_reset_device_pin(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_pin(self, client):
external_entropy = b"zlutoucky kun upel divoke ody" * 2 external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128 strength = 128
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=True, display_random=True,
strength=strength, strength=strength,
@ -112,34 +113,34 @@ class TestMsgResetDevice(TrezorTest):
# Do you want ... ? # Do you want ... ?
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Entropy screen #1 # Entropy screen #1
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Entropy screen #2 # Entropy screen #2
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time
pin_encoded = self.client.debug.encode_pin("654") pin_encoded = client.debug.encode_pin("654")
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for second time # Enter PIN for second time
pin_encoded = self.client.debug.encode_pin("654") pin_encoded = client.debug.encode_pin("654")
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_reset_entropy() internal_entropy = client.debug.read_reset_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) ret = client.call_raw(proto.EntropyAck(entropy=external_entropy))
# Generate mnemonic locally # Generate mnemonic locally
entropy = generate_entropy(strength, internal_entropy, external_entropy) entropy = generate_entropy(strength, internal_entropy, external_entropy)
@ -148,9 +149,9 @@ class TestMsgResetDevice(TrezorTest):
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
self.client.call_raw(proto.ButtonAck()) client.call_raw(proto.ButtonAck())
mnemonic = " ".join(mnemonic) mnemonic = " ".join(mnemonic)
@ -160,9 +161,9 @@ class TestMsgResetDevice(TrezorTest):
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
resp = self.client.call_raw(proto.ButtonAck()) resp = client.call_raw(proto.ButtonAck())
assert isinstance(resp, proto.Success) assert isinstance(resp, proto.Success)
@ -172,22 +173,23 @@ class TestMsgResetDevice(TrezorTest):
assert mnemonic == expected_mnemonic assert mnemonic == expected_mnemonic
# Check if device is properly initialized # Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize()) resp = client.call_raw(proto.Initialize())
assert resp.initialized is True assert resp.initialized is True
assert resp.needs_backup is False assert resp.needs_backup is False
assert resp.pin_protection is True assert resp.pin_protection is True
assert resp.passphrase_protection is True assert resp.passphrase_protection is True
# Do passphrase-protected action, PassphraseRequest should be raised # Do passphrase-protected action, PassphraseRequest should be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) resp = client.call_raw(proto.Ping(passphrase_protection=True))
assert isinstance(resp, proto.PassphraseRequest) assert isinstance(resp, proto.PassphraseRequest)
self.client.call_raw(proto.Cancel()) client.call_raw(proto.Cancel())
def test_failed_pin(self): @pytest.mark.setup_client(uninitialized=True)
def test_failed_pin(self, client):
# external_entropy = b'zlutoucky kun upel divoke ody' * 2 # external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128 strength = 128
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=True, display_random=True,
strength=strength, strength=strength,
@ -200,33 +202,32 @@ class TestMsgResetDevice(TrezorTest):
# Do you want ... ? # Do you want ... ?
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Entropy screen #1 # Entropy screen #1
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Entropy screen #2 # Entropy screen #2
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time
pin_encoded = self.client.debug.encode_pin(self.pin4) pin_encoded = client.debug.encode_pin(self.pin4)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.PinMatrixRequest) assert isinstance(ret, proto.PinMatrixRequest)
# Enter PIN for second time # Enter PIN for second time
pin_encoded = self.client.debug.encode_pin(self.pin6) pin_encoded = client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
def test_already_initialized(self): def test_already_initialized(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(Exception): with pytest.raises(Exception):
device.reset(self.client, False, 128, True, True, "label", "english") device.reset(client, False, 128, True, True, "label", "english")

View File

@ -14,6 +14,8 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import messages as proto from trezorlib import messages as proto
from .common import TrezorTest from .common import TrezorTest
@ -24,9 +26,9 @@ class TestMsgResetDeviceNobackup(TrezorTest):
external_entropy = b"zlutoucky kun upel divoke ody" * 2 external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128 strength = 128
def test_reset_device_no_backup(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_no_backup(self, client):
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=self.strength, strength=self.strength,
@ -39,27 +41,28 @@ class TestMsgResetDeviceNobackup(TrezorTest):
) )
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=self.external_entropy)) ret = client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check if device is properly initialized # Check if device is properly initialized
ret = self.client.call_raw(proto.Initialize()) ret = client.call_raw(proto.Initialize())
assert ret.initialized is True assert ret.initialized is True
assert ret.needs_backup is False assert ret.needs_backup is False
assert ret.unfinished_backup is False assert ret.unfinished_backup is False
assert ret.no_backup is True assert ret.no_backup is True
# start backup - should fail # start backup - should fail
ret = self.client.call_raw(proto.BackupDevice()) ret = client.call_raw(proto.BackupDevice())
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
def test_reset_device_no_backup_show_entropy_fail(self): @pytest.mark.setup_client(uninitialized=True)
ret = self.client.call_raw( def test_reset_device_no_backup_show_entropy_fail(self, client):
ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=True, display_random=True,
strength=self.strength, strength=self.strength,

View File

@ -16,7 +16,8 @@ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgResetDeviceT2(TrezorTest): class TestMsgResetDeviceT2(TrezorTest):
# TODO: test with different options # TODO: test with different options
def test_reset_device_shamir(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_shamir(self, client):
strength = 128 strength = 128
member_threshold = 3 member_threshold = 3
all_mnemonics = [] all_mnemonics = []
@ -25,42 +26,42 @@ class TestMsgResetDeviceT2(TrezorTest):
# Confirm Reset # Confirm Reset
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Backup your seed # Backup your seed
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm warning # Confirm warning
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# shares info # shares info
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Set & Confirm number of shares # Set & Confirm number of shares
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# threshold info # threshold info
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Set & confirm threshold value # Set & confirm threshold value
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm show seeds # Confirm show seeds
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# show & confirm shares # show & confirm shares
for h in range(5): for h in range(5):
@ -71,33 +72,33 @@ class TestMsgResetDeviceT2(TrezorTest):
# mnemonic phrases # mnemonic phrases
# 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256 # 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256
for i in range(6): for i in range(6):
words.extend(self.client.debug.read_reset_word().split()) words.extend(client.debug.read_reset_word().split())
if i < 5: if i < 5:
self.client.debug.swipe_down() client.debug.swipe_down()
else: else:
# last page is confirmation # last page is confirmation
self.client.debug.press_yes() client.debug.press_yes()
# check share # check share
for _ in range(3): for _ in range(3):
index = self.client.debug.read_reset_word_pos() index = client.debug.read_reset_word_pos()
self.client.debug.input(words[index]) client.debug.input(words[index])
all_mnemonics.extend([" ".join(words)]) all_mnemonics.extend([" ".join(words)])
# Confirm continue to next share # Confirm continue to next share
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
# safety warning # safety warning
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
with mock.patch("os.urandom", os_urandom), self.client: with mock.patch("os.urandom", os_urandom), client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=B.ResetDevice), proto.ButtonRequest(code=B.ResetDevice),
proto.EntropyRequest(), proto.EntropyRequest(),
@ -123,11 +124,11 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.Features(), proto.Features(),
] ]
) )
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
# No PIN, no passphrase, don't display random # No PIN, no passphrase, don't display random
device.reset( device.reset(
self.client, client,
display_random=False, display_random=False,
strength=strength, strength=strength,
passphrase_protection=False, passphrase_protection=False,
@ -138,17 +139,17 @@ class TestMsgResetDeviceT2(TrezorTest):
) )
# generate secret locally # generate secret locally
internal_entropy = self.client.debug.state().reset_entropy internal_entropy = client.debug.state().reset_entropy
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY) secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
# validate that all combinations will result in the correct master secret # validate that all combinations will result in the correct master secret
validate_mnemonics(all_mnemonics, member_threshold, secret) validate_mnemonics(all_mnemonics, member_threshold, secret)
# Check if device is properly initialized # Check if device is properly initialized
assert self.client.features.initialized is True assert client.features.initialized is True
assert self.client.features.needs_backup is False assert client.features.needs_backup is False
assert self.client.features.pin_protection is False assert client.features.pin_protection is False
assert self.client.features.passphrase_protection is False assert client.features.passphrase_protection is False
def validate_mnemonics(mnemonics, threshold, expected_ems): def validate_mnemonics(mnemonics, threshold, expected_ems):

View File

@ -28,9 +28,9 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
external_entropy = b"zlutoucky kun upel divoke ody" * 2 external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128 strength = 128
def test_reset_device_skip_backup(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_skip_backup(self, client):
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=self.strength, strength=self.strength,
@ -43,17 +43,17 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
) )
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_reset_entropy() internal_entropy = client.debug.read_reset_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=self.external_entropy)) ret = client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check if device is properly initialized # Check if device is properly initialized
ret = self.client.call_raw(proto.Initialize()) ret = client.call_raw(proto.Initialize())
assert ret.initialized is True assert ret.initialized is True
assert ret.needs_backup is True assert ret.needs_backup is True
assert ret.unfinished_backup is False assert ret.unfinished_backup is False
@ -66,14 +66,14 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy) expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
# start Backup workflow # start Backup workflow
ret = self.client.call_raw(proto.BackupDevice()) ret = client.call_raw(proto.BackupDevice())
mnemonic = [] mnemonic = []
for _ in range(self.strength // 32 * 3): for _ in range(self.strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
self.client.call_raw(proto.ButtonAck()) client.call_raw(proto.ButtonAck())
mnemonic = " ".join(mnemonic) mnemonic = " ".join(mnemonic)
@ -83,9 +83,9 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
mnemonic = [] mnemonic = []
for _ in range(self.strength // 32 * 3): for _ in range(self.strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(client.debug.read_reset_word())
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
@ -95,12 +95,12 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert mnemonic == expected_mnemonic assert mnemonic == expected_mnemonic
# start backup again - should fail # start backup again - should fail
ret = self.client.call_raw(proto.BackupDevice()) ret = client.call_raw(proto.BackupDevice())
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
def test_reset_device_skip_backup_break(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_skip_backup_break(self, client):
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=self.strength, strength=self.strength,
@ -113,26 +113,26 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
) )
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=self.external_entropy)) ret = client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check if device is properly initialized # Check if device is properly initialized
ret = self.client.call_raw(proto.Initialize()) ret = client.call_raw(proto.Initialize())
assert ret.initialized is True assert ret.initialized is True
assert ret.needs_backup is True assert ret.needs_backup is True
assert ret.unfinished_backup is False assert ret.unfinished_backup is False
assert ret.no_backup is False assert ret.no_backup is False
# start Backup workflow # start Backup workflow
ret = self.client.call_raw(proto.BackupDevice()) ret = client.call_raw(proto.BackupDevice())
# send Initialize -> break workflow # send Initialize -> break workflow
ret = self.client.call_raw(proto.Initialize()) ret = client.call_raw(proto.Initialize())
assert isinstance(ret, proto.Features) assert isinstance(ret, proto.Features)
assert ret.initialized is True assert ret.initialized is True
assert ret.needs_backup is False assert ret.needs_backup is False
@ -140,24 +140,24 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert ret.no_backup is False assert ret.no_backup is False
# start backup again - should fail # start backup again - should fail
ret = self.client.call_raw(proto.BackupDevice()) ret = client.call_raw(proto.BackupDevice())
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
# read Features again # read Features again
ret = self.client.call_raw(proto.Initialize()) ret = client.call_raw(proto.Initialize())
assert isinstance(ret, proto.Features) assert isinstance(ret, proto.Features)
assert ret.initialized is True assert ret.initialized is True
assert ret.needs_backup is False assert ret.needs_backup is False
assert ret.unfinished_backup is True assert ret.unfinished_backup is True
assert ret.no_backup is False assert ret.no_backup is False
def test_initialized_device_backup_fail(self): def test_initialized_device_backup_fail(self, client):
self.setup_mnemonic_nopin_nopassphrase() ret = client.call_raw(proto.BackupDevice())
ret = self.client.call_raw(proto.BackupDevice())
assert isinstance(ret, proto.Failure) assert isinstance(ret, proto.Failure)
def test_reset_device_skip_backup_show_entropy_fail(self): @pytest.mark.setup_client(uninitialized=True)
ret = self.client.call_raw( def test_reset_device_skip_backup_show_entropy_fail(self, client):
ret = client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=True, display_random=True,
strength=self.strength, strength=self.strength,

View File

@ -22,14 +22,15 @@ from mnemonic import Mnemonic
from trezorlib import device, messages as proto from trezorlib import device, messages as proto
from trezorlib.messages import ButtonRequestType as B from trezorlib.messages import ButtonRequestType as B
from .common import TrezorTest, generate_entropy from .common import MNEMONIC12, TrezorTest, generate_entropy
EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2 EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgResetDeviceT2(TrezorTest): class TestMsgResetDeviceT2(TrezorTest):
def test_reset_device(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device(self, client):
words = [] words = []
strength = 128 strength = 128
@ -37,48 +38,48 @@ class TestMsgResetDeviceT2(TrezorTest):
# Confirm Reset # Confirm Reset
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Backup your seed # Backup your seed
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm warning # Confirm warning
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# mnemonic phrases # mnemonic phrases
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
# 12 words, 3 pages # 12 words, 3 pages
for i in range(3): for i in range(3):
words.extend(self.client.debug.read_reset_word().split()) words.extend(client.debug.read_reset_word().split())
if i < 2: if i < 2:
self.client.debug.swipe_down() client.debug.swipe_down()
else: else:
# last page is confirmation # last page is confirmation
self.client.debug.press_yes() client.debug.press_yes()
# check backup words # check backup words
for _ in range(3): for _ in range(3):
index = self.client.debug.read_reset_word_pos() index = client.debug.read_reset_word_pos()
self.client.debug.input(words[index]) client.debug.input(words[index])
# confirm recovery seed check # confirm recovery seed check
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
# confirm success # confirm success
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
with mock.patch("os.urandom", os_urandom), self.client: with mock.patch("os.urandom", os_urandom), client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=B.ResetDevice), proto.ButtonRequest(code=B.ResetDevice),
proto.EntropyRequest(), proto.EntropyRequest(),
@ -91,11 +92,11 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.Features(), proto.Features(),
] ]
) )
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
# No PIN, no passphrase, don't display random # No PIN, no passphrase, don't display random
device.reset( device.reset(
self.client, client,
display_random=False, display_random=False,
strength=strength, strength=strength,
passphrase_protection=False, passphrase_protection=False,
@ -105,7 +106,7 @@ class TestMsgResetDeviceT2(TrezorTest):
) )
# generate mnemonic locally # generate mnemonic locally
internal_entropy = self.client.debug.state().reset_entropy internal_entropy = client.debug.state().reset_entropy
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY) entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy) expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
@ -113,13 +114,14 @@ class TestMsgResetDeviceT2(TrezorTest):
assert " ".join(words) == expected_mnemonic assert " ".join(words) == expected_mnemonic
# Check if device is properly initialized # Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize()) resp = client.call_raw(proto.Initialize())
assert resp.initialized is True assert resp.initialized is True
assert resp.needs_backup is False assert resp.needs_backup is False
assert resp.pin_protection is False assert resp.pin_protection is False
assert resp.passphrase_protection is False assert resp.passphrase_protection is False
def test_reset_device_pin(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_pin(self, client):
words = [] words = []
strength = 128 strength = 128
@ -127,61 +129,61 @@ class TestMsgResetDeviceT2(TrezorTest):
# Confirm Reset # Confirm Reset
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Enter new PIN # Enter new PIN
yield yield
self.client.debug.input("654") client.debug.input("654")
# Confirm PIN # Confirm PIN
yield yield
self.client.debug.input("654") client.debug.input("654")
# Confirm entropy # Confirm entropy
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Backup your seed # Backup your seed
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm warning # Confirm warning
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# mnemonic phrases # mnemonic phrases
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
# 12 words, 3 pages # 12 words, 3 pages
for i in range(3): for i in range(3):
words.extend(self.client.debug.read_reset_word().split()) words.extend(client.debug.read_reset_word().split())
if i < 2: if i < 2:
self.client.debug.swipe_down() client.debug.swipe_down()
else: else:
# last page is confirmation # last page is confirmation
self.client.debug.press_yes() client.debug.press_yes()
# check backup words # check backup words
for _ in range(3): for _ in range(3):
index = self.client.debug.read_reset_word_pos() index = client.debug.read_reset_word_pos()
self.client.debug.input(words[index]) client.debug.input(words[index])
# confirm recovery seed check # confirm recovery seed check
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
# confirm success # confirm success
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
with mock.patch("os.urandom", os_urandom), self.client: with mock.patch("os.urandom", os_urandom), client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=B.ResetDevice), proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Other), proto.ButtonRequest(code=B.Other),
@ -197,11 +199,11 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.Features(), proto.Features(),
] ]
) )
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
# PIN, passphrase, display random # PIN, passphrase, display random
device.reset( device.reset(
self.client, client,
display_random=True, display_random=True,
strength=strength, strength=strength,
passphrase_protection=True, passphrase_protection=True,
@ -211,7 +213,7 @@ class TestMsgResetDeviceT2(TrezorTest):
) )
# generate mnemonic locally # generate mnemonic locally
internal_entropy = self.client.debug.state().reset_entropy internal_entropy = client.debug.state().reset_entropy
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY) entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy) expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
@ -219,37 +221,38 @@ class TestMsgResetDeviceT2(TrezorTest):
assert " ".join(words) == expected_mnemonic assert " ".join(words) == expected_mnemonic
# Check if device is properly initialized # Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize()) resp = client.call_raw(proto.Initialize())
assert resp.initialized is True assert resp.initialized is True
assert resp.needs_backup is False assert resp.needs_backup is False
assert resp.pin_protection is True assert resp.pin_protection is True
assert resp.passphrase_protection is True assert resp.passphrase_protection is True
def test_failed_pin(self): @pytest.mark.setup_client(uninitialized=True)
def test_failed_pin(self, client):
# external_entropy = b'zlutoucky kun upel divoke ody' * 2 # external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128 strength = 128
ret = self.client.call_raw( ret = client.call_raw(
proto.ResetDevice(strength=strength, pin_protection=True, label="test") proto.ResetDevice(strength=strength, pin_protection=True, label="test")
) )
# Confirm Reset # Confirm Reset
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.press_yes() client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter PIN for first time # Enter PIN for first time
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.input("654") client.debug.input("654")
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
# Enter PIN for second time # Enter PIN for second time
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
self.client.debug.input("456") client.debug.input("456")
ret = self.client.call_raw(proto.ButtonAck()) ret = client.call_raw(proto.ButtonAck())
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
def test_already_initialized(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_already_initialized(self, client):
with pytest.raises(Exception): with pytest.raises(Exception):
device.reset(self.client, False, 128, True, True, "label", "english") device.reset(client, False, 128, True, True, "label", "english")

View File

@ -16,39 +16,35 @@
import pytest import pytest
from trezorlib import debuglink
from trezorlib.ripple import get_address from trezorlib.ripple import get_address
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import TrezorTest
CUSTOM_MNEMONIC = (
"armed bundle pudding lazy strategy impulse where identify "
"submit weekend physical antenna flight social acoustic absurd "
"whip snack decide blur unfold fiction pumpkin athlete"
)
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.ripple @pytest.mark.ripple
@pytest.mark.skip_t1 # T1 support is not planned @pytest.mark.skip_t1 # T1 support is not planned
class TestMsgRippleGetAddress(TrezorTest): class TestMsgRippleGetAddress(TrezorTest):
def test_ripple_get_address(self): def test_ripple_get_address(self, client):
# data from https://iancoleman.io/bip39/#english # data from https://iancoleman.io/bip39/#english
self.setup_mnemonic_allallall() address = get_address(client, parse_path("m/44'/144'/0'/0/0"))
address = get_address(self.client, parse_path("m/44'/144'/0'/0/0"))
assert address == "rNaqKtKrMSwpwZSzRckPf7S96DkimjkF4H" assert address == "rNaqKtKrMSwpwZSzRckPf7S96DkimjkF4H"
address = get_address(self.client, parse_path("m/44'/144'/0'/0/1")) address = get_address(client, parse_path("m/44'/144'/0'/0/1"))
assert address == "rBKz5MC2iXdoS3XgnNSYmF69K1Yo4NS3Ws" assert address == "rBKz5MC2iXdoS3XgnNSYmF69K1Yo4NS3Ws"
address = get_address(self.client, parse_path("m/44'/144'/1'/0/0")) address = get_address(client, parse_path("m/44'/144'/1'/0/0"))
assert address == "rJX2KwzaLJDyFhhtXKi3htaLfaUH2tptEX" assert address == "rJX2KwzaLJDyFhhtXKi3htaLfaUH2tptEX"
def test_ripple_get_address_other(self): @pytest.mark.setup_client(mnemonic=CUSTOM_MNEMONIC)
def test_ripple_get_address_other(self, client):
# data from https://github.com/you21979/node-ripple-bip32/blob/master/test/test.js # data from https://github.com/you21979/node-ripple-bip32/blob/master/test/test.js
debuglink.load_device_by_mnemonic( address = get_address(client, parse_path("m/44'/144'/0'/0/0"))
self.client,
mnemonic="armed bundle pudding lazy strategy impulse where identify submit weekend physical antenna flight social acoustic absurd whip snack decide blur unfold fiction pumpkin athlete",
pin="",
passphrase_protection=False,
label="test",
language="english",
)
address = get_address(self.client, parse_path("m/44'/144'/0'/0/0"))
assert address == "r4ocGE47gm4G4LkA9mriVHQqzpMLBTgnTY" assert address == "r4ocGE47gm4G4LkA9mriVHQqzpMLBTgnTY"
address = get_address(self.client, parse_path("m/44'/144'/0'/0/1")) address = get_address(client, parse_path("m/44'/144'/0'/0/1"))
assert address == "rUt9ULSrUvfCmke8HTFU1szbmFpWzVbBXW" assert address == "rUt9ULSrUvfCmke8HTFU1szbmFpWzVbBXW"

View File

@ -26,9 +26,7 @@ from .common import TrezorTest
@pytest.mark.ripple @pytest.mark.ripple
@pytest.mark.skip_t1 # T1 support is not planned @pytest.mark.skip_t1 # T1 support is not planned
class TestMsgRippleSignTx(TrezorTest): class TestMsgRippleSignTx(TrezorTest):
def test_ripple_sign_simple_tx(self): def test_ripple_sign_simple_tx(self, client):
self.setup_mnemonic_allallall()
msg = ripple.create_sign_tx_msg( msg = ripple.create_sign_tx_msg(
{ {
"TransactionType": "Payment", "TransactionType": "Payment",
@ -41,7 +39,7 @@ class TestMsgRippleSignTx(TrezorTest):
"Sequence": 25, "Sequence": 25,
} }
) )
resp = ripple.sign_tx(self.client, parse_path("m/44'/144'/0'/0/0"), msg) resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/0"), msg)
assert ( assert (
resp.signature.hex() resp.signature.hex()
== "3045022100e243ef623675eeeb95965c35c3e06d63a9fc68bb37e17dc87af9c0af83ec057e02206ca8aa5eaab8396397aef6d38d25710441faf7c79d292ee1d627df15ad9346c0" == "3045022100e243ef623675eeeb95965c35c3e06d63a9fc68bb37e17dc87af9c0af83ec057e02206ca8aa5eaab8396397aef6d38d25710441faf7c79d292ee1d627df15ad9346c0"
@ -62,7 +60,7 @@ class TestMsgRippleSignTx(TrezorTest):
"Sequence": 1, "Sequence": 1,
} }
) )
resp = ripple.sign_tx(self.client, parse_path("m/44'/144'/0'/0/2"), msg) resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
assert ( assert (
resp.signature.hex() resp.signature.hex()
== "3044022069900e6e578997fad5189981b74b16badc7ba8b9f1052694033fa2779113ddc002206c8006ada310edf099fb22c0c12073550c8fc73247b236a974c5f1144831dd5f" == "3044022069900e6e578997fad5189981b74b16badc7ba8b9f1052694033fa2779113ddc002206c8006ada310edf099fb22c0c12073550c8fc73247b236a974c5f1144831dd5f"
@ -86,7 +84,7 @@ class TestMsgRippleSignTx(TrezorTest):
"LastLedgerSequence": 333111, "LastLedgerSequence": 333111,
} }
) )
resp = ripple.sign_tx(self.client, parse_path("m/44'/144'/0'/0/2"), msg) resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
assert ( assert (
resp.signature.hex() resp.signature.hex()
== "30450221008770743a472bb2d1c746a53ef131cc17cc118d538ec910ca928d221db4494cf702201e4ef242d6c3bff110c3cc3897a471fed0f5ac10987ea57da63f98dfa01e94df" == "30450221008770743a472bb2d1c746a53ef131cc17cc118d538ec910ca928d221db4494cf702201e4ef242d6c3bff110c3cc3897a471fed0f5ac10987ea57da63f98dfa01e94df"
@ -96,9 +94,7 @@ class TestMsgRippleSignTx(TrezorTest):
== "120000228000000024000000642e0001e240201b00051537614000000005f5e109684000000000000064732103dbed1e77cb91a005e2ec71afbccce5444c9be58276665a3859040f692de8fed2744730450221008770743a472bb2d1c746a53ef131cc17cc118d538ec910ca928d221db4494cf702201e4ef242d6c3bff110c3cc3897a471fed0f5ac10987ea57da63f98dfa01e94df8114bdf86f3ae715ba346b7772ea0e133f48828b766483148fb40e1ffa5d557ce9851a535af94965e0dd0988" == "120000228000000024000000642e0001e240201b00051537614000000005f5e109684000000000000064732103dbed1e77cb91a005e2ec71afbccce5444c9be58276665a3859040f692de8fed2744730450221008770743a472bb2d1c746a53ef131cc17cc118d538ec910ca928d221db4494cf702201e4ef242d6c3bff110c3cc3897a471fed0f5ac10987ea57da63f98dfa01e94df8114bdf86f3ae715ba346b7772ea0e133f48828b766483148fb40e1ffa5d557ce9851a535af94965e0dd0988"
) )
def test_ripple_sign_invalid_fee(self): def test_ripple_sign_invalid_fee(self, client):
self.setup_mnemonic_allallall()
msg = ripple.create_sign_tx_msg( msg = ripple.create_sign_tx_msg(
{ {
"TransactionType": "Payment", "TransactionType": "Payment",
@ -112,7 +108,7 @@ class TestMsgRippleSignTx(TrezorTest):
} }
) )
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
ripple.sign_tx(self.client, parse_path("m/44'/144'/0'/0/2"), msg) ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
assert exc.value.args[0] == messages.FailureType.ProcessError assert exc.value.args[0] == messages.FailureType.ProcessError
assert exc.value.args[1].endswith( assert exc.value.args[1].endswith(
"Fee must be in the range of 10 to 10,000 drops" "Fee must be in the range of 10 to 10,000 drops"

View File

@ -16,10 +16,12 @@
import struct import struct
import pytest
from trezorlib import messages as proto, misc from trezorlib import messages as proto, misc
from trezorlib.tools import H_ from trezorlib.tools import H_
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
def check_path(identity): def check_path(identity):
@ -46,9 +48,8 @@ def check_path(identity):
class TestMsgSignidentity(TrezorTest): class TestMsgSignidentity(TrezorTest):
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
hidden = bytes.fromhex( hidden = bytes.fromhex(
"cd8552569d6e4509266ef137584d1e62c7579b5b8ed69bbafa4b864c6521e7c2" "cd8552569d6e4509266ef137584d1e62c7579b5b8ed69bbafa4b864c6521e7c2"
) )
@ -65,7 +66,7 @@ class TestMsgSignidentity(TrezorTest):
path="/login", path="/login",
index=0, index=0,
) )
sig = misc.sign_identity(self.client, identity, hidden, visual) sig = misc.sign_identity(client, identity, hidden, visual)
assert sig.address == "17F17smBTX9VTZA9Mj8LM5QGYNZnmziCjL" assert sig.address == "17F17smBTX9VTZA9Mj8LM5QGYNZnmziCjL"
assert ( assert (
sig.public_key.hex() sig.public_key.hex()
@ -87,7 +88,7 @@ class TestMsgSignidentity(TrezorTest):
path="/pub", path="/pub",
index=3, index=3,
) )
sig = misc.sign_identity(self.client, identity, hidden, visual) sig = misc.sign_identity(client, identity, hidden, visual)
assert sig.address == "1KAr6r5qF2kADL8bAaRQBjGKYEGxn9WrbS" assert sig.address == "1KAr6r5qF2kADL8bAaRQBjGKYEGxn9WrbS"
assert ( assert (
sig.public_key.hex() sig.public_key.hex()
@ -105,7 +106,7 @@ class TestMsgSignidentity(TrezorTest):
proto="ssh", user="satoshi", host="bitcoin.org", port="", path="", index=47 proto="ssh", user="satoshi", host="bitcoin.org", port="", path="", index=47
) )
sig = misc.sign_identity( sig = misc.sign_identity(
self.client, identity, hidden, visual, ecdsa_curve_name="nist256p1" client, identity, hidden, visual, ecdsa_curve_name="nist256p1"
) )
assert sig.address is None assert sig.address is None
assert ( assert (
@ -124,7 +125,7 @@ class TestMsgSignidentity(TrezorTest):
proto="ssh", user="satoshi", host="bitcoin.org", port="", path="", index=47 proto="ssh", user="satoshi", host="bitcoin.org", port="", path="", index=47
) )
sig = misc.sign_identity( sig = misc.sign_identity(
self.client, identity, hidden, visual, ecdsa_curve_name="ed25519" client, identity, hidden, visual, ecdsa_curve_name="ed25519"
) )
assert sig.address is None assert sig.address is None
assert ( assert (
@ -141,7 +142,7 @@ class TestMsgSignidentity(TrezorTest):
proto="gpg", user="satoshi", host="bitcoin.org", port="", path="" proto="gpg", user="satoshi", host="bitcoin.org", port="", path=""
) )
sig = misc.sign_identity( sig = misc.sign_identity(
self.client, identity, hidden, visual, ecdsa_curve_name="ed25519" client, identity, hidden, visual, ecdsa_curve_name="ed25519"
) )
assert sig.address is None assert sig.address is None
assert ( assert (
@ -158,7 +159,7 @@ class TestMsgSignidentity(TrezorTest):
proto="signify", user="satoshi", host="bitcoin.org", port="", path="" proto="signify", user="satoshi", host="bitcoin.org", port="", path=""
) )
sig = misc.sign_identity( sig = misc.sign_identity(
self.client, identity, hidden, visual, ecdsa_curve_name="ed25519" client, identity, hidden, visual, ecdsa_curve_name="ed25519"
) )
assert sig.address is None assert sig.address is None
assert ( assert (

View File

@ -21,14 +21,14 @@ import pytest
from trezorlib import btc from trezorlib import btc
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgSignmessage(TrezorTest): class TestMsgSignmessage(TrezorTest):
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, "Bitcoin", [0], "This is an example of a signed message." client, "Bitcoin", [0], "This is an example of a signed message."
) )
assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e"
assert ( assert (
@ -36,10 +36,10 @@ class TestMsgSignmessage(TrezorTest):
== "209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" == "209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80"
) )
def test_sign_testnet(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_testnet(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, "Testnet", [0], "This is an example of a signed message." client, "Testnet", [0], "This is an example of a signed message."
) )
assert sig.address == "mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL" assert sig.address == "mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL"
assert ( assert (
@ -48,10 +48,10 @@ class TestMsgSignmessage(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_sign_bch(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_bch(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, "Bcash", [0], "This is an example of a signed message." client, "Bcash", [0], "This is an example of a signed message."
) )
assert sig.address == "bitcoincash:qqj22md58nm09vpwsw82fyletkxkq36zxyxh322pru" assert sig.address == "bitcoincash:qqj22md58nm09vpwsw82fyletkxkq36zxyxh322pru"
assert ( assert (
@ -60,10 +60,9 @@ class TestMsgSignmessage(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_sign_grs(self): def test_sign_grs(self, client):
self.setup_mnemonic_allallall()
sig = btc.sign_message( sig = btc.sign_message(
self.client, "Groestlcoin", parse_path("44'/17'/0'/0/0"), "test" client, "Groestlcoin", parse_path("44'/17'/0'/0/0"), "test"
) )
assert sig.address == "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM" assert sig.address == "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM"
assert ( assert (
@ -71,29 +70,28 @@ class TestMsgSignmessage(TrezorTest):
== b"INOYaa/jj8Yxz3mD5k+bZfUmjkjB9VzoV4dNG7+RsBUyK30xL7I9yMgWWVvsL46C5yQtxtZY0cRRk7q9N6b+YTM=" == b"INOYaa/jj8Yxz3mD5k+bZfUmjkjB9VzoV4dNG7+RsBUyK30xL7I9yMgWWVvsL46C5yQtxtZY0cRRk7q9N6b+YTM="
) )
def test_sign_long(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_long(self, client):
sig = btc.sign_message(self.client, "Bitcoin", [0], "VeryLongMessage!" * 64) sig = btc.sign_message(client, "Bitcoin", [0], "VeryLongMessage!" * 64)
assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e"
assert ( assert (
sig.signature.hex() sig.signature.hex()
== "205ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" == "205ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed"
) )
def test_sign_utf(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_utf(self, client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
sig_nfkd = btc.sign_message(self.client, "Bitcoin", [0], words_nfkd) sig_nfkd = btc.sign_message(client, "Bitcoin", [0], words_nfkd)
assert sig_nfkd.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" assert sig_nfkd.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e"
assert ( assert (
sig_nfkd.signature.hex() sig_nfkd.signature.hex()
== "20d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" == "20d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6"
) )
sig_nfc = btc.sign_message(self.client, "Bitcoin", [0], words_nfc) sig_nfc = btc.sign_message(client, "Bitcoin", [0], words_nfc)
assert sig_nfc.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" assert sig_nfc.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e"
assert ( assert (
sig_nfc.signature.hex() sig_nfc.signature.hex()

View File

@ -19,17 +19,17 @@ import pytest
from trezorlib import btc from trezorlib import btc
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.decred @pytest.mark.decred
class TestMsgSignmessageDecred(TrezorTest): class TestMsgSignmessageDecred(TrezorTest):
def test_sign_mainnet(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_mainnet(self, client):
address_n = parse_path("m/44'/42'/0'/0/0") address_n = parse_path("m/44'/42'/0'/0/0")
sig = btc.sign_message( sig = btc.sign_message(
self.client, "Decred", address_n, "This is an example of a signed message." client, "Decred", address_n, "This is an example of a signed message."
) )
assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy"
assert ( assert (
@ -37,11 +37,11 @@ class TestMsgSignmessageDecred(TrezorTest):
== "20417ee6116304a65d267aec989a1450ed3699201cc0f2a6e8273a3ad31dfb3cda26a5b26f040aa3d0d76c66d6d7c1d1e5e424c1298b3ba1201c36a0a87971ed83" == "20417ee6116304a65d267aec989a1450ed3699201cc0f2a6e8273a3ad31dfb3cda26a5b26f040aa3d0d76c66d6d7c1d1e5e424c1298b3ba1201c36a0a87971ed83"
) )
def test_sign_testnet(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_testnet(self, client):
address_n = parse_path("m/44'/1'/0'/0/0") address_n = parse_path("m/44'/1'/0'/0/0")
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Decred Testnet", "Decred Testnet",
address_n, address_n,
"This is an example of a signed message.", "This is an example of a signed message.",
@ -52,33 +52,31 @@ class TestMsgSignmessageDecred(TrezorTest):
== "20260e5665cca98e0a08ebf33346a0e1cdb7ef313d0c50d1403f5c1ea7ef5958204c9a3f3ad3fa793456365b1b3ca700c7299099646813b43dcad6249ba77a469f" == "20260e5665cca98e0a08ebf33346a0e1cdb7ef313d0c50d1403f5c1ea7ef5958204c9a3f3ad3fa793456365b1b3ca700c7299099646813b43dcad6249ba77a469f"
) )
def test_sign_long(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_long(self, client):
address_n = parse_path("m/44'/42'/0'/0/0") address_n = parse_path("m/44'/42'/0'/0/0")
sig = btc.sign_message( sig = btc.sign_message(client, "Decred", address_n, "VeryLongMessage!" * 64)
self.client, "Decred", address_n, "VeryLongMessage!" * 64
)
assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy"
assert ( assert (
sig.signature.hex() sig.signature.hex()
== "1f4ce0f81b387d6c9ce3961baf9ae10c2fe14a2d13243ec5863131d526c77d4459636ba71217a47726ecf7517bde41e3ef95a3de10054ff88bbf8ca5cb0b5f3cea" == "1f4ce0f81b387d6c9ce3961baf9ae10c2fe14a2d13243ec5863131d526c77d4459636ba71217a47726ecf7517bde41e3ef95a3de10054ff88bbf8ca5cb0b5f3cea"
) )
def test_sign_utf(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_utf(self, client):
address_n = parse_path("m/44'/42'/0'/0/0") address_n = parse_path("m/44'/42'/0'/0/0")
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
sig_nfkd = btc.sign_message(self.client, "Decred", address_n, words_nfkd) sig_nfkd = btc.sign_message(client, "Decred", address_n, words_nfkd)
assert sig_nfkd.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" assert sig_nfkd.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy"
assert ( assert (
sig_nfkd.signature.hex() sig_nfkd.signature.hex()
== "1feb2e6eeabe6508fff655c7c3aa7b52098b09e01c9f0cfae404bd4d7baf856e762b72a4c13a8f826b7a42c0b48a5a1b12a96497ca90bd2b183e42f4b3d4eea16b" == "1feb2e6eeabe6508fff655c7c3aa7b52098b09e01c9f0cfae404bd4d7baf856e762b72a4c13a8f826b7a42c0b48a5a1b12a96497ca90bd2b183e42f4b3d4eea16b"
) )
sig_nfc = btc.sign_message(self.client, "Decred", address_n, words_nfc) sig_nfc = btc.sign_message(client, "Decred", address_n, words_nfc)
assert sig_nfc.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" assert sig_nfc.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy"
assert ( assert (
sig_nfc.signature.hex() sig_nfc.signature.hex()

View File

@ -21,14 +21,14 @@ import pytest
from trezorlib import btc, messages as proto from trezorlib import btc, messages as proto
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgSignmessageSegwit(TrezorTest): class TestMsgSignmessageSegwit(TrezorTest):
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
"This is an example of a signed message.", "This is an example of a signed message.",
@ -40,10 +40,10 @@ class TestMsgSignmessageSegwit(TrezorTest):
== "249e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" == "249e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80"
) )
def test_sign_testnet(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_testnet(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Testnet", "Testnet",
[0], [0],
"This is an example of a signed message.", "This is an example of a signed message.",
@ -56,10 +56,9 @@ class TestMsgSignmessageSegwit(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_sign_grs(self): def test_sign_grs(self, client):
self.setup_mnemonic_allallall()
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Groestlcoin", "Groestlcoin",
parse_path("49'/17'/0'/0/0"), parse_path("49'/17'/0'/0/0"),
"test", "test",
@ -71,10 +70,10 @@ class TestMsgSignmessageSegwit(TrezorTest):
== b"I/NA/J+epkaeE9vHQ7cDE+TQdrzYzoZ+3dcexBFg0CpKRiIF0h7G5JUCvz4qhGPUjolcpW9rOFsV7CzHVWKS7K4=" == b"I/NA/J+epkaeE9vHQ7cDE+TQdrzYzoZ+3dcexBFg0CpKRiIF0h7G5JUCvz4qhGPUjolcpW9rOFsV7CzHVWKS7K4="
) )
def test_sign_long(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_long(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
"VeryLongMessage!" * 64, "VeryLongMessage!" * 64,
@ -86,14 +85,13 @@ class TestMsgSignmessageSegwit(TrezorTest):
== "245ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" == "245ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed"
) )
def test_sign_utf(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_utf(self, client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
sig_nfkd = btc.sign_message( sig_nfkd = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
words_nfkd, words_nfkd,
@ -106,7 +104,7 @@ class TestMsgSignmessageSegwit(TrezorTest):
) )
sig_nfc = btc.sign_message( sig_nfc = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
words_nfc, words_nfc,

View File

@ -21,14 +21,14 @@ import pytest
from trezorlib import btc, messages as proto from trezorlib import btc, messages as proto
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
class TestMsgSignmessageSegwitNative(TrezorTest): class TestMsgSignmessageSegwitNative(TrezorTest):
def test_sign(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
"This is an example of a signed message.", "This is an example of a signed message.",
@ -40,10 +40,10 @@ class TestMsgSignmessageSegwitNative(TrezorTest):
== "289e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" == "289e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80"
) )
def test_sign_testnet(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_testnet(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Testnet", "Testnet",
[0], [0],
"This is an example of a signed message.", "This is an example of a signed message.",
@ -56,10 +56,9 @@ class TestMsgSignmessageSegwitNative(TrezorTest):
) )
@pytest.mark.altcoin @pytest.mark.altcoin
def test_sign_grs(self): def test_sign_grs(self, client):
self.setup_mnemonic_allallall()
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Groestlcoin", "Groestlcoin",
parse_path("84'/17'/0'/0/0"), parse_path("84'/17'/0'/0/0"),
"test", "test",
@ -71,10 +70,10 @@ class TestMsgSignmessageSegwitNative(TrezorTest):
== b"KIJT20tKHV2sBZKWOFMQo1PvgJksR3ekQTOjNdEtNETabCh9Mq7EBx7EmuMn4gj4m6ChFaEp8QYiHI3VWQ/T3xM=" == b"KIJT20tKHV2sBZKWOFMQo1PvgJksR3ekQTOjNdEtNETabCh9Mq7EBx7EmuMn4gj4m6ChFaEp8QYiHI3VWQ/T3xM="
) )
def test_sign_long(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_long(self, client):
sig = btc.sign_message( sig = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
"VeryLongMessage!" * 64, "VeryLongMessage!" * 64,
@ -86,14 +85,13 @@ class TestMsgSignmessageSegwitNative(TrezorTest):
== "285ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" == "285ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed"
) )
def test_sign_utf(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_utf(self, client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
sig_nfkd = btc.sign_message( sig_nfkd = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
words_nfkd, words_nfkd,
@ -106,7 +104,7 @@ class TestMsgSignmessageSegwitNative(TrezorTest):
) )
sig_nfc = btc.sign_message( sig_nfc = btc.sign_message(
self.client, client,
"Bitcoin", "Bitcoin",
[0], [0],
words_nfc, words_nfc,

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import btc, messages as proto from trezorlib import btc, messages as proto
from trezorlib.tools import H_, CallException, btc_hash, parse_path from trezorlib.tools import H_, CallException, btc_hash, parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .conftest import TREZOR_VERSION from .conftest import TREZOR_VERSION
from .tx_cache import tx_cache from .tx_cache import tx_cache
@ -152,9 +152,8 @@ def check_sign_tx(
class TestMsgSigntx(TrezorTest): class TestMsgSigntx(TrezorTest):
def test_one_one_fee(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_one_one_fee(self, client):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC # input 0: 0.0039 BTC
@ -172,7 +171,7 @@ class TestMsgSigntx(TrezorTest):
) )
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1], [out1], unknown_path=True client, "Bitcoin", [inp1], [out1], unknown_path=True
) )
# Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee # Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee
@ -181,8 +180,7 @@ class TestMsgSigntx(TrezorTest):
== "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000" == "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000"
) )
def test_testnet_one_two_fee(self): def test_testnet_one_two_fee(self, client):
self.setup_mnemonic_allallall()
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56 # see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
@ -206,15 +204,15 @@ class TestMsgSigntx(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = check_sign_tx(self.client, "Testnet", [inp1], [out1, out2]) _, serialized_tx = check_sign_tx(client, "Testnet", [inp1], [out1, out2])
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "0100000001cd3b93f5b24ae190ce5141235091cd93fbb2908e24e5b9ff6776aec11b0e04e5000000006b483045022100eba3bbcbb82ab1ebac88a394e8fb53b0263dadbb3e8072f0a21ee62818c911060220686a9b7f306d028b54a228b5c47cc6c27b1d01a3b0770440bcc64d55d8bace2c0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff021023cb01000000001976a91485eb47fe98f349065d6f044e27a4ac541af79ee288aca0bb0d00000000001976a9143d3cca567e00a04819742b21a696a67da796498b88ac00000000" == "0100000001cd3b93f5b24ae190ce5141235091cd93fbb2908e24e5b9ff6776aec11b0e04e5000000006b483045022100eba3bbcbb82ab1ebac88a394e8fb53b0263dadbb3e8072f0a21ee62818c911060220686a9b7f306d028b54a228b5c47cc6c27b1d01a3b0770440bcc64d55d8bace2c0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff021023cb01000000001976a91485eb47fe98f349065d6f044e27a4ac541af79ee288aca0bb0d00000000001976a9143d3cca567e00a04819742b21a696a67da796498b88ac00000000"
) )
def test_testnet_fee_too_high(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_testnet_fee_too_high(self, client):
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54 # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
# input 1: 10.00000000 BTC # input 1: 10.00000000 BTC
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
@ -239,7 +237,7 @@ class TestMsgSigntx(TrezorTest):
out2.force_confirm = True out2.force_confirm = True
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, client,
"Testnet", "Testnet",
[inp1], [inp1],
[out1, out2], [out1, out2],
@ -252,9 +250,7 @@ class TestMsgSigntx(TrezorTest):
== "0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006a47304402205ea68e9d52d4be14420ccecf7f2e11489d49b86bedb79ee99b5e9b7188884150022056219cb3384a5df8048cca286a9533403dbda1571afd84b51379cdaee6a6dea80121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff020084d717000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000" == "0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006a47304402205ea68e9d52d4be14420ccecf7f2e11489d49b86bedb79ee99b5e9b7188884150022056219cb3384a5df8048cca286a9533403dbda1571afd84b51379cdaee6a6dea80121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff020084d717000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000"
) )
def test_one_two_fee(self): def test_one_two_fee(self, client):
self.setup_mnemonic_allallall()
# tx: c275c333fd1b36bef4af316226c66a8b3693fbfcc081a5e16a2ae5fcb09e92bf # tx: c275c333fd1b36bef4af316226c66a8b3693fbfcc081a5e16a2ae5fcb09e92bf
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
@ -280,16 +276,15 @@ class TestMsgSigntx(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = check_sign_tx(self.client, "Bitcoin", [inp1], [out1, out2]) _, serialized_tx = check_sign_tx(client, "Bitcoin", [inp1], [out1, out2])
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000016d20f69067ad1ffd50ee7c0f377dde2c932ccb03e84b5659732da99c20f1f650010000006a47304402203429bd3ce7b38c5c1e8a15340edd79ced41a2939aae62e259d2e3d18e0c5ee7602201b83b10ebc4d6dcee3f9eb42ba8f1ef8a059a05397e0c1b9223d1565a3e6ec01012102a7a079c1ef9916b289c2ff21a992c808d0de3dfcf8a9f163205c5c9e21f55d5cffffffff0230750000000000001976a914954820f1de627a703596ac0396f986d958e3de4c88ac10270000000000001976a91405427736705cfbfaff76b1cff48283707fb1037088ac00000000" == "01000000016d20f69067ad1ffd50ee7c0f377dde2c932ccb03e84b5659732da99c20f1f650010000006a47304402203429bd3ce7b38c5c1e8a15340edd79ced41a2939aae62e259d2e3d18e0c5ee7602201b83b10ebc4d6dcee3f9eb42ba8f1ef8a059a05397e0c1b9223d1565a3e6ec01012102a7a079c1ef9916b289c2ff21a992c808d0de3dfcf8a9f163205c5c9e21f55d5cffffffff0230750000000000001976a914954820f1de627a703596ac0396f986d958e3de4c88ac10270000000000001976a91405427736705cfbfaff76b1cff48283707fb1037088ac00000000"
) )
def test_one_three_fee(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_one_three_fee(self, client):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC # input 0: 0.0039 BTC
@ -319,7 +314,7 @@ class TestMsgSigntx(TrezorTest):
out3.force_confirm = True out3.force_confirm = True
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1], [out1, out2, out3], unknown_path=True client, "Bitcoin", [inp1], [out1, out2, out3], unknown_path=True
) )
assert ( assert (
@ -327,9 +322,8 @@ class TestMsgSigntx(TrezorTest):
== "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100e695e2c530c7c0fc32e6b79b7cff56a7f70a8c9da787534f46b4204070f914fc02207b0879a81408a11e23b11d4c7965c62b5fc6d5c2d92340f5ee2da7b40e99314a0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0300650400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ace02e0000000000001976a9141fe1d337fb81afca42818051e12fd18245d1b17288ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000" == "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100e695e2c530c7c0fc32e6b79b7cff56a7f70a8c9da787534f46b4204070f914fc02207b0879a81408a11e23b11d4c7965c62b5fc6d5c2d92340f5ee2da7b40e99314a0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0300650400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ace02e0000000000001976a9141fe1d337fb81afca42818051e12fd18245d1b17288ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000"
) )
def test_two_two(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_two_two(self, client):
# tx: c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c # tx: c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c
# input 1: 0.0010 BTC # input 1: 0.0010 BTC
# tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e # tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e
@ -364,7 +358,7 @@ class TestMsgSigntx(TrezorTest):
out2.force_confirm = True out2.force_confirm = True
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1, inp2], [out1, out2], unknown_path=True client, "Bitcoin", [inp1, inp2], [out1, out2], unknown_path=True
) )
# Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb # Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
@ -375,8 +369,8 @@ class TestMsgSigntx(TrezorTest):
== "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000" == "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000"
) )
def test_lots_of_inputs(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_lots_of_inputs(self, client):
# Tests if device implements serialization of len(inputs) correctly # Tests if device implements serialization of len(inputs) correctly
# tx 4a7b7e0403ae5607e473949cfa03f09f2cd8b0f404bf99ce10b7303d86280bf7 : 100 UTXO for spending for unit tests # tx 4a7b7e0403ae5607e473949cfa03f09f2cd8b0f404bf99ce10b7303d86280bf7 : 100 UTXO for spending for unit tests
inputs = [] inputs = []
@ -394,7 +388,7 @@ class TestMsgSigntx(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", inputs, [out], unknown_path=True client, "Bitcoin", inputs, [out], unknown_path=True
) )
# Accepted by network: tx 23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92 # Accepted by network: tx 23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92
# too big put in unit test, only check hash # too big put in unit test, only check hash
@ -403,9 +397,8 @@ class TestMsgSigntx(TrezorTest):
== "23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92" == "23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92"
) )
def test_lots_of_outputs(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_lots_of_outputs(self, client):
# Tests if device implements serialization of len(outputs) correctly # Tests if device implements serialization of len(outputs) correctly
# tx: c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb # tx: c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
@ -438,7 +431,7 @@ class TestMsgSigntx(TrezorTest):
outputs.append(out) outputs.append(out)
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1, inp2], outputs, unknown_path=True client, "Bitcoin", [inp1, inp2], outputs, unknown_path=True
) )
assert ( assert (
@ -449,9 +442,8 @@ class TestMsgSigntx(TrezorTest):
+ "00000000" + "00000000"
) )
def test_fee_too_high(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_fee_too_high(self, client):
# tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6 # tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6
# input 0: 1.0 BTC # input 0: 1.0 BTC
@ -469,7 +461,7 @@ class TestMsgSigntx(TrezorTest):
) )
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1], [out1], fee_too_high=True, unknown_path=True client, "Bitcoin", [inp1], [out1], fee_too_high=True, unknown_path=True
) )
assert ( assert (
@ -477,9 +469,8 @@ class TestMsgSigntx(TrezorTest):
== "0100000001a6cab19c507e547ec87c1f3074d8fdd8379e90e6d5af7929f52c30b46e417015000000006b483045022100dc3531da7feb261575f03b5b9bbb35edc7f73bb081c92538827105de4102737002200161e34395f6a8ee93979200cb974fa75ccef6d7c14021511cf468eece90d6450121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff01d018ee05000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000" == "0100000001a6cab19c507e547ec87c1f3074d8fdd8379e90e6d5af7929f52c30b46e417015000000006b483045022100dc3531da7feb261575f03b5b9bbb35edc7f73bb081c92538827105de4102737002200161e34395f6a8ee93979200cb974fa75ccef6d7c14021511cf468eece90d6450121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff01d018ee05000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000"
) )
def test_not_enough_funds(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_not_enough_funds(self, client):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC # input 0: 0.0039 BTC
@ -498,7 +489,7 @@ class TestMsgSigntx(TrezorTest):
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
check_sign_tx( check_sign_tx(
self.client, client,
"Bitcoin", "Bitcoin",
[inp1], [inp1],
[out1], [out1],
@ -507,9 +498,8 @@ class TestMsgSigntx(TrezorTest):
) )
assert exc.value.args[0] == proto.FailureType.NotEnoughFunds assert exc.value.args[0] == proto.FailureType.NotEnoughFunds
def test_p2sh(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_p2sh(self, client):
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=400000, # amount=400000,
@ -524,7 +514,7 @@ class TestMsgSigntx(TrezorTest):
) )
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1], [out1], unknown_path=True client, "Bitcoin", [inp1], [out1], unknown_path=True
) )
# Accepted by network: tx 8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5 # Accepted by network: tx 8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5
@ -533,9 +523,7 @@ class TestMsgSigntx(TrezorTest):
== "0100000001a3fb2d38322c3b327e54005cebc0686d52fcdf536e53bb5ef481a7de8056aa54010000006b4830450221009e020b0390ccad533b73b552f8a99a9d827212c558e4f755503674d07c92ad4502202d606f7316990e0461c51d4add25054f19c697aa3e3c2ced4d568f0b2c57e62f0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0170f305000000000017a9147f844bdb0b8fd54b64e3d16c85dc1170f1ff97c18700000000" == "0100000001a3fb2d38322c3b327e54005cebc0686d52fcdf536e53bb5ef481a7de8056aa54010000006b4830450221009e020b0390ccad533b73b552f8a99a9d827212c558e4f755503674d07c92ad4502202d606f7316990e0461c51d4add25054f19c697aa3e3c2ced4d568f0b2c57e62f0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0170f305000000000017a9147f844bdb0b8fd54b64e3d16c85dc1170f1ff97c18700000000"
) )
def test_testnet_big_amount(self): def test_testnet_big_amount(self, client):
self.setup_mnemonic_allallall()
# This test is testing transaction with amount bigger than fits to uint32 # This test is testing transaction with amount bigger than fits to uint32
# tx: 2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c:1 # tx: 2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c:1
@ -552,23 +540,14 @@ class TestMsgSigntx(TrezorTest):
amount=411102528330, amount=411102528330,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = check_sign_tx(self.client, "Testnet", [inp1], [out1]) _, serialized_tx = check_sign_tx(client, "Testnet", [inp1], [out1])
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000010c0f4d514eba2b68b467bad8f97d7bac633f465595ea719a5754c6ded17aac2b010000006b4830450221008e3b926f04d8830bd5b67698af25c9e00c9db1b1ef3e5d69af794446753da94a02202d4a7509f26bba29ff643a7ac0d43fb128c1a632cc502b8f44eada8930fb9c9b0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff014ac39eb75f0000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000" == "01000000010c0f4d514eba2b68b467bad8f97d7bac633f465595ea719a5754c6ded17aac2b010000006b4830450221008e3b926f04d8830bd5b67698af25c9e00c9db1b1ef3e5d69af794446753da94a02202d4a7509f26bba29ff643a7ac0d43fb128c1a632cc502b8f44eada8930fb9c9b0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff014ac39eb75f0000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000"
) )
def test_attack_change_outputs(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
# This unit test attempts to modify data sent during ping-pong of streaming signing. def test_attack_change_outputs(self, client):
# Because device is asking for human confirmation only during first pass (first input),
# device must detect that data has been modified during other passes and fail to sign
# such modified data (which has not been confirmed by the user).
# Test firstly prepare normal transaction and send it to device. Then it send the same
# transaction again, but change amount of output 1 during signing the second input.
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
# amount=100000, # amount=100000,
@ -598,7 +577,7 @@ class TestMsgSigntx(TrezorTest):
out2.force_confirm = True out2.force_confirm = True
# Test if the transaction can be signed normally # Test if the transaction can be signed normally
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Bitcoin", [inp1, inp2], [out1, out2], unknown_path=True client, "Bitcoin", [inp1, inp2], [out1, out2], unknown_path=True
) )
# Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb # Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
@ -621,11 +600,11 @@ class TestMsgSigntx(TrezorTest):
return msg return msg
# Set up attack processors # Set up attack processors
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx( btc.sign_tx(
self.client, client,
"Bitcoin", "Bitcoin",
[inp1, inp2], [inp1, inp2],
[out1, out2], [out1, out2],
@ -637,11 +616,7 @@ class TestMsgSigntx(TrezorTest):
) )
assert exc.value.args[1].endswith("Transaction has changed during signing") assert exc.value.args[1].endswith("Transaction has changed during signing")
def test_attack_change_input_address(self): def test_attack_change_input_address(self, client):
# This unit test attempts to modify input address after the Trezor checked
# that it matches the change output
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/1'/4'/0/0"), address_n=parse_path("44'/1'/4'/0/0"),
# moUJnmge8SRXuediK7bW6t4YfrPqbE6hD7 # moUJnmge8SRXuediK7bW6t4YfrPqbE6hD7
@ -663,7 +638,7 @@ class TestMsgSigntx(TrezorTest):
) )
# Test if the transaction can be signed normally # Test if the transaction can be signed normally
_, serialized_tx = check_sign_tx(self.client, "Testnet", [inp1], [out1, out2]) _, serialized_tx = check_sign_tx(client, "Testnet", [inp1], [out1, out2])
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
@ -682,10 +657,10 @@ class TestMsgSigntx(TrezorTest):
return msg return msg
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
# Now run the attack, must trigger the exception # Now run the attack, must trigger the exception
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -733,7 +708,7 @@ class TestMsgSigntx(TrezorTest):
# Now run the attack, must trigger the exception # Now run the attack, must trigger the exception
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx( btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[inp1], [inp1],
[out1, out2], [out1, out2],
@ -748,13 +723,8 @@ class TestMsgSigntx(TrezorTest):
"Transaction has changed during signing" "Transaction has changed during signing"
) )
def test_spend_coinbase(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
# 25 TEST generated to m/1 (mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV) def test_spend_coinbase(self, client):
# tx: d6da21677d7cca5f42fbc7631d062c9ae918a0254f7c6c22de8e8cb7fd5b8236
# input 0: 25.0027823 BTC
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV
# amount=390000, # amount=390000,
@ -769,7 +739,7 @@ class TestMsgSigntx(TrezorTest):
) )
_, serialized_tx = check_sign_tx( _, serialized_tx = check_sign_tx(
self.client, "Testnet", [inp1], [out1], unknown_path=True client, "Testnet", [inp1], [out1], unknown_path=True
) )
# Accepted by network: tx # Accepted by network: tx
@ -778,8 +748,7 @@ class TestMsgSigntx(TrezorTest):
== "010000000136825bfdb78c8ede226c7c4f25a018e99a2c061d63c7fb425fca7c7d6721dad6000000006a473044022047845c366eb24f40be315c7815a154513c444c7989eb80f7ce7ff6aeb703d26a022007c1f5efadf67c5889634fd7ac39a7ce78bffac291673e8772ecd8389c901d9f01210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff01c6100795000000001976a9143d2496e67f5f57a924353da42d4725b318e7a8ea88ac00000000" == "010000000136825bfdb78c8ede226c7c4f25a018e99a2c061d63c7fb425fca7c7d6721dad6000000006a473044022047845c366eb24f40be315c7815a154513c444c7989eb80f7ce7ff6aeb703d26a022007c1f5efadf67c5889634fd7ac39a7ce78bffac291673e8772ecd8389c901d9f01210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff01c6100795000000001976a9143d2496e67f5f57a924353da42d4725b318e7a8ea88ac00000000"
) )
def test_two_changes(self): def test_two_changes(self, client):
self.setup_mnemonic_allallall()
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56 # see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
@ -811,10 +780,9 @@ class TestMsgSigntx(TrezorTest):
out_change2.force_confirm = True out_change2.force_confirm = True
check_sign_tx(self.client, "Testnet", [inp1], [out1, out_change1, out_change2]) check_sign_tx(client, "Testnet", [inp1], [out1, out_change1, out_change2])
def test_change_on_main_chain_allowed(self): def test_change_on_main_chain_allowed(self, client):
self.setup_mnemonic_allallall()
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56 # see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
@ -839,4 +807,4 @@ class TestMsgSigntx(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
check_sign_tx(self.client, "Testnet", [inp1], [out1, out_change]) check_sign_tx(client, "Testnet", [inp1], [out1, out_change])

View File

@ -27,8 +27,7 @@ TX_API = tx_cache("Bcash")
@pytest.mark.altcoin @pytest.mark.altcoin
class TestMsgSigntxBch(TrezorTest): class TestMsgSigntxBch(TrezorTest):
def test_send_bch_change(self): def test_send_bch_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/145'/0'/0/0"), address_n=parse_path("44'/145'/0'/0/0"),
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv # bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
@ -49,8 +48,8 @@ class TestMsgSigntxBch(TrezorTest):
amount=73452, amount=73452,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -82,7 +81,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -90,8 +89,7 @@ class TestMsgSigntxBch(TrezorTest):
== "0100000001781a716b1e15b41b07157933e5d777392a75bf87132650cb2e7d46fb8dc237bc000000006a473044022061aee4f17abe044d5df8c52c9ffd3b84e5a29743517e488b20ecf1ae0b3e4d3a02206bb84c55e407f3b684ff8d9bea0a3409cfd865795a19d10b3d3c31f12795c34a412103a020b36130021a0f037c1d1a02042e325c0cb666d6478c1afdcd9d913b9ef080ffffffff0272ee1c00000000001976a914b1401fce7e8bf123c88a0467e0ed11e3b9fbef5488acec1e0100000000001976a914d51eca49695cdf47e7f4b55507893e3ad53fe9d888ac00000000" == "0100000001781a716b1e15b41b07157933e5d777392a75bf87132650cb2e7d46fb8dc237bc000000006a473044022061aee4f17abe044d5df8c52c9ffd3b84e5a29743517e488b20ecf1ae0b3e4d3a02206bb84c55e407f3b684ff8d9bea0a3409cfd865795a19d10b3d3c31f12795c34a412103a020b36130021a0f037c1d1a02042e325c0cb666d6478c1afdcd9d913b9ef080ffffffff0272ee1c00000000001976a914b1401fce7e8bf123c88a0467e0ed11e3b9fbef5488acec1e0100000000001976a914d51eca49695cdf47e7f4b55507893e3ad53fe9d888ac00000000"
) )
def test_send_bch_nochange(self): def test_send_bch_nochange(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/145'/0'/1/0"), address_n=parse_path("44'/145'/0'/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw # bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
@ -117,8 +115,8 @@ class TestMsgSigntxBch(TrezorTest):
amount=1934960, amount=1934960,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -150,7 +148,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -158,8 +156,7 @@ class TestMsgSigntxBch(TrezorTest):
== "01000000022c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50000000006a47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2dffffffff2c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50010000006a473044022062151cf960b71823bbe68c7ed2c2a93ad1b9706a30255fddb02fcbe056d8c26102207bad1f0872bc5f0cfaf22e45c925c35d6c1466e303163b75cb7688038f1a5541412102595caf9aeb6ffdd0e82b150739a83297358b9a77564de382671056ad9e5b8c58ffffffff0170861d00000000001976a91434e9cec317896e818619ab7dc99d2305216ff4af88ac00000000" == "01000000022c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50000000006a47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2dffffffff2c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50010000006a473044022062151cf960b71823bbe68c7ed2c2a93ad1b9706a30255fddb02fcbe056d8c26102207bad1f0872bc5f0cfaf22e45c925c35d6c1466e303163b75cb7688038f1a5541412102595caf9aeb6ffdd0e82b150739a83297358b9a77564de382671056ad9e5b8c58ffffffff0170861d00000000001976a91434e9cec317896e818619ab7dc99d2305216ff4af88ac00000000"
) )
def test_send_bch_oldaddr(self): def test_send_bch_oldaddr(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/145'/0'/1/0"), address_n=parse_path("44'/145'/0'/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw # bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
@ -185,8 +182,8 @@ class TestMsgSigntxBch(TrezorTest):
amount=1934960, amount=1934960,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -218,7 +215,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -226,8 +223,7 @@ class TestMsgSigntxBch(TrezorTest):
== "01000000022c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50000000006a47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2dffffffff2c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50010000006a473044022062151cf960b71823bbe68c7ed2c2a93ad1b9706a30255fddb02fcbe056d8c26102207bad1f0872bc5f0cfaf22e45c925c35d6c1466e303163b75cb7688038f1a5541412102595caf9aeb6ffdd0e82b150739a83297358b9a77564de382671056ad9e5b8c58ffffffff0170861d00000000001976a91434e9cec317896e818619ab7dc99d2305216ff4af88ac00000000" == "01000000022c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50000000006a47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2dffffffff2c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50010000006a473044022062151cf960b71823bbe68c7ed2c2a93ad1b9706a30255fddb02fcbe056d8c26102207bad1f0872bc5f0cfaf22e45c925c35d6c1466e303163b75cb7688038f1a5541412102595caf9aeb6ffdd0e82b150739a83297358b9a77564de382671056ad9e5b8c58ffffffff0170861d00000000001976a91434e9cec317896e818619ab7dc99d2305216ff4af88ac00000000"
) )
def test_attack_amount(self): def test_attack_amount(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/145'/0'/1/0"), address_n=parse_path("44'/145'/0'/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw # bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
@ -255,8 +251,8 @@ class TestMsgSigntxBch(TrezorTest):
) )
# test if passes without modifications # test if passes without modifications
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -287,7 +283,7 @@ class TestMsgSigntxBch(TrezorTest):
proto.TxRequest(request_type=proto.RequestType.TXFINISHED), proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
] ]
) )
btc.sign_tx(self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API) btc.sign_tx(client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API)
run_attack = True run_attack = True
@ -304,9 +300,9 @@ class TestMsgSigntxBch(TrezorTest):
return msg return msg
# now fails # now fails
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -335,9 +331,7 @@ class TestMsgSigntxBch(TrezorTest):
) )
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx( btc.sign_tx(client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API)
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
)
assert exc.value.args[0] in ( assert exc.value.args[0] in (
proto.FailureType.ProcessError, proto.FailureType.ProcessError,
@ -345,8 +339,7 @@ class TestMsgSigntxBch(TrezorTest):
) )
assert exc.value.args[1].endswith("Transaction has changed during signing") assert exc.value.args[1].endswith("Transaction has changed during signing")
def test_attack_change_input(self): def test_attack_change_input(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/145'/10'/0/0"), address_n=parse_path("44'/145'/10'/0/0"),
amount=1995344, amount=1995344,
@ -380,10 +373,10 @@ class TestMsgSigntxBch(TrezorTest):
return msg return msg
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -407,14 +400,11 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
with pytest.raises(CallException): with pytest.raises(CallException):
btc.sign_tx( btc.sign_tx(client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API)
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
)
def test_send_bch_multisig_wrongchange(self): def test_send_bch_multisig_wrongchange(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("48'/145'/%d'" % i)).node btc.get_public_node(client, parse_path("48'/145'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
@ -462,8 +452,8 @@ class TestMsgSigntxBch(TrezorTest):
script_type=proto.OutputScriptType.PAYTOMULTISIG, script_type=proto.OutputScriptType.PAYTOMULTISIG,
amount=23000, amount=23000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -487,7 +477,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
(signatures1, serialized_tx) = btc.sign_tx( (signatures1, serialized_tx) = btc.sign_tx(
self.client, "Bcash", [inp1], [out1], prev_txes=TX_API client, "Bcash", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
signatures1[0].hex() signatures1[0].hex()
@ -498,10 +488,9 @@ class TestMsgSigntxBch(TrezorTest):
== "01000000015f3d291cae106548f3be5ed0f4cbedc65668fa881d60347ab0d512df10af8cf601000000fc0047304402201badcdcafef4855ed58621f95935efcbc72068510472140f4ec5e252faa0af93022003310a43488288f70aedee96a5af2643a255268a6858cda9ae3001ea5e3c75574147304402207274b5a4d15e75f3df7319a375557b0efba9b27bc63f9f183a17da95a6125c94022000efac57629f1522e2d3958430e2ef073b0706cfac06cce492651b79858f09ae414c69522102245739b55787a27228a4fe78b3a324366cc645fbaa708cad45da351a334341192102debbdcb0b6970d5ade84a50fdbda1c701cdde5c9925d9b6cd8e05a9a15dbef352102ffe5fa04547b2b0c3cfbc21c08a1ddfb147025fee10274cdcd5c1bdeee88eae253aeffffffff01d85900000000000017a914a23eb2a1ed4003d357770120f5c370e199ee55468700000000" == "01000000015f3d291cae106548f3be5ed0f4cbedc65668fa881d60347ab0d512df10af8cf601000000fc0047304402201badcdcafef4855ed58621f95935efcbc72068510472140f4ec5e252faa0af93022003310a43488288f70aedee96a5af2643a255268a6858cda9ae3001ea5e3c75574147304402207274b5a4d15e75f3df7319a375557b0efba9b27bc63f9f183a17da95a6125c94022000efac57629f1522e2d3958430e2ef073b0706cfac06cce492651b79858f09ae414c69522102245739b55787a27228a4fe78b3a324366cc645fbaa708cad45da351a334341192102debbdcb0b6970d5ade84a50fdbda1c701cdde5c9925d9b6cd8e05a9a15dbef352102ffe5fa04547b2b0c3cfbc21c08a1ddfb147025fee10274cdcd5c1bdeee88eae253aeffffffff01d85900000000000017a914a23eb2a1ed4003d357770120f5c370e199ee55468700000000"
) )
def test_send_bch_multisig_change(self): def test_send_bch_multisig_change(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("48'/145'/%d'" % i)).node btc.get_public_node(client, parse_path("48'/145'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
@ -531,8 +520,8 @@ class TestMsgSigntxBch(TrezorTest):
script_type=proto.OutputScriptType.PAYTOMULTISIG, script_type=proto.OutputScriptType.PAYTOMULTISIG,
amount=24000, amount=24000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -564,7 +553,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
(signatures1, serialized_tx) = btc.sign_tx( (signatures1, serialized_tx) = btc.sign_tx(
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -585,8 +574,8 @@ class TestMsgSigntxBch(TrezorTest):
) )
out2.address_n[2] = H_(1) out2.address_n[2] = H_(1)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -618,7 +607,7 @@ class TestMsgSigntxBch(TrezorTest):
] ]
) )
(signatures1, serialized_tx) = btc.sign_tx( (signatures1, serialized_tx) = btc.sign_tx(
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (

View File

@ -28,8 +28,7 @@ TX_API = tx_cache("Bgold")
# All data taken from T1 # All data taken from T1
@pytest.mark.altcoin @pytest.mark.altcoin
class TestMsgSigntxBitcoinGold(TrezorTest): class TestMsgSigntxBitcoinGold(TrezorTest):
def test_send_bitcoin_gold_change(self): def test_send_bitcoin_gold_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/0/0"), address_n=parse_path("44'/156'/0'/0/0"),
amount=1995344, amount=1995344,
@ -49,8 +48,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
amount=73452, amount=73452,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -82,7 +81,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -90,8 +89,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
== "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100963904da0731b71ce468afd45366dd80fbff566ec0d39c1161ab85d17459c7ca02202f5c24a7a7272d98b14a3f5bc000c7cde8ac0eb773f20f4c3131518186cc98854121023bd0ec4022d12d0106c5b7308a25572953ba1951f576f691354a7b147ee0cc1fffffffff0272ee1c00000000001976a9141c82b9c11f193ad82413caadc0955730572b50ae88acec1e0100000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000" == "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100963904da0731b71ce468afd45366dd80fbff566ec0d39c1161ab85d17459c7ca02202f5c24a7a7272d98b14a3f5bc000c7cde8ac0eb773f20f4c3131518186cc98854121023bd0ec4022d12d0106c5b7308a25572953ba1951f576f691354a7b147ee0cc1fffffffff0272ee1c00000000001976a9141c82b9c11f193ad82413caadc0955730572b50ae88acec1e0100000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000"
) )
def test_send_bitcoin_gold_nochange(self): def test_send_bitcoin_gold_nochange(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/1/0"), address_n=parse_path("44'/156'/0'/1/0"),
amount=1896050, amount=1896050,
@ -116,8 +114,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
amount=1934960, amount=1934960,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -149,7 +147,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -157,8 +155,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
== "010000000285c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100928852076c9fab160c07564cd54691af1cbc37fb28f0b7bee7299c7925ef62f0022058856387afecc6508f2f04ecdfd292a13026a5b2107ebdd2cc789bdf8820d552412102a6c3998d0d4e5197ff41aab5c53580253b3b91f583f4c31f7624be7dc83ce15fffffffff18fba85125ef7ccb651b5c79d920e0984a18430028f9e7db6e0e841b46c277db010000006b483045022100faa2f4f01cc95e680349a093923aae0aa2ea01429873555aa8a84bf630ef33a002204c3f4bf567e2d20540c0f71dc278481d6ccb6b95acda2a2f87ce521c79d6b872412102d54a7e5733b1635e5e9442943f48179b1700206b2d1925250ba10f1c86878be8ffffffff0170861d00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000" == "010000000285c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100928852076c9fab160c07564cd54691af1cbc37fb28f0b7bee7299c7925ef62f0022058856387afecc6508f2f04ecdfd292a13026a5b2107ebdd2cc789bdf8820d552412102a6c3998d0d4e5197ff41aab5c53580253b3b91f583f4c31f7624be7dc83ce15fffffffff18fba85125ef7ccb651b5c79d920e0984a18430028f9e7db6e0e841b46c277db010000006b483045022100faa2f4f01cc95e680349a093923aae0aa2ea01429873555aa8a84bf630ef33a002204c3f4bf567e2d20540c0f71dc278481d6ccb6b95acda2a2f87ce521c79d6b872412102d54a7e5733b1635e5e9442943f48179b1700206b2d1925250ba10f1c86878be8ffffffff0170861d00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000"
) )
def test_attack_change_input(self): def test_attack_change_input(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/11'/0/0"), address_n=parse_path("44'/156'/11'/0/0"),
amount=1995344, amount=1995344,
@ -192,9 +189,9 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
return msg return msg
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -218,14 +215,11 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
with pytest.raises(CallException): with pytest.raises(CallException):
btc.sign_tx( btc.sign_tx(client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API)
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
)
def test_send_btg_multisig_change(self): def test_send_btg_multisig_change(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("48'/156'/%d'" % i)).node btc.get_public_node(client, parse_path("48'/156'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
@ -256,8 +250,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
script_type=proto.OutputScriptType.PAYTOMULTISIG, script_type=proto.OutputScriptType.PAYTOMULTISIG,
amount=24000, amount=24000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -289,7 +283,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
signatures, serialized_tx = btc.sign_tx( signatures, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -309,8 +303,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
) )
out2.address_n[2] = H_(1) out2.address_n[2] = H_(1)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -342,7 +336,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
signatures, serialized_tx = btc.sign_tx( signatures, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -354,8 +348,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
== "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b522500000000fdfd00004730440220614f9a18695365a2edba0d930404a77cae970d3430ad86c5b5239a96fd54bf84022030bc76a322e3b2b1c987622b5eb6da23ac1e6c905ee9b3b6405a4e4edd5bbb8741483045022100d954f341ddd3ec96e4bc6cdb90f2df9b2032723f85e4a0187346dd743130bfca0220105ce08b795c70dc09a55569d7874bff684a877219ec2fc37c88cdffe12f332c414c695221035a8db79c0ef57a202664a3da60ca41e8865c6d86ed0aafc03f8e75173341b58021037fba152d8fca660cc49973d8bc9421ff49a75b44ea200873d70d3990f763ed4c210348cbcbd93e069416e0d5db93e86b5698852d9fd54502ad0bed9722fa83f90e4b53aeffffffff02c05d0000000000001976a914ea5f904d195079a350b534db4446433b3cec222e88acc05d00000000000017a914623c803f7fb654dac8dda7786fbf9bc38cd867f48700000000" == "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b522500000000fdfd00004730440220614f9a18695365a2edba0d930404a77cae970d3430ad86c5b5239a96fd54bf84022030bc76a322e3b2b1c987622b5eb6da23ac1e6c905ee9b3b6405a4e4edd5bbb8741483045022100d954f341ddd3ec96e4bc6cdb90f2df9b2032723f85e4a0187346dd743130bfca0220105ce08b795c70dc09a55569d7874bff684a877219ec2fc37c88cdffe12f332c414c695221035a8db79c0ef57a202664a3da60ca41e8865c6d86ed0aafc03f8e75173341b58021037fba152d8fca660cc49973d8bc9421ff49a75b44ea200873d70d3990f763ed4c210348cbcbd93e069416e0d5db93e86b5698852d9fd54502ad0bed9722fa83f90e4b53aeffffffff02c05d0000000000001976a914ea5f904d195079a350b534db4446433b3cec222e88acc05d00000000000017a914623c803f7fb654dac8dda7786fbf9bc38cd867f48700000000"
) )
def test_send_p2sh(self): def test_send_p2sh(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"), address_n=parse_path("49'/156'/0'/1/0"),
amount=123456789, amount=123456789,
@ -375,8 +368,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -413,7 +406,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -421,8 +414,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
== "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f06000000001976a914a8f757819ec6779409f45788f7b4a0e8f51ec50488ac02473044022073fcbf2876f073f78923ab427f14de5b2a0fbeb313a9b2b650b3567061f242a702202f45fc22c501108ff6222afe3aca7da9d8c7dc860f9cda335bef31fa184e7bef412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000" == "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f06000000001976a914a8f757819ec6779409f45788f7b4a0e8f51ec50488ac02473044022073fcbf2876f073f78923ab427f14de5b2a0fbeb313a9b2b650b3567061f242a702202f45fc22c501108ff6222afe3aca7da9d8c7dc860f9cda335bef31fa184e7bef412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000"
) )
def test_send_p2sh_witness_change(self): def test_send_p2sh_witness_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"), address_n=parse_path("49'/156'/0'/1/0"),
amount=123456789, amount=123456789,
@ -442,8 +434,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS, script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -479,7 +471,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -487,10 +479,9 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
== "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f060000000017a9140cd03822b799a452c106d1b3771844a067b17f118702483045022100d79b33384c686d8dd40ad5f84f46691d30994992c1cb42e934c2a625d86cb2f902206859805a9a98ba140b71a9d4b9a6b8df94a9424f9c40f3bd804149fd6e278d63412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000" == "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f060000000017a9140cd03822b799a452c106d1b3771844a067b17f118702483045022100d79b33384c686d8dd40ad5f84f46691d30994992c1cb42e934c2a625d86cb2f902206859805a9a98ba140b71a9d4b9a6b8df94a9424f9c40f3bd804149fd6e278d63412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000"
) )
def test_send_multisig_1(self): def test_send_multisig_1(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("49'/156'/%d'" % i)).node btc.get_public_node(client, parse_path("49'/156'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
multisig = proto.MultisigRedeemScriptType( multisig = proto.MultisigRedeemScriptType(
@ -514,8 +505,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -543,13 +534,13 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Bgold", [inp1], [out1], prev_txes=TX_API client, "Bgold", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[0] = signatures[0] inp1.multisig.signatures[0] = signatures[0]
# sign with third key # sign with third key
inp1.address_n[2] = H_(3) inp1.address_n[2] = H_(3)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -577,7 +568,7 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bgold", [inp1], [out1], prev_txes=TX_API client, "Bgold", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (

View File

@ -27,8 +27,7 @@ TX_API = tx_cache("Dash")
@pytest.mark.altcoin @pytest.mark.altcoin
class TestMsgSigntxDash(TrezorTest): class TestMsgSigntxDash(TrezorTest):
def test_send_dash(self): def test_send_dash(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/5'/0'/0/0"), address_n=parse_path("44'/5'/0'/0/0"),
# dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH # dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH
@ -44,8 +43,8 @@ class TestMsgSigntxDash(TrezorTest):
amount=999999000, amount=999999000,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -101,7 +100,7 @@ class TestMsgSigntxDash(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Dash", [inp1], [out1], prev_txes=TX_API client, "Dash", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -109,8 +108,7 @@ class TestMsgSigntxDash(TrezorTest):
== "01000000014fb02af26dca339e7e06c4f148dfce57c9afa5f537d0d8e733022a4ba6ea7955010000006a4730440220387be4d1e4b5e355614091416373e99e1a3532b8cc9a8629368060aff2681bdb02200a0c4a5e9eb2ce6adb6c2e01ec8f954463dcc04f531ed8a89a2b40019d5aeb0b012102936f80cac2ba719ddb238646eb6b78a170a55a52a9b9f08c43523a4a6bd5c896ffffffff0118c69a3b000000001976a9149710d6545407e78c326aa8c8ae386ec7f883b0af88ac00000000" == "01000000014fb02af26dca339e7e06c4f148dfce57c9afa5f537d0d8e733022a4ba6ea7955010000006a4730440220387be4d1e4b5e355614091416373e99e1a3532b8cc9a8629368060aff2681bdb02200a0c4a5e9eb2ce6adb6c2e01ec8f954463dcc04f531ed8a89a2b40019d5aeb0b012102936f80cac2ba719ddb238646eb6b78a170a55a52a9b9f08c43523a4a6bd5c896ffffffff0118c69a3b000000001976a9149710d6545407e78c326aa8c8ae386ec7f883b0af88ac00000000"
) )
def test_send_dash_dip2_input(self): def test_send_dash_dip2_input(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/5'/0'/0/0"), address_n=parse_path("44'/5'/0'/0/0"),
# dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH # dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH
@ -131,8 +129,8 @@ class TestMsgSigntxDash(TrezorTest):
amount=95000000, amount=95000000,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -202,7 +200,7 @@ class TestMsgSigntxDash(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Dash", [inp1], [out1, out2], prev_txes=TX_API client, "Dash", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (

View File

@ -48,9 +48,7 @@ TXHASH_16da18 = bytes.fromhex(
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.decred @pytest.mark.decred
class TestMsgSigntxDecred(TrezorTest): class TestMsgSigntxDecred(TrezorTest):
def test_send_decred(self): def test_send_decred(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz # TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
address_n=parse_path("m/44'/1'/0'/0/0"), address_n=parse_path("m/44'/1'/0'/0/0"),
@ -67,8 +65,8 @@ class TestMsgSigntxDecred(TrezorTest):
decred_script_version=0, decred_script_version=0,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -111,7 +109,7 @@ class TestMsgSigntxDecred(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Decred Testnet", [inp1], [out1], prev_txes=TX_API client, "Decred Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -119,9 +117,7 @@ class TestMsgSigntxDecred(TrezorTest):
== "0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac000000000000000001000000000000000000000000ffffffff6a473044022009e394c7dec76ab6988270b467839b1462ad781556bce37383b76e026418ce6302204f7f6ef535d2986b095d7c96232a0990a0b9ce3004894b39c167bb18e5833ac30121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" == "0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac000000000000000001000000000000000000000000ffffffff6a473044022009e394c7dec76ab6988270b467839b1462ad781556bce37383b76e026418ce6302204f7f6ef535d2986b095d7c96232a0990a0b9ce3004894b39c167bb18e5833ac30121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
) )
def test_send_decred_change(self): def test_send_decred_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz # TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
address_n=parse_path("m/44'/1'/0'/0/0"), address_n=parse_path("m/44'/1'/0'/0/0"),
@ -164,8 +160,8 @@ class TestMsgSigntxDecred(TrezorTest):
decred_script_version=0, decred_script_version=0,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -265,7 +261,7 @@ class TestMsgSigntxDecred(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Decred Testnet", "Decred Testnet",
[inp1, inp2, inp3], [inp1, inp2, inp3],
[out1, out2], [out1, out2],
@ -277,12 +273,10 @@ class TestMsgSigntxDecred(TrezorTest):
== "010000000370b95980a47b9bcb4ec2c2b450888a53179b1a5fdb23f5023cc533a300356e5e0000000000ffffffff74bc93bcfce18aff2e522d6822817522e2815a00175b2eae59ef20d20f5bf9cc0100000000ffffffff13317ab453832deabd684d2302eed42580c28ba3e715db66a731a8723eef95f30000000000ffffffff02d86c341d0000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00e1f5050000000000001976a9143ee6f9d662e7be18373d80e5eb44627014c2bf6688ac000000000000000003000000000000000000000000ffffffff6a47304402200e50a6d43c462045917792e7d03b4354900c3baccb7abef66f556a32b12f2ca6022031ae94fdf2a41dd6ed2e081faf0f8f1c64411a1b46eb26f7f35d94402b2bde110121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0000000000000000000000000ffffffff6a47304402204894c2f8e76c4645d2df600cdd01443aeb48807b72150c4bc10eebd126529532022054cd37462a3f0ddb85c75b4e874ab0c2aad7eebcff3e6c1ac20e1c16babe36720121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0000000000000000000000000ffffffff6b4830450221009f1ba584023da8aafd57374e83be68f1a097b906967ec9e50736f31bfc7989f102204a190fc2885e394572b5c2ced046657b1dd07abdb19144e21e78987968c7f17601210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852" == "010000000370b95980a47b9bcb4ec2c2b450888a53179b1a5fdb23f5023cc533a300356e5e0000000000ffffffff74bc93bcfce18aff2e522d6822817522e2815a00175b2eae59ef20d20f5bf9cc0100000000ffffffff13317ab453832deabd684d2302eed42580c28ba3e715db66a731a8723eef95f30000000000ffffffff02d86c341d0000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00e1f5050000000000001976a9143ee6f9d662e7be18373d80e5eb44627014c2bf6688ac000000000000000003000000000000000000000000ffffffff6a47304402200e50a6d43c462045917792e7d03b4354900c3baccb7abef66f556a32b12f2ca6022031ae94fdf2a41dd6ed2e081faf0f8f1c64411a1b46eb26f7f35d94402b2bde110121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0000000000000000000000000ffffffff6a47304402204894c2f8e76c4645d2df600cdd01443aeb48807b72150c4bc10eebd126529532022054cd37462a3f0ddb85c75b4e874ab0c2aad7eebcff3e6c1ac20e1c16babe36720121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0000000000000000000000000ffffffff6b4830450221009f1ba584023da8aafd57374e83be68f1a097b906967ec9e50736f31bfc7989f102204a190fc2885e394572b5c2ced046657b1dd07abdb19144e21e78987968c7f17601210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852"
) )
def test_decred_multisig_change(self): def test_decred_multisig_change(self, client):
self.setup_mnemonic_allallall()
paths = [parse_path("m/48'/1'/%d'" % index) for index in range(3)] paths = [parse_path("m/48'/1'/%d'" % index) for index in range(3)]
nodes = [ nodes = [
btc.get_public_node(self.client, address_n, coin_name="Decred Testnet").node btc.get_public_node(client, address_n, coin_name="Decred Testnet").node
for address_n in paths for address_n in paths
] ]
@ -336,8 +330,8 @@ class TestMsgSigntxDecred(TrezorTest):
decred_script_version=0, decred_script_version=0,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -413,7 +407,7 @@ class TestMsgSigntxDecred(TrezorTest):
] ]
) )
signature, serialized_tx = btc.sign_tx( signature, serialized_tx = btc.sign_tx(
self.client, client,
"Decred Testnet", "Decred Testnet",
[inp1, inp2], [inp1, inp2],
[out1, out2], [out1, out2],

View File

@ -27,9 +27,7 @@ TX_API = tx_cache("Groestlcoin")
@pytest.mark.altcoin @pytest.mark.altcoin
class TestMsgSigntxGRS(TrezorTest): class TestMsgSigntxGRS(TrezorTest):
def test_legacy(self): def test_legacy(self, client):
# http://blockbook.groestlcoin.org/tx/f56521b17b828897f72b30dd21b0192fd942342e89acbb06abf1d446282c30f5
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path( address_n=parse_path(
"44'/17'/0'/0/2" "44'/17'/0'/0/2"
@ -45,16 +43,14 @@ class TestMsgSigntxGRS(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin", [inp1], [out1], prev_txes=TX_API client, "Groestlcoin", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000014a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000" == "01000000014a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000"
) )
def test_legacy_change(self): def test_legacy_change(self, client):
# http://blockbook.groestlcoin.org/tx/f56521b17b828897f72b30dd21b0192fd942342e89acbb06abf1d446282c30f5
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path( address_n=parse_path(
"44'/17'/0'/0/2" "44'/17'/0'/0/2"
@ -72,16 +68,14 @@ class TestMsgSigntxGRS(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin", [inp1], [out1], prev_txes=TX_API client, "Groestlcoin", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000014a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000" == "01000000014a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000"
) )
def test_send_segwit_p2sh(self): def test_send_segwit_p2sh(self, client):
# https://blockbook-test.groestlcoin.org/tx/4ce0220004bdfe14e3dd49fd8636bcb770a400c0c9e9bff670b6a13bb8f15c72
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path( address_n=parse_path(
"49'/1'/0'/1/0" "49'/1'/0'/1/0"
@ -106,16 +100,14 @@ class TestMsgSigntxGRS(TrezorTest):
) )
details = proto.SignTx(lock_time=650756) details = proto.SignTx(lock_time=650756)
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000000101cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" == "01000000000101cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900"
) )
def test_send_segwit_p2sh_change(self): def test_send_segwit_p2sh_change(self, client):
# https://blockbook-test.groestlcoin.org/tx/4ce0220004bdfe14e3dd49fd8636bcb770a400c0c9e9bff670b6a13bb8f15c72
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path( address_n=parse_path(
"49'/1'/0'/1/0" "49'/1'/0'/1/0"
@ -140,16 +132,14 @@ class TestMsgSigntxGRS(TrezorTest):
) )
details = proto.SignTx(lock_time=650756) details = proto.SignTx(lock_time=650756)
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000000101cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" == "01000000000101cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900"
) )
def test_send_segwit_native(self): def test_send_segwit_native(self, client):
# https://blockbook-test.groestlcoin.org/tx/9b5c4859a8a31e69788cb4402812bb28f14ad71cbd8c60b09903478bc56f79a3
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"), address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000, amount=12300000,
@ -172,16 +162,14 @@ class TestMsgSigntxGRS(TrezorTest):
) )
details = proto.SignTx(lock_time=650713) details = proto.SignTx(lock_time=650713)
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000000101d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900" == "01000000000101d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900"
) )
def test_send_segwit_native_change(self): def test_send_segwit_native_change(self, client):
# https://blockbook-test.groestlcoin.org/tx/9b5c4859a8a31e69788cb4402812bb28f14ad71cbd8c60b09903478bc56f79a3
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"), address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000, amount=12300000,
@ -204,7 +192,7 @@ class TestMsgSigntxGRS(TrezorTest):
) )
details = proto.SignTx(lock_time=650713) details = proto.SignTx(lock_time=650713)
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details client, "Groestlcoin Testnet", [inp1], [out1, out2], details=details
) )
assert ( assert (
serialized_tx.hex() serialized_tx.hex()

View File

@ -37,9 +37,7 @@ TXHASH_7b28bd = bytes.fromhex(
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.komodo @pytest.mark.komodo
class TestMsgSigntxKomodo(TrezorTest): class TestMsgSigntxKomodo(TrezorTest):
def test_one_one_fee_sapling(self): def test_one_one_fee_sapling(self, client):
self.setup_mnemonic_allallall()
# prevout: 2807c5b126ec8e2b078cab0f12e4c8b4ce1d7724905f8ebef8dca26b0c8e0f1d:0 # prevout: 2807c5b126ec8e2b078cab0f12e4c8b4ce1d7724905f8ebef8dca26b0c8e0f1d:0
# input 1: 10.9998 KMD # input 1: 10.9998 KMD
@ -58,7 +56,7 @@ class TestMsgSigntxKomodo(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
er = [ er = [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -85,7 +83,7 @@ class TestMsgSigntxKomodo(TrezorTest):
proto.TxRequest(request_type=proto.RequestType.TXFINISHED), proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
] ]
self.client.set_expected_responses(er) client.set_expected_responses(er)
details = proto.SignTx( details = proto.SignTx(
version=4, version=4,
@ -95,7 +93,7 @@ class TestMsgSigntxKomodo(TrezorTest):
lock_time=0x5D2A30B8, lock_time=0x5D2A30B8,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Komodo", [inp1], [out1], details=details, prev_txes=TX_API client, "Komodo", [inp1], [out1], details=details, prev_txes=TX_API
) )
# Accepted by network: tx 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1 # Accepted by network: tx 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1
@ -104,9 +102,7 @@ class TestMsgSigntxKomodo(TrezorTest):
== "0400008085202f89011d0f8e0c6ba2dcf8be8e5f9024771dceb4c8e4120fab8c072b8eec26b1c50728000000006a4730440220158c970ca2fc6bcc33026eb5366f0342f63b35d178f7efb334b1df78fe90b67202207bc4ff69f67cf843b08564a5adc77bf5593e28ab4d5104911824ac13fe885d8f012102a87aef7b1a8f676e452d6240767699719cd58b0261c822472c25df146938bca5ffffffff01d0359041000000001976a91400178fa0b6fc253a3a402ee2cadd8a7bfec08f6388acb8302a5d000000000000000000000000000000" == "0400008085202f89011d0f8e0c6ba2dcf8be8e5f9024771dceb4c8e4120fab8c072b8eec26b1c50728000000006a4730440220158c970ca2fc6bcc33026eb5366f0342f63b35d178f7efb334b1df78fe90b67202207bc4ff69f67cf843b08564a5adc77bf5593e28ab4d5104911824ac13fe885d8f012102a87aef7b1a8f676e452d6240767699719cd58b0261c822472c25df146938bca5ffffffff01d0359041000000001976a91400178fa0b6fc253a3a402ee2cadd8a7bfec08f6388acb8302a5d000000000000000000000000000000"
) )
def test_one_one_rewards_claim(self): def test_one_one_rewards_claim(self, client):
self.setup_mnemonic_allallall()
# prevout: 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1:0 # prevout: 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1:0
# input 1: 10.9997 KMD # input 1: 10.9997 KMD
@ -132,7 +128,7 @@ class TestMsgSigntxKomodo(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
er = [ er = [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -167,7 +163,7 @@ class TestMsgSigntxKomodo(TrezorTest):
), ),
proto.TxRequest(request_type=proto.RequestType.TXFINISHED), proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
] ]
self.client.set_expected_responses(er) client.set_expected_responses(er)
details = proto.SignTx( details = proto.SignTx(
version=4, version=4,
@ -177,7 +173,7 @@ class TestMsgSigntxKomodo(TrezorTest):
lock_time=0x5D2AF1F2, lock_time=0x5D2AF1F2,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Komodo", "Komodo",
[inp1], [inp1],
[out1, out2], [out1, out2],

View File

@ -27,8 +27,7 @@ TX_API = tx_cache("Testnet")
class TestMsgSigntxSegwit(TrezorTest): class TestMsgSigntxSegwit(TrezorTest):
def test_send_p2sh(self): def test_send_p2sh(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -49,8 +48,8 @@ class TestMsgSigntxSegwit(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -87,7 +86,7 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -95,8 +94,7 @@ class TestMsgSigntxSegwit(TrezorTest):
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" == "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
) )
def test_send_p2sh_change(self): def test_send_p2sh_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -117,8 +115,8 @@ class TestMsgSigntxSegwit(TrezorTest):
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS, script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -154,7 +152,7 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -162,9 +160,7 @@ class TestMsgSigntxSegwit(TrezorTest):
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" == "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
) )
def test_testnet_segwit_big_amount(self): def test_testnet_segwit_big_amount(self, client):
self.setup_mnemonic_allallall()
# This test is testing transaction with amount bigger than fits to uint32 # This test is testing transaction with amount bigger than fits to uint32
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
@ -179,8 +175,8 @@ class TestMsgSigntxSegwit(TrezorTest):
amount=2 ** 32 + 1, amount=2 ** 32 + 1,
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -207,16 +203,15 @@ class TestMsgSigntxSegwit(TrezorTest):
proto.TxRequest(request_type=proto.RequestType.TXFINISHED), proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
] ]
) )
_, serialized_tx = btc.sign_tx(self.client, "Testnet", [inp1], [out1]) _, serialized_tx = btc.sign_tx(client, "Testnet", [inp1], [out1])
assert ( assert (
serialized_tx.hex() serialized_tx.hex()
== "01000000000101ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000171600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5cffffffff01010000000100000017a914097c569095163e84475d07aa95a1f736df895b7b8702483045022100cb9d3aa7a8064702e6b61c20c7fb9cb672c69d3786cf5efef8ad6d90136ca7d8022065119ff6c6e6e6960e6508fc5360359bb269bb25ef8d90019decaa0a050cc45a0121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" == "01000000000101ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000171600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5cffffffff01010000000100000017a914097c569095163e84475d07aa95a1f736df895b7b8702483045022100cb9d3aa7a8064702e6b61c20c7fb9cb672c69d3786cf5efef8ad6d90136ca7d8022065119ff6c6e6e6960e6508fc5360359bb269bb25ef8d90019decaa0a050cc45a0121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000"
) )
def test_send_multisig_1(self): def test_send_multisig_1(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("49'/1'/%d'" % i)).node btc.get_public_node(client, parse_path("49'/1'/%d'" % i)).node
for i in range(1, 4) for i in range(1, 4)
] ]
@ -241,8 +236,8 @@ class TestMsgSigntxSegwit(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -270,13 +265,13 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[0] = signatures[0] inp1.multisig.signatures[0] = signatures[0]
# sign with third key # sign with third key
inp1.address_n[2] = H_(3) inp1.address_n[2] = H_(3)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -304,7 +299,7 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -312,11 +307,7 @@ class TestMsgSigntxSegwit(TrezorTest):
== "01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c0100000023220020cf28684ff8a6dda1a7a9704dde113ddfcf236558da5ce35ad3f8477474dbdaf7ffffffff01887d1800000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac040047304402203fc3fbe6cd6250d82ace4a585debc07587c07d2efc8bb56558c91e1f810fe65402206025bd9a4e80960f617b6e5bfdd568e34aa085d093471b7976e6b14c2a2402a7014730440220327abf491a57964d75c67fad204eb782fa74aa4abde40e5ad30fb0b7696102b7022049e31f2302417be0a87e2f818b93a862a7e67d4178b7cbeee680264f0882113f0169522103d54ab3c8b81cb7f8f8088df4c62c105e8acaa2fb53b180f6bc6f922faecf3fdc21036aa47994f3f18f0976d6073ca79997003c3fa29c4f93907998fefc1151b4529b2102a092580f2828272517c402da9461425c5032860ab40180e041fbbb88ea2a520453ae00000000" == "01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c0100000023220020cf28684ff8a6dda1a7a9704dde113ddfcf236558da5ce35ad3f8477474dbdaf7ffffffff01887d1800000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac040047304402203fc3fbe6cd6250d82ace4a585debc07587c07d2efc8bb56558c91e1f810fe65402206025bd9a4e80960f617b6e5bfdd568e34aa085d093471b7976e6b14c2a2402a7014730440220327abf491a57964d75c67fad204eb782fa74aa4abde40e5ad30fb0b7696102b7022049e31f2302417be0a87e2f818b93a862a7e67d4178b7cbeee680264f0882113f0169522103d54ab3c8b81cb7f8f8088df4c62c105e8acaa2fb53b180f6bc6f922faecf3fdc21036aa47994f3f18f0976d6073ca79997003c3fa29c4f93907998fefc1151b4529b2102a092580f2828272517c402da9461425c5032860ab40180e041fbbb88ea2a520453ae00000000"
) )
def test_attack_change_input_address(self): def test_attack_change_input_address(self, client):
# This unit test attempts to modify input address after the Trezor checked
# that it matches the change output
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -339,8 +330,8 @@ class TestMsgSigntxSegwit(TrezorTest):
) )
# Test if the transaction can be signed normally # Test if the transaction can be signed normally
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -377,7 +368,7 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -397,9 +388,9 @@ class TestMsgSigntxSegwit(TrezorTest):
return msg return msg
# Now run the attack, must trigger the exception # Now run the attack, must trigger the exception
self.client.set_filter(proto.TxAck, attack_processor) client.set_filter(proto.TxAck, attack_processor)
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -423,9 +414,7 @@ class TestMsgSigntxSegwit(TrezorTest):
] ]
) )
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx( btc.sign_tx(client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API)
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
)
assert exc.value.args[0] == proto.FailureType.ProcessError assert exc.value.args[0] == proto.FailureType.ProcessError
if TREZOR_VERSION == 1: if TREZOR_VERSION == 1:
assert exc.value.args[1].endswith("Failed to compile input") assert exc.value.args[1].endswith("Failed to compile input")

View File

@ -14,6 +14,7 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc, messages as proto from trezorlib import btc, messages as proto
from trezorlib.ckd_public import deserialize from trezorlib.ckd_public import deserialize
from trezorlib.tools import H_, parse_path from trezorlib.tools import H_, parse_path
@ -25,8 +26,7 @@ TX_API = tx_cache("Testnet")
class TestMsgSigntxSegwitNative(TrezorTest): class TestMsgSigntxSegwitNative(TrezorTest):
def test_send_p2sh(self): def test_send_p2sh(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -47,8 +47,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -85,7 +85,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -93,8 +93,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100bd3d8b8ad35c094e01f6282277300e575f1021678fc63ec3f9945d6e35670da3022052e26ef0dd5f3741c9d5939d1dec5464c15ab5f2c85245e70a622df250d4eb7c012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" == "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100bd3d8b8ad35c094e01f6282277300e575f1021678fc63ec3f9945d6e35670da3022052e26ef0dd5f3741c9d5939d1dec5464c15ab5f2c85245e70a622df250d4eb7c012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
) )
def test_send_p2sh_change(self): def test_send_p2sh_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -115,8 +114,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS, script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -152,7 +151,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -160,8 +159,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100bd3d8b8ad35c094e01f6282277300e575f1021678fc63ec3f9945d6e35670da3022052e26ef0dd5f3741c9d5939d1dec5464c15ab5f2c85245e70a622df250d4eb7c012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" == "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100bd3d8b8ad35c094e01f6282277300e575f1021678fc63ec3f9945d6e35670da3022052e26ef0dd5f3741c9d5939d1dec5464c15ab5f2c85245e70a622df250d4eb7c012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
) )
def test_send_native(self): def test_send_native(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"), address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000, amount=12300000,
@ -181,8 +179,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -219,7 +217,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -227,8 +225,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f502473044022073ce72dcf2f6e42eeb44adbe7d5038cf3763f168d1c04bd8b873a19b53331f51022016b051725731e7f53a567021bcd9c370727f551c81e857ebae7c128472119652012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f86200000000" == "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f502473044022073ce72dcf2f6e42eeb44adbe7d5038cf3763f168d1c04bd8b873a19b53331f51022016b051725731e7f53a567021bcd9c370727f551c81e857ebae7c128472119652012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f86200000000"
) )
def test_send_native_change(self): def test_send_native_change(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"), address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000, amount=12300000,
@ -248,8 +245,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOWITNESS, script_type=proto.OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -285,7 +282,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -293,8 +290,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b024730440220067675423ca6a0be3ddd5e13da00a9433775041e5cebc838873d2686f1d2840102201a5819e0312e6451d6b6180689101bce995685a51524cc4c3a5383f7bdab979a012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f86200000000" == "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b024730440220067675423ca6a0be3ddd5e13da00a9433775041e5cebc838873d2686f1d2840102201a5819e0312e6451d6b6180689101bce995685a51524cc4c3a5383f7bdab979a012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f86200000000"
) )
def test_send_both(self): def test_send_both(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"), address_n=parse_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
@ -332,8 +328,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -391,11 +387,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client, "Testnet", [inp1, inp2], [out1, out2, out3], prev_txes=TX_API
"Testnet",
[inp1, inp2],
[out1, out2, out3],
prev_txes=TX_API,
) )
assert ( assert (
@ -403,10 +395,9 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "010000000001028a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090100000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff7b010c5faeb41cc5c253121b6bf69bf1a7c5867cd7f2d91569fea0ecd311b8650100000000ffffffff03e0aebb0000000000160014a579388225827d9f2fe9014add644487808c695d00cdb7020000000017a91491233e24a9bf8dbb19c1187ad876a9380c12e787870d859b03000000001976a914a579388225827d9f2fe9014add644487808c695d88ac02483045022100ead79ee134f25bb585b48aee6284a4bb14e07f03cc130253e83450d095515e5202201e161e9402c8b26b666f2b67e5b668a404ef7e57858ae9a6a68c3837e65fdc69012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7902463043021f585c54a84dc7326fa60e22729accd41153c7dd4725bd4c8f751aa3a8cd8d6a0220631bfd83fc312cc6d5d129572a25178696d81eaf50c8c3f16c6121be4f4c029d012103505647c017ff2156eb6da20fae72173d3b681a1d0a629f95f49e884db300689f00000000" == "010000000001028a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090100000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff7b010c5faeb41cc5c253121b6bf69bf1a7c5867cd7f2d91569fea0ecd311b8650100000000ffffffff03e0aebb0000000000160014a579388225827d9f2fe9014add644487808c695d00cdb7020000000017a91491233e24a9bf8dbb19c1187ad876a9380c12e787870d859b03000000001976a914a579388225827d9f2fe9014add644487808c695d88ac02483045022100ead79ee134f25bb585b48aee6284a4bb14e07f03cc130253e83450d095515e5202201e161e9402c8b26b666f2b67e5b668a404ef7e57858ae9a6a68c3837e65fdc69012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7902463043021f585c54a84dc7326fa60e22729accd41153c7dd4725bd4c8f751aa3a8cd8d6a0220631bfd83fc312cc6d5d129572a25178696d81eaf50c8c3f16c6121be4f4c029d012103505647c017ff2156eb6da20fae72173d3b681a1d0a629f95f49e884db300689f00000000"
) )
def test_send_multisig_1(self): def test_send_multisig_1(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("49'/1'/%d'" % index)) btc.get_public_node(client, parse_path("49'/1'/%d'" % index))
for index in range(1, 4) for index in range(1, 4)
] ]
multisig = proto.MultisigRedeemScriptType( multisig = proto.MultisigRedeemScriptType(
@ -433,8 +424,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -462,13 +453,13 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[0] = signatures[0] inp1.multisig.signatures[0] = signatures[0]
# sign with third key # sign with third key
inp1.address_n[2] = H_(3) inp1.address_n[2] = H_(3)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -496,7 +487,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -504,10 +495,9 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c01000000232200208d398cfb58a1d9cdb59ccbce81559c095e8c6f4a3e64966ca385078d9879f95effffffff01887d180000000000220020c5f4a0a4ea7c0392efe0a9670a73264cffa90b19107cd8a8e9750ff93c77fdfb0400483045022100dd6342c65197af27d7894d8b8b88b16b568ee3b5ebfdc55fdfb7caa9650e3b4c02200c7074a5bcb0068f63d9014c7cd2b0490aba75822d315d41aad444e9b86adf5201483045022100e7e6c2d21109512ba0609e93903e84bfb7731ac3962ee2c1cad54a7a30ff99a20220421497930226c39fc3834e8d6da3fc876516239518b0e82e2dc1e3c46271a17c01695221021630971f20fa349ba940a6ba3706884c41579cd760c89901374358db5dd545b92102f2ff4b353702d2bb03d4c494be19d77d0ab53d16161b53fbcaf1afeef4ad0cb52103e9b6b1c691a12ce448f1aedbbd588e064869c79fbd760eae3b8cd8a5f1a224db53ae00000000" == "01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c01000000232200208d398cfb58a1d9cdb59ccbce81559c095e8c6f4a3e64966ca385078d9879f95effffffff01887d180000000000220020c5f4a0a4ea7c0392efe0a9670a73264cffa90b19107cd8a8e9750ff93c77fdfb0400483045022100dd6342c65197af27d7894d8b8b88b16b568ee3b5ebfdc55fdfb7caa9650e3b4c02200c7074a5bcb0068f63d9014c7cd2b0490aba75822d315d41aad444e9b86adf5201483045022100e7e6c2d21109512ba0609e93903e84bfb7731ac3962ee2c1cad54a7a30ff99a20220421497930226c39fc3834e8d6da3fc876516239518b0e82e2dc1e3c46271a17c01695221021630971f20fa349ba940a6ba3706884c41579cd760c89901374358db5dd545b92102f2ff4b353702d2bb03d4c494be19d77d0ab53d16161b53fbcaf1afeef4ad0cb52103e9b6b1c691a12ce448f1aedbbd588e064869c79fbd760eae3b8cd8a5f1a224db53ae00000000"
) )
def test_send_multisig_2(self): def test_send_multisig_2(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("84'/1'/%d'" % index)) btc.get_public_node(client, parse_path("84'/1'/%d'" % index))
for index in range(1, 4) for index in range(1, 4)
] ]
multisig = proto.MultisigRedeemScriptType( multisig = proto.MultisigRedeemScriptType(
@ -534,8 +524,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -563,13 +553,13 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[1] = signatures[0] inp1.multisig.signatures[1] = signatures[0]
# sign with first key # sign with first key
inp1.address_n[2] = H_(1) inp1.address_n[2] = H_(1)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -597,7 +587,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -605,10 +595,9 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "010000000001012812fe3916f228cda6c7b57d5464541265a63ad118f430a805eeec8bddbe1cf40000000000ffffffff01a0791800000000002200201e8dda334f11171190b3da72e526d441491464769679a319a2f011da5ad312a10400473044022001b7f4f21a8ddcd5e0faaaee3b95515bf8b84f2a7cbfdf66996c64123617a5cf02202fc6a776a7225420dbca759ad4ac83a61d15bf8d2883b6bf1aa31de7437f9b6e0147304402206c4125c1189a3b3e93a77cdf54c60c0538b80e5a03ec74e6ac776dfa77706ee4022035be14de76259b9d8a24863131a06a65b95df02f7d3ace90d52b37e8d94b167f0169522103bab8ecdd9ae2c51a0dc858f4c751b27533143bf6013ba1725ba8a4ecebe7de8c21027d5e55696c875308b03f2ca3d8637f51d3e35da9456a5187aa14b3de8a89534f2103b78eabaea8b3a4868be4f4bb96d6f66973f7081faa7f1cafba321444611c241e53ae00000000" == "010000000001012812fe3916f228cda6c7b57d5464541265a63ad118f430a805eeec8bddbe1cf40000000000ffffffff01a0791800000000002200201e8dda334f11171190b3da72e526d441491464769679a319a2f011da5ad312a10400473044022001b7f4f21a8ddcd5e0faaaee3b95515bf8b84f2a7cbfdf66996c64123617a5cf02202fc6a776a7225420dbca759ad4ac83a61d15bf8d2883b6bf1aa31de7437f9b6e0147304402206c4125c1189a3b3e93a77cdf54c60c0538b80e5a03ec74e6ac776dfa77706ee4022035be14de76259b9d8a24863131a06a65b95df02f7d3ace90d52b37e8d94b167f0169522103bab8ecdd9ae2c51a0dc858f4c751b27533143bf6013ba1725ba8a4ecebe7de8c21027d5e55696c875308b03f2ca3d8637f51d3e35da9456a5187aa14b3de8a89534f2103b78eabaea8b3a4868be4f4bb96d6f66973f7081faa7f1cafba321444611c241e53ae00000000"
) )
def test_send_multisig_3_change(self): def test_send_multisig_3_change(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("84'/1'/%d'" % index)) btc.get_public_node(client, parse_path("84'/1'/%d'" % index))
for index in range(1, 4) for index in range(1, 4)
] ]
multisig = proto.MultisigRedeemScriptType( multisig = proto.MultisigRedeemScriptType(
@ -642,8 +631,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS, script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -670,14 +659,14 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[0] = signatures[0] inp1.multisig.signatures[0] = signatures[0]
# sign with third key # sign with third key
inp1.address_n[2] = H_(3) inp1.address_n[2] = H_(3)
out1.address_n[2] = H_(3) out1.address_n[2] = H_(3)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -704,7 +693,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -712,10 +701,9 @@ class TestMsgSigntxSegwitNative(TrezorTest):
== "01000000000101fc7901dd033f8c02da14f3ac916b6498036b80b4a0b4dc124e02c2bb408034c90000000000ffffffff01b87518000000000017a914536250d41937e5b641082447580ff6a8e46c122a870400473044022003c26107a5a47f1f900ef8aa758977530cd13ea37a33971abae8d75cac2f9f34022039e2b8c2c1d0c24ff4fc026652e1f27ad8e3ed6c9bf485f61d9aa691cb57830801483045022100963b0dc0ab46e963a66ab6e69e5e41bac6c4fedc127cac12c560b029d54fe87402205b3bcdcf313dccd78e5dce0540e7d3c8cc1bf83f13c1f9f01811eb791fd35c8101695221039dba3a72f5dc3cad17aa924b5a03c34561465f997d0cb15993f2ca2c0be771c42103cd39f3f08bbd508dce4d307d57d0c70c258c285878bfda579fa260acc738c25d2102cd631ba95beca1d64766f5540885092d0bb384a3c13b6c3a5334d0ebacf51b9553ae00000000" == "01000000000101fc7901dd033f8c02da14f3ac916b6498036b80b4a0b4dc124e02c2bb408034c90000000000ffffffff01b87518000000000017a914536250d41937e5b641082447580ff6a8e46c122a870400473044022003c26107a5a47f1f900ef8aa758977530cd13ea37a33971abae8d75cac2f9f34022039e2b8c2c1d0c24ff4fc026652e1f27ad8e3ed6c9bf485f61d9aa691cb57830801483045022100963b0dc0ab46e963a66ab6e69e5e41bac6c4fedc127cac12c560b029d54fe87402205b3bcdcf313dccd78e5dce0540e7d3c8cc1bf83f13c1f9f01811eb791fd35c8101695221039dba3a72f5dc3cad17aa924b5a03c34561465f997d0cb15993f2ca2c0be771c42103cd39f3f08bbd508dce4d307d57d0c70c258c285878bfda579fa260acc738c25d2102cd631ba95beca1d64766f5540885092d0bb384a3c13b6c3a5334d0ebacf51b9553ae00000000"
) )
def test_send_multisig_4_change(self): def test_send_multisig_4_change(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("49'/1'/%d'" % index)) btc.get_public_node(client, parse_path("49'/1'/%d'" % index))
for index in range(1, 4) for index in range(1, 4)
] ]
multisig = proto.MultisigRedeemScriptType( multisig = proto.MultisigRedeemScriptType(
@ -749,8 +737,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
script_type=proto.OutputScriptType.PAYTOWITNESS, script_type=proto.OutputScriptType.PAYTOWITNESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -777,14 +765,14 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
signatures, _ = btc.sign_tx( signatures, _ = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
# store signature # store signature
inp1.multisig.signatures[0] = signatures[0] inp1.multisig.signatures[0] = signatures[0]
# sign with third key # sign with third key
inp1.address_n[2] = H_(3) inp1.address_n[2] = H_(3)
out1.address_n[2] = H_(3) out1.address_n[2] = H_(3)
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -811,7 +799,7 @@ class TestMsgSigntxSegwitNative(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API client, "Testnet", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (

View File

@ -35,9 +35,7 @@ TXHASH_e38206 = bytes.fromhex(
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.zcash @pytest.mark.zcash
class TestMsgSigntxZcash(TrezorTest): class TestMsgSigntxZcash(TrezorTest):
def test_one_one_fee_overwinter(self): def test_one_one_fee_overwinter(self, client):
self.setup_mnemonic_allallall()
# prevout: aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc:1 # prevout: aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc:1
# input 1: 3.0 TAZ # input 1: 3.0 TAZ
@ -56,8 +54,8 @@ class TestMsgSigntxZcash(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -88,7 +86,7 @@ class TestMsgSigntxZcash(TrezorTest):
branch_id=0x5BA81B19, branch_id=0x5BA81B19,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Zcash Testnet", "Zcash Testnet",
[inp1], [inp1],
[out1], [out1],
@ -102,9 +100,7 @@ class TestMsgSigntxZcash(TrezorTest):
== "030000807082c40301dc754d63eff4698ee321476872519c53f14cfe58c9425c7ee464c206461ef5aa010000006a47304402207e45f303b4e42be824513855eb21653e1d2749cd94dcd0f0613d3f85d4efd1e20220699ffbdbcad889af7ede5ce9febf7a5ef8f5619b2464824529974c400cffaebc0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff016c9be111000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac000000000000000000" == "030000807082c40301dc754d63eff4698ee321476872519c53f14cfe58c9425c7ee464c206461ef5aa010000006a47304402207e45f303b4e42be824513855eb21653e1d2749cd94dcd0f0613d3f85d4efd1e20220699ffbdbcad889af7ede5ce9febf7a5ef8f5619b2464824529974c400cffaebc0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff016c9be111000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac000000000000000000"
) )
def test_one_one_fee_sapling(self): def test_one_one_fee_sapling(self, client):
self.setup_mnemonic_allallall()
# prevout: e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368:0 # prevout: e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368:0
# input 1: 3.0 TAZ # input 1: 3.0 TAZ
@ -123,8 +119,8 @@ class TestMsgSigntxZcash(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -155,7 +151,7 @@ class TestMsgSigntxZcash(TrezorTest):
branch_id=0x76B809BB, branch_id=0x76B809BB,
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Zcash Testnet", "Zcash Testnet",
[inp1], [inp1],
[out1], [out1],

View File

@ -16,50 +16,37 @@
import pytest import pytest
from trezorlib import debuglink, messages as proto, stellar from trezorlib import messages as proto, stellar
from trezorlib.tools import CallException, parse_path from trezorlib.tools import CallException, parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .conftest import TREZOR_VERSION from .conftest import TREZOR_VERSION
@pytest.mark.altcoin @pytest.mark.altcoin
@pytest.mark.stellar @pytest.mark.stellar
class TestMsgStellarGetAddress(TrezorTest): class TestMsgStellarGetAddress(TrezorTest):
def test_stellar_get_address(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_stellar_get_address(self, client):
address = stellar.get_address(client, parse_path(stellar.DEFAULT_BIP32_PATH))
address = stellar.get_address(
self.client, parse_path(stellar.DEFAULT_BIP32_PATH)
)
assert address == "GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW" assert address == "GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW"
def test_stellar_get_address_sep(self): @pytest.mark.setup_client(
mnemonic="illness spike retreat truth genius clock brain pass fit cave bargain toe"
)
def test_stellar_get_address_sep(self, client):
# data from https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md # data from https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
debuglink.load_device_by_mnemonic( address = stellar.get_address(client, parse_path(stellar.DEFAULT_BIP32_PATH))
self.client,
mnemonic="illness spike retreat truth genius clock brain pass fit cave bargain toe",
pin="",
passphrase_protection=False,
label="test",
language="english",
)
address = stellar.get_address(
self.client, parse_path(stellar.DEFAULT_BIP32_PATH)
)
assert address == "GDRXE2BQUC3AZNPVFSCEZ76NJ3WWL25FYFK6RGZGIEKWE4SOOHSUJUJ6" assert address == "GDRXE2BQUC3AZNPVFSCEZ76NJ3WWL25FYFK6RGZGIEKWE4SOOHSUJUJ6"
address = stellar.get_address( address = stellar.get_address(
self.client, parse_path("m/44h/148h/1h"), show_display=True client, parse_path("m/44h/148h/1h"), show_display=True
) )
assert address == "GBAW5XGWORWVFE2XTJYDTLDHXTY2Q2MO73HYCGB3XMFMQ562Q2W2GJQX" assert address == "GBAW5XGWORWVFE2XTJYDTLDHXTY2Q2MO73HYCGB3XMFMQ562Q2W2GJQX"
def test_stellar_get_address_fail(self): def test_stellar_get_address_fail(self, client):
self.setup_mnemonic_nopin_nopassphrase()
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
stellar.get_address(self.client, parse_path("m/0/1")) stellar.get_address(client, parse_path("m/0/1"))
if TREZOR_VERSION == 1: if TREZOR_VERSION == 1:
assert exc.value.args[0] == proto.FailureType.ProcessError assert exc.value.args[0] == proto.FailureType.ProcessError

View File

@ -53,7 +53,7 @@ import pytest
from trezorlib import messages as proto, stellar from trezorlib import messages as proto, stellar
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
@pytest.mark.altcoin @pytest.mark.altcoin
@ -63,24 +63,22 @@ class TestMsgStellarSignTransaction(TrezorTest):
ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH) ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH)
NETWORK_PASSPHRASE = "Test SDF Network ; September 2015" NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
def test_sign_tx_bump_sequence_op(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_tx_bump_sequence_op(self, client):
op = proto.StellarBumpSequenceOp() op = proto.StellarBumpSequenceOp()
op.bump_to = 0x7FFFFFFFFFFFFFFF op.bump_to = 0x7FFFFFFFFFFFFFFF
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
b64encode(response.signature) b64encode(response.signature)
== b"ZMIfHWhpyXdg40PzwOtkcXYnbZIO12Qy0WvkGqoYpb7jyWbG2HQCG7dgWhCoU5K81pvZTA2pMwiPjMwCXA//Bg==" == b"ZMIfHWhpyXdg40PzwOtkcXYnbZIO12Qy0WvkGqoYpb7jyWbG2HQCG7dgWhCoU5K81pvZTA2pMwiPjMwCXA//Bg=="
) )
def test_sign_tx_account_merge_op(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_sign_tx_account_merge_op(self, client):
op = proto.StellarAccountMergeOp() op = proto.StellarAccountMergeOp()
op.destination_account = ( op.destination_account = (
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V" "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
@ -89,7 +87,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -101,9 +99,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"2R3Pj89U+dWrqy7otUrLLjtANjAg0lmBQL8E+89Po0Y94oqZkauP8j3WE7+/z7vF6XvAMLoOdqRYkUzr2oh7Dg==" == b"2R3Pj89U+dWrqy7otUrLLjtANjAg0lmBQL8E+89Po0Y94oqZkauP8j3WE7+/z7vF6XvAMLoOdqRYkUzr2oh7Dg=="
) )
def test_sign_tx_create_account_op(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_create_account_op(self, client):
"""Create new account with initial balance of 100.0333""" """Create new account with initial balance of 100.0333"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarCreateAccountOp() op = proto.StellarCreateAccountOp()
op.new_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V" op.new_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
@ -112,7 +110,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -120,9 +118,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"vrRYqkM4b54NrDR05UrW7ZHU7CNcidV0fn+bk9dqOW1bCbmX3YfeRbk2Tf1aea8nr9SD0sfBhtrDpdyxUenjBw==" == b"vrRYqkM4b54NrDR05UrW7ZHU7CNcidV0fn+bk9dqOW1bCbmX3YfeRbk2Tf1aea8nr9SD0sfBhtrDpdyxUenjBw=="
) )
def test_sign_tx_payment_op_native(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_payment_op_native(self, client):
"""Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V""" """Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarPaymentOp() op = proto.StellarPaymentOp()
op.amount = 500111000 op.amount = 500111000
@ -133,7 +131,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -141,9 +139,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg==" == b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg=="
) )
def test_sign_tx_payment_op_native_explicit_asset(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_payment_op_native_explicit_asset(self, client):
"""Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V""" """Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarPaymentOp() op = proto.StellarPaymentOp()
op.amount = 500111000 op.amount = 500111000
@ -155,7 +153,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -163,9 +161,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg==" == b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg=="
) )
def test_sign_tx_payment_op_custom_asset1(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_payment_op_custom_asset1(self, client):
"""Custom asset payment (code length 1) of 50.0111 X to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V""" """Custom asset payment (code length 1) of 50.0111 X to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarPaymentOp() op = proto.StellarPaymentOp()
op.amount = 500111000 op.amount = 500111000
@ -179,7 +177,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -187,9 +185,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"ArZydOtXU2whoRuSjJLFIWPSIsq3AbsncJZ+THF24CRSriVWw5Fy/dHrDlUOu4fzU28I6osDMeI39aWezg5tDw==" == b"ArZydOtXU2whoRuSjJLFIWPSIsq3AbsncJZ+THF24CRSriVWw5Fy/dHrDlUOu4fzU28I6osDMeI39aWezg5tDw=="
) )
def test_sign_tx_payment_op_custom_asset12(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_payment_op_custom_asset12(self, client):
"""Custom asset payment (code length 12) of 50.0111 ABCDEFGHIJKL to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V""" """Custom asset payment (code length 12) of 50.0111 ABCDEFGHIJKL to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarPaymentOp() op = proto.StellarPaymentOp()
op.amount = 500111000 op.amount = 500111000
@ -205,7 +203,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -213,9 +211,9 @@ class TestMsgStellarSignTransaction(TrezorTest):
== b"QZIP4XKPfe4OpZtuJiyrMZBX9YBzvGpHGcngdgFfHn2kcdONreF384/pCF80xfEnGm8grKaoOnUEKxqcMKvxAA==" == b"QZIP4XKPfe4OpZtuJiyrMZBX9YBzvGpHGcngdgFfHn2kcdONreF384/pCF80xfEnGm8grKaoOnUEKxqcMKvxAA=="
) )
def test_sign_tx_set_options(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign_tx_set_options(self, client):
"""Set inflation destination""" """Set inflation destination"""
self.setup_mnemonic_nopin_nopassphrase()
op = proto.StellarSetOptionsOp() op = proto.StellarSetOptionsOp()
op.inflation_destination_account = ( op.inflation_destination_account = (
@ -224,7 +222,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
@ -241,7 +239,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
b64encode(response.signature) b64encode(response.signature)
@ -253,7 +251,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
b64encode(response.signature) b64encode(response.signature)
@ -267,7 +265,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
b64encode(response.signature) b64encode(response.signature)
@ -281,7 +279,7 @@ class TestMsgStellarSignTransaction(TrezorTest):
tx = self._create_msg() tx = self._create_msg()
response = stellar.sign_tx( response = stellar.sign_tx(
self.client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
) )
assert ( assert (
b64encode(response.signature) b64encode(response.signature)

View File

@ -26,13 +26,11 @@ from .common import TrezorTest
@pytest.mark.tezos @pytest.mark.tezos
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgTezosGetAddress(TrezorTest): class TestMsgTezosGetAddress(TrezorTest):
def test_tezos_get_address(self): def test_tezos_get_address(self, client):
self.setup_mnemonic_allallall()
path = parse_path("m/44'/1729'/0'") path = parse_path("m/44'/1729'/0'")
address = get_address(self.client, path, show_display=True) address = get_address(client, path, show_display=True)
assert address == "tz1Kef7BSg6fo75jk37WkKRYSnJDs69KVqt9" assert address == "tz1Kef7BSg6fo75jk37WkKRYSnJDs69KVqt9"
path = parse_path("m/44'/1729'/1'") path = parse_path("m/44'/1729'/1'")
address = get_address(self.client, path, show_display=True) address = get_address(client, path, show_display=True)
assert address == "tz1ekQapZCX4AXxTJhJZhroDKDYLHDHegvm1" assert address == "tz1ekQapZCX4AXxTJhJZhroDKDYLHDHegvm1"

View File

@ -26,13 +26,11 @@ from .common import TrezorTest
@pytest.mark.tezos @pytest.mark.tezos
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgTezosGetPublicKey(TrezorTest): class TestMsgTezosGetPublicKey(TrezorTest):
def test_tezos_get_public_key(self): def test_tezos_get_public_key(self, client):
self.setup_mnemonic_allallall()
path = parse_path("m/44'/1729'/0'") path = parse_path("m/44'/1729'/0'")
pk = get_public_key(self.client, path) pk = get_public_key(client, path)
assert pk == "edpkttLhEbVfMC3DhyVVFzdwh8ncRnEWiLD1x8TAuPU7vSJak7RtBX" assert pk == "edpkttLhEbVfMC3DhyVVFzdwh8ncRnEWiLD1x8TAuPU7vSJak7RtBX"
path = parse_path("m/44'/1729'/1'") path = parse_path("m/44'/1729'/1'")
pk = get_public_key(self.client, path) pk = get_public_key(client, path)
assert pk == "edpkuTPqWjcApwyD3VdJhviKM5C13zGk8c4m87crgFarQboF3Mp56f" assert pk == "edpkuTPqWjcApwyD3VdJhviKM5C13zGk8c4m87crgFarQboF3Mp56f"

View File

@ -31,11 +31,9 @@ TEZOS_PATH_10 = parse_path("m/44'/1729'/10'")
@pytest.mark.tezos @pytest.mark.tezos
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgTezosSignTx(TrezorTest): class TestMsgTezosSignTx(TrezorTest):
def test_tezos_sign_tx_transaction(self): def test_tezos_sign_tx_transaction(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH, TEZOS_PATH,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -71,11 +69,9 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "opNeGBdgbM5jN2ykz4o8NdsCuJfqNZ6WBEFVbBUmYH8gp45CJvH" resp.operation_hash == "opNeGBdgbM5jN2ykz4o8NdsCuJfqNZ6WBEFVbBUmYH8gp45CJvH"
) )
def test_tezos_sign_reveal_transaction(self): def test_tezos_sign_reveal_transaction(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH, TEZOS_PATH,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -122,11 +118,9 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "opQHu93L8juNm2VjmsMKioFowWNyMvGzopcuoVcuzFV1bJMhJef" resp.operation_hash == "opQHu93L8juNm2VjmsMKioFowWNyMvGzopcuoVcuzFV1bJMhJef"
) )
def test_tezos_sign_tx_origination(self): def test_tezos_sign_tx_origination(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH, TEZOS_PATH,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -162,11 +156,9 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "onuKkBtP4K2JMGg7YMv7qs869B8aHCEUQecvuiL71aKkY8iPCb6" resp.operation_hash == "onuKkBtP4K2JMGg7YMv7qs869B8aHCEUQecvuiL71aKkY8iPCb6"
) )
def test_tezos_sign_tx_delegation(self): def test_tezos_sign_tx_delegation(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH, TEZOS_PATH,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -198,18 +190,16 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "oocgc3hyKsGHPsw6WFWJpWT8jBwQLtebQAXF27KNisThkzoj635" resp.operation_hash == "oocgc3hyKsGHPsw6WFWJpWT8jBwQLtebQAXF27KNisThkzoj635"
) )
def input_flow(self, num_pages): def input_flow(self, debug, num_pages):
yield yield
for _ in range(num_pages - 1): for _ in range(num_pages - 1):
self.client.debug.swipe_down() debug.swipe_down()
self.client.debug.press_yes() debug.press_yes()
def test_tezos_sign_tx_proposal(self): def test_tezos_sign_tx_proposal(self, client):
self.setup_mnemonic_allallall() client.set_input_flow(self.input_flow(client.debug, num_pages=1))
self.client.set_input_flow(self.input_flow(num_pages=1))
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH_10, TEZOS_PATH_10,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -237,12 +227,10 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "opLqntFUu984M7LnGsFvfGW6kWe9QjAz4AfPDqQvwJ1wPM4Si4c" resp.operation_hash == "opLqntFUu984M7LnGsFvfGW6kWe9QjAz4AfPDqQvwJ1wPM4Si4c"
) )
def test_tezos_sign_tx_multiple_proposals(self): def test_tezos_sign_tx_multiple_proposals(self, client):
self.setup_mnemonic_allallall() client.set_input_flow(self.input_flow(client.debug, num_pages=2))
self.client.set_input_flow(self.input_flow(num_pages=2))
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH_10, TEZOS_PATH_10,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -271,11 +259,9 @@ class TestMsgTezosSignTx(TrezorTest):
resp.operation_hash == "onobSyNgiitGXxSVFJN6949MhUomkkxvH4ZJ2owgWwNeDdntF9Y" resp.operation_hash == "onobSyNgiitGXxSVFJN6949MhUomkkxvH4ZJ2owgWwNeDdntF9Y"
) )
def test_tezos_sing_tx_ballot_yay(self): def test_tezos_sing_tx_ballot_yay(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH_10, TEZOS_PATH_10,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -296,11 +282,9 @@ class TestMsgTezosSignTx(TrezorTest):
== "edsigtkxNm6YXwtV24DqeuimeZFTeFCn2jDYheSsXT4rHMcEjNvzsiSo55nVyVsQxtEe8M7U4PWJWT4rGYYGckQCgtkNJkd2roX" == "edsigtkxNm6YXwtV24DqeuimeZFTeFCn2jDYheSsXT4rHMcEjNvzsiSo55nVyVsQxtEe8M7U4PWJWT4rGYYGckQCgtkNJkd2roX"
) )
def test_tezos_sing_tx_ballot_nay(self): def test_tezos_sing_tx_ballot_nay(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH_10, TEZOS_PATH_10,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,
@ -320,11 +304,9 @@ class TestMsgTezosSignTx(TrezorTest):
== "edsigtqLaizfF6Cfc2JQL7TrsyniGhpZEojZAKMFW6AeudaUoU8KGXEHJH69Q4Lf27qFyUSTfbeHNnnCt69SGEPWkmpkgkgqMbL" == "edsigtqLaizfF6Cfc2JQL7TrsyniGhpZEojZAKMFW6AeudaUoU8KGXEHJH69Q4Lf27qFyUSTfbeHNnnCt69SGEPWkmpkgkgqMbL"
) )
def test_tezos_sing_tx_ballot_pass(self): def test_tezos_sing_tx_ballot_pass(self, client):
self.setup_mnemonic_allallall()
resp = tezos.sign_tx( resp = tezos.sign_tx(
self.client, client,
TEZOS_PATH_10, TEZOS_PATH_10,
dict_to_proto( dict_to_proto(
messages.TezosSignTx, messages.TezosSignTx,

View File

@ -24,10 +24,9 @@ from .common import TrezorTest
class TestMsgVerifymessage(TrezorTest): class TestMsgVerifymessage(TrezorTest):
def test_message_long(self): def test_message_long(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -37,10 +36,9 @@ class TestMsgVerifymessage(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_testnet(self): def test_message_testnet(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Testnet", "Testnet",
"mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL", "mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL",
bytes.fromhex( bytes.fromhex(
@ -51,10 +49,9 @@ class TestMsgVerifymessage(TrezorTest):
assert ret is True assert ret is True
@pytest.mark.altcoin @pytest.mark.altcoin
def test_message_grs(self): def test_message_grs(self, client):
self.setup_mnemonic_allallall()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Groestlcoin", "Groestlcoin",
"Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM", "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM",
base64.b64decode( base64.b64decode(
@ -64,12 +61,9 @@ class TestMsgVerifymessage(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_verify(self): def test_message_verify(self, client):
self.setup_mnemonic_nopin_nopassphrase()
# uncompressed pubkey - OK
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T", "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T",
bytes.fromhex( bytes.fromhex(
@ -81,7 +75,7 @@ class TestMsgVerifymessage(TrezorTest):
# uncompressed pubkey - FAIL - wrong sig # uncompressed pubkey - FAIL - wrong sig
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T", "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T",
bytes.fromhex( bytes.fromhex(
@ -93,7 +87,7 @@ class TestMsgVerifymessage(TrezorTest):
# uncompressed pubkey - FAIL - wrong msg # uncompressed pubkey - FAIL - wrong msg
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T", "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T",
bytes.fromhex( bytes.fromhex(
@ -105,7 +99,7 @@ class TestMsgVerifymessage(TrezorTest):
# compressed pubkey - OK # compressed pubkey - OK
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8", "1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8",
bytes.fromhex( bytes.fromhex(
@ -117,7 +111,7 @@ class TestMsgVerifymessage(TrezorTest):
# compressed pubkey - FAIL - wrong sig # compressed pubkey - FAIL - wrong sig
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8", "1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8",
bytes.fromhex( bytes.fromhex(
@ -129,7 +123,7 @@ class TestMsgVerifymessage(TrezorTest):
# compressed pubkey - FAIL - wrong msg # compressed pubkey - FAIL - wrong msg
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8", "1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8",
bytes.fromhex( bytes.fromhex(
@ -141,7 +135,7 @@ class TestMsgVerifymessage(TrezorTest):
# trezor pubkey - OK # trezor pubkey - OK
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -153,7 +147,7 @@ class TestMsgVerifymessage(TrezorTest):
# trezor pubkey - FAIL - wrong sig # trezor pubkey - FAIL - wrong sig
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -165,7 +159,7 @@ class TestMsgVerifymessage(TrezorTest):
# trezor pubkey - FAIL - wrong msg # trezor pubkey - FAIL - wrong msg
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -176,10 +170,9 @@ class TestMsgVerifymessage(TrezorTest):
assert res is False assert res is False
@pytest.mark.altcoin @pytest.mark.altcoin
def test_message_verify_bcash(self): def test_message_verify_bcash(self, client):
self.setup_mnemonic_nopin_nopassphrase()
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bcash", "Bcash",
"bitcoincash:qqj22md58nm09vpwsw82fyletkxkq36zxyxh322pru", "bitcoincash:qqj22md58nm09vpwsw82fyletkxkq36zxyxh322pru",
bytes.fromhex( bytes.fromhex(
@ -189,11 +182,9 @@ class TestMsgVerifymessage(TrezorTest):
) )
assert res is True assert res is True
def test_verify_bitcoind(self): def test_verify_bitcoind(self, client):
self.setup_mnemonic_nopin_nopassphrase()
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"1KzXE97kV7DrpxCViCN3HbGbiKhzzPM7TQ", "1KzXE97kV7DrpxCViCN3HbGbiKhzzPM7TQ",
bytes.fromhex( bytes.fromhex(
@ -204,14 +195,12 @@ class TestMsgVerifymessage(TrezorTest):
assert res is True assert res is True
def test_verify_utf(self): def test_verify_utf(self, client):
self.setup_mnemonic_nopin_nopassphrase()
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
res_nfkd = btc.verify_message( res_nfkd = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -221,7 +210,7 @@ class TestMsgVerifymessage(TrezorTest):
) )
res_nfc = btc.verify_message( res_nfc = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(

View File

@ -14,16 +14,16 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc from trezorlib import btc
from .common import TrezorTest from .common import TrezorTest
class TestMsgVerifymessageSegwit(TrezorTest): class TestMsgVerifymessageSegwit(TrezorTest):
def test_message_long(self): def test_message_long(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(
@ -33,10 +33,9 @@ class TestMsgVerifymessageSegwit(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_testnet(self): def test_message_testnet(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Testnet", "Testnet",
"2N4VkePSzKH2sv5YBikLHGvzUYvfPxV6zS9", "2N4VkePSzKH2sv5YBikLHGvzUYvfPxV6zS9",
bytes.fromhex( bytes.fromhex(
@ -46,12 +45,9 @@ class TestMsgVerifymessageSegwit(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_verify(self): def test_message_verify(self, client):
self.setup_mnemonic_nopin_nopassphrase()
# trezor pubkey - OK
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(
@ -63,7 +59,7 @@ class TestMsgVerifymessageSegwit(TrezorTest):
# trezor pubkey - FAIL - wrong sig # trezor pubkey - FAIL - wrong sig
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(
@ -75,7 +71,7 @@ class TestMsgVerifymessageSegwit(TrezorTest):
# trezor pubkey - FAIL - wrong msg # trezor pubkey - FAIL - wrong msg
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(
@ -85,14 +81,12 @@ class TestMsgVerifymessageSegwit(TrezorTest):
) )
assert res is False assert res is False
def test_verify_utf(self): def test_verify_utf(self, client):
self.setup_mnemonic_nopin_nopassphrase()
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
res_nfkd = btc.verify_message( res_nfkd = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(
@ -102,7 +96,7 @@ class TestMsgVerifymessageSegwit(TrezorTest):
) )
res_nfc = btc.verify_message( res_nfc = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1", "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1",
bytes.fromhex( bytes.fromhex(

View File

@ -14,16 +14,16 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc from trezorlib import btc
from .common import TrezorTest from .common import TrezorTest
class TestMsgVerifymessageSegwitNative(TrezorTest): class TestMsgVerifymessageSegwitNative(TrezorTest):
def test_message_long(self): def test_message_long(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(
@ -33,10 +33,9 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_testnet(self): def test_message_testnet(self, client):
self.setup_mnemonic_nopin_nopassphrase()
ret = btc.verify_message( ret = btc.verify_message(
self.client, client,
"Testnet", "Testnet",
"tb1qyjjkmdpu7metqt5r36jf872a34syws336p3n3p", "tb1qyjjkmdpu7metqt5r36jf872a34syws336p3n3p",
bytes.fromhex( bytes.fromhex(
@ -46,12 +45,9 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
) )
assert ret is True assert ret is True
def test_message_verify(self): def test_message_verify(self, client):
self.setup_mnemonic_nopin_nopassphrase()
# trezor pubkey - OK
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(
@ -63,7 +59,7 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
# trezor pubkey - FAIL - wrong sig # trezor pubkey - FAIL - wrong sig
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(
@ -75,7 +71,7 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
# trezor pubkey - FAIL - wrong msg # trezor pubkey - FAIL - wrong msg
res = btc.verify_message( res = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(
@ -85,14 +81,12 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
) )
assert res is False assert res is False
def test_verify_utf(self): def test_verify_utf(self, client):
self.setup_mnemonic_nopin_nopassphrase()
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
res_nfkd = btc.verify_message( res_nfkd = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(
@ -102,7 +96,7 @@ class TestMsgVerifymessageSegwitNative(TrezorTest):
) )
res_nfc = btc.verify_message( res_nfc = btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j", "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j",
bytes.fromhex( bytes.fromhex(

View File

@ -14,23 +14,25 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import device, messages as proto from trezorlib import device, messages as proto
from .common import TrezorTest from .common import TrezorTest
class TestMsgWipedevice(TrezorTest): class TestMsgWipedevice(TrezorTest):
def test_wipe_device(self): @pytest.mark.setup_client(pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_wipe_device(self, client):
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.initialized is True assert features.initialized is True
assert features.pin_protection is True assert features.pin_protection is True
assert features.passphrase_protection is True assert features.passphrase_protection is True
device_id = features.device_id device_id = features.device_id
device.wipe(self.client) device.wipe(client)
features = self.client.call_raw(proto.Initialize()) features = client.call_raw(proto.Initialize())
assert features.initialized is False assert features.initialized is False
assert features.pin_protection is False assert features.pin_protection is False

View File

@ -19,7 +19,7 @@ import pytest
from trezorlib import btc, ckd_public as bip32, messages as proto from trezorlib import btc, ckd_public as bip32, messages as proto
from trezorlib.tools import CallException, parse_path from trezorlib.tools import CallException, parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .tx_cache import tx_cache from .tx_cache import tx_cache
TX_API = tx_cache("Bitcoin") TX_API = tx_cache("Bitcoin")
@ -30,10 +30,9 @@ TXHASH_c6091a = bytes.fromhex(
class TestMultisig(TrezorTest): class TestMultisig(TrezorTest):
def test_2_of_3(self): def test_2_of_3(self, client):
self.setup_mnemonic_allallall()
nodes = [ nodes = [
btc.get_public_node(self.client, parse_path("48'/0'/%d'" % index)).node btc.get_public_node(client, parse_path("48'/0'/%d'" % index)).node
for index in range(1, 4) for index in range(1, 4)
] ]
@ -55,8 +54,8 @@ class TestMultisig(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -108,7 +107,7 @@ class TestMultisig(TrezorTest):
# Now we have first signature # Now we have first signature
signatures1, _ = btc.sign_tx( signatures1, _ = btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API client, "Bitcoin", [inp1], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -139,8 +138,8 @@ class TestMultisig(TrezorTest):
multisig=multisig, multisig=multisig,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -190,7 +189,7 @@ class TestMultisig(TrezorTest):
] ]
) )
signatures2, serialized_tx = btc.sign_tx( signatures2, serialized_tx = btc.sign_tx(
self.client, "Bitcoin", [inp3], [out1], prev_txes=TX_API client, "Bitcoin", [inp3], [out1], prev_txes=TX_API
) )
assert ( assert (
@ -203,9 +202,8 @@ class TestMultisig(TrezorTest):
== "010000000152ba4dfcde9c4bed88f55479cdea03e711ae586e9a89352a98230c4cdf1a09c601000000fc00473044022052f4a3dc5ca3e86ed66abb1e2b4d9b9ace7d96f5615944beea19e58280847c2902201bd3ff32a38366a4eed0373e27da26ebc0d2a4c2bbeffd83e8a60e313d95b9e30147304402203828fd48540811be6a1b12967e7012587c46e6f05c78d42471e7b25c06bc7afc0220749274bc1aa698335b00400c5ba946a70b6b46c711324fbc4989279737a57f49014c6952210203ed6187880ae932660086e55d4561a57952dd200aa3ed2aa66b73e5723a0ce7210360e7f32fd3c8dee27a166f6614c598929699ee66acdcbda5fb24571bf2ae1ca021037c4c7e5d3293ab0f97771dcfdf83caadab341f427f54713da8b2c590a834f03b53aeffffffff01a0860100000000001976a91412e8391ad256dcdc023365978418d658dfecba1c88ac00000000" == "010000000152ba4dfcde9c4bed88f55479cdea03e711ae586e9a89352a98230c4cdf1a09c601000000fc00473044022052f4a3dc5ca3e86ed66abb1e2b4d9b9ace7d96f5615944beea19e58280847c2902201bd3ff32a38366a4eed0373e27da26ebc0d2a4c2bbeffd83e8a60e313d95b9e30147304402203828fd48540811be6a1b12967e7012587c46e6f05c78d42471e7b25c06bc7afc0220749274bc1aa698335b00400c5ba946a70b6b46c711324fbc4989279737a57f49014c6952210203ed6187880ae932660086e55d4561a57952dd200aa3ed2aa66b73e5723a0ce7210360e7f32fd3c8dee27a166f6614c598929699ee66acdcbda5fb24571bf2ae1ca021037c4c7e5d3293ab0f97771dcfdf83caadab341f427f54713da8b2c590a834f03b53aeffffffff01a0860100000000001976a91412e8391ad256dcdc023365978418d658dfecba1c88ac00000000"
) )
def test_15_of_15(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_15_of_15(self, client):
""" """
pubs = [] pubs = []
for x in range(15): for x in range(15):
@ -252,9 +250,9 @@ class TestMultisig(TrezorTest):
multisig=multisig, multisig=multisig,
) )
with self.client: with client:
sig, serialized_tx = btc.sign_tx( sig, serialized_tx = btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API client, "Bitcoin", [inp1], [out1], prev_txes=TX_API
) )
signatures[x] = sig[0] signatures[x] = sig[0]
@ -264,23 +262,8 @@ class TestMultisig(TrezorTest):
== "01000000011553ef34c683f4d6a8d346844409e6e7fc4ff01eaa25b7e8ce215abbfee3896101000000fd43060048304502210098e23085ad7282de988bf98afa1e9add9c9830009132f8902a9fa4624d5dc98b0220733216e70ab67791aa64be5c83d2050cb4ed9ff7eda2a1acc35da024d2ab2a670147304402201f8c11fb6e90fd616e484986e9451929797eba039882a9abcc203210948060b9022044da031530de7d9747d3c5a8e7cec04b04b7af495c9120b854ce7362af7fa05a01483045022100ea67c70186acef019bdf1551881bf38e6f88186501b64d3a756a2ce18e4ba18002201c35110325653e21e448b60053a4b5dda46b61096faf701a1faca61fcde91f00014730440220315598992f156d2f9d7b4275395fa067aa61ea95829fa17730885c86df4de70d02203eda9ade1656e2198c668603b17e197acb0969ed183ab0841303ea261205618901473044022060fdd6621edde9b8cf6776bc4eef26ace9b57514d725b7214ba11d333520a30e022044c30744f94484aec0f896233c5613a3256878ec0379f566226906b6d1b6061401483045022100b1d907e3574f60f7834c7e9f2e367998ce0461dad7d742d84ef8917d713f41f902203b3ac54f7bb2f7fb8685f582d2a94f7213a37cb508acffe29090cc06ae01588b01483045022100e3bf90ff3ad6395e42f46002f253f94ca0e8ffaa0620f2ceb4fa21493abdca4d02201d4c28b10b740bb2dc4b3695b4205c18f8c0dad2bb69540eb8a36576463cd5280147304402202cfaf9fab7dc1c9f0c3c23bd46bd6d5cea0664d914139fc9add80766ce998808022012db2802c07853e4cbe147afdf0b47e60bdcbcd31f9df19e04c177ed9aa66c6d0147304402207cbc2d83f351eee5ee91df26bb0c7e1cb07fe328cbbcdb0bb9656d37922c497302201b3435d4c71ffd1b34d45892f2a487bd79c8c7f57cc04373287642bb9610cb840147304402202dc3eab30ccb06553703e794212f43ee9a659f5e787a8374e9ea0bf6de0def7402201a70e970c21a807783313ed102bf4f0a3406ac7c84f94bc8194c5e209464d7230147304402206b04530c190c46a879d7771a6ad53acd33547e0d7fd320d5ad0b5b1fdeb5d4c202207b812be81c3419daadc942cca0c55aa32c7759fa7566c6dc35f030ca87a1c5be01483045022100ce523dddd6eef73d5ae7c44c870466e1ac5a7a77d43475e8def024af68977a1e022028be0276435bfa2ea887d6cf89fa829f96c1c7a55edc57bb3fd667d523fd3bf601473044022019410b20ebcd8eb3ee7ec1eff6bf0f9cbfaea82116811c61f3cf24af7e4434b1022009e5823f3349f695be09ae40754185300d8442a22715ddb5ffa17c4213140e7201483045022100964ef26a9074c3cdafffcfbe4bd445933f8c842ba11fd887922adcf7fabe0c82022023055d94c75ab223c767fbaa825c917e9beecbc7d5758cccf20d886c63d4b72a0147304402207aa3a98197697d258a8baae681f0b4c0ee682982f4205534e6c95a37dabaddd60220517a7ed5c03da2f242e17ccfdae0d81d6f454d7f9ea931fc62df6c0eab922186014d01025f21023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43d210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a621038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e32103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a79022103fe91eca10602d7dad4c9dab2b2a0858f71e25a219a6940749ce7a48118480dae210234716c01c2dd03fa7ee302705e2b8fbd1311895d94b1dca15e62eedea9b0968f210341fb2ead334952cf60f4481ba435c4693d0be649be01d2cfe9b02018e483e7bd2102dad8b2bce360a705c16e74a50a36459b4f8f4b78f9cd67def29d54ef6f7c7cf9210222dbe3f5f197a34a1d50e2cbe2a1085cac2d605c9e176f9a240e0fd0c669330d2103fb41afab56c9cdb013fda63d777d4938ddc3cb2ad939712da688e3ed333f95982102435f177646bdc717cb3211bf46656ca7e8d642726144778c9ce816b8b8c36ccf2102158d8e20095364031d923c7e9f7f08a14b1be1ddee21fe1a5431168e31345e5521026259794892428ca0818c8fb61d2d459ddfe20e57f50803c7295e6f4e2f5586652102815f910a8689151db627e6e262e0a2075ad5ec2993a6bc1b876a9d420923d681210318f54647f645ff01bd49fedc0219343a6a22d3ea3180a3c3d3097e4b888a8db45faeffffffff0110270000000000001976a9144a087d89f8ad16ca029c675b037c02fd1c5f9aec88ac00000000" == "01000000011553ef34c683f4d6a8d346844409e6e7fc4ff01eaa25b7e8ce215abbfee3896101000000fd43060048304502210098e23085ad7282de988bf98afa1e9add9c9830009132f8902a9fa4624d5dc98b0220733216e70ab67791aa64be5c83d2050cb4ed9ff7eda2a1acc35da024d2ab2a670147304402201f8c11fb6e90fd616e484986e9451929797eba039882a9abcc203210948060b9022044da031530de7d9747d3c5a8e7cec04b04b7af495c9120b854ce7362af7fa05a01483045022100ea67c70186acef019bdf1551881bf38e6f88186501b64d3a756a2ce18e4ba18002201c35110325653e21e448b60053a4b5dda46b61096faf701a1faca61fcde91f00014730440220315598992f156d2f9d7b4275395fa067aa61ea95829fa17730885c86df4de70d02203eda9ade1656e2198c668603b17e197acb0969ed183ab0841303ea261205618901473044022060fdd6621edde9b8cf6776bc4eef26ace9b57514d725b7214ba11d333520a30e022044c30744f94484aec0f896233c5613a3256878ec0379f566226906b6d1b6061401483045022100b1d907e3574f60f7834c7e9f2e367998ce0461dad7d742d84ef8917d713f41f902203b3ac54f7bb2f7fb8685f582d2a94f7213a37cb508acffe29090cc06ae01588b01483045022100e3bf90ff3ad6395e42f46002f253f94ca0e8ffaa0620f2ceb4fa21493abdca4d02201d4c28b10b740bb2dc4b3695b4205c18f8c0dad2bb69540eb8a36576463cd5280147304402202cfaf9fab7dc1c9f0c3c23bd46bd6d5cea0664d914139fc9add80766ce998808022012db2802c07853e4cbe147afdf0b47e60bdcbcd31f9df19e04c177ed9aa66c6d0147304402207cbc2d83f351eee5ee91df26bb0c7e1cb07fe328cbbcdb0bb9656d37922c497302201b3435d4c71ffd1b34d45892f2a487bd79c8c7f57cc04373287642bb9610cb840147304402202dc3eab30ccb06553703e794212f43ee9a659f5e787a8374e9ea0bf6de0def7402201a70e970c21a807783313ed102bf4f0a3406ac7c84f94bc8194c5e209464d7230147304402206b04530c190c46a879d7771a6ad53acd33547e0d7fd320d5ad0b5b1fdeb5d4c202207b812be81c3419daadc942cca0c55aa32c7759fa7566c6dc35f030ca87a1c5be01483045022100ce523dddd6eef73d5ae7c44c870466e1ac5a7a77d43475e8def024af68977a1e022028be0276435bfa2ea887d6cf89fa829f96c1c7a55edc57bb3fd667d523fd3bf601473044022019410b20ebcd8eb3ee7ec1eff6bf0f9cbfaea82116811c61f3cf24af7e4434b1022009e5823f3349f695be09ae40754185300d8442a22715ddb5ffa17c4213140e7201483045022100964ef26a9074c3cdafffcfbe4bd445933f8c842ba11fd887922adcf7fabe0c82022023055d94c75ab223c767fbaa825c917e9beecbc7d5758cccf20d886c63d4b72a0147304402207aa3a98197697d258a8baae681f0b4c0ee682982f4205534e6c95a37dabaddd60220517a7ed5c03da2f242e17ccfdae0d81d6f454d7f9ea931fc62df6c0eab922186014d01025f21023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43d210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a621038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e32103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a79022103fe91eca10602d7dad4c9dab2b2a0858f71e25a219a6940749ce7a48118480dae210234716c01c2dd03fa7ee302705e2b8fbd1311895d94b1dca15e62eedea9b0968f210341fb2ead334952cf60f4481ba435c4693d0be649be01d2cfe9b02018e483e7bd2102dad8b2bce360a705c16e74a50a36459b4f8f4b78f9cd67def29d54ef6f7c7cf9210222dbe3f5f197a34a1d50e2cbe2a1085cac2d605c9e176f9a240e0fd0c669330d2103fb41afab56c9cdb013fda63d777d4938ddc3cb2ad939712da688e3ed333f95982102435f177646bdc717cb3211bf46656ca7e8d642726144778c9ce816b8b8c36ccf2102158d8e20095364031d923c7e9f7f08a14b1be1ddee21fe1a5431168e31345e5521026259794892428ca0818c8fb61d2d459ddfe20e57f50803c7295e6f4e2f5586652102815f910a8689151db627e6e262e0a2075ad5ec2993a6bc1b876a9d420923d681210318f54647f645ff01bd49fedc0219343a6a22d3ea3180a3c3d3097e4b888a8db45faeffffffff0110270000000000001976a9144a087d89f8ad16ca029c675b037c02fd1c5f9aec88ac00000000"
) )
def test_missing_pubkey(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_missing_pubkey(self, client):
# key1 = self.client.get_public_node([1])
# key2 = self.client.get_public_node([2])
# key3 = self.client.get_public_node([3])
# pubkeys:
# 0338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6
# 038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3
# 03477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a7902
# multisig address: 3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz
# xpub:
# print(bip32.serialize(self.client.get_public_node([]).node))
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
node = bip32.deserialize( node = bip32.deserialize(
"xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy"
) )
@ -311,7 +294,7 @@ class TestMultisig(TrezorTest):
) )
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API) btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
assert exc.value.args[0] == proto.FailureType.DataError assert exc.value.args[0] == proto.FailureType.DataError
assert exc.value.args[1].endswith("Pubkey not found in multisig script") assert exc.value.args[1].endswith("Pubkey not found in multisig script")

View File

@ -14,10 +14,12 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import btc, ckd_public as bip32, messages as proto from trezorlib import btc, ckd_public as bip32, messages as proto
from trezorlib.tools import H_, parse_path from trezorlib.tools import H_, parse_path
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .tx_cache import tx_cache from .tx_cache import tx_cache
TX_API = tx_cache("Testnet") TX_API = tx_cache("Testnet")
@ -236,9 +238,8 @@ class TestMultisigChange(TrezorTest):
return resp return resp
# both outputs are external # both outputs are external
def test_external_external(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_external_external(self, client):
out1 = proto.TxOutputType( out1 = proto.TxOutputType(
address="muevUcG1Bb8eM2nGUGhqmeujHRX7YXjSEu", address="muevUcG1Bb8eM2nGUGhqmeujHRX7YXjSEu",
amount=40000000, amount=40000000,
@ -251,10 +252,10 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2)) client.set_expected_responses(self._responses(self.inp1, self.inp2))
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -267,9 +268,8 @@ class TestMultisigChange(TrezorTest):
) )
# first external, second internal # first external, second internal
def test_external_internal(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_external_internal(self, client):
out1 = proto.TxOutputType( out1 = proto.TxOutputType(
address="muevUcG1Bb8eM2nGUGhqmeujHRX7YXjSEu", address="muevUcG1Bb8eM2nGUGhqmeujHRX7YXjSEu",
amount=40000000, amount=40000000,
@ -282,12 +282,12 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
self._responses(self.inp1, self.inp2, change=2) self._responses(self.inp1, self.inp2, change=2)
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -300,9 +300,8 @@ class TestMultisigChange(TrezorTest):
) )
# first internal, second external # first internal, second external
def test_internal_external(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_internal_external(self, client):
out1 = proto.TxOutputType( out1 = proto.TxOutputType(
address_n=parse_path("45'/0/1/0"), address_n=parse_path("45'/0/1/0"),
amount=40000000, amount=40000000,
@ -315,12 +314,12 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
self._responses(self.inp1, self.inp2, change=1) self._responses(self.inp1, self.inp2, change=1)
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -333,9 +332,8 @@ class TestMultisigChange(TrezorTest):
) )
# both outputs are external # both outputs are external
def test_multisig_external_external(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_multisig_external_external(self, client):
out1 = proto.TxOutputType( out1 = proto.TxOutputType(
address="2N2aFoogGntQFFwdUVPfRmutXD22ThcNTsR", address="2N2aFoogGntQFFwdUVPfRmutXD22ThcNTsR",
amount=40000000, amount=40000000,
@ -348,10 +346,10 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2)) client.set_expected_responses(self._responses(self.inp1, self.inp2))
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -364,9 +362,8 @@ class TestMultisigChange(TrezorTest):
) )
# inputs match, change matches (first is change) # inputs match, change matches (first is change)
def test_multisig_change_match_first(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_multisig_change_match_first(self, client):
multisig_out1 = proto.MultisigRedeemScriptType( multisig_out1 = proto.MultisigRedeemScriptType(
nodes=[self.node_ext2, self.node_ext1, self.node_int], nodes=[self.node_ext2, self.node_ext1, self.node_int],
address_n=[1, 0], address_n=[1, 0],
@ -387,12 +384,12 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
self._responses(self.inp1, self.inp2, change=1) self._responses(self.inp1, self.inp2, change=1)
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -405,9 +402,8 @@ class TestMultisigChange(TrezorTest):
) )
# inputs match, change matches (second is change) # inputs match, change matches (second is change)
def test_multisig_change_match_second(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_multisig_change_match_second(self, client):
multisig_out2 = proto.MultisigRedeemScriptType( multisig_out2 = proto.MultisigRedeemScriptType(
nodes=[self.node_ext1, self.node_ext2, self.node_int], nodes=[self.node_ext1, self.node_ext2, self.node_int],
address_n=[1, 1], address_n=[1, 1],
@ -428,12 +424,12 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOMULTISIG, script_type=proto.OutputScriptType.PAYTOMULTISIG,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
self._responses(self.inp1, self.inp2, change=2) self._responses(self.inp1, self.inp2, change=2)
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -446,9 +442,8 @@ class TestMultisigChange(TrezorTest):
) )
# inputs match, change mismatches (second tries to be change but isn't) # inputs match, change mismatches (second tries to be change but isn't)
def test_multisig_mismatch_change(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_multisig_mismatch_change(self, client):
multisig_out2 = proto.MultisigRedeemScriptType( multisig_out2 = proto.MultisigRedeemScriptType(
nodes=[self.node_ext1, self.node_int, self.node_ext3], nodes=[self.node_ext1, self.node_int, self.node_ext3],
address_n=[1, 0], address_n=[1, 0],
@ -469,10 +464,10 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOMULTISIG, script_type=proto.OutputScriptType.PAYTOMULTISIG,
) )
with self.client: with client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2)) client.set_expected_responses(self._responses(self.inp1, self.inp2))
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp2], [self.inp1, self.inp2],
[out1, out2], [out1, out2],
@ -485,9 +480,8 @@ class TestMultisigChange(TrezorTest):
) )
# inputs mismatch, change matches with first input # inputs mismatch, change matches with first input
def test_multisig_mismatch_inputs(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_multisig_mismatch_inputs(self, client):
multisig_out1 = proto.MultisigRedeemScriptType( multisig_out1 = proto.MultisigRedeemScriptType(
nodes=[self.node_ext2, self.node_ext1, self.node_int], nodes=[self.node_ext2, self.node_ext1, self.node_int],
address_n=[1, 0], address_n=[1, 0],
@ -508,10 +502,10 @@ class TestMultisigChange(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp3)) client.set_expected_responses(self._responses(self.inp1, self.inp3))
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, client,
"Testnet", "Testnet",
[self.inp1, self.inp3], [self.inp1, self.inp3],
[out1, out2], [out1, out2],

View File

@ -31,9 +31,7 @@ TXHASH_d5f65e = bytes.fromhex(
class TestOpReturn(TrezorTest): class TestOpReturn(TrezorTest):
def test_opreturn(self): def test_opreturn(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/0'/0'/0/2"), prev_hash=TXHASH_d5f65e, prev_index=0 address_n=parse_path("44'/0'/0'/0/2"), prev_hash=TXHASH_d5f65e, prev_index=0
) )
@ -50,8 +48,8 @@ class TestOpReturn(TrezorTest):
script_type=proto.OutputScriptType.PAYTOOPRETURN, script_type=proto.OutputScriptType.PAYTOOPRETURN,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -114,7 +112,7 @@ class TestOpReturn(TrezorTest):
] ]
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1, out2], prev_txes=TX_API client, "Bitcoin", [inp1], [out1, out2], prev_txes=TX_API
) )
assert ( assert (
@ -122,9 +120,7 @@ class TestOpReturn(TrezorTest):
== "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100bc36e1227b334e856c532bbef86d30a96823a5f2461738f4dbf969dfbcf1b40b022078c5353ec9a4bce2bb05bd1ec466f2ab379c1aad926e208738407bba4e09784b012103330236b68aa6fdcaca0ea72e11b360c84ed19a338509aa527b678a7ec9076882ffffffff0260cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000000000001c6a1a74657374206f6620746865206f705f72657475726e206461746100000000" == "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100bc36e1227b334e856c532bbef86d30a96823a5f2461738f4dbf969dfbcf1b40b022078c5353ec9a4bce2bb05bd1ec466f2ab379c1aad926e208738407bba4e09784b012103330236b68aa6fdcaca0ea72e11b360c84ed19a338509aa527b678a7ec9076882ffffffff0260cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000000000001c6a1a74657374206f6620746865206f705f72657475726e206461746100000000"
) )
def test_nonzero_opreturn(self): def test_nonzero_opreturn(self, client):
self.setup_mnemonic_allallall()
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=parse_path("44'/0'/10'/0/5"), address_n=parse_path("44'/0'/10'/0/5"),
prev_hash=TXHASH_d5f65e, prev_hash=TXHASH_d5f65e,
@ -137,8 +133,8 @@ class TestOpReturn(TrezorTest):
script_type=proto.OutputScriptType.PAYTOOPRETURN, script_type=proto.OutputScriptType.PAYTOOPRETURN,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.TxRequest( proto.TxRequest(
request_type=proto.RequestType.TXINPUT, request_type=proto.RequestType.TXINPUT,
@ -175,7 +171,7 @@ class TestOpReturn(TrezorTest):
) )
with pytest.raises(CallException) as exc: with pytest.raises(CallException) as exc:
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API) btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
if TREZOR_VERSION == 1: if TREZOR_VERSION == 1:
assert exc.value.args[0] == proto.FailureType.ProcessError assert exc.value.args[0] == proto.FailureType.ProcessError

View File

@ -28,9 +28,9 @@ from .common import TrezorTest
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestProtectCall(TrezorTest): class TestProtectCall(TrezorTest):
def _some_protected_call(self, button, pin, passphrase): def _some_protected_call(self, client, button, pin, passphrase):
# This method perform any call which have protection in the device # This method perform any call which have protection in the device
res = self.client.ping( res = client.ping(
"random data", "random data",
button_protection=button, button_protection=button,
pin_protection=pin, pin_protection=pin,
@ -85,41 +85,37 @@ class TestProtectCall(TrezorTest):
scenario5() scenario5()
""" """
def test_no_protection(self): def test_no_protection(self, client):
self.setup_mnemonic_nopin_nopassphrase() with client:
assert client.debug.read_pin()[0] is None
client.set_expected_responses([proto.Success()])
self._some_protected_call(client, False, True, True)
with self.client: @pytest.mark.setup_client(pin="1234", passphrase=True)
assert self.client.debug.read_pin()[0] is None def test_pin(self, client):
self.client.set_expected_responses([proto.Success()]) with client:
self._some_protected_call(False, True, True) assert client.debug.read_pin()[0] == "1234"
client.setup_debuglink(button=True, pin_correct=True)
def test_pin(self): client.set_expected_responses(
self.setup_mnemonic_pin_passphrase()
with self.client:
assert self.client.debug.read_pin()[0] == self.pin4
self.client.setup_debuglink(button=True, pin_correct=True)
self.client.set_expected_responses(
[proto.ButtonRequest(), proto.PinMatrixRequest(), proto.Success()] [proto.ButtonRequest(), proto.PinMatrixRequest(), proto.Success()]
) )
self._some_protected_call(True, True, False) self._some_protected_call(client, True, True, False)
def test_incorrect_pin(self): @pytest.mark.setup_client(pin="1234", passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_incorrect_pin(self, client):
self.client.setup_debuglink(button=True, pin_correct=False) client.setup_debuglink(button=True, pin_correct=False)
with pytest.raises(PinException): with pytest.raises(PinException):
self._some_protected_call(False, True, False) self._some_protected_call(client, False, True, False)
def test_cancelled_pin(self): @pytest.mark.setup_client(pin="1234", passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_cancelled_pin(self, client):
self.client.setup_debuglink(button=True, pin_correct=False) # PIN cancel client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
with pytest.raises(PinException): with pytest.raises(PinException):
self._some_protected_call(False, True, False) self._some_protected_call(client, False, True, False)
def test_exponential_backoff_with_reboot(self): @pytest.mark.setup_client(pin="1234", passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_exponential_backoff_with_reboot(self, client):
client.setup_debuglink(button=True, pin_correct=False)
self.client.setup_debuglink(button=True, pin_correct=False)
def test_backoff(attempts, start): def test_backoff(attempts, start):
if attempts <= 1: if attempts <= 1:
@ -138,5 +134,5 @@ class TestProtectCall(TrezorTest):
for attempt in range(1, 4): for attempt in range(1, 4):
start = time.time() start = time.time()
with pytest.raises(PinException): with pytest.raises(PinException):
self._some_protected_call(False, True, False) self._some_protected_call(client, False, True, False)
test_backoff(attempt, start) test_backoff(attempt, start)

View File

@ -18,7 +18,7 @@ import pytest
from trezorlib import btc, debuglink, device, messages as proto, misc from trezorlib import btc, debuglink, device, messages as proto, misc
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .tx_cache import tx_cache from .tx_cache import tx_cache
TXHASH_d5f65e = bytes.fromhex( TXHASH_d5f65e = bytes.fromhex(
@ -28,16 +28,16 @@ TXHASH_d5f65e = bytes.fromhex(
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestProtectionLevels(TrezorTest): class TestProtectionLevels(TrezorTest):
def test_initialize(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_initialize(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses([proto.Features()]) client.set_expected_responses([proto.Features()])
self.client.init_device() client.init_device()
def test_apply_settings(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_apply_settings(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
proto.ButtonRequest(), proto.ButtonRequest(),
@ -45,12 +45,12 @@ class TestProtectionLevels(TrezorTest):
proto.Features(), proto.Features(),
] ]
) # TrezorClient reinitializes device ) # TrezorClient reinitializes device
device.apply_settings(self.client, label="nazdar") device.apply_settings(client, label="nazdar")
def test_change_pin(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_change_pin(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(), proto.ButtonRequest(),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -60,12 +60,12 @@ class TestProtectionLevels(TrezorTest):
proto.Features(), proto.Features(),
] ]
) )
device.change_pin(self.client) device.change_pin(client)
def test_ping(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_ping(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(), proto.ButtonRequest(),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -73,45 +73,46 @@ class TestProtectionLevels(TrezorTest):
proto.Success(), proto.Success(),
] ]
) )
self.client.ping("msg", True, True, True) client.ping("msg", True, True, True)
def test_get_entropy(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_get_entropy(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses([proto.ButtonRequest(), proto.Entropy()]) client.set_expected_responses([proto.ButtonRequest(), proto.Entropy()])
misc.get_entropy(self.client, 10) misc.get_entropy(client, 10)
def test_get_public_key(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_get_public_key(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.PublicKey()] [proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.PublicKey()]
) )
btc.get_public_node(self.client, []) btc.get_public_node(client, [])
def test_get_address(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_get_address(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Address()] [proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Address()]
) )
btc.get_address(self.client, "Bitcoin", []) btc.get_address(client, "Bitcoin", [])
def test_wipe_device(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_wipe_device(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[proto.ButtonRequest(), proto.Success(), proto.Features()] [proto.ButtonRequest(), proto.Success(), proto.Features()]
) )
device.wipe(self.client) device.wipe(client)
def test_load_device(self): @pytest.mark.setup_client(uninitialized=True)
with self.client: def test_load_device(self, client):
self.client.set_expected_responses( with client:
client.set_expected_responses(
[proto.ButtonRequest(), proto.Success(), proto.Features()] [proto.ButtonRequest(), proto.Success(), proto.Features()]
) )
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
"this is mnemonic", "this is mnemonic",
"1234", "1234",
True, True,
@ -123,7 +124,7 @@ class TestProtectionLevels(TrezorTest):
# This must fail, because device is already initialized # This must fail, because device is already initialized
with pytest.raises(Exception): with pytest.raises(Exception):
debuglink.load_device_by_mnemonic( debuglink.load_device_by_mnemonic(
self.client, client,
"this is mnemonic", "this is mnemonic",
"1234", "1234",
True, True,
@ -132,55 +133,45 @@ class TestProtectionLevels(TrezorTest):
skip_checksum=True, skip_checksum=True,
) )
def test_reset_device(self): @pytest.mark.setup_client(uninitialized=True)
with self.client: def test_reset_device(self, client):
self.client.set_expected_responses( with client:
client.set_expected_responses(
[proto.ButtonRequest()] [proto.ButtonRequest()]
+ [proto.EntropyRequest()] + [proto.EntropyRequest()]
+ [proto.ButtonRequest()] * 24 + [proto.ButtonRequest()] * 24
+ [proto.Success(), proto.Features()] + [proto.Success(), proto.Features()]
) )
device.reset(self.client, False, 128, True, False, "label", "english") device.reset(client, False, 128, True, False, "label", "english")
# This must fail, because device is already initialized # This must fail, because device is already initialized
with pytest.raises(Exception): with pytest.raises(Exception):
device.reset(self.client, False, 128, True, False, "label", "english") device.reset(client, False, 128, True, False, "label", "english")
def test_recovery_device(self): @pytest.mark.setup_client(uninitialized=True)
self.client.set_mnemonic(self.mnemonic12) def test_recovery_device(self, client):
with self.client: client.set_mnemonic(self.mnemonic12)
self.client.set_expected_responses( with client:
client.set_expected_responses(
[proto.ButtonRequest()] [proto.ButtonRequest()]
+ [proto.WordRequest()] * 24 + [proto.WordRequest()] * 24
+ [proto.Success(), proto.Features()] + [proto.Success(), proto.Features()]
) )
device.recover( device.recover(
self.client, client, 12, False, False, "label", "english", client.mnemonic_callback
12,
False,
False,
"label",
"english",
self.client.mnemonic_callback,
) )
# This must fail, because device is already initialized # This must fail, because device is already initialized
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
device.recover( device.recover(
self.client, client, 12, False, False, "label", "english", client.mnemonic_callback
12,
False,
False,
"label",
"english",
self.client.mnemonic_callback,
) )
def test_sign_message(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_sign_message(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(), proto.ButtonRequest(),
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
@ -188,16 +179,16 @@ class TestProtectionLevels(TrezorTest):
proto.MessageSignature(), proto.MessageSignature(),
] ]
) )
btc.sign_message(self.client, "Bitcoin", [], "testing message") btc.sign_message(client, "Bitcoin", [], "testing message")
def test_verify_message(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
with self.client: def test_verify_message(self, client):
self.setup_mnemonic_pin_passphrase() with client:
self.client.set_expected_responses( client.set_expected_responses(
[proto.ButtonRequest(), proto.ButtonRequest(), proto.Success()] [proto.ButtonRequest(), proto.ButtonRequest(), proto.Success()]
) )
btc.verify_message( btc.verify_message(
self.client, client,
"Bitcoin", "Bitcoin",
"14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e", "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e",
bytes.fromhex( bytes.fromhex(
@ -206,9 +197,8 @@ class TestProtectionLevels(TrezorTest):
"This is an example of a signed message.", "This is an example of a signed message.",
) )
def test_signtx(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12, pin=True, passphrase=True)
self.setup_mnemonic_pin_passphrase() def test_signtx(self, client):
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
prev_hash=TXHASH_d5f65e, prev_hash=TXHASH_d5f65e,
@ -221,9 +211,9 @@ class TestProtectionLevels(TrezorTest):
script_type=proto.OutputScriptType.PAYTOADDRESS, script_type=proto.OutputScriptType.PAYTOADDRESS,
) )
with self.client: with client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.PinMatrixRequest(), proto.PinMatrixRequest(),
proto.PassphraseRequest(), proto.PassphraseRequest(),
@ -275,7 +265,7 @@ class TestProtectionLevels(TrezorTest):
] ]
) )
btc.sign_tx( btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin") client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin")
) )
# def test_firmware_erase(self): # def test_firmware_erase(self):

View File

@ -14,9 +14,11 @@
# You should have received a copy of the License along with this library. # 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>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import btc, messages as proto from trezorlib import btc, messages as proto
from .common import TrezorTest from .common import MNEMONIC12, TrezorTest
from .tx_cache import tx_cache from .tx_cache import tx_cache
TXHASH_d5f65e = bytes.fromhex( TXHASH_d5f65e = bytes.fromhex(
@ -59,9 +61,8 @@ class TestZerosig(TrezorTest):
return return
""" """
def test_one_zero_signature(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_one_zero_signature(self, client):
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000, # amount=390000,
@ -77,16 +78,15 @@ class TestZerosig(TrezorTest):
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin") client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin")
) )
siglen = serialized_tx[44] siglen = serialized_tx[44]
# Trezor must strip leading zero from signature # Trezor must strip leading zero from signature
assert siglen == 67 assert siglen == 67
def test_two_zero_signature(self): @pytest.mark.setup_client(mnemonic=MNEMONIC12)
self.setup_mnemonic_nopin_nopassphrase() def test_two_zero_signature(self, client):
inp1 = proto.TxInputType( inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000, # amount=390000,
@ -102,7 +102,7 @@ class TestZerosig(TrezorTest):
) )
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
self.client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin") client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin")
) )
siglen = serialized_tx[44] siglen = serialized_tx[44]