def compare_txs_old_to_current( self, converted_current_message: TxsMessage, original_current_message: TxsMessage, ): self.assertEqual( original_current_message.rawbytes(), converted_current_message.rawbytes(), )
def test_txs_with_short_ids_message(self): txs_info = [ TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)), helpers.generate_bytearray(200), 111), TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)), helpers.generate_bytearray(300), 222), TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)), helpers.generate_bytearray(400), 333) ] msg = TxsMessage(txs=txs_info) msg_bytes = msg.rawbytes() self.assertTrue(msg_bytes) parsed_msg = TxsMessage(buf=msg_bytes) self.assertTrue(parsed_msg) parsed_txs_info = parsed_msg.get_txs() self.assertEqual(len(parsed_txs_info), len(txs_info)) for index in range(len(txs_info)): self.assertEqual(parsed_txs_info[index].short_id, txs_info[index].short_id) self.assertEqual(parsed_txs_info[index].contents, txs_info[index].contents) self.assertEqual(parsed_txs_info[index].hash, txs_info[index].hash)
def process_txs_message( self, msg: TxsMessage ) -> Set[MissingTransactions]: msg_bytes = msg.rawbytes() missing_transactions: Set[MissingTransactions] = set() result_buffer = memoryview(self.proxy.process_txs_msg(tpe.InputBytes(msg_bytes))) # result_buffer is a bytearray that consists of # number of missing transactions - 2 bytes # a list of: # short_id - 4 bytes # Sha256Hash - 32 bytes # content length that was added to transaction service - 4 bytes offset = 0 missing_transactions_count, = struct.unpack_from("<H", result_buffer, offset) offset += constants.UL_SHORT_SIZE_IN_BYTES if missing_transactions_count == 0: return missing_transactions while offset < len(result_buffer): short_id, = struct.unpack_from("<L", result_buffer, offset) offset += constants.SID_LEN transaction_hash = Sha256Hash(result_buffer[offset:offset + crypto.SHA256_HASH_LEN]) offset += crypto.SHA256_HASH_LEN content_length, = struct.unpack_from("<L", result_buffer, offset) offset += constants.UL_INT_SIZE_IN_BYTES if content_length > 0: self.set_transaction_contents_base( transaction_hash, transaction_hash, True, 0, False, None, content_length ) missing_transactions.add(MissingTransactions(short_id, transaction_hash)) return missing_transactions