mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-26 08:08:51 +00:00
tests: convert setup_client to a marker
This commit is contained in:
parent
1e4cf8d801
commit
4b2235ab78
@ -14,7 +14,6 @@
|
||||
# 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>.
|
||||
|
||||
import functools
|
||||
import os
|
||||
|
||||
import pytest
|
||||
@ -58,41 +57,44 @@ def device_version():
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def client():
|
||||
def client(request):
|
||||
client = get_device()
|
||||
wipe_device(client)
|
||||
|
||||
client.open()
|
||||
|
||||
# fmt: off
|
||||
setup_params = dict(
|
||||
uninitialized=False,
|
||||
mnemonic=" ".join(["all"] * 12),
|
||||
pin=None,
|
||||
passphrase=False,
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
marker = request.node.get_closest_marker("setup_client")
|
||||
if marker:
|
||||
setup_params.update(marker.kwargs)
|
||||
|
||||
if not setup_params["uninitialized"]:
|
||||
if setup_params["pin"] is True:
|
||||
setup_params["pin"] = "1234"
|
||||
|
||||
debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
mnemonic=setup_params["mnemonic"],
|
||||
pin=setup_params["pin"],
|
||||
passphrase_protection=setup_params["passphrase"],
|
||||
label="test",
|
||||
language="english",
|
||||
)
|
||||
if setup_params["passphrase"] and client.features.model != "1":
|
||||
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)
|
||||
|
||||
yield client
|
||||
client.close()
|
||||
|
||||
|
||||
def setup_client(mnemonic=None, pin="", passphrase=False):
|
||||
if mnemonic is None:
|
||||
mnemonic = " ".join(["all"] * 12)
|
||||
if pin is True:
|
||||
pin = "1234"
|
||||
|
||||
def client_decorator(function):
|
||||
@functools.wraps(function)
|
||||
def wrapper(client, *args, **kwargs):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
mnemonic=mnemonic,
|
||||
pin=pin,
|
||||
passphrase_protection=passphrase,
|
||||
label="test",
|
||||
language="english",
|
||||
)
|
||||
if TREZOR_VERSION > 1 and passphrase:
|
||||
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)
|
||||
return function(*args, client=client, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return client_decorator
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
# try to figure out trezor version
|
||||
global TREZOR_VERSION
|
||||
@ -104,6 +106,10 @@ def pytest_configure(config):
|
||||
# register known markers
|
||||
config.addinivalue_line("markers", "skip_t1: skip the test on Trezor One")
|
||||
config.addinivalue_line("markers", "skip_t2: skip the test on Trezor T")
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
'setup_client(mnemonic="all all all...", pin=None, passphrase=False, uninitialized=False): configure the client instance',
|
||||
)
|
||||
with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f:
|
||||
for line in f:
|
||||
config.addinivalue_line("markers", line.strip())
|
||||
|
@ -19,10 +19,7 @@ import pytest
|
||||
import trezorlib.messages as m
|
||||
from trezorlib.exceptions import Cancelled
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
|
||||
@setup_client()
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
[
|
||||
@ -46,7 +43,6 @@ def test_cancel_message_via_cancel(client, message):
|
||||
client.call(message)
|
||||
|
||||
|
||||
@setup_client()
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
[
|
||||
|
@ -3,8 +3,6 @@ import pytest
|
||||
from trezorlib.binance import get_address
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
BINANCE_ADDRESS_TEST_VECTORS = [
|
||||
("m/44'/714'/0'/0/0", "bnb1hgm0p7khfk85zpz5v0j8wnej3a90w709vhkdfu"),
|
||||
("m/44'/714'/0'/0/1", "bnb1egswqkszzfc2uq78zjslc6u2uky4pw46x4rstd"),
|
||||
@ -14,7 +12,7 @@ BINANCE_ADDRESS_TEST_VECTORS = [
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.binance
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(
|
||||
@pytest.mark.setup_client(
|
||||
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
|
||||
)
|
||||
@pytest.mark.parametrize("path, expected_address", BINANCE_ADDRESS_TEST_VECTORS)
|
||||
|
@ -3,15 +3,13 @@ import pytest
|
||||
from trezorlib import binance
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
BINANCE_PATH = parse_path("m/44h/714h/0h/0/0")
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.binance
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(
|
||||
@pytest.mark.setup_client(
|
||||
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
|
||||
)
|
||||
def test_binance_get_public_key(client):
|
||||
|
@ -3,8 +3,6 @@ import pytest
|
||||
from trezorlib import binance
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
BINANCE_TEST_VECTORS = [
|
||||
( # CANCEL
|
||||
{
|
||||
@ -89,7 +87,7 @@ BINANCE_TEST_VECTORS = [
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.binance
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(
|
||||
@pytest.mark.setup_client(
|
||||
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
|
||||
)
|
||||
@pytest.mark.parametrize("message, expected_response", BINANCE_TEST_VECTORS)
|
||||
|
@ -20,7 +20,6 @@ from trezorlib.cardano import get_address
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .common import TrezorTest
|
||||
from .conftest import setup_client
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@ -43,7 +42,7 @@ from .conftest import setup_client
|
||||
),
|
||||
],
|
||||
)
|
||||
@setup_client(mnemonic=TrezorTest.mnemonic12)
|
||||
@pytest.mark.setup_client(mnemonic=TrezorTest.mnemonic12)
|
||||
def test_cardano_get_address(client, path, expected_address):
|
||||
# data from https://iancoleman.io/bip39/#english
|
||||
|
||||
|
@ -19,8 +19,6 @@ import pytest
|
||||
from trezorlib.cardano import get_address
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
SLIP39_MNEMONIC = [
|
||||
"extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern",
|
||||
"extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse",
|
||||
@ -48,7 +46,7 @@ SLIP39_MNEMONIC = [
|
||||
),
|
||||
],
|
||||
)
|
||||
@setup_client(mnemonic=SLIP39_MNEMONIC, passphrase=True)
|
||||
@pytest.mark.setup_client(mnemonic=SLIP39_MNEMONIC, passphrase=True)
|
||||
def test_cardano_get_address(client, path, expected_address):
|
||||
# enter passphrase
|
||||
assert client.features.passphrase_protection is True
|
||||
|
@ -19,13 +19,10 @@ import pytest
|
||||
from trezorlib.cardano import get_public_key
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.cardano
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(mnemonic=" ".join(["all"] * 12))
|
||||
@pytest.mark.parametrize(
|
||||
"path,public_key,chain_code",
|
||||
[
|
||||
|
@ -19,8 +19,6 @@ import pytest
|
||||
from trezorlib.cardano import get_public_key
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
SLIP39_MNEMONIC = [
|
||||
"extra extend academic bishop cricket bundle tofu goat apart victim "
|
||||
"enlarge program behavior permit course armed jerky faint language modern",
|
||||
@ -34,7 +32,7 @@ SLIP39_MNEMONIC = [
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.cardano
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(mnemonic=SLIP39_MNEMONIC, passphrase=True)
|
||||
@pytest.mark.setup_client(mnemonic=SLIP39_MNEMONIC, passphrase=True)
|
||||
@pytest.mark.parametrize(
|
||||
"path,public_key,chain_code",
|
||||
[
|
||||
|
@ -19,8 +19,6 @@ import pytest
|
||||
from trezorlib import cardano, messages
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
PROTOCOL_MAGICS = {"mainnet": 764824073, "testnet": 1097911063}
|
||||
|
||||
SAMPLE_INPUTS = [
|
||||
@ -173,7 +171,6 @@ INVALID_VECTORS = [
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.cardano
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client()
|
||||
@pytest.mark.parametrize(
|
||||
"protocol_magic,inputs,outputs,transactions,tx_hash,tx_body", VALID_VECTORS
|
||||
)
|
||||
@ -213,7 +210,6 @@ def test_cardano_sign_tx(
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.cardano
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client()
|
||||
@pytest.mark.parametrize(
|
||||
"protocol_magic,inputs,outputs,transactions,expected_error_message", INVALID_VECTORS
|
||||
)
|
||||
|
@ -18,8 +18,6 @@ import pytest
|
||||
|
||||
from trezorlib import cardano, messages
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
SHARES_20_3of6 = [
|
||||
"extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern",
|
||||
"extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse",
|
||||
@ -115,7 +113,7 @@ VALID_VECTORS = [
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.cardano
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client(mnemonic=SHARES_20_3of6, passphrase=True)
|
||||
@pytest.mark.setup_client(mnemonic=SHARES_20_3of6, passphrase=True)
|
||||
@pytest.mark.parametrize(
|
||||
"protocol_magic,inputs,outputs,transactions,tx_hash,tx_body", VALID_VECTORS
|
||||
)
|
||||
|
@ -92,6 +92,7 @@ def test_secret(client, shares, secret):
|
||||
assert debug.read_mnemonic_secret().hex() == secret
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_recover_with_pin_passphrase(client):
|
||||
debug = client.debug
|
||||
|
||||
@ -117,6 +118,7 @@ def test_recover_with_pin_passphrase(client):
|
||||
assert client.features.passphrase_protection is True
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_abort(client):
|
||||
debug = client.debug
|
||||
|
||||
@ -136,6 +138,7 @@ def test_abort(client):
|
||||
assert client.features.initialized is False
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_noabort(client):
|
||||
debug = client.debug
|
||||
|
||||
@ -155,6 +158,7 @@ def test_noabort(client):
|
||||
assert client.features.initialized is True
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@pytest.mark.parametrize("nth_word", range(3))
|
||||
def test_wrong_nth_word(client, nth_word):
|
||||
debug = client.debug
|
||||
@ -194,6 +198,7 @@ def test_wrong_nth_word(client, nth_word):
|
||||
device.recover(client, pin_protection=False, label="label")
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_same_share(client):
|
||||
debug = client.debug
|
||||
first_share = SHARES_20_3of6[0].split(" ")
|
||||
|
@ -3,8 +3,6 @@ import pytest
|
||||
from trezorlib import device, messages
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
pytestmark = pytest.mark.skip_t1
|
||||
|
||||
SHARES_20_2of3 = [
|
||||
@ -19,7 +17,7 @@ INVALID_SHARES_20_2of3 = [
|
||||
]
|
||||
|
||||
|
||||
@setup_client(mnemonic=SHARES_20_2of3[0:2], passphrase=True)
|
||||
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2], passphrase=True)
|
||||
def test_2of3_dryrun(client):
|
||||
debug = client.debug
|
||||
|
||||
@ -47,7 +45,7 @@ def test_2of3_dryrun(client):
|
||||
)
|
||||
|
||||
|
||||
@setup_client(mnemonic=SHARES_20_2of3[0:2], passphrase=True)
|
||||
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2], passphrase=True)
|
||||
def test_2of3_invalid_seed_dryrun(client):
|
||||
debug = client.debug
|
||||
|
||||
|
@ -19,7 +19,6 @@ import pytest
|
||||
from trezorlib import btc, messages
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from .conftest import setup_client
|
||||
from .tx_cache import tx_cache
|
||||
|
||||
TXHASH_3bf506 = bytes.fromhex(
|
||||
@ -34,7 +33,6 @@ TXHASH_f3a6e6 = bytes.fromhex(
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.capricoin
|
||||
@pytest.mark.skip_t1 # T1 support is not planned
|
||||
@setup_client()
|
||||
def test_timestamp_included(client):
|
||||
# tx: 3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f
|
||||
# input 0: 0.01 CPC
|
||||
|
@ -19,10 +19,8 @@ import pytest
|
||||
|
||||
from trezorlib import btc
|
||||
|
||||
from .conftest import setup_client
|
||||
|
||||
|
||||
@setup_client(
|
||||
@pytest.mark.setup_client(
|
||||
mnemonic=(
|
||||
"extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern",
|
||||
"extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse",
|
||||
@ -43,7 +41,7 @@ def test_3of6_passphrase(client):
|
||||
assert address == "18oZEMRWurCZW1FeK8sWYyXuWx2bFqEKyX"
|
||||
|
||||
|
||||
@setup_client(
|
||||
@pytest.mark.setup_client(
|
||||
mnemonic=(
|
||||
"hobo romp academic axis august founder knife legal recover alien expect emphasis loan kitchen involve teacher capture rebuild trial numb spider forward ladle lying voter typical security quantity hawk legs idle leaves gasoline",
|
||||
"hobo romp academic agency ancestor industry argue sister scene midst graduate profile numb paid headset airport daisy flame express scene usual welcome quick silent downtown oral critical step remove says rhythm venture aunt",
|
||||
|
@ -6,6 +6,7 @@ from trezorlib.tools import parse_path
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_reset_recovery(client):
|
||||
mnemonics = reset(client)
|
||||
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
|
||||
|
Loading…
Reference in New Issue
Block a user