def test_that_sci_callback_should_raise_exception_on_receiving_invalid_golem_message(self): with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream'): with mock.patch('core.payments.sci_callback.unescape_stream', side_effect=self.frame_iterator): with mock.patch('middleman_protocol.message.AbstractFrame.deserialize', side_effect=MessageError): with self.assertRaises(SCICallbackPayloadError): sci_callback(self.transaction)
def test_that_sci_callback_should_raise_exception_when_response_is_not_signed_transaction_golem_message(self): with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream'): with mock.patch('core.payments.sci_callback.unescape_stream', side_effect=self.frame_iterator): with mock.patch( 'middleman_protocol.message.AbstractFrame.deserialize', return_value=GolemMessageFrame(payload=Ping(), request_id=self.request_id), ): with self.assertRaises(SCICallbackPayloadError): sci_callback(self.transaction)
def test_that_sci_callback_should_raise_exception_when_golem_message_is_not_signed_by_signing_service(self): wrong_signed_golem_message = self._create_signed_transaction() wrong_signed_golem_message.sign_message(DIFFERENT_CONCENT_PRIVATE_KEY) with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream'): with mock.patch('core.payments.sci_callback.unescape_stream', side_effect=self.frame_iterator): with mock.patch( 'middleman_protocol.message.AbstractFrame.deserialize', return_value=GolemMessageFrame(payload=wrong_signed_golem_message, request_id=self.request_id), ): with self.assertRaises(SCICallbackPayloadSignatureError): sci_callback(self.transaction)
def test_that_sci_callback_should_raise_exception_when_response_signature_is_not_correct(self): wrong_signed_transaction = self._create_signed_transaction() wrong_signed_transaction.v = self.v - 10 wrong_signed_transaction.sign_message(SIGNING_SERVICE_PRIVATE_KEY) with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream'): with mock.patch('core.payments.sci_callback.unescape_stream', side_effect=self.frame_iterator): with mock.patch( 'middleman_protocol.message.AbstractFrame.deserialize', return_value=GolemMessageFrame(payload=wrong_signed_transaction, request_id=self.request_id), ): with self.assertRaises(SCICallbackTransactionSignatureError): sci_callback(self.transaction)
def test_that_sci_callback_should_sign_transaction_after_two_retries(self): with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream', side_effect=[socket.timeout, socket.timeout, None]): with mock.patch('core.payments.sci_callback.unescape_stream', side_effect=self.frame_iterator): signed_transaction = sci_callback(self.transaction) self.assertEqual(signed_transaction.v, self.v) self.assertEqual(signed_transaction.r, self.r) self.assertEqual(signed_transaction.s, self.s)
def test_that_sci_callback_should_raise_exception_on_timeout(self): with mock.patch('core.payments.sci_callback.socket.socket.connect'): with mock.patch('core.payments.sci_callback.send_over_stream', side_effect=socket.timeout): with self.assertRaises(SCICallbackTimeoutError): sci_callback(self.transaction)