From 9e62934151ea21c5ab86c10b8afd462cae963559 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 15 Sep 2025 09:28:41 +0000 Subject: [PATCH] test suite: support `ethkey` as alternative to `eth-keys` --- test/gentest.py | 27 +++++++++++++++++++++------ test/include/common.py | 12 ++++++++++++ test/modtest_d/testdep.py | 12 +++++++++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/test/gentest.py b/test/gentest.py index 67025b48..b2c04fa3 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -107,7 +107,10 @@ EXAMPLES: SUPPORTED EXTERNAL TOOLS: + eth-keys (for ETH, ETC) - https://github.com/ethereum/eth-keys + https://github.com/ethereum/eth-keys + + + ethkey (eth-keys alternative for MSYS2, or if eth-keys is unavailable) + https://github.com/openethereum/openethereum/releases/tag/v3.1.0 + zcash-mini (for Zcash-Z addresses and view keys) https://github.com/FiloSottile/zcash-mini @@ -166,13 +169,25 @@ class GenToolEth_keys(GenTool): desc = 'eth-keys' def __init__(self, *args, **kwargs): - from eth_keys import keys - self.keys = keys + self.keys = self.cmdname = None + try: + from eth_keys import keys + self.keys = keys + except ImportError: + self.cmdname = get_ethkey() + self.desc = 'ethkey' + if not (self.keys or self.cmdname): + die(2, 'Neither the ‘eth-keys’ package nor the ‘ethkey’ executable ' + 'could be found on the system!') super().__init__(*args, **kwargs) def run(self, sec, vcoin): - sk = self.keys.PrivateKey(sec) - return gtr(str(sk)[2:], sk.public_key.to_address()[2:], None) + if self.keys: + sk = self.keys.PrivateKey(sec) + return gtr(str(sk)[2:], sk.public_key.to_address()[2:], None) + else: + o = get_cmd_output([self.cmdname, 'info', sec.hex()]) + return gtr(o[0].split()[1], o[-1].split()[1], None) class GenToolKeyconv(GenTool): desc = 'keyconv' @@ -562,7 +577,7 @@ from mmgen.key import PrivKey from mmgen.addr import MMGenAddrType from mmgen.addrgen import KeyGenerator, AddrGenerator from mmgen.keygen import get_backends -from test.include.common import getrand, set_globals +from test.include.common import getrand, get_ethkey, set_globals gtr = namedtuple('gen_tool_result', ['wif', 'addr', 'viewkey']) sd = namedtuple('saved_data_item', ['reduced', 'wif', 'addr', 'viewkey']) diff --git a/test/include/common.py b/test/include/common.py index 99d794a4..06eb9325 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -339,6 +339,18 @@ def check_solc_ver(): omsg(res) return False +def get_ethkey(): + cmdnames = ('ethkey', 'openethereum-ethkey') + for cmdname in cmdnames: + try: + cp = run([cmdname, '--help'], stdout=PIPE, text=True) + except: + pass + else: + if 'Parity' in cp.stdout: + return cmdname + return None + def do_run(cmd, check=True): return run(cmd, stdout=PIPE, stderr=DEVNULL, check=check) diff --git a/test/modtest_d/testdep.py b/test/modtest_d/testdep.py index 466dcc13..8f67f286 100755 --- a/test/modtest_d/testdep.py +++ b/test/modtest_d/testdep.py @@ -8,7 +8,7 @@ import os from subprocess import run, DEVNULL from mmgen.util import ymsg, bmsg -from ..include.common import cfg +from ..include.common import cfg, get_ethkey sec = 'deadbeef' * 8 @@ -61,8 +61,14 @@ class unit_tests: return True def eth_keys(self, name, ut): - from eth_keys import keys - return True + try: + from eth_keys import keys + return True + except ImportError: + if get_ethkey(): + return True + ymsg('Neither the ‘eth-keys’ package nor the Parity ‘ethkey’ executable ' + 'could be found on the system!') def ssh_socks_proxy(self, name, ut): from test.cmdtest_d.include.proxy import TestProxy