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()
Пример #2
0
    async def test_publish_transaction_duplicate_transaction(self):
        self.sut.subscribe({})

        self.sut.serialize = MagicMock(wraps=self.sut.serialize)
        raw_transaction = mock_eth_messages.generate_eth_raw_transaction()

        self.sut.publish(raw_transaction)
        self.sut.publish(raw_transaction)

        self.sut.serialize.assert_called_once()
    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)
Пример #4
0
    async def test_publish_duplicate_transaction_subscriber_wants_duplicates(
            self):
        subscriber = self.sut.subscribe({"duplicates": True})

        self.sut.serialize = MagicMock(wraps=self.sut.serialize)
        subscriber.queue = MagicMock(wraps=subscriber.queue)
        raw_transaction = mock_eth_messages.generate_eth_raw_transaction()

        self.sut.publish(raw_transaction)
        self.sut.serialize.assert_called_once()
        self.sut.serialize.reset_mock()
        subscriber.queue.assert_called_once()
        subscriber.queue.reset_mock()

        self.sut.publish(raw_transaction)
        self.sut.serialize.assert_called_once()
        subscriber.queue.assert_called_once()
Пример #5
0
    async def test_publish_transaction_no_subscribers(self):
        self.sut.serialize = MagicMock(wraps=self.sut.serialize)

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

        self.sut.serialize.assert_not_called()