Пример #1
0
def run_test_mediated_transfer_with_node_consuming_more_than_allocated_fee(
        raiden_network, number_of_nodes, deposit, token_addresses,
        network_wait):
    app0, app1, app2 = raiden_network
    token_address = token_addresses[0]
    chain_state = views.state_from_app(app0)
    payment_network_id = app0.raiden.default_registry.address
    token_network_identifier = views.get_token_network_identifier_by_token_address(
        chain_state, payment_network_id, token_address)
    fee = 5
    amount = 10

    app1_app2_channel_state = views.get_channelstate_by_token_network_and_partner(
        chain_state=views.state_from_raiden(app1.raiden),
        token_network_id=token_network_identifier,
        partner_address=app2.raiden.address,
    )

    # Let app1 consume all of the allocated mediation fee
    action_set_fee = ActionChannelSetFee(
        canonical_identifier=app1_app2_channel_state.canonical_identifier,
        mediation_fee=fee * 2)

    app1.raiden.handle_state_change(state_change=action_set_fee)

    secret = factories.make_secret(0)
    secrethash = sha3(secret)

    wait_message_handler = WaitForMessage()
    app0.raiden.message_handler = wait_message_handler
    secret_request_received = wait_message_handler.wait_for_message(
        SecretRequest, {"secrethash": secrethash})

    app0.raiden.start_mediated_transfer_with_secret(
        token_network_identifier=token_network_identifier,
        amount=amount,
        fee=fee,
        target=app2.raiden.address,
        identifier=1,
        payment_hash_invoice=EMPTY_PAYMENT_HASH_INVOICE,
        secret=secret,
    )

    app0_app1_channel_state = views.get_channelstate_by_token_network_and_partner(
        chain_state=views.state_from_raiden(app0.raiden),
        token_network_id=token_network_identifier,
        partner_address=app1.raiden.address,
    )

    msg = "App0 should have the transfer in secrethashes_to_lockedlocks"
    assert secrethash in app0_app1_channel_state.our_state.secrethashes_to_lockedlocks, msg

    msg = "App0 should have locked the amount + fee"
    lock_amount = app0_app1_channel_state.our_state.secrethashes_to_lockedlocks[
        secrethash].amount
    assert lock_amount == amount + fee, msg

    secret_request_received.wait()

    app0_chain_state = views.state_from_app(app0)
    initiator_task = app0_chain_state.payment_mapping.secrethashes_to_task[
        secrethash]

    msg = "App0 should have never revealed the secret"
    assert initiator_task.manager_state.initiator_transfers[
        secrethash].revealsecret is None
Пример #2
0
def run_test_mediated_transfer_with_allocated_fee(raiden_network,
                                                  number_of_nodes, deposit,
                                                  token_addresses,
                                                  network_wait):
    app0, app1, app2, app3 = raiden_network
    token_address = token_addresses[0]
    chain_state = views.state_from_app(app0)
    payment_network_id = app0.raiden.default_registry.address
    token_network_identifier = views.get_token_network_identifier_by_token_address(
        chain_state, payment_network_id, token_address)
    fee = 5
    amount = 10

    transfer(
        initiator_app=app0,
        target_app=app3,
        token_address=token_address,
        amount=amount,
        identifier=1,
        fee=fee,
        timeout=network_wait * number_of_nodes,
    )

    with gevent.Timeout(network_wait):
        wait_assert(
            assert_synced_channel_state,
            token_network_identifier,
            app0,
            deposit - amount - fee,
            [],
            app1,
            deposit + amount + fee,
            [],
        )
    with gevent.Timeout(network_wait):
        wait_assert(
            assert_synced_channel_state,
            token_network_identifier,
            app1,
            deposit - amount - fee,
            [],
            app2,
            deposit + amount + fee,
            [],
        )

    app1_app2_channel_state = views.get_channelstate_by_token_network_and_partner(
        chain_state=views.state_from_raiden(app1.raiden),
        token_network_id=token_network_identifier,
        partner_address=app2.raiden.address,
    )

    # Let app1 consume all of the allocated mediation fee
    action_set_fee = ActionChannelSetFee(
        canonical_identifier=app1_app2_channel_state.canonical_identifier,
        mediation_fee=fee)

    app1.raiden.handle_state_change(state_change=action_set_fee)

    transfer(
        initiator_app=app0,
        target_app=app3,
        token_address=token_address,
        amount=amount,
        identifier=2,
        fee=fee,
        timeout=network_wait * number_of_nodes,
    )

    # The fees have been consumed exclusively by app1
    with gevent.Timeout(network_wait):
        wait_assert(
            assert_synced_channel_state,
            token_network_identifier,
            app0,
            deposit - 2 * (amount + fee),
            [],
            app1,
            deposit + 2 * (amount + fee),
            [],
        )

    # app2's poor soul gets no mediation fees on the second transfer.
    # Only the first transfer had a fee which was paid to app2 though
    # app2 doesn't set its fee but it would still receive the complete
    # locked amount = transfer amount + fee.
    # However app1 received from app0 two transfers
    # which it sent to app2. The first transfer
    # to app2 included the fee as it did not deduct
    # any fee (the channel's fee was 0).
    # The second transfer's fee was deducted by
    # app1 (provided we've set the fee of the channel)
    with gevent.Timeout(network_wait):
        wait_assert(
            assert_synced_channel_state,
            token_network_identifier,
            app1,
            deposit - (amount * 2) - fee,
            [],
            app2,
            deposit + (amount * 2) + fee,
            [],
        )