示例#1
0
def get_update_is_creator_event():
    event_type = user_event_types_lookup["update_is_creator"]
    update_is_creator_event = AttrDict({"_userId": 1, "_isCreator": True})
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_is_creator_event
    })
def get_playlist_deleted_event():
    event_type = playlist_event_types_lookup["playlist_deleted"]
    playlist_deleted_event = AttrDict({"_playlistId": 1})
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_deleted_event
    })
示例#3
0
def get_update_bio_event():
    event_type = user_event_types_lookup["update_bio"]
    update_bio_event = AttrDict({"_userId": 1, "_bio": "change description"})
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_bio_event
    })
def get_playlist_track_added_event(playlistId, addedTrackId):
    event_type = playlist_event_types_lookup["playlist_track_added"]
    playlist_track_added_event = AttrDict({
        "_playlistId": playlistId,
        "_addedTrackId": addedTrackId
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_track_added_event
    })
def get_playlist_description_updated_event():
    event_type = playlist_event_types_lookup["playlist_description_updated"]
    playlist_description_updated_event = AttrDict({
        "_playlistId": 1,
        "_playlistDescription": "adf"
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_description_updated_event
    })
def get_playlist_name_updated_event():
    event_type = playlist_event_types_lookup["playlist_name_updated"]
    playlist_name_updated_event = AttrDict({
        "_playlistId": 1,
        "_updatedPlaylistName": "asdfg"
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_name_updated_event
    })
def get_playlist_privacy_updated_event():
    event_type = playlist_event_types_lookup["playlist_privacy_updated"]
    playlist_privacy_updated_event = AttrDict({
        "_playlistId": 1,
        "_updatedIsPrivate": False
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_privacy_updated_event
    })
def get_playlist_tracks_ordered_event():
    event_type = playlist_event_types_lookup["playlist_tracks_ordered"]
    playlist_tracks_ordered_event = AttrDict({
        "_playlistId": 1,
        "_orderedTrackIds": [2, 1]
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_tracks_ordered_event
    })
示例#9
0
def get_update_multihash_event():
    event_type = user_event_types_lookup["update_multihash"]
    update_multihash_event = AttrDict({
        "_userId":
        1,
        "_multihashDigest":
        b"\x94uU\x06@\xa2\x93\xf1$d:\xe8m|rj\x02y\x93\xdf\x9bf?\xe7h\xb3y\xa6\x19\x0c\x81\xb0",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_multihash_event
    })
示例#10
0
def get_update_name_event():
    event_type = user_event_types_lookup["update_name"]
    update_name_event = AttrDict({
        "_userId":
        1,
        "_name":
        b"joey\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_name_event
    })
示例#11
0
def get_update_cover_photo_event():
    event_type = user_event_types_lookup["update_cover_photo"]
    update_cover_photo_event = AttrDict({
        "_userId":
        1,
        "_coverPhotoDigest":
        b"C\x9a\r\xa5PO\x99\x8c\xdf;\x8cT\xdc\x18\xf5**\x80" +
        b"\x01\xe3j-\xd7\x11_\x84\xde%T\xd0\xcd\xc6",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_cover_photo_event
    })
def get_playlist_cover_photo_updated_event():
    event_type = playlist_event_types_lookup["playlist_cover_photo_updated"]
    playlist_cover_photo_updated_event = AttrDict({
        "_playlistId":
        1,
        "_playlistImageMultihashDigest":
        b"\xad\x8d\x1eeG\xf2\x12\xe3\x817" +
        b"\x7f\xb1A\xc6 M~\xfe\x03F\x98f\xab\xfa3\x17ib\xdcC>\xed",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_cover_photo_updated_event
    })
def get_playlist_created_event():
    event_type = playlist_event_types_lookup["playlist_created"]
    playlist_created_event = AttrDict({
        "_playlistId": 1,
        "_playlistOwnerId": 1,
        "_isPrivate": True,
        "_isAlbum": False,
        "_trackIds": [],  # This is a list of numbers (track ids)
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_created_event
    })
示例#14
0
def get_update_creator_node_endpoint_event():
    event_type = user_event_types_lookup["update_creator_node_endpoint"]
    update_creator_node_endpoint_event = AttrDict({
        "_userId":
        1,
        "_creatorNodeEndpoint":
        "http://cn2_creator-node_1:4001,http://cn1_creator-node_1:4000," +
        "http://cn3_creator-node_1:4002",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_creator_node_endpoint_event
    })
示例#15
0
def get_update_profile_photo_event():
    event_type = user_event_types_lookup["update_profile_photo"]
    update_profile_photo_event = AttrDict({
        "_userId":
        1,
        "_profilePhotoDigest":
        b"\xc6\x0f\xc2@\x8f\xd1\xb7R\xbb\xe3\xf6\xc3" +
        b"\xa45\x19\x9d\xc6\x10g\x8dm\xe4\x15\x86|\x91\\r\xaa\x01\xab-",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_profile_photo_event
    })
示例#16
0
def get_update_location_event():
    event_type = user_event_types_lookup["update_location"]
    update_location_event = AttrDict({
        "_userId":
        1,
        "_location":
        b"location\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
        b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": update_location_event
    })
示例#17
0
def get_add_user_event():
    event_type = user_event_types_lookup["add_user"]
    add_user_event = AttrDict({
        "_userId":
        1,
        "_handle":
        b"joe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
        "_wallet":
        "0x82Fc85A842c9922A9Db9091Cf6573754Cd2D0F14",
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": add_user_event
    })
def get_playlist_track_delete_event(playlistId, deletedTrackId,
                                    deletedTrackTimestamp):
    event_type = playlist_event_types_lookup["playlist_track_deleted"]
    playlist_track_delete_event = AttrDict({
        "_playlistId":
        playlistId,
        "_deletedTrackId":
        deletedTrackId,
        "_deletedTrackTimestamp":
        deletedTrackTimestamp,
    })
    return event_type, AttrDict({
        "blockHash": block_hash,
        "args": playlist_track_delete_event
    })
def test_user_replica_set_indexing_skip_tx(app, mocker):
    """Tests that URSM indexing skips cursed txs without throwing an error and are able to process other tx in block"""
    with app.app_context():
        db = get_db()
        cid_metadata_client = CIDMetadataClient({})
        web3 = Web3()
        challenge_event_bus = setup_challenge_bus()
        update_task = UpdateTask(cid_metadata_client, web3, challenge_event_bus)

    class TestUserReplicaSetTransaction:
        pass

    blessed_user_tx_hash = (
        "0x34004dfaf5bb7cf9998eaf387b877d72d198c6508608e309df3f89e57def4db3"
    )
    blessed_user_tx = TestUserReplicaSetTransaction()
    blessed_user_tx.transactionHash = update_task.web3.toBytes(
        hexstr=blessed_user_tx_hash
    )
    cursed_user_tx_hash = (
        "0x5fe51d735309d3044ae30055ad29101018a1a399066f6c53ea23800225e3a3be"
    )
    cursed_user_tx = TestUserReplicaSetTransaction()
    cursed_user_tx.transactionHash = update_task.web3.toBytes(
        hexstr=cursed_user_tx_hash
    )
    blessed_cnode_tx_hash = (
        "0x42c66d0542383f06e22ef6a235ddba238050d85562bcbd18667c9711c1daee72"
    )
    blessed_cnode_tx = TestUserReplicaSetTransaction()
    blessed_cnode_tx.transactionHash = update_task.web3.toBytes(
        hexstr=blessed_cnode_tx_hash
    )
    cursed_cnode_tx_hash = (
        "0xa022761e229302abc2490f8bdc7ec0e642916b0f5cbc2908ccd49498243c1806"
    )
    cursed_cnode_tx = TestUserReplicaSetTransaction()
    cursed_cnode_tx.transactionHash = update_task.web3.toBytes(
        hexstr=cursed_cnode_tx_hash
    )
    test_block_number = 25278765
    test_block_timestamp = 1
    test_block_hash = update_task.web3.toHex(block_hash)
    test_user_replica_set_mgr_txs = [
        cursed_user_tx,
        blessed_user_tx,
        cursed_cnode_tx,
        blessed_cnode_tx,
    ]
    test_timestamp = datetime.utcfromtimestamp(test_block_timestamp)
    test_wallet = "0x0birbchickemcatlet"
    blessed_user_record = User(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=blessed_user_tx_hash,
        user_id=1,
        name="tobey maguire",
        is_creator=False,
        is_current=True,
        updated_at=test_timestamp,
        created_at=test_timestamp,
    )
    cursed_user_record = User(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=cursed_user_tx_hash,
        user_id=2,
        name="birb",
        is_current=None,
        is_creator=None,
        updated_at=test_timestamp,
        created_at=None,
    )
    blessed_content_node_record = URSMContentNode(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=blessed_cnode_tx_hash,
        is_current=True,
        cnode_sp_id=1,
        delegate_owner_wallet=test_wallet,
        owner_wallet=test_wallet,
        created_at=test_timestamp,
    )
    cursed_content_node_record = URSMContentNode(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=cursed_cnode_tx_hash,
        is_current=None,
        cnode_sp_id=2,
        delegate_owner_wallet=test_wallet,
        created_at=None,
    )

    mocker.patch(
        "src.tasks.user_replica_set.lookup_user_record",
        side_effect=[cursed_user_record, blessed_user_record],
        autospec=True,
    )
    mocker.patch(
        "src.tasks.user_replica_set.lookup_ursm_cnode",
        side_effect=[cursed_content_node_record, blessed_content_node_record],
        autospec=True,
    )
    mocker.patch(
        "src.tasks.user_replica_set.get_endpoint_string_from_sp_ids",
        return_value="http://localhost:4001,http://localhost:4002,",
        autospec=True,
    )
    mocker.patch(
        "src.tasks.user_replica_set.get_ursm_cnode_endpoint",
        return_value="http://localhost:4001,http://localhost:4002,",
        autospec=True,
    )
    mocker.patch(
        # because we do not have the real contract set up in the test
        # we mock the return value of this fn w events parsed from an imaginary tx
        "src.tasks.user_replica_set.get_user_replica_set_mgr_tx",
        side_effect=[
            [
                {
                    "args": AttrDict(
                        {
                            "_userId": cursed_user_record.user_id,
                            "_primaryId": 1,
                            "_secondaryIds": [2, 3, 4],
                            "_signer": "mobey taguire",
                        }
                    )
                },
            ],  # first tx receipt - update replica set
            [],  # first tx receipt - update content node
            [
                {
                    "args": AttrDict(
                        {
                            "_userId": blessed_user_record.user_id,
                            "_primaryId": 1,
                            "_secondaryIds": [2, 3, 4],
                            "_signer": "dirsten kunst",
                        }
                    )
                },
            ],  # second tx receipt - update replica set
            [],  # second tx receipt - update content node
            [],  # third tx receipt - update replica set
            [
                {
                    "args": AttrDict(
                        {
                            "_cnodeSpId": cursed_content_node_record.cnode_sp_id,
                            "_cnodeDelegateOwnerWallet": test_wallet,
                            "_cnodeOwnerWallet": test_wallet,
                            "_proposer1DelegateOwnerWallet": test_wallet,
                            "_proposer2DelegateOwnerWallet": test_wallet,
                            "_proposer3DelegateOwnerWallet": test_wallet,
                            "_proposerSpIds": [1, 2],
                        }
                    )
                },
            ],  # third tx receipt - update content node
            [],  # fourth tx receipt - update replica set
            [
                {
                    "args": AttrDict(
                        {
                            "_cnodeSpId": blessed_content_node_record.cnode_sp_id,
                            "_cnodeDelegateOwnerWallet": test_wallet,
                            "_cnodeOwnerWallet": test_wallet,
                            "_proposer1DelegateOwnerWallet": test_wallet,
                            "_proposer2DelegateOwnerWallet": test_wallet,
                            "_proposer3DelegateOwnerWallet": test_wallet,
                            "_proposerSpIds": [1, 2],
                        }
                    )
                },
            ],  # fourth tx receipt - update content node
        ],
        autospec=True,
    )

    test_ipfs_metadata = {}
    test_blacklisted_cids = {}

    with db.scoped_session() as session:
        try:
            current_block = Block(
                blockhash=test_block_hash,
                parenthash=test_block_hash,
                number=test_block_number,
                is_current=True,
            )
            session.add(current_block)
            (total_changes, updated_user_ids_set) = user_replica_set_state_update(
                update_task,
                update_task,
                session,
                test_user_replica_set_mgr_txs,
                test_block_number,
                test_block_timestamp,
                block_hash,
                test_ipfs_metadata,
                test_blacklisted_cids,
            )
            assert len(updated_user_ids_set) == 1
            assert list(updated_user_ids_set)[0] == blessed_user_record.user_id
            assert total_changes == 2
            assert (
                session.query(SkippedTransaction)
                .filter(
                    SkippedTransaction.txhash == cursed_cnode_tx_hash,
                    SkippedTransaction.level == SkippedTransactionLevel.node,
                )
                .first()
            )
            assert (
                session.query(SkippedTransaction)
                .filter(
                    SkippedTransaction.txhash == cursed_user_tx_hash,
                    SkippedTransaction.level == SkippedTransactionLevel.node,
                )
                .first()
            )
            assert (
                session.query(User)
                .filter(User.user_id == blessed_user_record.user_id)
                .first()
            )
            assert (
                session.query(User)
                .filter(User.user_id == cursed_user_record.user_id)
                .first()
            ) == None
            assert (
                session.query(URSMContentNode)
                .filter(
                    URSMContentNode.cnode_sp_id
                    == blessed_content_node_record.cnode_sp_id
                )
                .first()
            )
            assert (
                session.query(URSMContentNode)
                .filter(
                    URSMContentNode.cnode_sp_id
                    == cursed_content_node_record.cnode_sp_id
                )
                .first()
            ) == None
        except Exception:
            assert False
示例#20
0
def test_user_indexing_skip_tx(bus_mock: mock.MagicMock, app, mocker):
    """Tests that users skip cursed txs without throwing an error and are able to process other tx in block"""
    with app.app_context():
        db = get_db()
        redis = get_redis()
        web3 = Web3()
        bus_mock(redis)
        update_task = DatabaseTask(
            cid_metadata_client=cid_metadata_client,
            web3=web3,
            challenge_event_bus=bus_mock,
            redis=redis,
        )

    class TestUserTransaction:
        def __init__(self):
            self.transactionHash = None

        pass

    blessed_tx_hash = (
        "0x34004dfaf5bb7cf9998eaf387b877d72d198c6508608e309df3f89e57def4db3")
    blessed_tx = TestUserTransaction()
    blessed_tx.transactionHash = update_task.web3.toBytes(
        hexstr=blessed_tx_hash)
    cursed_tx_hash = (
        "0x5fe51d735309d3044ae30055ad29101018a1a399066f6c53ea23800225e3a3be")
    cursed_tx = TestUserTransaction()
    cursed_tx.transactionHash = update_task.web3.toBytes(hexstr=cursed_tx_hash)
    test_block_number = 25278765
    test_block_timestamp = 1
    test_block_hash = update_task.web3.toHex(block_hash)
    test_user_factory_txs = [cursed_tx, blessed_tx]
    test_timestamp = datetime.utcfromtimestamp(test_block_timestamp)
    blessed_user_record = User(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=blessed_tx_hash,
        user_id=91232,
        name="tobey maguire",
        is_creator=False,
        is_current=True,
        updated_at=test_timestamp,
        created_at=test_timestamp,
    )
    cursed_user_record = User(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=cursed_tx_hash,
        user_id=91238,
        name="birbs",
        is_current=None,
        is_creator=None,
        updated_at=test_timestamp,
        created_at=None,
    )

    mocker.patch(
        "src.tasks.users.lookup_user_record",
        side_effect=[cursed_user_record, blessed_user_record],
        autospec=True,
    )
    mocker.patch(
        "src.tasks.users.get_user_events_tx",
        side_effect=[
            [],  # no user added events
            [],
            [
                {
                    "args":
                    AttrDict({
                        "_userId": cursed_user_record.user_id,
                        "_name": cursed_user_record.name.encode("utf-8"),
                    })
                },
            ],  # update name event
            [],
            [],
            [],
            [],
            [],
            [],
            [],
            [],  # second tx receipt
            [],
            [
                {
                    "args":
                    AttrDict({
                        "_userId": blessed_user_record.user_id,
                        "_name": blessed_user_record.name.encode("utf-8"),
                    })
                },
            ],  # update name event
            [],
            [],
            [],
            [],
            [],
            [],
            [],
        ],
        autospec=True,
    )
    test_ipfs_metadata: Dict[str, Any] = {}
    test_blacklisted_cids: Dict[str, Any] = {}

    with db.scoped_session() as session, bus_mock.use_scoped_dispatch_queue():
        try:
            current_block = Block(
                blockhash=test_block_hash,
                parenthash=test_block_hash,
                number=test_block_number,
                is_current=True,
            )
            session.add(current_block)
            (total_changes, updated_user_ids_set) = user_state_update(
                update_task,
                update_task,
                session,
                test_user_factory_txs,
                test_block_number,
                test_block_timestamp,
                block_hash,
                test_ipfs_metadata,
                test_blacklisted_cids,
            )
            assert len(updated_user_ids_set) == 1
            assert list(updated_user_ids_set)[0] == blessed_user_record.user_id
            assert total_changes == 1
            assert (session.query(SkippedTransaction).filter(
                SkippedTransaction.txhash == cursed_user_record.txhash,
                SkippedTransaction.level == SkippedTransactionLevel.node,
            ).first())
            assert (session.query(User).filter(
                User.user_id == blessed_user_record.user_id).first())
            assert (session.query(User).filter(
                User.user_id == cursed_user_record.user_id).first()) == None
        except Exception:
            assert False
def test_playlist_indexing_skip_tx(app, mocker):
    """Tests that playlists skip cursed txs without throwing an error and are able to process other tx in block"""
    with app.app_context():
        db = get_db()
        cid_metadata_client = CIDMetadataClient({})
        web3 = Web3()
        challenge_event_bus = setup_challenge_bus()
        update_task = UpdateTask(cid_metadata_client, web3,
                                 challenge_event_bus)

    class TestPlaylistTransaction:
        pass

    blessed_tx_hash = (
        "0x34004dfaf5bb7cf9998eaf387b877d72d198c6508608e309df3f89e57def4db3")
    blessed_tx = TestPlaylistTransaction()
    blessed_tx.transactionHash = update_task.web3.toBytes(
        hexstr=blessed_tx_hash)
    cursed_tx_hash = (
        "0x5fe51d735309d3044ae30055ad29101018a1a399066f6c53ea23800225e3a3be")
    cursed_tx = TestPlaylistTransaction()
    cursed_tx.transactionHash = update_task.web3.toBytes(hexstr=cursed_tx_hash)
    test_block_number = 25278765
    test_block_timestamp = 1
    test_block_hash = update_task.web3.toHex(block_hash)
    test_playlist_factory_txs = [cursed_tx, blessed_tx]
    test_timestamp = datetime.utcfromtimestamp(test_block_timestamp)
    blessed_playlist_record = Playlist(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=blessed_tx_hash,
        playlist_id=91232,
        is_album=False,
        is_private=False,
        playlist_name="test",
        playlist_contents={},
        playlist_image_multihash=None,
        playlist_image_sizes_multihash=None,
        description="testing!",
        upc=None,
        is_current=True,
        is_delete=True,
        last_added_to=None,
        updated_at=test_timestamp,
        created_at=test_timestamp,
        playlist_owner_id=1,
    )
    cursed_playlist_record = Playlist(
        blockhash=test_block_hash,
        blocknumber=test_block_number,
        txhash=cursed_tx_hash,
        playlist_id=91238,
        is_album=None,
        is_private=None,
        playlist_name=None,
        playlist_image_multihash=None,
        playlist_image_sizes_multihash=None,
        description=None,
        upc=None,
        is_current=True,
        is_delete=True,
        last_added_to=None,
        updated_at=test_timestamp,
        created_at=None,
    )

    mocker.patch(
        "src.tasks.playlists.lookup_playlist_record",
        side_effect=[cursed_playlist_record, blessed_playlist_record],
        autospec=True,
    )
    mocker.patch(
        "src.tasks.playlists.get_playlist_events_tx",
        side_effect=[
            [],  # no playlist created events
            [
                {
                    "args":
                    AttrDict({
                        "_playlistId": cursed_playlist_record.playlist_id,
                    })
                },
            ],  # playlist deleted event
            [],
            [],
            [],
            [],
            [],
            [],
            [],
            [],
            [],  # second tx receipt
            [
                {
                    "args":
                    AttrDict({
                        "_playlistId":
                        blessed_playlist_record.playlist_id,
                    })
                },
            ],  # playlist deleted event
            [],
            [],
            [],
            [],
            [],
            [],
            [],
            [],
        ],
        autospec=True,
    )
    test_ipfs_metadata = {}
    test_blacklisted_cids = {}

    with db.scoped_session() as session:
        try:
            current_block = Block(
                blockhash=test_block_hash,
                parenthash=test_block_hash,
                number=test_block_number,
                is_current=True,
            )
            session.add(current_block)
            (total_changes, updated_playlist_ids_set) = playlist_state_update(
                update_task,
                update_task,
                session,
                test_playlist_factory_txs,
                test_block_number,
                test_block_timestamp,
                block_hash,
                test_ipfs_metadata,
                test_blacklisted_cids,
            )
            assert len(updated_playlist_ids_set) == 1
            assert (list(updated_playlist_ids_set)[0] ==
                    blessed_playlist_record.playlist_id)
            assert total_changes == 1
            assert (session.query(SkippedTransaction).filter(
                SkippedTransaction.txhash == cursed_playlist_record.txhash,
                SkippedTransaction.level == SkippedTransactionLevel.node,
            ).first())
            assert (session.query(Playlist).filter(
                Playlist.playlist_id ==
                blessed_playlist_record.playlist_id).first())
            assert (session.query(Playlist).filter(
                Playlist.playlist_id ==
                cursed_playlist_record.playlist_id).first()) == None
        except Exception:
            assert False