def test_handle_message_transaction(self, m_Transaction): """ This handler handles a MessageTransaction type Transaction. :param m_Transaction: :return: """ m_Transaction.from_pbdata.return_value = Mock( autospec=MessageTransaction, txhash=b'12345') self.channel.factory.master_mr.isRequested.return_value = True # Yes, this is a Message which we have requested self.channel.factory.buffered_chain.tx_pool.pending_tx_pool_hash = [ ] # No, we haven't processed this TX before mtData = qrl_pb2.Transaction() msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.MT, mtData=mtData) P2PTxManagement.handle_message_transaction(self.channel, msg) self.channel.factory.add_unprocessed_txn.assert_called() # What if we ended up parsing a Transaction that we never requested in the first place? self.channel.factory.add_unprocessed_txn.reset_mock() self.channel.factory.master_mr.isRequested.return_value = False P2PTxManagement.handle_message_transaction(self.channel, msg) self.channel.factory.add_unprocessed_txn.assert_not_called()
def test_handle_message_transaction_invalid_transaction( self, m_Transaction, logger): """ If the Transaction was so malformed that parsing it caused an exception, the peer should be disconnected. :param m_Transaction: :param logger: :return: """ m_Transaction.from_pbdata.side_effect = Exception mtData = qrl_pb2.Transaction() msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.MT, mtData=mtData) P2PTxManagement.handle_message_transaction(self.channel, msg) self.channel.loseConnection.assert_called()