コード例 #1
0
ファイル: test_multiplexer.py プロジェクト: pamir-s/trinity
async def test_multiplexer_properties():
    multiplexer, _ = MultiplexerPairFactory(protocol_types=(SecondProtocol,
                                                            ThirdProtocol), )
    transport = multiplexer.get_transport()

    base_protocol = multiplexer.get_protocol_by_type(P2PProtocolV5)
    second_protocol = multiplexer.get_protocol_by_type(SecondProtocol)
    third_protocol = multiplexer.get_protocol_by_type(ThirdProtocol)

    assert multiplexer.get_base_protocol() is base_protocol
    assert multiplexer.get_protocols() == (base_protocol, second_protocol,
                                           third_protocol)

    assert multiplexer.get_protocol_by_type(P2PProtocolV5) is base_protocol
    assert multiplexer.get_protocol_by_type(SecondProtocol) is second_protocol
    assert multiplexer.get_protocol_by_type(ThirdProtocol) is third_protocol

    assert multiplexer.has_protocol(P2PProtocolV5) is True
    assert multiplexer.has_protocol(SecondProtocol) is True
    assert multiplexer.has_protocol(ThirdProtocol) is True
    assert multiplexer.has_protocol(UnsupportedProtocol) is False

    assert multiplexer.has_protocol(base_protocol) is True
    assert multiplexer.has_protocol(second_protocol) is True
    assert multiplexer.has_protocol(third_protocol) is True
    assert multiplexer.has_protocol(UnsupportedProtocol(transport, 16,
                                                        False)) is False

    assert multiplexer.remote is transport.remote
コード例 #2
0
def test_multiplexer_pair_factory():
    alice_remote, bob_remote = NodeFactory.create_batch(2)
    alice_multiplexer, bob_multiplexer = MultiplexerPairFactory(
        alice_remote=alice_remote,
        bob_remote=bob_remote,
    )
    assert alice_multiplexer.remote == bob_remote
    assert bob_multiplexer.remote == alice_remote

    assert alice_multiplexer.get_base_protocol().version == DEVP2P_V5
    assert bob_multiplexer.get_base_protocol().version == DEVP2P_V5
コード例 #3
0
async def test_multiplexer_pair_factory_with_different_p2p_versions(
    alice_p2p_version,
    bob_p2p_version,
    expected_base_protocol_class,
):
    alice_multiplexer, bob_multiplexer = MultiplexerPairFactory(
        alice_p2p_version=alice_p2p_version,
        bob_p2p_version=bob_p2p_version,
    )
    alice_base_protocol = alice_multiplexer.get_base_protocol()
    bob_base_protocol = bob_multiplexer.get_base_protocol()

    assert type(alice_base_protocol) is expected_base_protocol_class
    assert type(bob_base_protocol) is expected_base_protocol_class

    assert alice_base_protocol.version == expected_base_protocol_class.version
    assert bob_base_protocol.version == expected_base_protocol_class.version