Browse Source

cmdtest.py rune, runeswap: add txhex checksum tests

The MMGen Project 5 months ago
parent
commit
218e6683e0
3 changed files with 41 additions and 5 deletions
  1. 20 3
      test/cmdtest_d/rune.py
  2. 18 0
      test/cmdtest_d/runeswap.py
  3. 3 2
      test/cmdtest_d/swap.py

+ 20 - 3
test/cmdtest_d/rune.py

@@ -12,6 +12,10 @@
 test.cmdtest_d.rune: THORChain RUNE tests for the cmdtest.py test suite
 """
 
+from hashlib import md5
+
+from mmgen.fileutil import get_data_from_file
+
 from .include.common import dfl_sid, dfl_words_file
 from .include.proxy import TestProxy
 from .httpd.thornode.rpc import ThornodeRPCServer
@@ -27,6 +31,7 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 	tmpdir_nums = [50]
 	color = True
 	menu_prompt = 'efresh balance:\b'
+	txhex_chksum = '83f85785'
 
 	cmd_group_in = (
 		('subgroup.init',   []),
@@ -47,6 +52,7 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 			('txsign1',              'signing the transaction'),
 			('txsend1_test',         'testing whether the transaction can be sent'),
 			('txsend1',              'sending the transaction'),
+			('txhex1',               'dumping the transaction hex'),
 		),
 	}
 
@@ -69,6 +75,8 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 
 		TestProxy(cfg)
 
+		self.txhex_file = f'{self.tmpdir}/tx_dump.hex'
+
 	def addrgen(self):
 		return self._addrgen()
 
@@ -114,21 +122,30 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 	def txsend1(self):
 		return self._txsend()
 
-	def _txsend(self, add_args=[]):
+	def _txsend(self, add_opts=[], *, test=False, dump_hex=False):
 		t = self.spawn(
 			'mmgen-txsend',
-			self.rune_opts + add_args + [self.get_file_with_ext('sigtx')],
+			self.rune_opts + add_opts + [self.get_file_with_ext('sigtx')],
 			no_passthru_opts = ['coin'])
 		t.expect('view: ', 'y')
 		t.expect('to continue: ', 'z')
 		t.expect('(y/N): ', 'n') # edit comment?
-		if add_args == ['--test']:
+		if dump_hex:
+			t.written_to_file('hex data')
+		elif test:
 			t.expect('can be sent')
 		else:
 			t.expect('to confirm: ', 'YES\n')
 			t.written_to_file('Sent transaction')
 		return t
 
+	def txhex1(self):
+		t = self._txsend(add_opts=[f'--dump-hex={self.txhex_file}'], dump_hex=True)
+		t.read()
+		txhex = get_data_from_file(self.cfg, self.txhex_file, silent=True)
+		assert md5(txhex.encode()).hexdigest()[:8] == self.txhex_chksum
+		return t
+
 	def rpc_server_stop(self):
 		return CmdTestSwapMethods._thornode_server_stop(
 			self, attrname='rpc_server', name='Thornode RPC server')

+ 18 - 0
test/cmdtest_d/runeswap.py

@@ -12,6 +12,10 @@
 test.cmdtest_d.runeswap: THORChain swap tests for the cmdtest.py test suite
 """
 
+from hashlib import md5
+
+from mmgen.fileutil import get_data_from_file
+
 from .httpd.thornode.swap import ThornodeSwapServer
 from .include.proxy import TestProxy
 
@@ -59,6 +63,7 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest):
 			('rune_swaptxsend1',    ''),
 			('rune_swaptxstatus1',  ''),
 			('rune_swaptxreceipt1', ''),
+			('rune_swaptxhex1',     ''),
 		),
 	}
 
@@ -88,6 +93,7 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune):
 	tmpdir_nums = [58]
 	input_sels_prompt = 'to spend from: '
 	is_helper = True
+	txhex_chksum = '34980b41'
 
 	cmd_group_in = CmdTestRune.cmd_group_in + (
 		# rune_swap:
@@ -96,9 +102,14 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune):
 		('swaptxsend1',              'sending the transaction'),
 		('swaptxstatus1',            'getting the transaction status'),
 		('swaptxreceipt1',           'getting the transaction receipt'),
+		('swaptxhex1',               'dumping the transaction hex'),
 		('thornode_server_stop',     'stopping Thornode server'),
 	)
 
+	def __init__(self, *args, **kwargs):
+		super().__init__(*args, **kwargs)
+		self.txhex_file = f'{self.tmpdir}/tx_dump.hex'
+
 	def swaptxcreate1(self):
 		t = self._swaptxcreate(['RUNE', '8.765', 'BTC'])
 		t.expect('OK? (Y/n): ', 'y')
@@ -115,3 +126,10 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune):
 
 	def swaptxreceipt1(self):
 		return self._swaptxsend(add_opts=['--receipt'], spawn_only=True)
+
+	def swaptxhex1(self):
+		t = self._swaptxsend(add_opts=[f'--dump-hex={self.txhex_file}'], dump_hex=True)
+		t.read()
+		txhex = get_data_from_file(self.cfg, self.txhex_file, silent=True)
+		assert md5(txhex.encode()).hexdigest()[:8] == self.txhex_chksum
+		return t

+ 3 - 2
test/cmdtest_d/swap.py

@@ -197,7 +197,7 @@ class CmdTestSwapMethods:
 			],
 			spawn_only = spawn_only)
 
-	def _swaptxsend(self, *, add_opts=[], spawn_only=False, status=False):
+	def _swaptxsend(self, *, add_opts=[], spawn_only=False, status=False, dump_hex=False):
 		fn = self.get_file_with_ext('sigtx')
 		t = self.spawn(
 			'mmgen-txsend',
@@ -209,7 +209,8 @@ class CmdTestSwapMethods:
 		if status:
 			return t
 		t.expect('(y/N): ', 'n')
-		t.expect('to confirm: ', 'YES\n')
+		if not dump_hex:
+			t.expect('to confirm: ', 'YES\n')
 		return t
 
 	def _swaptxsign(self, *, add_opts=[], expect=None):