From 4aa9f731c23bbe26dba09c13620e84c271b4d6de Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 5 Oct 2022 19:22:41 +0000 Subject: [PATCH] test suite: use monero-python as reference tool --- mmgen/altcoin.py | 2 +- test/gentest.py | 23 +++++++++++++---------- test/unit_tests_d/ut_testdep.py | 10 +++++----- test/unit_tests_d/ut_xmrseed.py | 19 ++++++++++--------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/mmgen/altcoin.py b/mmgen/altcoin.py index a8aea77c..c9a4d8f7 100755 --- a/mmgen/altcoin.py +++ b/mmgen/altcoin.py @@ -672,7 +672,7 @@ class CoinInfo(object): 'WUBS', 'XC', 'XPM', 'YAC', 'ZOOM', 'ZRC'), 'ethkey': ('ETH','ETC'), 'zcash-mini': ('ZEC',), - 'moneropy': ('XMR',), + 'monero-python': ('XMR',), }, 'testnet': { 'pycoin': { diff --git a/test/gentest.py b/test/gentest.py index 8b797de4..834e3d56 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -94,9 +94,9 @@ EXAMPLES: Same for Zcash: $ test/gentest.py --coin=zec --type=zcash_z 1 10000 - Test all configured Monero backends against 'moneropy' library, 3 rounds + Test all configured Monero backends against the 'monero-python' library, 3 rounds + edge cases: - $ test/gentest.py --coin=xmr all:moneropy 3 + $ test/gentest.py --coin=xmr all:monero-python 3 Test 'nacl' and 'ed25519ll_djbec' backends against each other, 10,000 rounds + edge cases: @@ -111,8 +111,8 @@ SUPPORTED EXTERNAL TOOLS: + zcash-mini (for Zcash-Z addresses and view keys) https://github.com/FiloSottile/zcash-mini - + moneropy (for Monero addresses and view keys) - https://github.com/bigreddmachine/MoneroPy + + monero-python (for Monero addresses and view keys) + https://github.com/monero-ecosystem/monero-python + pycoin (for supported coins) https://github.com/richardkiss/pycoin @@ -226,19 +226,22 @@ class GenToolPycoin(GenTool): addr = key.address() return gtr( key.wif(), addr, None ) -class GenToolMoneropy(GenTool): - desc = 'moneropy' +class GenToolMonero_python(GenTool): + desc = 'monero-python' def __init__(self,*args,**kwargs): super().__init__(*args,**kwargs) try: - import moneropy.account + from monero.seed import Seed except: - raise ImportError('Unable to import moneropy. Is moneropy installed on your system?') - self.mpa = moneropy.account + raise ImportError('Unable to import monero-python. Is monero-python installed on your system?') + self.Seed = Seed def run(self,sec,vcoin): - sk,vk,addr = self.mpa.account_from_spend_key(sec.hex()) # VERY slow! + seed = self.Seed( sec.orig_bytes.hex() ) + sk = seed.secret_spend_key() + vk = seed.secret_view_key() + addr = seed.public_address() return gtr( sk, addr, vk ) def find_or_check_tool(proto,addr_type,toolname): diff --git a/test/unit_tests_d/ut_testdep.py b/test/unit_tests_d/ut_testdep.py index 2247020b..168af18b 100755 --- a/test/unit_tests_d/ut_testdep.py +++ b/test/unit_tests_d/ut_testdep.py @@ -10,8 +10,8 @@ sec = 'deadbeef' * 8 class unit_tests: - altcoin_deps = ('pycoin','moneropy','keyconv','zcash_mini','ethkey','ssh_socks_proxy') - win_skip = ('losetup','moneropy','zcash_mini') + altcoin_deps = ('pycoin','monero_python','keyconv','zcash_mini','ethkey','ssh_socks_proxy') + win_skip = ('losetup','monero_python','zcash_mini') def core_repo(self,name,ut): crr = os.getenv('CORE_REPO_ROOT') @@ -33,9 +33,9 @@ class unit_tests: addr = network.address.for_p2pkh_wit(hash160_c) return True - def moneropy(self,name,ut): - from moneropy import account - res = account.account_from_spend_key(sec) + def monero_python(self,name,ut): + from monero.seed import Seed + res = Seed('deadbeef' * 8).public_address() return True def keyconv(self,name,ut): diff --git a/test/unit_tests_d/ut_xmrseed.py b/test/unit_tests_d/ut_xmrseed.py index 450b247e..35b5bd92 100755 --- a/test/unit_tests_d/ut_xmrseed.py +++ b/test/unit_tests_d/ut_xmrseed.py @@ -59,9 +59,9 @@ class unit_test(object): vmsg(f' {chk}') chk = tuple(chk.split()) res = b.fromhex(privhex) - if use_moneropy: - mp_chk = tuple( mnemonic.mn_encode(privhex) ) - assert res[:24] == mp_chk, f'check failed:\nres: {res[:24]}\nchk: {chk}' + if use_monero_python: + mp_chk = tuple( wl.encode(privhex).split() ) + assert res == mp_chk, f'check failed:\nres: {res}\nchk: {chk}' assert res == chk, f'check failed:\nres: {res}\nchk: {chk}' def test_tohex(b): @@ -70,8 +70,8 @@ class unit_test(object): for chk,words in self.vectors: vmsg(f' {chk}') res = b.tohex( words.split() ) - if use_moneropy: - mp_chk = mnemonic.mn_decode( words.split() ) + if use_monero_python: + mp_chk = wl.decode( words ) assert res == mp_chk, f'check failed:\nres: {res}\nchk: {mp_chk}' assert res == chk, f'check failed:\nres: {res}\nchk: {chk}' @@ -84,12 +84,13 @@ class unit_test(object): b.check_wordlist() try: - from moneropy import mnemonic + from monero.wordlists.english import English + wl = English() except ImportError: - use_moneropy = False - ymsg('Warning: unable to import moneropy, skipping external library checks') + use_monero_python = False + ymsg('Warning: unable to import monero-python, skipping external library checks') else: - use_moneropy = True + use_monero_python = True test_fromhex(b) test_tohex(b)