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)
async def setUp(self) -> None: 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.feed_manager = FeedManager(self.node) self.node.feed_manager = self.feed_manager self.rpc = SubscriptionRpcHandler(self.node, self.feed_manager, Case.SNAKE) self.feed_name = NewTransactionFeed.NAME self.node.init_live_feeds() self.feed_service_model = FeedServiceModelBase( allow_filtering=True, available_fields=["all"]) self.base_feed_service_model = BdnFeedServiceModelConfigBase( expire_date="2999-01-01", feed=self.feed_service_model) self.node.account_model = BdnAccountModelBase( account_id="account_id", certificate="", logical_account_name="test", new_transaction_streaming=self.base_feed_service_model, )
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() ) ) gateway_opts = gateway_helpers.get_gateway_opts(8000, ws=True) gateway_opts.set_account_options(account_model) self.gateway_node = MockGatewayNode(gateway_opts) self.gateway_node.NODE_TYPE = NodeType.INTERNAL_GATEWAY self.transaction_streamer_peer = OutboundPeerModel("127.0.0.1", 8006, node_type=NodeType.INTERNAL_GATEWAY) self.gateway_node.requester = ThreadedRequestService( "mock_thread_service", self.gateway_node.alarm_queue, constants.THREADED_HTTP_POOL_SLEEP_INTERVAL_S ) self.gateway_node.requester.start() self.server = WsServer( constants.LOCALHOST, 8005, self.gateway_node.feed_manager, self.gateway_node ) self.ws_uri = f"ws://{constants.LOCALHOST}:8005" await self.server.start()
async def setUp(self) -> None: self.feed_service_model = FeedServiceModelBase( allow_filtering=True, available_fields=["all"]) self.base_feed_service_model = BdnFeedServiceModelConfigBase( expire_date="2999-01-01", feed=self.feed_service_model) account_model = BdnAccountModelBase( "account_id", "account_name", "fake_certificate", tier_name="Developer", new_transaction_streaming=self.base_feed_service_model, new_pending_transaction_streaming=self.base_feed_service_model, on_block_feed=self.base_feed_service_model, transaction_receipts_feed=self.base_feed_service_model) gateway_opts = gateway_helpers.get_gateway_opts(8000, ws=True) gateway_opts.set_account_options(account_model) self.gateway_node = MockGatewayNode(gateway_opts) self.gateway_node.NODE_TYPE = NodeType.INTERNAL_GATEWAY self.transaction_streamer_peer = OutboundPeerModel( "127.0.0.1", 8006, node_type=NodeType.INTERNAL_GATEWAY) self.gateway_node.requester = ThreadedRequestService( "mock_thread_service", self.gateway_node.alarm_queue, constants.THREADED_HTTP_POOL_SLEEP_INTERVAL_S, ) self.gateway_node.requester.start() self.server = WsServer(constants.LOCALHOST, 8005, self.gateway_node.feed_manager, self.gateway_node) self.ws_uri = f"ws://{constants.LOCALHOST}:8005" await self.server.start() self.gateway_node.get_ws_server_status = MagicMock(return_value=True)
def get_gateway_opts(self) -> GatewayOpts: 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", )
def test_cloud_api_account_setting(self): new_account_model = BdnAccountModelBase( "fake_id", "fake_name", "fake_cert", tx_paid=BdnQuotaServiceModelConfigBase(), block_paid=BdnQuotaServiceModelConfigBase(), cloud_api=BdnFeedServiceModelConfigBase( expire_date=str(date.today() + timedelta(days=100)), ), new_transaction_streaming=BdnFeedServiceModelConfigBase()) new_account_model_json = json_encoder.to_json(new_account_model) old_account_model = model_loader.load_model_from_json( BdnOldAccountModelBase, new_account_model_json) self.assertTrue(new_account_model.cloud_api.is_service_valid()) self.assertTrue(old_account_model.cloud_api.is_service_valid()) self.assertFalse( old_account_model.new_transaction_streaming.is_service_valid())
def test_network_is_optional(self): argv = [ "--blockchain-ip", "172.17.0.1", "--blockchain-port", "9333", "--source-version", "1.2.3", "--external-port", "7000", "--blockchain-protocol", "Bitcoin" ] args = main.get_opts(argv) account_model = BdnAccountModelBase("fake_id", "fake_account_name", "fake_certificate") args.set_account_options(account_model) args.validate_network_opts() self.assertEqual(9333, args.blockchain_port) self.assertEqual("bitcoin", args.blockchain_protocol) self.assertEqual("mainnet", args.blockchain_network) self.assertEqual(0, len(args.peer_gateways)) self.assertEqual(0, len(args.peer_relays)) self.assertEqual(0, len(args.outbound_peers))
def setUp(self) -> None: self.gateway = MockGatewayNode(gateway_helpers.get_gateway_opts(8000)) self.feed_manager = FeedManager(self.gateway) self.rpc = SubscriptionRpcHandler(self.gateway, self.feed_manager, Case.SNAKE) self.feed_service_model = FeedServiceModelBase( allow_filtering=True, available_fields=["all"]) self.base_feed_service_model = BdnFeedServiceModelConfigBase( expire_date="2999-01-01", feed=self.feed_service_model) self.gateway.account_model = BdnAccountModelBase( account_id="account_id", certificate="", logical_account_name="test", new_transaction_streaming=self.base_feed_service_model, ) self.gateway.account_model.get_feed_service_config_by_name = MagicMock( return_value=self.gateway.account_model.new_transaction_streaming)
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) }
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) }
def get_gateway_opts(self) -> GatewayOpts: feed_service_model = FeedServiceModelBase(allow_filtering=True, available_fields=["all"]) base_feed_service_model = BdnFeedServiceModelConfigBase( expire_date="2999-01-01", feed=feed_service_model) 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( )), new_transaction_streaming=base_feed_service_model, new_pending_transaction_streaming=base_feed_service_model, on_block_feed=base_feed_service_model, new_block_streaming=base_feed_service_model, transaction_state_feed=base_feed_service_model, blockchain_protocol="Ethereum", blockchain_network="Mainnet", )