def handle_paymentsentsuccess( raiden: "RaidenService", payment_sent_success_event: EventPaymentSentSuccess ) -> None: # pragma: no unittest feedback_token = raiden.route_to_feedback_token.get( tuple(payment_sent_success_event.route)) pfs_config = raiden.config.pfs_config if feedback_token and pfs_config: log.debug( "Received payment success event", route=[ to_checksum_address(node) for node in payment_sent_success_event.route ], feedback_token=feedback_token, ) post_pfs_feedback( routing_mode=raiden.routing_mode, pfs_config=pfs_config, token_network_address=payment_sent_success_event. token_network_address, route=payment_sent_success_event.route, token=feedback_token, successful=True, )
def handle_routefailed( raiden: "RaidenService", route_failed_event: EventRouteFailed ) -> None: # pragma: no unittest feedback_token = raiden.route_to_feedback_token.get( tuple(route_failed_event.route)) pfs_config = raiden.config.pfs_config if feedback_token and pfs_config: log.debug( "Received event for failed route", route=[ to_checksum_address(node) for node in route_failed_event.route ], secrethash=encode_hex(route_failed_event.secrethash), feedback_token=feedback_token, ) post_pfs_feedback( routing_mode=raiden.routing_mode, pfs_config=pfs_config, token_network_address=route_failed_event.token_network_address, route=route_failed_event.route, token=feedback_token, successful=False, )
def test_post_pfs_feedback(query_paths_args): """ Test POST feedback to PFS """ feedback_token = uuid4() token_network_address = factories.make_token_network_address() route = [factories.make_address(), factories.make_address()] with patch.object(session, "post", return_value=mocked_json_response()) as feedback: post_pfs_feedback( routing_mode=RoutingMode.PFS, pfs_config=query_paths_args["pfs_config"], token_network_address=token_network_address, route=route, token=feedback_token, successful=True, ) assert feedback.called assert feedback.call_args[0][0].find( to_checksum_address(token_network_address)) > 0 payload = feedback.call_args[1]["json"] assert payload["token"] == feedback_token.hex assert payload["success"] is True assert payload["path"] == [to_checksum_address(addr) for addr in route] with patch.object(session, "post", return_value=mocked_json_response()) as feedback: post_pfs_feedback( routing_mode=RoutingMode.PFS, pfs_config=query_paths_args["pfs_config"], token_network_address=token_network_address, route=route, token=feedback_token, successful=False, ) assert feedback.called assert feedback.call_args[0][0].find( to_checksum_address(token_network_address)) > 0 payload = feedback.call_args[1]["json"] assert payload["token"] == feedback_token.hex assert payload["success"] is False assert payload["path"] == [to_checksum_address(addr) for addr in route] with patch.object(session, "post", return_value=mocked_json_response()) as feedback: post_pfs_feedback( routing_mode=RoutingMode.PRIVATE, pfs_config=query_paths_args["pfs_config"], token_network_address=token_network_address, route=route, token=feedback_token, successful=False, ) assert not feedback.called