ut_tx.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. """
  3. test.unit_tests_d.ut_tx: TX unit test for the MMGen suite
  4. """
  5. import re
  6. from mmgen.common import *
  7. from mmgen.tx import MMGenTX
  8. from mmgen.txfile import MMGenTxFile
  9. class unit_tests:
  10. def txfile(self,name,ut):
  11. qmsg(' Testing TX file operations')
  12. fns = ( # TODO: add altcoin TX files
  13. '0B8D5A[15.31789,14,tl=1320969600].rawtx',
  14. '0C7115[15.86255,14,tl=1320969600].testnet.rawtx',
  15. '460D4D-BCH[10.19764,tl=1320969600].rawtx',
  16. '25EFA3[2.34].testnet.rawtx',
  17. )
  18. for fn in fns:
  19. fpath = os.path.join('test','ref',fn)
  20. tx = MMGenTX(filename=fpath,quiet_open=True)
  21. f = MMGenTxFile(tx)
  22. fn_gen = f.make_filename()
  23. vmsg(f' parsed: {fn_gen}')
  24. assert fn_gen == fn, f'{fn_gen} != {fn}'
  25. text = f.format()
  26. # New in version 3.3: Support for the unicode legacy literal (u'value') was
  27. # reintroduced to simplify the maintenance of dual Python 2.x and 3.x codebases.
  28. # See PEP 414 for more information.
  29. chk = re.subn(r"\bu'",r"'",open(fpath).read())[0] # remove Python2 'u' string prefixes from ref files
  30. nLines = len([i for i in get_ndiff(chk,text) if i.startswith('-')])
  31. assert nLines == 1, f'{nLines} lines differ: only checksum line should differ'
  32. break # FIXME - test BCH, testnet
  33. qmsg(' OK')
  34. return True