Exemplo n.º 1
0
 def setUp(self) -> None:
     self._account_model = BdnAccountModelBase(
         account_id="",
         logical_account_name="",
         certificate="",
         expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat(),
         cloud_api=BdnServiceModelConfigBase(
             msg_quota=None,
             permit=BdnServiceModelBase(service_type=BdnServiceType.PERMIT),
             expire_date=utils_constants.DEFAULT_EXPIRATION_DATE.isoformat(
             ),
         ),
         blockchain_protocol="Ethereum",
         blockchain_network="Mainnet",
     )
     self.rpc_port = helpers.get_free_port()
     opts = gateway_helpers.get_gateway_opts(
         8000,
         rpc_port=self.rpc_port,
         account_model=self._account_model,
         blockchain_protocol="Ethereum",
     )
     self.node = MockGatewayNode(opts)
     self.node.eth_ws_proxy_publisher = MockEthWsProxyPublisher(
         None, None, None, self.node)
     self.node.eth_ws_proxy_publisher.call_rpc = AsyncMock(
         return_value=JsonRpcResponse(request_id=1))
     self.sut = EthOnBlockFeed(self.node)
Exemplo n.º 2
0
 async def setUp(self) -> None:
     self.rpc_port = helpers.get_free_port()
     self.rpc_url = f"http://{constants.LOCALHOST}:{self.rpc_port}"
     self.rpc_user = "******"
     self.rpc_password = "******"
     await super().setUp()
     self.rpc_server = GatewayHttpRpcServer(self.gateway_node)
     await self.rpc_server.start()
Exemplo n.º 3
0
    def setUp(self):
        self.main_port = helpers.get_free_port()
        self.peer_port = helpers.get_free_port()

        sdn_http_service.fetch_gateway_peers = MagicMock(return_value=[])

        self.main_opts = gateway_helpers.get_gateway_opts(
            self.main_port, node_id="main",
            peer_gateways=[OutboundPeerModel(LOCALHOST, self.peer_port, node_type=NodeType.EXTERNAL_GATEWAY)],
            non_ssl_port=helpers.get_free_port()
        )
        self.main_gateway = NullGatewayNode(self.main_opts)
        self.main_event_loop = NodeEventLoop(self.main_gateway)

        self.peer_opts = gateway_helpers.get_gateway_opts(self.peer_port, node_id="peer", non_ssl_port=helpers.get_free_port())
        self.peer_gateway = NullGatewayNode(self.peer_opts)
        self.peer_event_loop = NodeEventLoop(self.peer_gateway)
Exemplo n.º 4
0
    def test_multiplexing__delayed_connect(self):
        receiver_port = helpers.get_free_port()
        receiver_node = TestNode(receiver_port, [], 0.01)
        receiver_event_loop = create_event_loop(receiver_node)
        receiver_thread = Thread(target=receiver_event_loop.run)

        send_bytes = generate_bytearray(1000)

        sender_port = helpers.get_free_port()
        sender_node = TestNode(sender_port, [], 0.01, send_bytes)
        sender_event_loop = create_event_loop(sender_node)
        sender_thread = Thread(target=sender_event_loop.run)

        try:
            print("Starting event loop on receiver")
            receiver_thread.start()

            print("Starting event loop on sender")
            sender_thread.start()

            # let threads run for 0.1 sec
            time.sleep(0.1)

            self.assertEqual(len(receiver_node.connections), 0)
            self.assertEqual(len(sender_node.connections), 0)

            # request connection while clients are running
            sender_node.enqueue_connection('0.0.0.0', receiver_node.port)

            receiver_thread.join()
            sender_thread.join()

            self._validate_successful_run(send_bytes, sender_node,
                                          receiver_node, sender_event_loop,
                                          receiver_event_loop)
        finally:
            if receiver_thread.is_alive():
                receiver_thread.join()

            if sender_thread.is_alive():
                sender_thread.join()

            receiver_event_loop.close()
            sender_event_loop.close()
Exemplo n.º 5
0
    def test_multiplexing__disconnect(self):
        receiver_port = helpers.get_free_port()
        receiver_node = TestNode(receiver_port, [], 0.01)
        receiver_event_loop = create_event_loop(receiver_node)
        receiver_thread = Thread(name="receiver",
                                 target=receiver_event_loop.run)

        sender_port = helpers.get_free_port()
        sender_node = TestNode(sender_port, [receiver_port], 0.01)
        sender_event_loop = create_event_loop(sender_node)
        sender_thread = Thread(name="sender", target=sender_event_loop.run)

        try:
            print("Starting event loop on receiver")
            receiver_thread.start()
            sender_thread.start()

            # let threads run for 0.1 sec
            time.sleep(0.1)

            self.assertEqual(len(receiver_node.connections), 1)
            self.assertEqual(len(sender_node.connections), 1)

            # request disconnect while clients are running
            sender_node.enqueue_disconnect(sender_node.connections[0][0],
                                           False)

            # sender and receiver have to disconnect and exit
            receiver_thread.join()
            sender_thread.join()
        finally:
            if receiver_thread.is_alive():
                receiver_thread.join()

            if sender_thread.is_alive():
                sender_thread.join()

            receiver_event_loop.close()
            sender_event_loop.close()
Exemplo n.º 6
0
    async def setUp(self) -> None:
        crypto_utils.recover_public_key = MagicMock(return_value=bytes(32))
        account_model = BdnAccountModelBase(
            "account_id",
            "account_name",
            "fake_certificate",
            new_transaction_streaming=BdnServiceModelConfigBase(
                expire_date=date(2999, 1, 1).isoformat()))

        self.eth_ws_port = helpers.get_free_port()
        self.eth_ws_uri = f"ws://127.0.0.1:{self.eth_ws_port}"
        self.eth_ws_server_message_queue = asyncio.Queue()
        await self.start_server()

        gateway_opts = gateway_helpers.get_gateway_opts(
            8000, eth_ws_uri=self.eth_ws_uri, ws=True)
        gateway_opts.set_account_options(account_model)
        self.gateway_node = MockGatewayNode(gateway_opts)
        self.gateway_node.transaction_streamer_peer = OutboundPeerModel(
            "127.0.0.1", 8006, node_type=NodeType.INTERNAL_GATEWAY)
        self.gateway_node.feed_manager.register_feed(
            EthPendingTransactionFeed(self.gateway_node.alarm_queue))

        self.eth_ws_proxy_publisher = EthWsProxyPublisher(
            self.eth_ws_uri, self.gateway_node.feed_manager,
            self.gateway_node.get_tx_service(), self.gateway_node)
        self.subscriber: Subscriber[
            RawTransactionFeedEntry] = self.gateway_node.feed_manager.subscribe_to_feed(
                EthPendingTransactionFeed.NAME, {})
        self.assertIsNotNone(self.subscriber)

        await self.eth_ws_proxy_publisher.start()
        await asyncio.sleep(0.01)

        self.assertEqual(len(self.eth_ws_proxy_publisher.receiving_tasks), 2)
        self.assertEqual(0, self.subscriber.messages.qsize())

        self.sample_transactions = {
            i: mock_eth_messages.get_dummy_transaction(i)
            for i in range(10)
        }
Exemplo n.º 7
0
    async def setUp(self) -> None:
        account_model = BdnAccountModelBase(
            "account_id", "account_name", "fake_certificate",
            new_transaction_streaming=BdnServiceModelConfigBase(
                expire_date=date(2999, 1, 1).isoformat()
            )
        )

        self.eth_ws_port = helpers.get_free_port()
        self.eth_ws_uri = f"ws://127.0.0.1:{self.eth_ws_port}"
        self.eth_ws_server_message_queue = asyncio.Queue()
        self.eth_subscription_id = "sub_id"
        await self.start_server()

        gateway_opts = gateway_helpers.get_gateway_opts(
            8000, eth_ws_uri=self.eth_ws_uri, ws=True)
        gateway_opts.set_account_options(account_model)
        self.gateway_node = MockGatewayNode(gateway_opts)
        self.gateway_node.feed_manager.register_feed(
            EthPendingTransactionFeed(self.gateway_node.alarm_queue)
        )

        self.eth_ws_subscriber = EthWsSubscriber(
            self.eth_ws_uri, self.gateway_node.feed_manager, self.gateway_node.get_tx_service()
        )
        self.subscriber: Subscriber[
            RawTransactionFeedEntry
        ] = self.gateway_node.feed_manager.subscribe_to_feed(EthPendingTransactionFeed.NAME, {})
        self.assertIsNotNone(self.subscriber)

        await self.eth_ws_subscriber.start()
        await asyncio.sleep(0.01)

        self.assertIsNotNone(self.eth_ws_subscriber.receiving_task)
        self.assertEqual(0, self.subscriber.messages.qsize())

        self.sample_transactions = {
            i: mock_eth_messages.get_dummy_transaction(i) for i in range(10)
        }