def handle_message_processed( raiden: "RaidenService", message: Processed # pylint: disable=unused-argument ) -> List[StateChange]: assert message.sender, "message must be signed" processed = ReceiveProcessed(message.sender, message.message_identifier) return [processed]
def handle_message_processed(cls, raiden: RaidenService, message: Processed, is_light_client: bool = False) -> None: processed = ReceiveProcessed(message.sender, message.message_identifier) raiden.handle_and_track_state_change(processed) if is_light_client: LightClientMessageHandler.store_lc_processed(message, raiden.wal)
def test_inplace_delete_message_queue(chain_state): sender = factories.make_address() canonical_identifier = factories.make_canonical_identifier() message_id = factories.make_message_identifier() delivered_state_change = ReceiveDelivered(sender=sender, message_identifier=message_id) processed_state_change = ReceiveProcessed(sender=sender, message_identifier=message_id) global_identifier = QueueIdentifier( recipient=sender, canonical_identifier=CANONICAL_IDENTIFIER_GLOBAL_QUEUE) chain_state.queueids_to_queues[global_identifier] = None assert global_identifier in chain_state.queueids_to_queues, "queue mapping insertion failed" inplace_delete_message_queue(chain_state=chain_state, state_change=delivered_state_change, queueid=global_identifier) assert global_identifier not in chain_state.queueids_to_queues, "did not clear queue" chain_state.queueids_to_queues[global_identifier] = [ SendMessageEvent( recipient=sender, canonical_identifier=canonical_identifier, message_identifier=message_id, ) ] assert global_identifier in chain_state.queueids_to_queues, "queue mapping insertion failed" handle_receive_delivered(chain_state=chain_state, state_change=delivered_state_change) assert global_identifier not in chain_state.queueids_to_queues, "did not clear queue" queue_identifier = QueueIdentifier( recipient=sender, canonical_identifier=canonical_identifier) assert queue_identifier not in chain_state.queueids_to_queues, "queue not empty" chain_state.queueids_to_queues[queue_identifier] = [ SendMessageEvent( recipient=sender, canonical_identifier=canonical_identifier, message_identifier=message_id, ) ] assert queue_identifier in chain_state.queueids_to_queues, "queue mapping not mutable" handle_receive_processed(chain_state=chain_state, state_change=processed_state_change) assert queue_identifier not in chain_state.queueids_to_queues, "queue did not clear"
def handle_message_processed(self, raiden: RaidenService, message: Processed): processed = ReceiveProcessed(message.sender, message.message_identifier) raiden.handle_state_change(processed)
def test_message_handler(): """ Test for MessageHandler.on_message and the different methods it dispatches into. Each of them results in a call to a RaidenService method, which is checked with a Mock. """ our_address = factories.make_address() sender_privkey, sender = factories.make_privkey_address() signer = LocalSigner(sender_privkey) message_handler = MessageHandler() mock_raiden = Mock( address=our_address, default_secret_registry=Mock(is_secret_registered=lambda **_: False) ) properties = factories.LockedTransferProperties(sender=sender, pkey=sender_privkey) locked_transfer = factories.create(properties) message_handler.on_message(mock_raiden, locked_transfer) assert_method_call(mock_raiden, "mediate_mediated_transfer", locked_transfer) locked_transfer_for_us = factories.create(factories.replace(properties, target=our_address)) message_handler.on_message(mock_raiden, locked_transfer_for_us) assert_method_call(mock_raiden, "target_mediated_transfer", locked_transfer_for_us) mock_raiden.default_secret_registry.is_secret_registered = lambda **_: True message_handler.on_message(mock_raiden, locked_transfer) assert not mock_raiden.mediate_mediated_transfer.called assert not mock_raiden.target_mediated_transfer.called mock_raiden.default_secret_registry.is_secret_registered = lambda **_: False params = dict( payment_identifier=13, amount=14, expiration=15, secrethash=factories.UNIT_SECRETHASH ) secret_request = SecretRequest( message_identifier=16, signature=factories.EMPTY_SIGNATURE, **params ) secret_request.sign(signer) receive = ReceiveSecretRequest(sender=sender, **params) message_handler.on_message(mock_raiden, secret_request) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive]) secret = factories.make_secret() reveal_secret = RevealSecret( message_identifier=100, signature=factories.EMPTY_SIGNATURE, secret=secret ) reveal_secret.sign(signer) receive = ReceiveSecretReveal(sender=sender, secret=secret) message_handler.on_message(mock_raiden, reveal_secret) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive]) properties: factories.UnlockProperties = factories.create_properties( factories.UnlockProperties() ) unlock = factories.create(properties) unlock.sign(signer) balance_proof = factories.make_signed_balance_proof_from_unsigned( factories.create(properties.balance_proof), signer, unlock.message_hash ) receive = ReceiveUnlock( message_identifier=properties.message_identifier, secret=properties.secret, balance_proof=balance_proof, sender=sender, ) message_handler.on_message(mock_raiden, unlock) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive]) properties: factories.LockExpiredProperties = factories.create_properties( factories.LockExpiredProperties() ) lock_expired = factories.create(properties) lock_expired.sign(signer) balance_proof = factories.make_signed_balance_proof_from_unsigned( factories.create(properties.balance_proof), signer, lock_expired.message_hash ) receive = ReceiveLockExpired( balance_proof=balance_proof, message_identifier=properties.message_identifier, secrethash=properties.secrethash, # pylint: disable=no-member sender=sender, ) message_handler.on_message(mock_raiden, lock_expired) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive]) delivered = Delivered(delivered_message_identifier=1, signature=factories.EMPTY_SIGNATURE) delivered.sign(signer) receive = ReceiveDelivered(message_identifier=1, sender=sender) message_handler.on_message(mock_raiden, delivered) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive]) processed = Processed(message_identifier=42, signature=factories.EMPTY_SIGNATURE) processed.sign(signer) receive = ReceiveProcessed(message_identifier=42, sender=sender) message_handler.on_message(mock_raiden, processed) assert_method_call(mock_raiden, "handle_and_track_state_changes", [receive])
def handle_message_processed(raiden: "RaidenService", message: Processed) -> None: assert message.sender, "message must be signed" processed = ReceiveProcessed(message.sender, message.message_identifier) raiden.handle_and_track_state_changes([processed])
def handle_message_processed(raiden: RaidenService, message: Processed) -> None: processed = ReceiveProcessed(message.sender, message.message_identifier) raiden.handle_and_track_state_change(processed)
def handle_message_processed(raiden: 'RaidenService', message: Processed): processed = ReceiveProcessed(message.message_identifier) raiden.handle_state_change(processed)