Esempio n. 1
0
def test_cancel_transfer():
    identifier = 1
    amount = factories.UNIT_TRANSFER_AMOUNT
    block_number = 1
    mediator_address = factories.HOP1
    target_address = factories.HOP2
    our_address = factories.ADDR

    routes = [
        factories.make_route(mediator_address, available_balance=amount),
    ]

    current_state = make_initiator_state(
        routes,
        target_address,
        block_number=block_number,
        our_address=our_address,
        secret_generator=SequenceGenerator(),
        identifier=identifier,
    )

    state_change = ActionCancelTransfer(identifier=identifier)

    initiator_state_machine = StateManager(
        initiator.state_transition,
        current_state,
    )
    assert initiator_state_machine.current_state is not None

    events = initiator_state_machine.dispatch(state_change)
    assert len(events) == 1
    assert isinstance(events[0], EventTransferSentFailed)
    assert initiator_state_machine.current_state is None
Esempio n. 2
0
def test_transfer_statechange_operators():
    a = Block(2)
    b = Block(2)
    c = Block(3)

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c

    a = ActionCancelTransfer(2)
    b = ActionCancelTransfer(2)
    c = ActionCancelTransfer(3)

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c

    a = ActionTransferDirect(2, 2, ADDRESS, ADDRESS)
    b = ActionTransferDirect(2, 2, ADDRESS, ADDRESS)
    c = ActionTransferDirect(3, 4, ADDRESS, ADDRESS2)

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c

    a = ReceiveTransferDirect(2, 2, ADDRESS, ADDRESS)
    b = ReceiveTransferDirect(2, 2, ADDRESS, ADDRESS)
    c = ReceiveTransferDirect(3, 4, ADDRESS, ADDRESS2)

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c