def test_ping(self): self.setup_mnemonic_pin_passphrase() self.client.clear_session() with self.client: self.client.set_expected_responses([proto.Success()]) res = self.client.ping('random data') self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Ping), proto.Success()]) res = self.client.ping('random data', button_protection=True) self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()]) res = self.client.ping('random data', pin_protection=True) self.assertEqual(res, 'random data') with self.client: self.client.set_expected_responses([ proto.PassphraseRequest(), proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Success() ]) res = self.client.ping('random data', passphrase_protection=True) self.assertEqual(res, 'random data')
def test_apply_settings_passphrase(self): self.setup_mnemonic_pin_nopassphrase() self.assertEqual(self.client.features.passphrase_protection, False) with self.client: self.client.set_expected_responses( [proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=True) self.assertEqual(self.client.features.passphrase_protection, True) with self.client: self.client.set_expected_responses( [proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=False) self.assertEqual(self.client.features.passphrase_protection, False) with self.client: self.client.set_expected_responses( [proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(use_passphrase=True) self.assertEqual(self.client.features.passphrase_protection, True)
def test_wipe_device(self): with self.client: self.setup_mnemonic_pin_passphrase() self.client.set_expected_responses([proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.wipe_device()
def test_no_protection(self): self.setup_mnemonic_nopin_nopassphrase() with self.client: self.assertEqual(self.client.debug.read_pin()[0], '') self.client.set_expected_responses([proto.Success()]) self._some_protected_call(False, True, True)
def test_ping(self): with self.client: self.setup_mnemonic_pin_passphrase() self.client.clear_session() self.client.set_expected_responses([proto.ButtonRequest(), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()]) self.client.ping('msg', True, True, True)
def test_apply_settings(self): with self.client: self.setup_mnemonic_pin_passphrase() self.client.clear_session() self.client.set_expected_responses([proto.ButtonRequest(), proto.PinMatrixRequest(), proto.Success(), proto.Features()]) # KeepKeyClient reinitializes device self.client.apply_settings(label='nazdar')
def test_verify_message(self): with self.client: self.setup_mnemonic_pin_passphrase() self.client.set_expected_responses([proto.Success()]) self.client.verify_message( 'Bitcoin', '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e', binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), 'This is an example of a signed message.')
def test_load_device(self): with self.client: self.client.set_expected_responses([proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.load_device_by_mnemonic('this is mnemonic', '1234', True, 'label', 'english', skip_checksum=True) # This must fail, because device is already initialized self.assertRaises(Exception, self.client.load_device_by_mnemonic, 'this is mnemonic', '1234', True, 'label', 'english', skip_checksum=True)
def test_change_pin(self): with self.client: self.setup_mnemonic_pin_passphrase() self.client.set_expected_responses([proto.ButtonRequest(), proto.PinMatrixRequest(), proto.PinMatrixRequest(), proto.PinMatrixRequest(), proto.Success(), proto.Features()]) self.client.change_pin()
def test_recovery_device(self): with self.client: self.client.set_mnemonic(self.mnemonic12) self.client.set_expected_responses([proto.WordRequest()] * 24 + \ [proto.Success(), proto.Features()]) self.client.recovery_device(True, 12, False, False, 'label', 'english') # This must fail, because device is already initialized self.assertRaises(Exception, self.client.recovery_device, 12, False, False, 'label', 'english')
def test_reset_device(self): with self.client: self.client.set_expected_responses([proto.EntropyRequest(), \ proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.reset_device(False, 128, True, False, 'label', 'english') # This must fail, because device is already initialized self.assertRaises(Exception, self.client.reset_device, False, 128, True, False, 'label', 'english')
def test_apply_settings(self): self.setup_mnemonic_pin_passphrase() self.assertEqual(self.client.features.label, 'test') with self.client: self.client.set_expected_responses( [proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(label='new label') self.assertEqual(self.client.features.label, 'new label')
def test_invalid_language(self): self.setup_mnemonic_pin_passphrase() self.assertEqual(self.client.features.language, 'english') with self.client: self.client.set_expected_responses( [proto.ButtonRequest(), proto.Success(), proto.Features()]) self.client.apply_settings(language='nonexistent') self.assertEqual(self.client.features.language, 'english')
def test_pin(self): self.setup_mnemonic_pin_passphrase() self.client.clear_session() with self.client: self.assertEqual(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() ]) self._some_protected_call(True, True, False)
def test_ping_format_specifier_sanitize(self): self.setup_mnemonic_pin_passphrase() self.client.clear_session() with self.client: self.client.set_expected_responses([ proto.ButtonRequest(code=proto_types.ButtonRequest_Ping), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Success() ]) res = self.client.ping('%s%x%n%p', button_protection=True, pin_protection=True, passphrase_protection=True) self.assertEqual(res, '%s%x%n%p')
def test_ping(self): ping = self.client.call(messages.Ping(message='ahoj!')) self.assertEqual(ping, messages.Success(message='ahoj!'))