From 035c63a1672ec68f4d33d33ccac3ca72886c1ff0 Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Sun, 25 Nov 2018 01:01:19 +0530 Subject: [PATCH] Fix Home variable --- mythril/ethereum/util.py | 7 +++++-- mythril/mythril.py | 5 ++++- tests/cmd_line_test.py | 9 ++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mythril/ethereum/util.py b/mythril/ethereum/util.py index 93cb2c06..6a441f3e 100644 --- a/mythril/ethereum/util.py +++ b/mythril/ethereum/util.py @@ -6,6 +6,7 @@ from subprocess import Popen, PIPE import binascii import os import json +from pathlib import Path def safe_decode(hex_encoded_string): @@ -45,7 +46,7 @@ def get_solc_json(file, solc_binary="solc", solc_args=None): ) except FileNotFoundError: raise CompilerError( - "Compiler not found. Make sure that solc is installed and in PATH, or set the SOLC environment variable." + "Compiler not found.+ Make sure that solc is installed and in PATH, or set the SOLC environment variable." ) out = stdout.decode("UTF-8") @@ -73,7 +74,9 @@ def get_indexed_address(index): def solc_exists(version): solc_binary = os.path.join( - os.environ["HOME"], ".py-solc/solc-v" + version, "bin/solc" + os.environ.get("HOME", str(Path.home())), + ".py-solc/solc-v" + version, + "bin/solc", ) if os.path.exists(solc_binary): return True diff --git a/mythril/mythril.py b/mythril/mythril.py index 6a8a2578..ce1ffbe0 100644 --- a/mythril/mythril.py +++ b/mythril/mythril.py @@ -9,6 +9,7 @@ import logging import json import os import re +from pathlib import Path from ethereum import utils import codecs @@ -243,7 +244,9 @@ class Mythril(object): ) solc_binary = os.path.join( - os.environ["HOME"], ".py-solc/solc-v" + version, "bin/solc" + os.environ.get("HOME", str(Path.home())), + ".py-solc/solc-v" + version, + "bin/solc", ) logging.info("Setting the compiler to " + str(solc_binary)) else: diff --git a/tests/cmd_line_test.py b/tests/cmd_line_test.py index c346323f..ef846480 100644 --- a/tests/cmd_line_test.py +++ b/tests/cmd_line_test.py @@ -9,16 +9,11 @@ def output_of(command): class CommandLineToolTestCase(BaseTestCase): - def install_solc_test_version(self): - # This initializes the solc v0.4.24 - command = "python3 {} MYTH -d --solv 0.4.24".format(MYTH) - output_of(command) - def test_disassemble_code_correctly(self): command = "python3 {} MYTH -d --bin-runtime -c 0x5050 --solv 0.4.24".format( MYTH ) - self.assertEqual("0 POP\n1 POP\n", output_of(command)) + self.assertIn("0 POP\n1 POP\n", output_of(command)) def test_disassemble_solidity_file_correctly(self): solidity_file = str(TESTDATA / "input_contracts" / "metacoin.sol") @@ -27,7 +22,7 @@ class CommandLineToolTestCase(BaseTestCase): def test_hash_a_function_correctly(self): command = "python3 {} --solv 0.4.24 --hash 'setOwner(address)'".format(MYTH) - self.assertEqual("0x13af4035\n", output_of(command)) + self.assertIn("0x13af4035\n", output_of(command)) class TruffleTestCase(BaseTestCase):