From 05b16ca1ed27b3c94bdb83ad4b5cc5d28af1d697 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Fri, 22 Nov 2024 23:10:24 +0100 Subject: [PATCH] fix bitcoin tests --- python/src/trezorlib/client.py | 15 ++++++++++++--- python/src/trezorlib/debuglink.py | 4 +++- python/src/trezorlib/transport/session.py | 4 ++-- .../bitcoin/test_authorize_coinjoin.py | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index 84c19d2b97..a9524711c4 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -129,6 +129,18 @@ class TrezorClient: return SessionV2.new(self, passphrase, derive_cardano) raise NotImplementedError # TODO + def resume_session(self, session: Session): + from trezorlib.transport.session import SessionV1, SessionV2 + + if isinstance(session, SessionV2): + return session + elif isinstance(session, SessionV1): + session.init_session() + return session + + else: + raise NotImplementedError + def get_management_session(self, new_session: bool = False) -> Session: from .transport.session import SessionV1, SessionV2 @@ -178,9 +190,6 @@ class TrezorClient: # TODO implement raise NotImplementedError - def resume_session(self, session_id: bytes) -> Session: - raise NotImplementedError # TODO - def _get_protocol(self) -> ProtocolAndChannel: self.transport.open() diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index aec80f8d2b..f4a2dc653d 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -1344,7 +1344,9 @@ class TrezorClientDebugLink(TrezorClient): # self.debug.close() def get_session( - self, passphrase: str | None = None, derive_cardano: bool = False + self, + passphrase: str | None = None, + derive_cardano: bool = False, ) -> Session: if passphrase is not None: passphrase = Mnemonic.normalize_string(passphrase) diff --git a/python/src/trezorlib/transport/session.py b/python/src/trezorlib/transport/session.py index 98866b2564..b51d2a4a8f 100644 --- a/python/src/trezorlib/transport/session.py +++ b/python/src/trezorlib/transport/session.py @@ -111,7 +111,7 @@ class SessionV1(Session): session.passphrase_callback = _callback_passphrase session.passphrase = passphrase session.derive_cardano = derive_cardano - session._init_session() + session.init_session() return session def _write(self, msg: t.Any) -> None: @@ -124,7 +124,7 @@ class SessionV1(Session): assert isinstance(self.client.protocol, ProtocolV1) return self.client.protocol.read() - def _init_session(self): + def init_session(self): if self.id == b"": session_id = None else: diff --git a/tests/device_tests/bitcoin/test_authorize_coinjoin.py b/tests/device_tests/bitcoin/test_authorize_coinjoin.py index be55b058a7..41eeaf770d 100644 --- a/tests/device_tests/bitcoin/test_authorize_coinjoin.py +++ b/tests/device_tests/bitcoin/test_authorize_coinjoin.py @@ -855,7 +855,7 @@ def test_multisession_authorization(client: Client): # Switch back to the first session. # session_id2 = session.session_id # TODO client.init_device(session_id=session_id1) - + client.resume_session(session1) # Requesting a preauthorized ownership proof for www.example1.com should succeed in session 1. ownership_proof, _ = btc.get_ownership_proof( session1, @@ -901,7 +901,7 @@ def test_multisession_authorization(client: Client): # Switch to the second session. # TODO client.init_device(session_id=session_id2) - + client.resume_session(session2) # Requesting a preauthorized ownership proof for www.example2.com should still succeed in session 2. ownership_proof, _ = btc.get_ownership_proof( session2,