Browse Source

tx.file.format(): remove false boolean values from outputs

The MMGen Project 1 month ago
parent
commit
73efa84b48
2 changed files with 12 additions and 2 deletions
  1. 2 1
      mmgen/tx/file.py
  2. 10 1
      test/modtest_d/ut_tx.py

+ 2 - 1
mmgen/tx/file.py

@@ -269,7 +269,8 @@ class MMGenTxFile(MMGenObject):
 					k: getattr(tx, k) for k in self.attrs
 				} | {
 					'inputs':  [e._asdict() for e in tx.inputs],
-					'outputs': [e._asdict() for e in tx.outputs]
+					'outputs': [{k:v for k,v in e._asdict().items() if not (type(v) is bool and v is False)}
+									for e in tx.outputs]
 				} | {
 					k: getattr(tx, k) for k in self.extra_attrs if getattr(tx, k)
 				})

+ 10 - 1
test/modtest_d/ut_tx.py

@@ -30,10 +30,19 @@ async def do_txfile_test(desc, fns, cfg=cfg, check=False):
 		assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}'
 
 		if check:
+			import json
+			from mmgen.tx.file import json_dumps
+			from mmgen.util import make_chksum_6
 			text = f.format()
 			with open(fpath) as fh:
 				text_chk = fh.read()
-			assert text == text_chk, f'\nformatted text:\n{text}\n  !=\noriginal file:\n{text_chk}'
+			data_chk = json.loads(text_chk)
+			outputs = data_chk['MMGenTransaction']['outputs']
+			for n, o in enumerate(outputs):
+				outputs[n] = {k:v for k,v in o.items() if not (type(v) is bool and v is False)}
+			data_chk['chksum'] = make_chksum_6(json_dumps(data_chk['MMGenTransaction']))
+			text_chk_fixed = json_dumps(data_chk)
+			assert text == text_chk_fixed, f'\nformatted text:\n{text}\n  !=\noriginal file:\n{text_chk_fixed}'
 
 	qmsg('  OK')
 	return True