def test_pull_answer_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(
        address=om_network.address, reply_to=om_network_client.address
    )

    target_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id
    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    answer_msg = SignalingAnswerMessage(
        address=om_network.address,
        payload="SDP",
        host_metadata=alice_vm.get_metadata_for_client(),
        target_peer=target_id,
        host_peer=host_id,
    )
    om_network_client.send_immediate_msg_without_reply(msg=answer_msg)

    assert (
        om_network.signaling_msgs[target_id][SyftMessage].get(answer_msg.id)
        == answer_msg
    )

    ans_pull_req = AnswerPullRequestMessage(
        address=om_network.address,
        target_peer=host_id,
        host_peer=target_id,
        reply_to=om_network_client.address,
    )

    response = om_network_client.send_immediate_msg_with_reply(msg=ans_pull_req)

    assert response == answer_msg
def test_loopback_answer_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(
        address=om_network.address, reply_to=om_network_client.address
    )

    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    metadata = alice_vm.get_metadata_for_client()
    answer_msg = SignalingAnswerMessage(
        address=om_network.address,
        payload="SDP",
        host_metadata=metadata,
        target_peer=host_id,
        host_peer=host_id,
    )
    om_network_client.send_immediate_msg_without_reply(msg=answer_msg)

    # Do not enqueue loopback requests
    assert len(om_network.signaling_msgs[host_id][SyftMessage]) == 0

    ans_pull_req = AnswerPullRequestMessage(
        address=om_network.address,
        target_peer=host_id,
        host_peer=host_id,
        reply_to=om_network_client.address,
    )

    response = om_network_client.send_immediate_msg_with_reply(msg=ans_pull_req)

    # Return InvalidLoopBackMessage
    assert isinstance(response, InvalidLoopBackRequest)
def test_not_found_pull_ans_requests_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(
        address=om_network.address, reply_to=om_network_client.address
    )

    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id
    target_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    ans_pull_req = AnswerPullRequestMessage(
        address=om_network.address,
        target_peer=target_id,
        host_peer=host_id,
        reply_to=om_network_client.address,
    )

    response = om_network_client.send_immediate_msg_with_reply(msg=ans_pull_req)

    assert isinstance(response, SignalingRequestsNotFound)
def test_push_offer_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(address=om_network.address,
                                 reply_to=om_network_client.address)

    target_id = om_network_client.send_immediate_msg_with_reply(
        msg=msg).peer_id
    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    offer_msg = SignalingOfferMessage(
        address=om_network.address,
        payload="SDP",
        host_metadata=alice_vm.get_metadata_for_client(),
        target_peer=target_id,
        host_peer=host_id,
    )
    om_network_client.send_immediate_msg_without_reply(msg=offer_msg)

    assert (om_network.signaling_msgs[target_id][SyftMessage].pop(
        offer_msg.id) == offer_msg)