Beispiel #1
0
def test_saveing_multiple_channel(ms_database: Database):
    ms_database.conn.execute(
        "INSERT INTO token_network (address, settle_timeout) VALUES (?, ?)",
        [
            to_checksum_address(DEFAULT_TOKEN_NETWORK_ADDRESS),
            DEFAULT_TOKEN_NETWORK_SETTLE_TIMEOUT
        ],
    )
    tn_address2 = make_token_network_address()
    ms_database.conn.execute(
        "INSERT INTO token_network (address, settle_timeout) VALUES (?, ?)",
        [
            to_checksum_address(tn_address2),
            DEFAULT_TOKEN_NETWORK_SETTLE_TIMEOUT
        ],
    )

    channel1 = create_channel()
    channel2 = create_channel()
    channel2.token_network_address = tn_address2

    ms_database.upsert_channel(channel1)
    loaded_channel1 = ms_database.get_channel(
        token_network_address=channel1.token_network_address,
        channel_id=channel1.identifier)
    assert loaded_channel1 == channel1
    assert ms_database.channel_count() == 1

    ms_database.upsert_channel(channel2)
    loaded_channel2 = ms_database.get_channel(
        token_network_address=channel2.token_network_address,
        channel_id=channel2.identifier)
    assert loaded_channel2 == channel2
    assert ms_database.channel_count() == 2
Beispiel #2
0
def test_purge_old_monitor_requests(
    ms_database: Database,
    build_request_monitoring,
    request_collector,
    monitoring_service: MonitoringService,
):
    # We'll test the purge on MRs for three different channels
    req_mons = [
        build_request_monitoring(channel_id=1),
        build_request_monitoring(channel_id=2),
        build_request_monitoring(channel_id=3),
    ]
    for req_mon in req_mons:
        request_collector.on_monitor_request(req_mon)

    # Channel 1 exists in the db
    token_network_address = req_mons[0].balance_proof.token_network_address
    ms_database.conn.execute(
        "INSERT INTO token_network VALUES (?, ?)",
        [
            to_checksum_address(token_network_address),
            DEFAULT_TOKEN_NETWORK_SETTLE_TIMEOUT
        ],
    )
    ms_database.upsert_channel(
        Channel(
            identifier=ChannelID(1),
            token_network_address=token_network_address,
            participant1=Address(b"1" * 20),
            participant2=Address(b"2" * 20),
        ))

    # The request for channel 2 is recent (default), but the one for channel 3
    # has been added 16 minutes ago.
    saved_at = (datetime.utcnow() - timedelta(minutes=16)).timestamp()
    ms_database.conn.execute(
        """
        UPDATE monitor_request
        SET saved_at = ?
        WHERE channel_identifier = ?
        """,
        [saved_at, hex256(3)],
    )

    monitoring_service._purge_old_monitor_requests()  # pylint: disable=protected-access
    remaining_mrs = ms_database.conn.execute("""
        SELECT channel_identifier, waiting_for_channel
        FROM monitor_request ORDER BY channel_identifier
        """).fetchall()
    assert [tuple(mr) for mr in remaining_mrs] == [(1, False), (2, True)]
Beispiel #3
0
def test_save_and_load_channel(ms_database: Database):
    ms_database.conn.execute(
        "INSERT INTO token_network (address) VALUES (?)",
        [to_checksum_address(DEFAULT_TOKEN_NETWORK_ADDRESS)],
    )
    for update_status in [
            None,
            OnChainUpdateStatus(update_sender_address=Address(bytes([1] * 20)),
                                nonce=random.randint(0, UINT256_MAX)),
    ]:
        channel = create_channel(update_status)
        ms_database.upsert_channel(channel)
        loaded_channel = ms_database.get_channel(
            token_network_address=channel.token_network_address,
            channel_id=channel.identifier)
        assert loaded_channel == channel