diff --git a/tests/device_tests/bitcoin/test_authorize_coinjoin.py b/tests/device_tests/bitcoin/test_authorize_coinjoin.py index f6454726f7..3d24cad951 100644 --- a/tests/device_tests/bitcoin/test_authorize_coinjoin.py +++ b/tests/device_tests/bitcoin/test_authorize_coinjoin.py @@ -850,7 +850,7 @@ def test_multisession_authorization(client: Client): ) # Switch back to the first session. - session1 = client.resume_session(session1) + session1.resume() # Requesting a preauthorized ownership proof for www.example1.com should succeed in session 1. ownership_proof, _ = btc.get_ownership_proof( session1, @@ -895,7 +895,7 @@ def test_multisession_authorization(client: Client): ) # Switch to the second session. - session2 = client.resume_session(session2) + session2.resume() # Requesting a preauthorized ownership proof for www.example2.com should still succeed in session 2. ownership_proof, _ = btc.get_ownership_proof( session2, diff --git a/tests/device_tests/test_autolock.py b/tests/device_tests/test_autolock.py index a36487fbcb..bc9c03a3e7 100644 --- a/tests/device_tests/test_autolock.py +++ b/tests/device_tests/test_autolock.py @@ -137,7 +137,6 @@ def test_autolock_cancels_ui(session: Session): def test_autolock_ignores_initialize(session: Session): - client = session.client set_autolock_delay(session, 10 * 1000) assert session.features.unlocked is True @@ -145,7 +144,7 @@ def test_autolock_ignores_initialize(session: Session): start = time.monotonic() while time.monotonic() - start < 11: # init_device should always work even if locked - client.resume_session(session) + session.resume() time.sleep(0.1) # after 11 seconds we are definitely locked diff --git a/tests/device_tests/test_msg_backup_device.py b/tests/device_tests/test_msg_backup_device.py index c7a8156b50..f0bd163de0 100644 --- a/tests/device_tests/test_msg_backup_device.py +++ b/tests/device_tests/test_msg_backup_device.py @@ -208,18 +208,17 @@ def test_interrupt_backup_fails(session: Session): session.call_raw(messages.BackupDevice()) # interupt backup by sending initialize - session2 = session.client.resume_session(session) - session2.refresh_features() + session.resume() + session.refresh_features() # check that device state is as expected - assert session2.features.initialized is True + assert session.features.initialized is True assert ( - session2.features.backup_availability - == messages.BackupAvailability.NotAvailable + session.features.backup_availability == messages.BackupAvailability.NotAvailable ) - assert session2.features.unfinished_backup is True - assert session2.features.no_backup is False + assert session.features.unfinished_backup is True + assert session.features.no_backup is False # Second attempt at backup should fail with pytest.raises(TrezorFailure, match=r".*Seed already backed up"): - device.backup(session2) + device.backup(session) diff --git a/tests/device_tests/test_msg_change_wipe_code_t1.py b/tests/device_tests/test_msg_change_wipe_code_t1.py index c66c386a7a..9c657ea8c5 100644 --- a/tests/device_tests/test_msg_change_wipe_code_t1.py +++ b/tests/device_tests/test_msg_change_wipe_code_t1.py @@ -199,6 +199,6 @@ def test_set_wipe_code_invalid(session: Session, invalid_wipe_code: str): assert isinstance(ret, messages.Failure) # Check that there's still no wipe code protection. - session = session.client.resume_session(session) + session.resume() session.ensure_unlocked() assert session.features.wipe_code_protection is False diff --git a/tests/device_tests/test_msg_changepin_t1.py b/tests/device_tests/test_msg_changepin_t1.py index 0ed0013502..15cbb03d96 100644 --- a/tests/device_tests/test_msg_changepin_t1.py +++ b/tests/device_tests/test_msg_changepin_t1.py @@ -189,7 +189,7 @@ def test_set_invalid(session: Session, invalid_pin): assert isinstance(ret, messages.Failure) # Check that there's still no PIN protection now - session = session.client.resume_session(session) + session.resume() assert session.features.pin_protection is False _check_no_pin(session) diff --git a/tests/device_tests/test_session.py b/tests/device_tests/test_session.py index 19cbfb2d95..34ae585080 100644 --- a/tests/device_tests/test_session.py +++ b/tests/device_tests/test_session.py @@ -46,7 +46,7 @@ def test_clear_session(client: Client): session.set_expected_responses(init_responses + cached_responses) assert get_public_node(session, ADDRESS_N).xpub == XPUB - client.resume_session(session) + session.resume() with session: # pin and passphrase are cached session.set_expected_responses(cached_responses) @@ -62,7 +62,7 @@ def test_clear_session(client: Client): session.set_expected_responses(init_responses + cached_responses) assert get_public_node(session, ADDRESS_N).xpub == XPUB - client.resume_session(session) + session.resume() with session: # pin and passphrase are cached session.set_expected_responses(cached_responses) @@ -104,14 +104,14 @@ def test_cannot_resume_ended_session(client: Client): session = client.get_session() session_id = session.id - session_resumed = client.resume_session(session) + session.resume() - assert session_resumed.id == session_id + assert session.id == session_id session.end() - session_resumed2 = client.resume_session(session) + session.resume() - assert session_resumed2.id != session_id + assert session.id != session_id def test_end_session_only_current(client: Client): @@ -124,12 +124,12 @@ def test_end_session_only_current(client: Client): # assert client.session_id is None # resume ended session - session_b_resumed = client.resume_session(session_b) - assert session_b_resumed.id != session_b_id + session_b.resume() + assert session_b.id != session_b_id # resume first session that was not ended - session_a_resumed = client.resume_session(session_a) - assert session_a_resumed.id == session_a.id + session_a.resume() + assert session_a.id == session_a.id @pytest.mark.setup_client(passphrase=True) @@ -155,7 +155,7 @@ def test_session_recycling(client: Client): with session: # passphrase should still be cached session.set_expected_responses([messages.Address] * 3) - client.resume_session(session) + session.resume() get_test_address(session) get_test_address(session) assert address == get_test_address(session) @@ -170,8 +170,8 @@ def test_derive_cardano_empty_session(client: Client): session_id = session.id # restarting same session should go well - session_2 = client.resume_session(session) - assert session.id == session_2.id + session.resume() + assert session.id == session_id # restarting same session should go well with any setting session_3 = client.get_session(session_id=session_id, derive_cardano=False) @@ -186,7 +186,7 @@ def test_derive_cardano_empty_session(client: Client): def test_derive_cardano_running_session(client: Client): # start new session session = client.get_session(derive_cardano=False) - + session_id = session.id # force derivation of seed get_test_address(session) @@ -195,23 +195,24 @@ def test_derive_cardano_running_session(client: Client): cardano.get_public_key(session, parse_path("m/44h/1815h/0h")) # restarting same session should go well - session_2 = client.resume_session(session) - assert session.id == session_2.id + session.resume() + assert session.id == session_id # restarting same session should go well if we _don't_ want to derive cardano - session_3 = client.get_session(session_id=session_2.id, derive_cardano=False) + session_3 = client.get_session(session_id=session_id, derive_cardano=False) assert session_3.id == session.id # restarting with derive_cardano=True should kill old session and create new one session_4 = client.get_session(derive_cardano=True) - assert session_4.id != session.id + session_4_id = session_4.id + assert session_4_id != session.id # new session should have Cardano capability cardano.get_public_key(session_4, parse_path("m/44h/1815h/0h")) # restarting with derive_cardano=True should keep same session - session_5 = client.resume_session(session_4) - assert session_5.id == session_4.id + session_4.resume() + assert session_4.id == session_4_id # restarting with derive_cardano=False should kill old session and create new one session_6 = client.get_session(session_id=session_4.id, derive_cardano=False) diff --git a/tests/device_tests/test_session_id_and_passphrase.py b/tests/device_tests/test_session_id_and_passphrase.py index f710e7162e..8b7fd0b281 100644 --- a/tests/device_tests/test_session_id_and_passphrase.py +++ b/tests/device_tests/test_session_id_and_passphrase.py @@ -83,9 +83,9 @@ def test_session_with_passphrase(client: Client): # Call Initialize again, this time with the received session id and then call # GetPublicKey. The passphrase should be cached now so Trezor must # not ask for it again, whilst returning the same xpub. - session2 = client.resume_session(session) - assert session2.id == session_id - assert _get_xpub(session2) == XPUB_PASSPHRASES["A"] + session.resume() + assert session.id == session_id + assert _get_xpub(session) == XPUB_PASSPHRASES["A"] # If we set session id in Initialize to None, the cache will be cleared # and Trezor will ask for the passphrase again. @@ -113,34 +113,34 @@ def test_multiple_sessions(client: Client): # Resume each session for i in range(SESSIONS_STORED): - resumed_session = client.resume_session(sessions[i]) - assert session_ids[i] == resumed_session.id + sessions[i].resume() + assert session_ids[i] == sessions[i].id # Creating a new session replaces the least-recently-used session client.get_session() # Resuming session 1 through SESSIONS_STORED will still work for i in range(1, SESSIONS_STORED): - resumed_session = client.resume_session(sessions[i]) - assert session_ids[i] == resumed_session.id + sessions[i].resume() + assert session_ids[i] == sessions[i].id # Resuming session 0 will not work - resumed_session = client.resume_session(sessions[0]) - assert session_ids[0] != resumed_session.id + sessions[0].resume() + assert session_ids[0] != sessions[0].id # New session bumped out the least-recently-used anonymous session. # Resuming session 1 through SESSIONS_STORED will still work for i in range(1, SESSIONS_STORED): - resumed_session = client.resume_session(sessions[i]) - assert session_ids[i] == resumed_session.id + sessions[i].resume() + assert session_ids[i] == sessions[i].id # Creating a new session replaces session_ids[0] again client.get_session() # Resuming all sessions one by one will in turn bump out the previous session. for i in range(SESSIONS_STORED): - resumed_session = client.resume_session(sessions[i]) - assert session_ids[i] != resumed_session.id + sessions[i].resume() + assert session_ids[i] != sessions[i].id @pytest.mark.setup_client(passphrase=True) @@ -150,11 +150,11 @@ def test_multiple_passphrases(client: Client): session_a_id = session_a.id assert _get_xpub(session_a, expected_passphrase_req=True) == XPUB_PASSPHRASES["A"] # start it again wit the same session id - session_a_resumed = client.resume_session(session_a) + session_a.resume() # session is the same - assert session_a_resumed.id == session_a_id + assert session_a.id == session_a_id # passphrase is not prompted - assert _get_xpub(session_a_resumed) == XPUB_PASSPHRASES["A"] + assert _get_xpub(session_a) == XPUB_PASSPHRASES["A"] # start a second session session_b = client.get_session(passphrase="B") @@ -163,19 +163,19 @@ def test_multiple_passphrases(client: Client): assert _get_xpub(session_b, expected_passphrase_req=True) == XPUB_PASSPHRASES["B"] # provide the same session id -> must not ask for passphrase again. - session_b_resumed = client.resume_session(session_b) - assert session_b_resumed.id == session_b_id - assert _get_xpub(session_b_resumed) == XPUB_PASSPHRASES["B"] + session_b.resume() + assert session_b.id == session_b_id + assert _get_xpub(session_b) == XPUB_PASSPHRASES["B"] # provide the first session id -> must not ask for passphrase again and return the same result. - session_a_resumed_again = client.resume_session(session_a) - assert session_a_resumed_again.id == session_a_id - assert _get_xpub(session_a_resumed_again) == XPUB_PASSPHRASES["A"] + session_a.resume() + assert session_a.id == session_a_id + assert _get_xpub(session_a) == XPUB_PASSPHRASES["A"] # provide the second session id -> must not ask for passphrase again and return the same result. - session_b_resumed_again = client.resume_session(session_b) - assert session_b_resumed_again.id == session_b_id - assert _get_xpub(session_b_resumed_again) == XPUB_PASSPHRASES["B"] + session_b.resume() + assert session_b.id == session_b_id + assert _get_xpub(session_b) == XPUB_PASSPHRASES["B"] @pytest.mark.slow @@ -201,15 +201,15 @@ def test_max_sessions_with_passphrases(client: Client): for _ in range(20): random.shuffle(shuffling) for passphrase in shuffling: - resumed_session = client.resume_session(sessions[passphrase]) - assert resumed_session.id == session_ids[passphrase] - assert _get_xpub(resumed_session) == XPUB_PASSPHRASES[passphrase] + sessions[passphrase].resume() + assert sessions[passphrase].id == session_ids[passphrase] + assert _get_xpub(sessions[passphrase]) == XPUB_PASSPHRASES[passphrase] # make sure the usage order is the reverse of the creation order for passphrase in reversed(passphrases): - resumed_session = client.resume_session(sessions[passphrase]) - assert resumed_session.id == session_ids[passphrase] - assert _get_xpub(resumed_session) == XPUB_PASSPHRASES[passphrase] + sessions[passphrase].resume() + assert sessions[passphrase].id == session_ids[passphrase] + assert _get_xpub(sessions[passphrase]) == XPUB_PASSPHRASES[passphrase] # creating one more session will exceed the limit new_session = client.get_session(passphrase="XX") @@ -218,9 +218,9 @@ def test_max_sessions_with_passphrases(client: Client): # restoring the sessions in reverse will evict the next-up session for passphrase in reversed(passphrases): - resumed_session = client.resume_session(sessions[passphrase]) + sessions[passphrase].resume() _get_xpub( - resumed_session, + sessions[passphrase], expected_passphrase_req=True, ) # passphrase is prompted @@ -239,9 +239,9 @@ def test_session_enable_passphrase(client: Client): # The session id is unchanged, therefore we do not prompt for the passphrase. session_id = session.id - resumed_session = client.resume_session(session) - assert session_id == resumed_session.id - assert _get_xpub(resumed_session) == XPUB_PASSPHRASE_NONE + session.resume() + assert session_id == session.id + assert _get_xpub(session) == XPUB_PASSPHRASE_NONE # We clear the session id now, so the passphrase should be asked. new_session = client.get_session(passphrase="A") @@ -308,8 +308,8 @@ def test_passphrase_always_on_device(client: Client): assert response.xpub == XPUB_PASSPHRASE_NONE # Passphrase will not be prompted. The session id stays the same and the passphrase is cached. - resumed_session = client.resume_session(session) - response = resumed_session.call_raw(XPUB_REQUEST) + session.resume() + response = session.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PublicKey) assert response.xpub == XPUB_PASSPHRASE_NONE @@ -507,10 +507,10 @@ def test_cardano_passphrase(client: Client): assert _get_xpub_cardano(session) == XPUB_CARDANO_PASSPHRASE_B # Initialize with the session id does not destroy the state - resumed_session = client.resume_session(session) + session.resume() # _init_session(client, session_id=session_id, derive_cardano=True) - assert _get_xpub(resumed_session) == XPUB_PASSPHRASES["B"] - assert _get_xpub_cardano(resumed_session) == XPUB_CARDANO_PASSPHRASE_B + assert _get_xpub(session) == XPUB_PASSPHRASES["B"] + assert _get_xpub_cardano(session) == XPUB_CARDANO_PASSPHRASE_B # New session will destroy the state new_session = client.get_session(passphrase="A", derive_cardano=True)