Fix json issue (#1503)

* Fix json issue

* Add missing files
pull/1506/head
Nikhil Parasaram 3 years ago committed by GitHub
parent 05a1b5bb7e
commit e1f8b51c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      mythril/ethereum/util.py
  2. 1
      tests/integration_tests/analysis_tests.py
  3. 29
      tests/integration_tests/test_solc_settings.py
  4. 8
      tests/testdata/json_test_dir/PRC20.sol
  5. 7
      tests/testdata/json_test_dir/dir_a/input_file.sol
  6. 6
      tests/testdata/json_test_dir/test_file.json

@ -44,8 +44,10 @@ def get_solc_json(file, solc_binary="solc", solc_settings_json=None):
:return:
"""
cmd = [solc_binary, "--standard-json", "--allow-paths", "."]
settings = json.loads(solc_settings_json) if solc_settings_json else {}
settings = {}
if solc_settings_json:
with open(solc_settings_json) as f:
settings = json.load(f)
settings.update(
{
"optimizer": {"enabled": True},
@ -62,6 +64,7 @@ def get_solc_json(file, solc_binary="solc", solc_settings_json=None):
},
}
)
input_json = json.dumps(
{
"language": "Solidity",

@ -29,5 +29,4 @@ def test_analysis(file_name, tx_data, calldata):
assert len(output[0]["issues"]) == tx_data["ISSUE_COUNT"]
test_case = output[0]["issues"][tx_data["ISSUE_NUMBER"]]["extra"]["testCases"][0]
print(test_case["steps"])
assert test_case["steps"][tx_data["TX_OUTPUT"]]["input"] == calldata

@ -0,0 +1,29 @@
import pytest
import json
import sys
from subprocess import check_output, STDOUT
from tests import PROJECT_DIR, TESTDATA
MYTH = str(PROJECT_DIR / "myth")
def test_positive_solc_settings():
file_dir = str(TESTDATA / "json_test_dir" / "dir_a")
json_file_path = str(TESTDATA / "json_test_dir" / "test_file.json")
file_path = file_dir + "/input_file.sol"
command = f"cd {file_dir} && python3 {MYTH} analyze {file_path} --solc-json {json_file_path} --solv 0.8.0"
output = check_output(command, shell=True, stderr=STDOUT).decode("UTF-8")
assert "The analysis was completed successfully" in output
def test_negative_solc_settings():
file_path = str(TESTDATA / "json_test_dir" / "dir_a" / "input_file.sol")
command = f"python3 {MYTH} analyze {file_path} --solv 0.8.0"
output = check_output(command, shell=True, stderr=STDOUT).decode("UTF-8")
assert (
"""ParserError: Source "@openzeppelin/contracts/token/PRC20/PRC20.sol"""
in output
)

@ -0,0 +1,8 @@
pragma solidity ^0.8.0;
contract PRC20{
function nothing1(uint256 a, uint256 b) public pure returns(uint256) {
return a+b;
}
}

@ -0,0 +1,7 @@
import "@openzeppelin/contracts/token/PRC20/PRC20.sol";
contract Nothing is PRC20{
function nothing() public pure{
}
}

@ -0,0 +1,6 @@
{
"remappings": [ "@openzeppelin/contracts/token/PRC20/=../" ],
"optimizer": {
"enabled": true
}
}
Loading…
Cancel
Save