Fix Home variable

pull/753/head
Nikhil Parasaram 6 years ago
parent 75c0f1ac16
commit 035c63a167
  1. 7
      mythril/ethereum/util.py
  2. 5
      mythril/mythril.py
  3. 9
      tests/cmd_line_test.py

@ -6,6 +6,7 @@ from subprocess import Popen, PIPE
import binascii import binascii
import os import os
import json import json
from pathlib import Path
def safe_decode(hex_encoded_string): def safe_decode(hex_encoded_string):
@ -45,7 +46,7 @@ def get_solc_json(file, solc_binary="solc", solc_args=None):
) )
except FileNotFoundError: except FileNotFoundError:
raise CompilerError( 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") out = stdout.decode("UTF-8")
@ -73,7 +74,9 @@ def get_indexed_address(index):
def solc_exists(version): def solc_exists(version):
solc_binary = os.path.join( 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): if os.path.exists(solc_binary):
return True return True

@ -9,6 +9,7 @@ import logging
import json import json
import os import os
import re import re
from pathlib import Path
from ethereum import utils from ethereum import utils
import codecs import codecs
@ -243,7 +244,9 @@ class Mythril(object):
) )
solc_binary = os.path.join( 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)) logging.info("Setting the compiler to " + str(solc_binary))
else: else:

@ -9,16 +9,11 @@ def output_of(command):
class CommandLineToolTestCase(BaseTestCase): 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): def test_disassemble_code_correctly(self):
command = "python3 {} MYTH -d --bin-runtime -c 0x5050 --solv 0.4.24".format( command = "python3 {} MYTH -d --bin-runtime -c 0x5050 --solv 0.4.24".format(
MYTH 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): def test_disassemble_solidity_file_correctly(self):
solidity_file = str(TESTDATA / "input_contracts" / "metacoin.sol") solidity_file = str(TESTDATA / "input_contracts" / "metacoin.sol")
@ -27,7 +22,7 @@ class CommandLineToolTestCase(BaseTestCase):
def test_hash_a_function_correctly(self): def test_hash_a_function_correctly(self):
command = "python3 {} --solv 0.4.24 --hash 'setOwner(address)'".format(MYTH) 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): class TruffleTestCase(BaseTestCase):

Loading…
Cancel
Save