Beispiel #1
0
def test_make_reply_squeak(
    admin_stub, saved_squeak_hash, signing_profile_id
):
    # Make another squeak as a reply
    reply_1_squeak_hash = make_squeak(
        admin_stub,
        signing_profile_id,
        "Reply #1",
        saved_squeak_hash,
    )

    # Make a second squeak as a reply
    reply_2_squeak_hash = make_squeak(
        admin_stub,
        signing_profile_id,
        "Reply #2",
        reply_1_squeak_hash,
    )

    # Get the squeak and check that the reply field is correct
    get_reply_squeak_display_entry = get_squeak_display(
        admin_stub, reply_2_squeak_hash)
    assert (
        get_reply_squeak_display_entry.squeak_hash == reply_2_squeak_hash
    )
    assert (
        get_reply_squeak_display_entry.reply_to == reply_1_squeak_hash
    )

    # Get the ancestors of the latest reply squeak
    get_ancestors_response = admin_stub.GetAncestorSqueakDisplays(
        squeak_admin_pb2.GetAncestorSqueakDisplaysRequest(
            squeak_hash=reply_2_squeak_hash,
        )
    )
    assert len(get_ancestors_response.squeak_display_entries) == 3

    # Get the replies of the original squeak
    get_replies_response = admin_stub.GetReplySqueakDisplays(
        squeak_admin_pb2.GetReplySqueakDisplaysRequest(
            squeak_hash=saved_squeak_hash,
            limit=100,
        )
    )
    assert len(get_replies_response.squeak_display_entries) == 1
    assert reply_1_squeak_hash in [
        entry.squeak_hash
        for entry in get_replies_response.squeak_display_entries
    ]
def test_make_squeak(admin_stub, signing_profile_id):
    # Create a new squeak using the new profile
    make_squeak_content = "Hello from the profile on the server!"
    make_squeak_hash = make_squeak(admin_stub, signing_profile_id,
                                   make_squeak_content)
    assert len(make_squeak_hash) == 32 * 2

    # Get the squeak display item
    get_squeak_display_entry = get_squeak_display(admin_stub, make_squeak_hash)
    assert get_squeak_display_entry.squeak_hash == make_squeak_hash
    assert (get_squeak_display_entry.content_str ==
            "Hello from the profile on the server!")
    # assert get_squeak_display_response.squeak_display_entry.author_address == signing_profile_address
    assert get_squeak_display_entry.is_author_known
    assert get_squeak_display_entry.HasField("author")
    assert len(get_squeak_display_entry.author.profile_image) > 0
    assert not get_squeak_display_entry.is_reply
    assert not bool(get_squeak_display_entry.reply_to)
    assert len(get_squeak_display_entry.secret_key_hex) == 32 * 2

    # Block time should be within the past hour
    block_time = datetime.datetime.fromtimestamp(
        get_squeak_display_entry.block_time, )
    one_hour = datetime.timedelta(hours=1)
    assert block_time > datetime.datetime.now() - one_hour
    assert block_time < datetime.datetime.now() + one_hour

    # Get the squeak profile
    squeak_profile = get_squeak_profile(admin_stub, signing_profile_id)
    squeak_profile_address = squeak_profile.address
    squeak_profile_name = squeak_profile.profile_name

    # Get all squeak displays for the known address
    get_address_squeak_display_response = admin_stub.GetAddressSqueakDisplays(
        squeak_admin_pb2.GetAddressSqueakDisplaysRequest(
            address=squeak_profile_address,
            limit=100,
        ), )
    assert len(get_address_squeak_display_response.squeak_display_entries) == 1
    for (squeak_display_entry
         ) in get_address_squeak_display_response.squeak_display_entries:
        assert squeak_display_entry.author.profile_name == squeak_profile_name
        assert squeak_display_entry.author.address == squeak_profile_address

    # check serialized squeak hex string
    serialized_squeak_hex = get_squeak_display_entry.serialized_squeak_hex
    # print("serialized_squeak_hex: {}".format(serialized_squeak_hex))
    assert len(serialized_squeak_hex) > 200
    serialized_squeak = bytes.fromhex(serialized_squeak_hex)
    deserialized_squeak = CSqueak.deserialize(serialized_squeak)
    assert get_hash(deserialized_squeak) == make_squeak_hash
    CheckSqueak(deserialized_squeak)
def test_subscribe_squeaks(
    admin_stub,
    other_admin_stub,
    signing_profile_id,
):

    # Get the squeak profile
    squeak_profile = get_squeak_profile(admin_stub, signing_profile_id)
    squeak_profile_address = squeak_profile.address
    squeak_profile_name = squeak_profile.profile_name

    # Add the contact profile to the other server and set the profile to be following
    contact_profile_id = create_contact_profile(other_admin_stub,
                                                squeak_profile_name,
                                                squeak_profile_address)
    other_admin_stub.SetSqueakProfileFollowing(
        squeak_admin_pb2.SetSqueakProfileFollowingRequest(
            profile_id=contact_profile_id,
            following=True,
        ))

    with free_price(admin_stub), \
        open_peer_connection(
        other_admin_stub,
        "test_peer",
        "squeaknode",
        18777,
    ):
        # Create a new squeak using the new profile
        make_squeak_content = "Hello this message should be subscribed!"
        make_squeak_hash = make_squeak(
            admin_stub,
            signing_profile_id,
            make_squeak_content,
        )

        time.sleep(2)

        # Get the squeak display item
        squeak_display_entry = get_squeak_display(
            other_admin_stub,
            make_squeak_hash,
        )
        assert squeak_display_entry is not None

        # Get the squeak display item
        get_squeak_display_entry = get_squeak_display(
            other_admin_stub,
            make_squeak_hash,
        )
        assert (get_squeak_display_entry.content_str == make_squeak_content)
def test_search(admin_stub, signing_profile_id):
    make_squeak_content = "Just some random weird text."
    make_squeak_hash = make_squeak(admin_stub, signing_profile_id,
                                   make_squeak_content)
    assert len(make_squeak_hash) == 32 * 2

    # Get all squeak displays for the given search text.
    search_results = get_search_squeaks(
        admin_stub,
        "Weird",
    )
    assert len(search_results) == 1

    # Get all squeak displays for other search text that shouldn't be there.
    missing_search_results = get_search_squeaks(
        admin_stub,
        "strange",
    )
    assert len(missing_search_results) == 0
Beispiel #5
0
def test_make_private_squeak(admin_stub, signing_profile_id, recipient_contact_profile_id):
    make_squeak_content = "This is a private squeak!"
    make_squeak_hash = make_squeak(
        admin_stub,
        signing_profile_id,
        make_squeak_content,
        recipient_profile_id=recipient_contact_profile_id,
    )
    assert len(make_squeak_hash) == 32 * 2

    # Get the squeak display item
    get_squeak_display_entry = get_squeak_display(
        admin_stub, make_squeak_hash)
    assert get_squeak_display_entry.squeak_hash == make_squeak_hash
    assert (
        get_squeak_display_entry.content_str == "This is a private squeak!"
    )
    assert get_squeak_display_entry.is_author_known
    assert get_squeak_display_entry.HasField("author")
    assert len(
        get_squeak_display_entry.author.profile_image) > 0
    assert not get_squeak_display_entry.is_reply
    assert not bool(get_squeak_display_entry.reply_to)
    assert len(get_squeak_display_entry.secret_key_hex) == 32 * 2