Ejemplo n.º 1
0
 def test_payment(iou, service_fee=TokenAmount(1)):
     process_payment(
         iou,
         pfs,
         service_fee=service_fee,
         one_to_n_address=decode_hex(one_to_n_contract.address),
     )
Ejemplo n.º 2
0
 def test_payment(iou, service_fee=TokenAmount(1)):
     process_payment(
         iou=iou,
         pathfinding_service=pfs,
         service_fee=service_fee,
         one_to_n_address=to_canonical_address(one_to_n_contract.address),
     )
Ejemplo n.º 3
0
def test_process_payment_errors(pathfinding_service_web3_mock, web3,
                                deposit_to_udc, create_account,
                                get_private_key):
    pfs = pathfinding_service_web3_mock
    pfs.service_fee = 1
    sender = create_account()
    privkey = get_private_key(sender)

    # expires too early
    iou = make_iou(privkey,
                   pfs.address,
                   expiration_block=web3.eth.blockNumber + 5)
    with pytest.raises(exceptions.IOUExpiredTooEarly):
        process_payment(iou, pfs)

    # it fails it the no deposit is in the UDC
    iou = make_iou(privkey, pfs.address)
    with pytest.raises(exceptions.DepositTooLow):
        process_payment(iou, pfs)

    # must succeed if we add enough deposit to UDC
    deposit_to_udc(sender, 10)
    iou = make_iou(privkey, pfs.address)
    process_payment(iou, pfs)

    # wrong recipient
    iou = make_iou(privkey, get_random_address())
    with pytest.raises(exceptions.WrongIOURecipient):
        process_payment(iou, pfs)

    # payment too low
    pfs.service_fee = 2
    iou = make_iou(privkey, pfs.address)
    with pytest.raises(exceptions.InsufficientServicePayment):
        process_payment(iou, pfs)
Ejemplo n.º 4
0
def test_process_payment(
    pathfinding_service_web3_mock,
    deposit_to_udc,
    create_account,
    get_private_key,
    make_iou,
    one_to_n_contract,
):
    pfs = pathfinding_service_web3_mock
    service_fee = TokenAmount(1)
    sender = create_account()
    privkey = get_private_key(sender)
    deposit_to_udc(sender, round(1 * UDC_SECURITY_MARGIN_FACTOR))
    one_to_n_address = decode_hex(one_to_n_contract.address)

    # Make payment
    iou = make_iou(privkey, pfs.address, amount=1)
    process_payment(iou, pfs, service_fee, one_to_n_address)

    # The same payment can't be reused
    with pytest.raises(exceptions.InsufficientServicePayment):
        process_payment(iou, pfs, service_fee, one_to_n_address)

    # Increasing the amount would make the payment work again, if we had enough
    # deposit. But we set the deposit one token too low.
    deposit_to_udc(sender, round(2 * UDC_SECURITY_MARGIN_FACTOR) - 1)
    iou = make_iou(privkey, pfs.address, amount=2)
    with pytest.raises(exceptions.DepositTooLow):
        process_payment(iou, pfs, service_fee, one_to_n_address)

    # With the higher amount and enough deposit, it works again!
    deposit_to_udc(sender, round(2 * UDC_SECURITY_MARGIN_FACTOR))
    iou = make_iou(privkey, pfs.address, amount=2)
    process_payment(iou, pfs, service_fee, one_to_n_address)

    # Make sure the client does not create new sessions unnecessarily
    iou = make_iou(privkey, pfs.address, expiration_block=20000)
    with pytest.raises(exceptions.UseThisIOU):
        process_payment(iou, pfs, service_fee, one_to_n_address)

    # Complain if the IOU has been claimed
    iou = make_iou(privkey, pfs.address, amount=3)
    pfs.database.conn.execute("UPDATE iou SET claimed=1")
    with pytest.raises(exceptions.IOUAlreadyClaimed):
        process_payment(iou, pfs, service_fee, one_to_n_address)
Ejemplo n.º 5
0
def test_process_payment(
    pathfinding_service_web3_mock,
    deposit_to_udc,
    create_account,
    get_private_key,
    make_iou,
    one_to_n_contract,
    web3,
):
    pfs = pathfinding_service_web3_mock
    service_fee = TokenAmount(1)
    sender = create_account()
    privkey = get_private_key(sender)
    deposit_to_udc(sender, round(1 * UDC_SECURITY_MARGIN_FACTOR_PFS))
    web3.testing.mine(pathfinding_service_web3_mock.required_confirmations)
    one_to_n_address = to_canonical_address(one_to_n_contract.address)

    # Make payment
    iou = make_iou(privkey, pfs.address, amount=1)
    process_payment(iou, pfs, service_fee, one_to_n_address)

    # The same payment can't be reused
    with pytest.raises(exceptions.InsufficientServicePayment):
        process_payment(iou, pfs, service_fee, one_to_n_address)

    # Increasing the amount would make the payment work again, if we had enough
    # deposit. But we set the deposit one token too low.
    deposit_to_udc(sender, round(2 * UDC_SECURITY_MARGIN_FACTOR_PFS) - 1)
    iou = make_iou(privkey, pfs.address, amount=2)
    with pytest.raises(exceptions.DepositTooLow) as tb:
        process_payment(iou, pfs, service_fee, one_to_n_address)
    assert tb.value.error_details[
        "required_deposit"] == 2 * UDC_SECURITY_MARGIN_FACTOR_PFS
    assert tb.value.error_details[
        "seen_deposit"] == 1 * UDC_SECURITY_MARGIN_FACTOR_PFS
    assert tb.value.error_details["block_number"] == web3.eth.blockNumber

    # With the higher amount and enough deposit, it works again!
    deposit_to_udc(sender, round(2 * UDC_SECURITY_MARGIN_FACTOR_PFS))
    web3.testing.mine(pathfinding_service_web3_mock.required_confirmations)
    iou = make_iou(privkey, pfs.address, amount=2)
    process_payment(iou, pfs, service_fee, one_to_n_address)

    # Make sure the client does not create new sessions unnecessarily
    iou = make_iou(privkey, pfs.address, expiration_block=20000)
    with pytest.raises(exceptions.UseThisIOU):
        process_payment(iou, pfs, service_fee, one_to_n_address)

    # Complain if the IOU has been claimed
    iou = make_iou(privkey, pfs.address, amount=3)
    pfs.database.conn.execute("UPDATE iou SET claimed=1")
    with pytest.raises(exceptions.IOUAlreadyClaimed):
        process_payment(iou, pfs, service_fee, one_to_n_address)