class EthNewTransactionFeedTest(AbstractTestCase):
    def setUp(self) -> None:
        self.sut = EthNewTransactionFeed()

    @async_test
    async def test_publish_from_blockchain(self):
        normal_subscriber = self.sut.subscribe(
            {"include_from_blockchain": False})
        yes_from_bc_subscriber = self.sut.subscribe(
            {"include_from_blockchain": True})

        self.sut.publish(
            mock_eth_messages.generate_eth_raw_transaction(
                FeedSource.BLOCKCHAIN_SOCKET))

        result = await asyncio.wait_for(yes_from_bc_subscriber.receive(), 0.01)
        self.assertIsNotNone(result)

        with self.assertRaises(asyncio.TimeoutError):
            await asyncio.wait_for(normal_subscriber.receive(), 0.01)

    @async_test
    async def test_publish_from_blockchain_skips_publish_no_subscribers(self):
        self.sut.subscribe({"include_from_blockchain": False})
        self.sut.serialize = MagicMock(wraps=self.sut.serialize)

        self.sut.publish(
            mock_eth_messages.generate_eth_raw_transaction(
                FeedSource.BLOCKCHAIN_SOCKET))

        self.sut.serialize.assert_not_called()
Example #2
0
 def init_live_feeds(self) -> None:
     self.feed_manager.register_feed(EthNewTransactionFeed())
     self.feed_manager.register_feed(
         EthPendingTransactionFeed(self.alarm_queue))
     self.feed_manager.register_feed(EthOnBlockFeed(self))
     self.feed_manager.register_feed(EthNewBlockFeed(self))
     self.feed_manager.register_feed(EthTransactionReceiptsFeed(self))
Example #3
0
    async def test_eth_new_transactions_feed_subscribe_filters(self):
        self.gateway_node.feed_manager.feeds.clear()
        self.gateway_node.feed_manager.register_feed(EthNewTransactionFeed())
        to = "0x1111111111111111111111111111111111111111"
        eth_tx_message = generate_new_eth_with_to_transaction(to[2:])
        eth_transaction = EthRawTransaction(eth_tx_message.tx_hash(),
                                            eth_tx_message.tx_val(),
                                            FeedSource.BLOCKCHAIN_SOCKET,
                                            local_region=True)
        expected_tx_hash = f"0x{str(eth_transaction.tx_hash)}"
        logger.error(expected_tx_hash)
        async with WsProvider(self.ws_uri) as ws:
            subscription_id = await ws.subscribe(
                "newTxs", options={"filters": f"to = {to} or to = aaaa"})

            self.gateway_node.feed_manager.publish_to_feed(
                FeedKey("newTxs"), eth_transaction)

            subscription_message = await ws.get_next_subscription_notification_by_id(
                subscription_id)
            self.assertEqual(subscription_id,
                             subscription_message.subscription_id)
            self.assertEqual(expected_tx_hash,
                             subscription_message.notification["txHash"])

            expected_tx_contents = get_expected_eth_tx_contents(eth_tx_message)
            self.assertEqual(expected_tx_contents,
                             subscription_message.notification["txContents"])
Example #4
0
    async def test_eth_new_tx_feed_subscribe_include_from_blockchain(self):
        self.gateway_node.feed_manager.feeds.clear()
        self.gateway_node.feed_manager.register_feed(EthNewTransactionFeed())

        eth_tx_message = generate_new_eth_transaction()
        eth_transaction = EthRawTransaction(eth_tx_message.tx_hash(),
                                            eth_tx_message.tx_val(),
                                            FeedSource.BLOCKCHAIN_SOCKET,
                                            local_region=True)
        expected_tx_hash = f"0x{str(eth_transaction.tx_hash)}"

        async with WsProvider(self.ws_uri) as ws:
            subscription_id = await ws.subscribe(
                "newTxs", {"include_from_blockchain": True})

            self.gateway_node.feed_manager.publish_to_feed(
                FeedKey("newTxs"), eth_transaction)

            subscription_message = await ws.get_next_subscription_notification_by_id(
                subscription_id)
            self.assertEqual(subscription_id,
                             subscription_message.subscription_id)
            self.assertEqual(expected_tx_hash,
                             subscription_message.notification["txHash"])

            expected_tx_contents = get_expected_eth_tx_contents(eth_tx_message)
            self.assertEqual(expected_tx_contents,
                             subscription_message.notification["txContents"])
            self.assertTrue(subscription_message.notification["localRegion"])
Example #5
0
    async def test_eth_new_tx_feed_subscribe_not_include_from_blockchain(self):
        self.gateway_node.feed_manager.feeds.clear()
        self.gateway_node.feed_manager.register_feed(EthNewTransactionFeed())

        eth_tx_message = generate_new_eth_transaction()
        eth_transaction = EthRawTransaction(
            eth_tx_message.tx_hash(), eth_tx_message.tx_val(), FeedSource.BDN_SOCKET, local_region=True
        )
        expected_tx_hash = f"0x{str(eth_transaction.tx_hash)}"

        eth_tx_message_blockchain = generate_new_eth_transaction()
        eth_transaction_blockchain = EthRawTransaction(
            eth_tx_message_blockchain.tx_hash(),
            eth_tx_message_blockchain.tx_val(),
            FeedSource.BLOCKCHAIN_SOCKET,
            local_region=True
        )

        async with WsProvider(self.ws_uri) as ws:
            subscription_id = await ws.subscribe(
                "newTxs", {"include_from_blockchain": False}
            )

            self.gateway_node.feed_manager.publish_to_feed(FeedKey("newTxs"), eth_transaction)
            subscription_message = await ws.get_next_subscription_notification_by_id(
                subscription_id
            )
            self.assertEqual(subscription_id, subscription_message.subscription_id)
            self.assertEqual(
                expected_tx_hash, subscription_message.notification["txHash"]
            )

            self.gateway_node.feed_manager.publish_to_feed(
                FeedKey("newTxs"), eth_transaction_blockchain
            )
            with self.assertRaises(asyncio.TimeoutError):
                await asyncio.wait_for(
                    ws.get_next_subscription_notification_by_id(subscription_id), 0.1
                )
 def setUp(self) -> None:
     self.sut = EthNewTransactionFeed()