Browse Source

various fixes and cleanups

The MMGen Project 2 years ago
parent
commit
01f52617f6

+ 5 - 9
mmgen/base_proto/ethereum/pyethereum/utils.py

@@ -6,15 +6,11 @@ from py_ecc.secp256k1 import privtopub,ecdsa_raw_sign,ecdsa_raw_recover
 from .. import rlp
 from .. import rlp
 from ..rlp.sedes import Binary
 from ..rlp.sedes import Binary
 
 
-from mmgen.globalvars import g
-try:
-	assert not g.use_internal_keccak_module
-	import sha3 as _sha3
-	def sha3_256(x): return _sha3.keccak_256(x).digest()
-except:
-	from mmgen.keccak import keccak_256
-	def sha3_256(x):
-		return keccak_256(x).digest()
+from ....util import get_keccak
+keccak_256 = get_keccak()
+
+def sha3_256(bstr):
+	return keccak_256(bstr).digest()
 
 
 import struct
 import struct
 ALL_BYTES = tuple( struct.pack('B', i) for i in range(256) )
 ALL_BYTES = tuple( struct.pack('B', i) for i in range(256) )

+ 1 - 1
mmgen/daemon.py

@@ -25,7 +25,7 @@ from subprocess import run,PIPE,CompletedProcess
 from collections import namedtuple
 from collections import namedtuple
 
 
 from .globalvars import g
 from .globalvars import g
-from .util import msg,die
+from .util import msg,Msg_r,die
 from .flags import *
 from .flags import *
 
 
 _dd = namedtuple('daemon_data',['coind_name','coind_version','coind_version_str']) # latest tested version
 _dd = namedtuple('daemon_data',['coind_name','coind_version','coind_version_str']) # latest tested version

+ 1 - 0
mmgen/main_autosign.py

@@ -168,6 +168,7 @@ async def check_daemons_running():
 		proto = init_proto(coin,testnet=g.testnet,need_amt=True)
 		proto = init_proto(coin,testnet=g.testnet,need_amt=True)
 		if proto.sign_mode == 'daemon':
 		if proto.sign_mode == 'daemon':
 			vmsg(f'Checking {coin} daemon')
 			vmsg(f'Checking {coin} daemon')
+			from .exception import SocketError
 			try:
 			try:
 				await rpc_init(proto)
 				await rpc_init(proto)
 			except SocketError as e:
 			except SocketError as e:

+ 1 - 1
mmgen/msg.py

@@ -15,7 +15,7 @@ msg: base message signing classes
 import os,importlib,json
 import os,importlib,json
 from .globalvars import g
 from .globalvars import g
 from .objmethods import MMGenObject,Hilite,InitErrors
 from .objmethods import MMGenObject,Hilite,InitErrors
-from .util import msg,vmsg,die,suf,make_chksum_6,fmt_list,remove_dups
+from .util import msg,die,suf,make_chksum_6,fmt_list,remove_dups
 from .color import red,orange,grnbg
 from .color import red,orange,grnbg
 from .protocol import init_proto
 from .protocol import init_proto
 from .fileutil import get_data_from_file,write_data_to_file
 from .fileutil import get_data_from_file,write_data_to_file

+ 0 - 2
mmgen/opts.py

@@ -57,8 +57,6 @@ def print_help(po,opts_data,opt_filter):
 		opts_data['code']['long_options'] = common_opts_data['code']
 		opts_data['code']['long_options'] = common_opts_data['code']
 		def remove_unneeded_long_opts():
 		def remove_unneeded_long_opts():
 			d = opts_data['text']['long_options']
 			d = opts_data['text']['long_options']
-			if g.prog_name != 'mmgen-tool':
-				d = '\n'.join(''+i for i in d.split('\n') if not '--monero-wallet' in i)
 			if proto.base_proto != 'Ethereum':
 			if proto.base_proto != 'Ethereum':
 				d = '\n'.join(''+i for i in d.split('\n') if not '--token' in i)
 				d = '\n'.join(''+i for i in d.split('\n') if not '--token' in i)
 			opts_data['text']['long_options'] = d
 			opts_data['text']['long_options'] = d

+ 1 - 1
mmgen/tool/util.py

@@ -69,7 +69,7 @@ class tool_cmd(tool_cmd_base):
 		"decode hexdump from file (use '-' for stdin) (warning: outputs binary data)"
 		"decode hexdump from file (use '-' for stdin) (warning: outputs binary data)"
 		from ..globalvars import g
 		from ..globalvars import g
 		if g.platform == 'win':
 		if g.platform == 'win':
-			import msvcrt
+			import sys,os,msvcrt
 			msvcrt.setmode( sys.stdout.fileno(), os.O_BINARY )
 			msvcrt.setmode( sys.stdout.fileno(), os.O_BINARY )
 		from ..fileutil import get_data_from_file
 		from ..fileutil import get_data_from_file
 		from ..util import decode_pretty_hexdump
 		from ..util import decode_pretty_hexdump

+ 1 - 1
mmgen/tx/info.py

@@ -15,7 +15,7 @@ tx.info: transaction info class
 from ..globalvars import *
 from ..globalvars import *
 from ..color import red,green,orange
 from ..color import red,green,orange
 from ..opts import opt
 from ..opts import opt
-from ..util import msg,msg_r
+from ..util import msg,msg_r,do_pager
 
 
 import importlib
 import importlib
 
 

+ 2 - 2
setup.cfg

@@ -23,7 +23,7 @@ python_requires = >=3.7
 include_package_data = True
 include_package_data = True
 
 
 # pysha3 is used by XMR and ETH for the keccak hash function only.  If the
 # pysha3 is used by XMR and ETH for the keccak hash function only.  If the
-# module is not available, the native Python implementation in mmgen.keccak
+# module is unavailable, the native Python implementation in contrib.keccak
 # will be used instead.
 # will be used instead.
 install_requires =
 install_requires =
 	importlib-resources; python_version < "3.9"
 	importlib-resources; python_version < "3.9"
@@ -34,7 +34,7 @@ install_requires =
 	requests
 	requests
 	pysocks # xmrwallet.py
 	pysocks # xmrwallet.py
 	pexpect
 	pexpect
-	scrypt; platform_system != "Windows" # requires user intervention to install on MSYS2
+	scrypt; platform_system != "Windows" # must be installed by hand on MSYS2
 	semantic-version; platform_system != "Windows" # scripts/create-token.py
 	semantic-version; platform_system != "Windows" # scripts/create-token.py
 	aiohttp; platform_system != "Windows"
 	aiohttp; platform_system != "Windows"
 	pysha3; platform_system != "Windows"
 	pysha3; platform_system != "Windows"

+ 1 - 0
test/ref/713E94[BTC].rawmsg.json → test/ref/997F55[BTC].rawmsg.json

@@ -6,6 +6,7 @@
             "99E0FC61:S:102"
             "99E0FC61:S:102"
         ],
         ],
         "message": "24/3/2022 Russia announces it will sell gas for bitcoin",
         "message": "24/3/2022 Russia announces it will sell gas for bitcoin",
+        "msghash_type": "raw",
         "network": "btc_mainnet"
         "network": "btc_mainnet"
     },
     },
     "signatures": {}
     "signatures": {}

+ 1 - 0
test/ref/9DA060[BTC].rawmsg.json → test/ref/ED405C[BTC].rawmsg.json

@@ -6,6 +6,7 @@
             "DEADBEEF:C:1"
             "DEADBEEF:C:1"
         ],
         ],
         "message": "08/Jun/2021 Bitcoin Law Enacted by El Salvador Legislative Assembly",
         "message": "08/Jun/2021 Bitcoin Law Enacted by El Salvador Legislative Assembly",
+        "msghash_type": "raw",
         "network": "btc_mainnet"
         "network": "btc_mainnet"
     },
     },
     "signatures": {}
     "signatures": {}

+ 1 - 0
test/ref/litecoin/685D23[LTC].rawmsg.json → test/ref/litecoin/6C01C6[LTC].rawmsg.json

@@ -5,6 +5,7 @@
             "98831F3A:B:1"
             "98831F3A:B:1"
         ],
         ],
         "message": "24/3/2022 Russia announces it will sell gas for bitcoin",
         "message": "24/3/2022 Russia announces it will sell gas for bitcoin",
+        "msghash_type": "raw",
         "network": "ltc_mainnet"
         "network": "ltc_mainnet"
     },
     },
     "signatures": {}
     "signatures": {}

+ 2 - 2
test/test-release.sh

@@ -134,10 +134,10 @@ do
 	N)  test_py+=" --no-timings" ;;
 	N)  test_py+=" --no-timings" ;;
 	O)  test_py+=" --pexpect-spawn" ;;
 	O)  test_py+=" --pexpect-spawn" ;;
 	p)  PAUSE=1 ;;
 	p)  PAUSE=1 ;;
-	s)  SKIP_LIST="$OPTARG" ;;
+	s)  SKIP_LIST+=" $OPTARG" ;;
 	t)  LIST_CMDS=1 ;;
 	t)  LIST_CMDS=1 ;;
 	v)  EXACT_OUTPUT=1 test_py+=" --exact-output" ;&
 	v)  EXACT_OUTPUT=1 test_py+=" --exact-output" ;&
-	V)  VERBOSE=1
+	V)  VERBOSE='--verbose'
 		[ "$EXACT_OUTPUT" ] || test_py+=" --verbose"
 		[ "$EXACT_OUTPUT" ] || test_py+=" --verbose"
 		unit_tests_py="${unit_tests_py/--quiet/--verbose}"
 		unit_tests_py="${unit_tests_py/--quiet/--verbose}"
 		altcoin_mod_opts="${altcoin_mod_opts/--quiet/--verbose}"
 		altcoin_mod_opts="${altcoin_mod_opts/--quiet/--verbose}"

+ 1 - 1
test/test_py_d/ts_autosign.py

@@ -264,7 +264,7 @@ class TestSuiteAutosignBase(TestSuiteBase):
 		else:
 		else:
 			for fn in self.ref_msgfiles:
 			for fn in self.ref_msgfiles:
 				if op == 'copy':
 				if op == 'copy':
-					if os.path.basename(fn) == '9DA060[BTC].rawmsg.json': # contains bad Seed ID
+					if os.path.basename(fn) == 'ED405C[BTC].rawmsg.json': # contains bad Seed ID
 						self.bad_msg_count += 1
 						self.bad_msg_count += 1
 					else:
 					else:
 						self.good_msg_count += 1
 						self.good_msg_count += 1

+ 6 - 5
test/test_py_d/ts_ethdev.py

@@ -383,11 +383,12 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
 			for d in ('mm1','mm2'):
 			for d in ('mm1','mm2'):
 				copytree(os.path.join(srcdir,d),os.path.join(self.tmpdir,d))
 				copytree(os.path.join(srcdir,d),os.path.join(self.tmpdir,d))
 
 
+		if g.daemon_id == 'geth' and not (opt.resume or opt.resume_after or opt.skip_deps):
+			self.geth_setup()
+			set_vt100()
+			# await geth_devnet_init_bug_workaround() # uncomment to enable testing with v1.10.17
+
 		if not opt.no_daemon_autostart:
 		if not opt.no_daemon_autostart:
-			if g.daemon_id == 'geth':
-				self.geth_setup()
-				set_vt100()
-				# await geth_devnet_init_bug_workaround() # uncomment to enable testing with v1.10.17
 			if not start_test_daemons(
 			if not start_test_daemons(
 					self.proto.coin+'_rt',
 					self.proto.coin+'_rt',
 					remove_datadir = not g.daemon_id in ('geth','erigon') ):
 					remove_datadir = not g.daemon_id in ('geth','erigon') ):
@@ -438,7 +439,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
 
 
 		def init_genesis(fn):
 		def init_genesis(fn):
 			cmd = f'geth init --datadir {d.datadir} {fn}'
 			cmd = f'geth init --datadir {d.datadir} {fn}'
-			cp = run(cmd.split(),stdout=PIPE,stderr=PIPE)
+			cp = run( cmd.split(), stdout=PIPE, stderr=PIPE )
 			if cp.returncode:
 			if cp.returncode:
 				die(1,cp.stderr.decode())
 				die(1,cp.stderr.decode())