Example #1
0
def payment_path(request):

    cost = 1
    path = []
    value = 1
    fee_payer = request.param

    return PaymentPath(cost, path, value, fee_payer=fee_payer)
Example #2
0
def test_close_trustline_zero_balance(
        complex_community_with_trustlines_and_fees):
    """H owes money to C and C wants to close the trustline"""
    result = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        timestamp=int(time.time()), source=C, target=H)
    assert result == PaymentPath(fee=0,
                                 path=[],
                                 value=0,
                                 fee_payer=FeePayer.SENDER)
Example #3
0
def test_close_trustline_multi(complex_community_with_trustlines_and_fees):
    """A owes money to H and A wants to close the trustline"""
    complex_community_with_trustlines_and_fees.update_balance(A, H, -5000)
    result = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        timestamp=int(time.time()), source=A, target=H)
    assert result in [
        PaymentPath(
            fee=315,
            path=[A, B, D, E, F, G, H, A],
            value=5000,
            fee_payer=FeePayer.SENDER,
        ),
        PaymentPath(
            fee=315,
            path=[A, C, D, E, F, G, H, A],
            value=5000,
            fee_payer=FeePayer.SENDER,
        ),
    ]
Example #4
0
def test_close_trustline_negative_balance(
        complex_community_with_trustlines_and_fees):
    """C owes money to H and C wants to close the trustline"""
    complex_community_with_trustlines_and_fees.update_balance(C, H, -5000)
    result = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        timestamp=int(time.time()), source=C, target=H)
    assert result == PaymentPath(fee=261,
                                 path=[C, D, E, F, G, H, C],
                                 value=5000,
                                 fee_payer=FeePayer.SENDER)
Example #5
0
def test_close_trustline_positive_balance(
        complex_community_with_trustlines_and_fees):
    """H owes money to C and C wants to close the trustline"""
    complex_community_with_trustlines_and_fees.update_balance(C, H, 5000)
    result = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        timestamp=int(time.time()), source=C, target=H)
    assert result == PaymentPath(fee=198,
                                 path=[C, H, G, F, E, D, C],
                                 value=5000,
                                 fee_payer=FeePayer.RECEIVER)
Example #6
0
def test_close_trustline_target_not_in_graph(balances_community,
                                             address_not_used_in_graphs):
    """Test that we do not have an error when querying for a close path to an unknown address"""
    now = int(time.time())
    payment_path = balances_community.close_trustline_path_triangulation(
        now, A, address_not_used_in_graphs)
    assert payment_path == PaymentPath(fee=0,
                                       path=[],
                                       value=0,
                                       fee_payer=FeePayer.SENDER)
Example #7
0
def test_close_trustline_with_cost_exact_amount(
        complex_community_with_trustlines_and_fees):
    """A owes money to B and A wants to close the trustline"""
    complex_community_with_trustlines_and_fees.update_balance(
        A, B, -10000)  # amount B owes A
    complex_community_with_trustlines_and_fees.update_balance(A, C, -10000)
    complex_community_with_trustlines_and_fees.update_balance(B, D, 10000)
    complex_community_with_trustlines_and_fees.update_balance(C, D, -10000)
    result = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        timestamp=int(time.time()), source=A, target=B)
    assert result == PaymentPath(fee=309,
                                 path=[A, C, D, B, A],
                                 value=10000,
                                 fee_payer=FeePayer.SENDER)
Example #8
0
def test_close_trustline_not_enough_capacity(
        complex_community_with_trustlines_and_fees):
    """A owes money to B and A wants to reduce that amount with the help of C"""
    complex_community_with_trustlines_and_fees.update_balance(
        A, B, -100000)  # amount B owes A
    complex_community_with_trustlines_and_fees.update_balance(A, C, 10000)
    complex_community_with_trustlines_and_fees.update_balance(B, D, -10000)
    complex_community_with_trustlines_and_fees.update_balance(C, D, 10000)
    now = int(time.time())
    payment_path = complex_community_with_trustlines_and_fees.close_trustline_path_triangulation(
        now, A, B)
    assert payment_path == PaymentPath(fee=0,
                                       path=[],
                                       value=100000,
                                       fee_payer=FeePayer.SENDER)
Example #9
0
    def post(self, args, network_address: str):
        abort_if_unknown_or_frozen_network(self.trustlines, network_address)
        timestamp = int(time.time())

        source = args["from"]
        target = args["to"]
        value = args["value"]
        max_fees = args["maxFees"]
        max_hops = args["maxHops"]
        fee_payer = FeePayer(args["feePayer"])

        if fee_payer == FeePayer.SENDER:
            cost, path = self.trustlines.currency_network_graphs[
                network_address].find_transfer_path_sender_pays_fees(
                    source=source,
                    target=target,
                    value=value,
                    max_fees=max_fees,
                    max_hops=max_hops,
                    timestamp=timestamp,
                )
        elif fee_payer == FeePayer.RECEIVER:
            cost, path = self.trustlines.currency_network_graphs[
                network_address].find_transfer_path_receiver_pays_fees(
                    source=source,
                    target=target,
                    value=value,
                    max_fees=max_fees,
                    max_hops=max_hops,
                    timestamp=timestamp,
                )
        else:
            raise ValueError(
                f"feePayer has to be one of {[fee_payer.name for fee_payer in FeePayer]}: {fee_payer}"
            )

        return PaymentPath(cost, path, value, fee_payer=fee_payer)
Example #10
0
 def make_payment_path(self, data, partial, many):
     return PaymentPath(**data)