Ejemplo n.º 1
0
    def setUp(self):
        opts = gateway_helpers.get_gateway_opts(8000,
                                                include_default_ont_args=True)
        if opts.use_extensions:
            helpers.set_extensions_parallelism()
        self.node = MockOntGatewayNode(opts)
        self.node.neutrality_service = MagicMock()

        self.connection = OntNodeConnection(
            MockSocketConnection(1,
                                 node=self.node,
                                 ip_address=LOCALHOST,
                                 port=123), self.node)
        gateway_helpers.add_blockchain_peer(self.node, self.connection)

        self.tx_hash = OntObjectHash(buf=helpers.generate_bytearray(32),
                                     length=ONT_HASH_LEN)
        self.block_hash = OntObjectHash(buf=helpers.generate_bytearray(32),
                                        length=ONT_HASH_LEN)

        self.sut = OntNodeConnectionProtocol(self.connection)

        while self.connection.outputbuf.length > 0:
            initial_bytes = self.connection.get_bytes_to_send()
            self.connection.advance_sent_bytes(len(initial_bytes))
Ejemplo n.º 2
0
    def setUp(self):
        opts = gateway_helpers.get_gateway_opts(
            8000,
            include_default_eth_args=True,
            track_detailed_sent_messages=True)
        if opts.use_extensions:
            helpers.set_extensions_parallelism()

        self.node = MockGatewayNode(opts)
        self.node.block_processing_service = MagicMock()

        self.connection = MagicMock()
        gateway_helpers.add_blockchain_peer(self.node, self.connection)
        self.connection.node = self.node
        self.connection.peer_ip = LOCALHOST
        self.connection.peer_port = 8001
        self.connection.network_num = 2
        self.connection.endpoint = IpEndpoint(self.connection.peer_ip,
                                              self.connection.peer_port)
        self.node.blockchain_peers.add(
            BlockchainPeerInfo(self.connection.peer_ip,
                               self.connection.peer_port))
        gateway_bdn_performance_stats_service.set_node(self.node)

        dummy_private_key = crypto_utils.make_private_key(
            helpers.generate_bytearray(111))
        dummy_public_key = crypto_utils.private_to_public_key(
            dummy_private_key)
        self.sut = EthNodeConnectionProtocol(self.connection, True,
                                             dummy_private_key,
                                             dummy_public_key)
Ejemplo n.º 3
0
    def setUp(self):
        opts = gateway_helpers.get_gateway_opts(8000, include_default_btc_args=True)
        if opts.use_extensions:
            helpers.set_extensions_parallelism(opts.thread_pool_parallelism_degree)
        node_ssl_service = MockNodeSSLService(BtcGatewayNode.NODE_TYPE, MagicMock())
        self.gateway_node = BtcGatewayNode(opts, node_ssl_service)
        self.gateway_node.opts.has_fully_updated_tx_service = True
        self.sut = BtcRelayConnection(
            MockSocketConnection(1, node=self.gateway_node, ip_address=LOCALHOST, port=8001), self.gateway_node
            )
        self.gateway_node.message_converter = converter_factory.create_btc_message_converter(
            12345, self.gateway_node.opts
        )

        self.node_conn = MockConnection(
            MockSocketConnection(1, self.gateway_node, ip_address=LOCALHOST, port=8002), self.gateway_node
            )
        self.gateway_node.connection_pool.add(1, LOCALHOST, 8002, self.node_conn)
        gateway_helpers.add_blockchain_peer(self.gateway_node, self.node_conn)

        self.node_conn_2 = MockConnection(
            MockSocketConnection(1, self.gateway_node, ip_address=LOCALHOST, port=8003), self.gateway_node
            )
        self.gateway_node.connection_pool.add(1, LOCALHOST, 8003, self.node_conn_2)
        gateway_helpers.add_blockchain_peer(self.gateway_node, self.node_conn_2)

        self.blockchain_connections = [self.node_conn, self.node_conn_2]

        self.node_conn.enqueue_msg = MagicMock()
        self.node_conn_2.enqueue_msg = MagicMock()
        self.gateway_node.broadcast = MagicMock()
        self.sut.enqueue_msg = MagicMock()
        gateway_transaction_stats_service.set_node(self.gateway_node)

        self.gateway_node.has_active_blockchain_peer = MagicMock(return_value=True)
Ejemplo n.º 4
0
    def setUp(self) -> None:
        pub_key = "a04f30a45aae413d0ca0f219b4dcb7049857bc3f91a6351288cce603a2c9646294a02b987bf6586b370b2c22d74662355677007a14238bb037aedf41c2d08866"
        node_ssl_service = MockNodeSSLService(EthGatewayNode.NODE_TYPE, MagicMock())
        opts = gateway_helpers.get_gateway_opts(
            8000,
            include_default_eth_args=True,
            blockchain_protocol=BlockchainProtocol.ETHEREUM.name,
            blockchain_network_num=5,
            pub_key=pub_key,
        )
        self.node = EthGatewayNode(opts, node_ssl_service)
        self.enqueued_messages = []
        self.broadcast_to_node_messages = []
        self.broadcast_messages = []
        self.node.opts.has_fully_updated_tx_service = True
        self.node.init_live_feeds()

        self.connection = helpers.create_connection(
            EthNodeConnection, self.node, opts, port=opts.blockchain_port
        )

        gateway_helpers.add_blockchain_peer(self.node, self.connection)
        self.block_queuing_service = self.node.block_queuing_service_manager.get_designated_block_queuing_service()

        self.connection.on_connection_established()
        self.node.node_conn = self.connection
        gateway_bdn_performance_stats_service.set_node(self.node)

        def mocked_enqueue_msg(msg, prepend=False):
            self.enqueued_messages.append(msg)

        self.connection.enqueue_msg = mocked_enqueue_msg

        def mocked_broadcast(msg, broadcasting_conn=None, prepend_to_queue=False, connection_types=None):
            if connection_types is None:
                connection_types = [ConnectionType.RELAY_ALL]
            if len(connection_types) == 1 and connection_types[0] == ConnectionType.BLOCKCHAIN_NODE:
                self.broadcast_to_node_messages.append(msg)
            else:
                self.broadcast_messages.append(msg)

        self.node.broadcast = mocked_broadcast

        self.cleanup_service = self.node.block_cleanup_service
        self.node.block_processing_service.queue_block_for_processing = MagicMock()

        self.sut = self.connection.connection_protocol
        self.sut._waiting_checkpoint_headers_request = False
        self.node.opts.ws = True
        self.node.publish_block = MagicMock()
Ejemplo n.º 5
0
    def setUp(self) -> None:

        crypto_utils.recover_public_key = MagicMock(return_value=bytes(32))

        pub_key = "a04f30a45aae413d0ca0f219b4dcb7049857bc3f91a6351288cce603a2c9646294a02b987bf6586b370b2c22d74662355677007a14238bb037aedf41c2d08866"
        opts = gateway_helpers.get_gateway_opts(8000,
                                                include_default_eth_args=True,
                                                pub_key=pub_key)
        if opts.use_extensions:
            helpers.set_extensions_parallelism()
        node_ssl_service = MockNodeSSLService(EthGatewayNode.NODE_TYPE,
                                              MagicMock())
        self.node = EthGatewayNode(opts, node_ssl_service)
        self.node_conn = MockConnection(
            MockSocketConnection(1, self.node, ip_address=LOCALHOST,
                                 port=8002), self.node)
        self.node.connection_pool.add(1, LOCALHOST, 8002, self.node_conn)
        gateway_helpers.add_blockchain_peer(self.node, self.node_conn)
        self.block_queuing_service = self.node.block_queuing_service_manager.get_designated_block_queuing_service(
        )

        self.sut = EthNewBlockFeed(self.node)
    def setUp(self):
        opts = gateway_helpers.get_gateway_opts(8000,
                                                include_default_btc_args=True)
        if opts.use_extensions:
            helpers.set_extensions_parallelism()
        self.node = MockGatewayNode(opts)
        self.node.block_processing_service = MagicMock()

        self.connection = MagicMock()
        gateway_helpers.add_blockchain_peer(self.node, self.connection)
        self.connection.node = self.node
        self.connection.peer_ip = LOCALHOST
        self.connection.peer_port = 8001
        self.connection.network_num = 2
        self.connection.endpoint = IpEndpoint(self.connection.peer_ip,
                                              self.connection.peer_port)
        self.node.blockchain_peers.add(
            BlockchainPeerInfo(self.connection.peer_ip,
                               self.connection.peer_port))
        gateway_bdn_performance_stats_service.set_node(self.node)

        self.sut = BtcBaseConnectionProtocol(self.connection)