Exemple #1
0
def test_get_event_feed_trustline_update(
    currency_network: CurrencyNetworkProxy,
    wait_for_ethindex_to_sync,
    accounts,
    generic_db_connection,
):
    from_ = accounts[0]
    to = accounts[1]
    creditline_given = 100
    creditline_received = 200
    interest_rate_given = 1
    interest_rate_received = 2
    currency_network.update_trustline_with_accept(
        from_,
        to,
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
    )
    wait_for_ethindex_to_sync()
    feed_updates = get_graph_updates_feed(generic_db_connection)
    assert len(feed_updates) == 1
    update = feed_updates[0]
    assert type(update) == TrustlineUpdateFeedUpdate
    update = cast(TrustlineUpdateFeedUpdate, update)
    assert update.from_ == from_
    assert update.to == to
    assert update.creditline_received == creditline_received
    assert update.creditline_given == creditline_given
    assert update.interest_rate_given == interest_rate_given
    assert update.interest_rate_received == interest_rate_received
Exemple #2
0
def test_get_total_sum_transferred_with_noise(
    ethindex_db_for_currency_network_with_trustlines,
    currency_network_with_trustlines_session: CurrencyNetworkProxy,
    accounts,
    wait_for_ethindex_to_sync,
):

    sender = accounts[1]
    receiver = accounts[3]
    value = 11

    currency_network_with_trustlines_session.transfer_on_path(
        value,
        path=[accounts[0], accounts[1], accounts[2], accounts[3], accounts[4]])
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[accounts[0], accounts[1], accounts[2], accounts[3]])
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[accounts[1], accounts[2], accounts[3], accounts[4]])
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[receiver, accounts[2], sender])
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[sender, accounts[2], receiver])

    wait_for_ethindex_to_sync()
    sum = EventsInformationFetcher(
        ethindex_db_for_currency_network_with_trustlines
    ).get_total_sum_transferred(sender, receiver)

    assert sum == value
Exemple #3
0
def test_get_event_feed_reversed_trustline_update_to_empty(
    currency_network: CurrencyNetworkProxy,
    wait_for_ethindex_to_sync,
    accounts,
    generic_db_connection,
    chain,
    replace_blocks_with_empty_from_snapshot,
):
    """Test that if the chain reverts, we get a new information in the feed informing that the trustline is null"""
    from_ = accounts[0]
    to = accounts[1]
    creditline_given = 100
    creditline_received = 200
    interest_rate_given = 1
    interest_rate_received = 2
    snapshot = chain.take_snapshot()
    currency_network.update_trustline_with_accept(
        from_,
        to,
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
    )
    wait_for_ethindex_to_sync()

    replace_blocks_with_empty_from_snapshot(snapshot)
    wait_for_ethindex_to_sync()

    feed_updates = get_graph_updates_feed(generic_db_connection)
    print("feed updates")
    for update in feed_updates:
        print(update)
        print()

    assert len(feed_updates) == 2
    update = feed_updates[0]
    assert type(update) == TrustlineUpdateFeedUpdate
    update = cast(TrustlineUpdateFeedUpdate, update)
    assert update.from_ == from_
    assert update.to == to
    assert update.creditline_received == creditline_received
    assert update.creditline_given == creditline_given
    assert update.interest_rate_given == interest_rate_given
    assert update.interest_rate_received == interest_rate_received

    second_update = feed_updates[1]
    assert type(second_update) == TrustlineUpdateFeedUpdate
    second_update = cast(TrustlineUpdateFeedUpdate, second_update)
    assert second_update.from_ == from_
    assert second_update.to == to
    assert second_update.creditline_received == 0
    assert second_update.creditline_given == 0
    assert second_update.interest_rate_given == 0
    assert second_update.interest_rate_received == 0
Exemple #4
0
def test_get_event_feed_replaced_trustline_update(
    currency_network: CurrencyNetworkProxy,
    wait_for_ethindex_to_sync,
    accounts,
    generic_db_connection,
    chain,
):
    """Test that if the chain reverts replacing the trustline update, we get information about the new trustline"""
    from_ = accounts[0]
    to = accounts[1]
    creditline_given = 100
    creditline_received = 200
    interest_rate_given = 1
    interest_rate_received = 2
    snapshot = chain.take_snapshot()
    currency_network.update_trustline_with_accept(
        from_,
        to,
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
    )
    wait_for_ethindex_to_sync()

    chain.revert_to_snapshot(snapshot)
    currency_network.update_trustline_with_accept(
        from_,
        to,
        2 * creditline_given,
        2 * creditline_received,
        2 * interest_rate_given,
        2 * interest_rate_received,
    )
    chain.mine_block()
    wait_for_ethindex_to_sync()

    feed_updates = get_graph_updates_feed(generic_db_connection)

    update = feed_updates[len(feed_updates) - 1]
    assert type(update) == TrustlineUpdateFeedUpdate
    update = cast(TrustlineUpdateFeedUpdate, update)
    assert update.from_ == from_
    assert update.to == to
    assert update.creditline_received == 2 * creditline_received
    assert update.creditline_given == 2 * creditline_given
    assert update.interest_rate_given == 2 * interest_rate_given
    assert update.interest_rate_received == 2 * interest_rate_received
Exemple #5
0
def test_sync_with_reordering_of_events(
    currency_network_with_trustlines_and_interests_session:
    CurrencyNetworkProxy,
    wait_for_ethindex_to_sync,
    accounts,
    generic_db_connection,
    chain,
):
    """Test that if we have a reordering of events with the same values, we still get a correct graph from syncing"""

    currency_network = currency_network_with_trustlines_and_interests_session
    feed_graph = Graph(
        currency_network.capacity_imbalance_fee_divisor,
        currency_network.default_interest_rate,
        currency_network.custom_interests,
        currency_network.prevent_mediator_interests,
    )

    from_ = accounts[0]
    to = accounts[1]
    credit_limit_1 = 1_000_000
    credit_limit_2 = 2_000_000

    time_1 = 2_000_000_000

    snapshot = chain.take_snapshot()
    chain.time_travel(time_1)

    currency_network_with_trustlines_and_interests_session.update_trustline_with_accept(
        from_, to, credit_limit_1, credit_limit_1)
    currency_network_with_trustlines_and_interests_session.update_trustline_with_accept(
        from_, to, credit_limit_2, credit_limit_2)

    wait_for_ethindex_to_sync()

    chain.revert_to_snapshot(snapshot)
    chain.time_travel(time_1)
    currency_network_with_trustlines_and_interests_session.update_trustline_with_accept(
        from_, to, credit_limit_2, credit_limit_2)
    currency_network_with_trustlines_and_interests_session.update_trustline_with_accept(
        from_, to, credit_limit_1, credit_limit_1)

    chain.mine_block()
    wait_for_ethindex_to_sync()

    feed_updates = get_graph_updates_feed(generic_db_connection)
    feed_graph.apply_feed_updates_on_graph(feed_updates)
    trustline_data = feed_graph.graph.get_edge_data(from_, to)

    assert trustline_data["creditline_ab"] == credit_limit_1
    assert trustline_data["creditline_ba"] == credit_limit_1
Exemple #6
0
def test_get_total_sum_transferred_time_window(
    ethindex_db_for_currency_network_with_trustlines,
    currency_network_with_trustlines_session: CurrencyNetworkProxy,
    accounts,
    wait_for_ethindex_to_sync,
    chain,
):

    sender = accounts[0]
    receiver = accounts[1]
    value = 11
    start_time = 2_000_000_000
    end_time = 2_100_000_000

    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[sender, receiver])
    chain.time_travel(start_time)
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[sender, receiver])
    chain.time_travel(end_time + 1)
    currency_network_with_trustlines_session.transfer_on_path(
        value, path=[sender, receiver])

    wait_for_ethindex_to_sync()
    sum = EventsInformationFetcher(
        ethindex_db_for_currency_network_with_trustlines
    ).get_total_sum_transferred(sender, receiver, start_time, end_time)

    assert sum == value
Exemple #7
0
def test_get_total_sum_transferred_multi_transfer(
    ethindex_db_for_currency_network_with_trustlines,
    currency_network_with_trustlines_session: CurrencyNetworkProxy,
    accounts,
    wait_for_ethindex_to_sync,
):

    sender = accounts[0]
    receiver = accounts[1]
    value = 11
    number_transfer = 5

    for x in range(number_transfer):
        currency_network_with_trustlines_session.transfer_on_path(
            value, path=[sender, receiver])

    wait_for_ethindex_to_sync()
    sum = EventsInformationFetcher(
        ethindex_db_for_currency_network_with_trustlines
    ).get_total_sum_transferred(sender, receiver)

    assert sum == value * number_transfer
Exemple #8
0
def test_get_total_sum_transferred_trustline_update(
    ethindex_db_for_currency_network,
    currency_network: CurrencyNetworkProxy,
    accounts,
    wait_for_ethindex_to_sync,
):
    """Test getting the sum transferred for transfer occurring while opening a trustline"""
    sender = accounts[0]
    receiver = accounts[1]
    value = 123

    currency_network.update_trustline_with_accept(
        sender,
        receiver,
        12345,
        12345,
        0,
        0,
        False,
        value,
    )
    currency_network.settle_and_close_trustline(sender, receiver)
    currency_network.update_trustline_with_accept(
        sender,
        receiver,
        12345,
        12345,
        0,
        0,
        False,
        -value,
    )

    wait_for_ethindex_to_sync()
    sum = EventsInformationFetcher(
        ethindex_db_for_currency_network).get_total_sum_transferred(
            sender, receiver)

    assert sum == value