From 218e6683e0e2a1ffd88cf73df587148abcc1d99e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 16 Jun 2025 14:35:30 +0000 Subject: [PATCH] cmdtest.py rune, runeswap: add txhex checksum tests --- test/cmdtest_d/rune.py | 23 ++++++++++++++++++++--- test/cmdtest_d/runeswap.py | 18 ++++++++++++++++++ test/cmdtest_d/swap.py | 5 +++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index 15807632..8dffe945 100755 --- a/test/cmdtest_d/rune.py +++ b/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') diff --git a/test/cmdtest_d/runeswap.py b/test/cmdtest_d/runeswap.py index 57fa4e81..be585b14 100755 --- a/test/cmdtest_d/runeswap.py +++ b/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 diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 5a49ab18..8cd2fad5 100755 --- a/test/cmdtest_d/swap.py +++ b/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):