Browse Source

unit_tests.py tx: test signed and altcoin transactions

The MMGen Project 3 years ago
parent
commit
cc3a03911b
2 changed files with 67 additions and 37 deletions
  1. 7 0
      test/ref/542169[5.68152,34].sigtx
  2. 60 37
      test/unit_tests_d/ut_tx.py

+ 7 - 0
test/ref/542169[5.68152,34].sigtx

@@ -0,0 +1,7 @@
+ed37e7
+MAINNET 542169 5.68152 20111111_111111 1000000
+02000000012926cbf10ae20d59af8fc77cffbdbb766c2307f7c4a6f503d1aa2e54d75b8aa1030000008a4730440220527d16638bb29baf03878faf5adf920bb510184408c9c1b788e235811cf841c402207fe7d31b927a9bf17a5ad7828ad1433c27ee7987fab90641389beda1f5fba81d014104cab44f37258e5e31a9dd83820238d40e0dfcd677c42633a66a8e0b7070943453c4896a539f83364c65248521d78043b1e928cbf4a2fc986be8f8b7debf408e11fdffffff03f01a42080000000017a91496ab2040607ada968a80e9dcbb19d0c87314006887d0349b19000000001976a91482ec5f144f0d227f15306a05533f13903bc1448c88acf00e3843000000001976a914254e031d0d22109ea5fbe367c5a3bf697773021688ac00000000
+[{'label': 'Automotive', 'vout': 3, 'txid': 'a18a5bd7542eaad103f5a6c4f707236c76bbbdff7cc78faf590de20af1cb2629', 'scriptPubKey': '76a9143f815dd1bc511d71271a7c0ddd5aa705adbebc3388ac', 'amt': '16.95909312', 'addr': '16nnYdJywwRVFr5pKipAfWUVsSaVEc3SdS', 'confs': 537793, 'mmid': '81852D53:L:5', 'sequence': 4294967293}]
+[{'addr': '3FRgHMqLmYQMC6qcajYpSHYYNJPBddaVnk', 'amt': '1.3855', 'is_chg': False}, {'addr': '1CwG1K3CuNdGtuCKn8RVztZfvVikosHNQe', 'amt': '4.29602', 'is_chg': False, 'mmid': '81852D53:L:12'}, {'addr': '14QFTUiDaCQ4LrU63UrgVaN6cuxsFbDgz4', 'amt': '11.27747312', 'is_chg': True, 'mmid': '81852D53:L:99'}]
+-
+c6eb937008c05161bfdfa3bf959e702d47bb32fe0b65e8fc2d3d9ccebbe73b3d

+ 60 - 37
test/unit_tests_d/ut_tx.py

@@ -1,18 +1,52 @@
 #!/usr/bin/env python3
 """
-test.unit_tests_d.ut_tx: TX unit test for the MMGen suite
+test.unit_tests_d.ut_tx: TX unit tests for the MMGen suite
 """
 
 import re
+
 from mmgen.common import *
-from mmgen.tx import NewTX,UnsignedTX
+from mmgen.tx import NewTX,CompletedTX
 from mmgen.txfile import MMGenTxFile
-from mmgen.rpc import rpc_init
 from mmgen.daemon import CoinDaemon
 from mmgen.protocol import init_proto
 
+async def do_txfile_test(desc,fns):
+	qmsg(f'  Testing CompletedTX initializer ({desc})')
+	for fn in fns:
+		qmsg(f'     parsing: {os.path.basename(fn)}')
+		fpath = os.path.join('test','ref',fn)
+		tx = await CompletedTX(filename=fpath,quiet_open=True)
+
+		vmsg(tx.info.format())
+
+		f = MMGenTxFile(tx)
+		fn_gen = f.make_filename()
+
+		if g.debug_utf8:
+			fn_gen = fn_gen.replace('-α','')
+		assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}'
+
+		text = f.format()
+
+		with open(fpath) as fp:
+			# remove Python2 'u' string prefixes from ref files:
+			#   New in version 3.3: Support for the unicode legacy literal (u'value') was
+			#   reintroduced to simplify the maintenance of dual Python 2.x and 3.x codebases.
+			#   See PEP 414 for more information.
+			chk = re.subn( r"\bu(['\"])", r'\1', fp.read() )[0]
+
+		diff = get_ndiff(chk,text)
+		nLines = len([i for i in diff if i.startswith('-')])
+		assert nLines in (0,1), f'{nLines} lines differ: only checksum line may differ'
+
+	qmsg('  OK')
+	return True
+
 class unit_tests:
 
+	altcoin_deps = ('txfile_alt',)
+
 	async def tx(self,name,ut):
 		qmsg('  Testing NewTX initializer')
 		d = CoinDaemon('btc',test_suite=True)
@@ -25,39 +59,28 @@ class unit_tests:
 		qmsg('  OK')
 		return True
 
-	def txfile(self,name,ut):
-		qmsg('  Testing TX file operations')
-
-		fns = ( # TODO: add altcoin TX files
-			'0B8D5A[15.31789,14,tl=1320969600].rawtx',
-			'0C7115[15.86255,14,tl=1320969600].testnet.rawtx',
-			'25EFA3[2.34].testnet.rawtx',
-			'460D4D-BCH[10.19764,tl=1320969600].rawtx',
+	async def txfile(self,name,ut):
+		return await do_txfile_test(
+			'Bitcoin',
+			(
+				'0B8D5A[15.31789,14,tl=1320969600].rawtx',
+				'542169[5.68152,34].sigtx',
+				'0C7115[15.86255,14,tl=1320969600].testnet.rawtx',
+				'25EFA3[2.34].testnet.rawtx',
+			)
 		)
-		for fn in fns:
-			qmsg(f'     parsing: {os.path.basename(fn)}')
-			fpath = os.path.join('test','ref',fn)
-			tx = UnsignedTX(filename=fpath,quiet_open=True)
-
-			vmsg(tx.info.format())
-
-			f = MMGenTxFile(tx)
-			fn_gen = f.make_filename()
-
-			if g.debug_utf8:
-				fn_gen = fn_gen.replace('-α','')
-			assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}'
-
-			text = f.format()
-			# New in version 3.3: Support for the unicode legacy literal (u'value') was
-			# reintroduced to simplify the maintenance of dual Python 2.x and 3.x codebases.
-			# See PEP 414 for more information.
-			with open(fpath) as fp:
-				# remove Python2 'u' string prefixes from ref files
-				chk = re.subn( r"\bu(['\"])", r'\1', fp.read() )[0]
-			diff = get_ndiff(chk,text)
-			nLines = len([i for i in diff if i.startswith('-')])
-			assert nLines in (0,1), f'{nLines} lines differ: only checksum line may differ'
 
-		qmsg('  OK')
-		return True
+	async def txfile_alt(self,name,ut):
+		return await do_txfile_test(
+			'altcoins',
+			(
+				'460D4D-BCH[10.19764,tl=1320969600].rawtx',
+				'ethereum/5881D2-MM1[1.23456,50000].rawtx',
+				'ethereum/6BDB25-MM1[1.23456,50000].testnet.rawtx',
+				'ethereum/88FEFD-ETH[23.45495,40000].rawtx',
+				'ethereum/B472BD-ETH[23.45495,40000].testnet.rawtx',
+				'ethereum/B472BD-ETH[23.45495,40000].testnet.sigtx',
+				'litecoin/A5A1E0-LTC[1454.64322,1453,tl=1320969600].testnet.rawtx',
+				'litecoin/AF3CDF-LTC[620.76194,1453,tl=1320969600].rawtx',
+			)
+		)