From 816781ec7ab057944ca8158e91983b5b6e9509b3 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 17 Mar 2025 10:16:18 +0000 Subject: [PATCH] minor changes, whitespace --- mmgen/proto/eth/tx/unsigned.py | 17 ++++++++++++----- test/cmdtest.py | 7 ++++++- test/cmdtest_d/ct_autosign.py | 4 +++- test/cmdtest_d/ct_ethdev.py | 25 ++++++++++++++++--------- test/cmdtest_d/ct_ref_altcoin.py | 1 + 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/mmgen/proto/eth/tx/unsigned.py b/mmgen/proto/eth/tx/unsigned.py index 0eb625db..a522fa5e 100755 --- a/mmgen/proto/eth/tx/unsigned.py +++ b/mmgen/proto/eth/tx/unsigned.py @@ -15,7 +15,7 @@ proto.eth.tx.unsigned: Ethereum unsigned transaction class import json from ....tx import unsigned as TxBase -from ....util import msg, msg_r +from ....util import msg, msg_r, die from ....obj import CoinTxID, ETHNonce, Int, HexStr from ....addr import CoinAddr, TokenAddr from ..contract import Token @@ -74,11 +74,18 @@ class Unsigned(Completed, TxBase.Unsigned): o = self.txobj - m = 'mismatch -- a compromised online installation may have altered your serialized data!' - assert o['from'] == self.inputs[0].addr, f'from_addr {m}' + def do_mismatch_err(io, j, k, desc): + m = 'A compromised online installation may have altered your serialized data!' + fs = '\n{} mismatch!\n{}\n orig: {}\n serialized: {}' + die(3, fs.format(desc.upper(), m, getattr(io[0], k), o[j])) + + if o['from'] != self.inputs[0].addr: + do_mismatch_err(self.inputs, 'from', 'addr', 'from-address') if self.outputs: - assert o['to'] == self.outputs[0].addr, f'to_addr {m}' - assert o['amt'] == self.outputs[0].amt, f'to_amt {m}' + if o['to'] != self.outputs[0].addr: + do_mismatch_err(self.outputs, 'to', 'addr', 'to-address') + if o['amt'] != self.outputs[0].amt: + do_mismatch_err(self.outputs, 'amt', 'amt', 'amount') msg_r(f'Signing transaction{tx_num_str}...') diff --git a/test/cmdtest.py b/test/cmdtest.py index 23615153..db86295b 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -569,11 +569,16 @@ class CmdTestRunner: cmd if cfg.system # cfg.system is broken for main test group with overlay tree else os.path.relpath(os.path.join(repo_root, cmd_dir, cmd))) + passthru_opts = ( + self.passthru_opts if not no_passthru_opts else + [] if no_passthru_opts is True else + [o for o in self.passthru_opts if o[2:].split('=')[0] not in no_passthru_opts]) + args = ( self.pre_args + ([] if no_exec_wrapper else ['scripts/exec_wrapper.py']) + [cmd_path] + - ([] if no_passthru_opts else self.passthru_opts) + + passthru_opts + args) try: diff --git a/test/cmdtest_d/ct_autosign.py b/test/cmdtest_d/ct_autosign.py index 17d1b881..35ae9454 100755 --- a/test/cmdtest_d/ct_autosign.py +++ b/test/cmdtest_d/ct_autosign.py @@ -692,8 +692,10 @@ class CmdTestAutosign(CmdTestAutosignBase): self.bad_msg_count = 0 if self.simulate_led: - LEDControl.create_dummy_control_files() db = LEDControl.boards['dummy'] + for fn in (db.control, db.trigger): + run(f'sudo rm -f {fn}'.split(), check=True) + LEDControl.create_dummy_control_files() usrgrp = {'linux': 'root:root', 'darwin': 'root:wheel'}[sys.platform] for fn in (db.control, db.trigger): # trigger the auto-chmod feature run(f'sudo chmod 644 {fn}'.split(), check=True) diff --git a/test/cmdtest_d/ct_ethdev.py b/test/cmdtest_d/ct_ethdev.py index c5203197..0cfb8d0c 100755 --- a/test/cmdtest_d/ct_ethdev.py +++ b/test/cmdtest_d/ct_ethdev.py @@ -715,13 +715,13 @@ class CmdTestEthdev(CmdTestBase, CmdTestShared): txfile = self.get_file_with_ext(ext, no_dot=True) t = self.spawn( 'mmgen-txsign', - self.eth_args - + [f'--coin={self.proto.coin}'] - + ['--rpc-host=bad_host'] # ETH signing must work without RPC - + ([], ['--yes'])[ni] - + ([f'--keys-from-file={keyfile}'] if dev_send else []) - + add_args - + [txfile, dfl_words_file]) + self.eth_args + + [f'--coin={self.proto.coin}'] + + ['--rpc-host=bad_host'] # ETH signing must work without RPC + + ([], ['--yes'])[ni] + + ([f'--keys-from-file={keyfile}'] if dev_send else []) + + add_args + + [txfile, dfl_words_file]) return self.txsign_ui_common(t, ni=ni, has_label=True) def txsend(self, ext='{}.regtest.sigtx', add_args=[], test=False): @@ -1221,9 +1221,16 @@ class CmdTestEthdev(CmdTestBase, CmdTestShared): def token_bal1(self): return self.token_bal(n='1') - def token_txcreate(self, args=[], token='', inputs='1', fee='50G', file_desc='Unsigned transaction'): + def token_txcreate( + self, + args = [], + token = '', + inputs = '1', + fee = '50G', + file_desc = 'Unsigned transaction'): return self.txcreate_ui_common( - self.spawn('mmgen-txcreate', self.eth_args + [f'--token={token}', '-B', f'--fee={fee}'] + args), + self.spawn('mmgen-txcreate', + self.eth_args + [f'--token={token}', '-B', f'--fee={fee}'] + args), menu = [], inputs = inputs, input_sels_prompt = 'to spend from', diff --git a/test/cmdtest_d/ct_ref_altcoin.py b/test/cmdtest_d/ct_ref_altcoin.py index e524a940..23b01a9d 100755 --- a/test/cmdtest_d/ct_ref_altcoin.py +++ b/test/cmdtest_d/ct_ref_altcoin.py @@ -109,6 +109,7 @@ class CmdTestRefAltcoin(CmdTestRef, CmdTestBase): t = self.spawn( 'mmgen-txsign', ['--outdir=test/trash', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile], + no_passthru_opts = ['coin'], extra_desc = f'{proto.coin}{token_desc} {proto.network}') t.read() t.ok()