From 73efa84b48c0e2025ebd5f1442a7a699a9dc5ded Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 24 Feb 2025 11:27:48 +0000 Subject: [PATCH] tx.file.format(): remove false boolean values from outputs --- mmgen/tx/file.py | 3 ++- test/modtest_d/ut_tx.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mmgen/tx/file.py b/mmgen/tx/file.py index 4dd7d19a..d963a5e1 100755 --- a/mmgen/tx/file.py +++ b/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) }) diff --git a/test/modtest_d/ut_tx.py b/test/modtest_d/ut_tx.py index 709549ef..c382ce22 100755 --- a/test/modtest_d/ut_tx.py +++ b/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