Beispiel #1
0
def test_inplace_delete_message_queue(chain_state):
    sender = factories.make_address()
    canonical_identifier = factories.make_canonical_identifier()
    message_id = factories.make_message_identifier()
    delivered_state_change = ReceiveDelivered(sender=sender,
                                              message_identifier=message_id)
    processed_state_change = ReceiveProcessed(sender=sender,
                                              message_identifier=message_id)

    global_identifier = QueueIdentifier(
        recipient=sender,
        canonical_identifier=CANONICAL_IDENTIFIER_GLOBAL_QUEUE)

    chain_state.queueids_to_queues[global_identifier] = None
    assert global_identifier in chain_state.queueids_to_queues, "queue mapping insertion failed"
    inplace_delete_message_queue(chain_state=chain_state,
                                 state_change=delivered_state_change,
                                 queueid=global_identifier)
    assert global_identifier not in chain_state.queueids_to_queues, "did not clear queue"

    chain_state.queueids_to_queues[global_identifier] = [
        SendMessageEvent(
            recipient=sender,
            canonical_identifier=canonical_identifier,
            message_identifier=message_id,
        )
    ]
    assert global_identifier in chain_state.queueids_to_queues, "queue mapping insertion failed"
    handle_receive_delivered(chain_state=chain_state,
                             state_change=delivered_state_change)
    assert global_identifier not in chain_state.queueids_to_queues, "did not clear queue"

    queue_identifier = QueueIdentifier(
        recipient=sender, canonical_identifier=canonical_identifier)
    assert queue_identifier not in chain_state.queueids_to_queues, "queue not empty"
    chain_state.queueids_to_queues[queue_identifier] = [
        SendMessageEvent(
            recipient=sender,
            canonical_identifier=canonical_identifier,
            message_identifier=message_id,
        )
    ]
    assert queue_identifier in chain_state.queueids_to_queues, "queue mapping not mutable"
    handle_receive_processed(chain_state=chain_state,
                             state_change=processed_state_change)
    assert queue_identifier not in chain_state.queueids_to_queues, "queue did not clear"
Beispiel #2
0
def test_withdraw_request_message_cleanup(chain_id, token_network_state):
    pseudo_random_generator = random.Random()
    block_number = 10
    our_address = factories.make_address()
    recipient1 = factories.make_address()
    recipient2 = factories.make_address()
    channel_identifier = 1
    message_identifier = random.randint(0, 2**16)

    chain_state = state.ChainState(
        pseudo_random_generator=pseudo_random_generator,
        block_number=block_number,
        block_hash=factories.make_block_hash(),
        our_address=our_address,
        chain_id=chain_id,
    )
    queue_identifier = QueueIdentifier(recipient1,
                                       CANONICAL_IDENTIFIER_GLOBAL_QUEUE)

    withdraw_message = SendWithdrawRequest(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        participant=our_address,
        recipient=recipient1,
        nonce=1,
        expiration=10,
    )

    chain_state.queueids_to_queues[queue_identifier] = [withdraw_message]
    processed_message = state_change.ReceiveProcessed(recipient1,
                                                      message_identifier)

    iteration = node.handle_receive_processed(chain_state, processed_message)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])

    # Processed should not have removed the WithdrawRequest message
    assert withdraw_message in new_queue

    receive_withdraw = ReceiveWithdrawConfirmation(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        signature=factories.make_32bytes(),
        sender=recipient2,
        participant=recipient2,
        nonce=1,
        expiration=10,
    )
    iteration = node.handle_receive_withdraw_confirmation(
        chain_state, receive_withdraw)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])

    # ReceiveWithdraw from another recipient should not remove the WithdrawRequest
    assert withdraw_message in new_queue

    receive_withdraw = ReceiveWithdrawConfirmation(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        signature=factories.make_32bytes(),
        sender=recipient1,
        participant=recipient1,
        nonce=1,
        expiration=10,
    )
    iteration = node.handle_receive_withdraw_confirmation(
        chain_state, receive_withdraw)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])
    assert withdraw_message not in new_queue