def test_dump_tx_size(self): # GIVEN tx = Transaction() tx.put_data("TEST") tx.transaction_type = TransactionStatus.confirmed tx_only_data = TransactionDataOnly() tx_only_data.data = "TEST" # WHEN dump_a = pickle.dumps(tx_only_data) dump_b = pickle.dumps(tx) # THEN logging.debug("size of tx_only_data: " + str(sys.getsizeof(dump_a))) logging.debug("size of tx: " + str(sys.getsizeof(dump_b))) self.assertLessEqual(sys.getsizeof(dump_a), sys.getsizeof(dump_b) * 1.5)
def test_tx_json_serialize(self): # GIVEN tx = Transaction() tx.put_data("TEST") tx.transaction_type = TransactionStatus.confirmed logging.debug(f"transaction for test({tx})") # WHEN wrap_up = {"__Transaction__": tx} serialized = json.dumps(wrap_up, sort_keys=True, cls=CustomEncoder) logging.debug(f"serialized tx: {serialized}") tx_json = json.loads(serialized, object_hook=decode_object) logging.debug(f"deserialized tx: {tx_json}") wrap_up_again = {"__Transaction__": tx_json} serialized_again = json.dumps(wrap_up_again, sort_keys=True, cls=CustomEncoder) logging.debug(f"re-serialized tx: {serialized_again}") # THEN self.assertEqual(serialized, serialized_again)