mirror of https://github.com/ConsenSys/mythril
blockchainethereumsmart-contractssoliditysecurityprogram-analysissecurity-analysissymbolic-execution
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.5 KiB
38 lines
1.5 KiB
from pathlib import Path
|
|
|
|
from mythril.solidity.soliditycontract import SolidityContract
|
|
from tests import BaseTestCase
|
|
|
|
TEST_FILES = Path(__file__).parent / "testdata/input_contracts"
|
|
|
|
|
|
class SolidityContractTest(BaseTestCase):
|
|
def test_get_source_info_without_name_gets_latest_contract_info(self):
|
|
input_file = TEST_FILES / "multi_contracts.sol"
|
|
contract = SolidityContract(str(input_file))
|
|
|
|
code_info = contract.get_source_info(142)
|
|
|
|
self.assertEqual(code_info.filename, str(input_file))
|
|
self.assertEqual(code_info.lineno, 14)
|
|
self.assertEqual(code_info.code, "msg.sender.transfer(2 ether)")
|
|
|
|
def test_get_source_info_with_contract_name_specified(self):
|
|
input_file = TEST_FILES / "multi_contracts.sol"
|
|
contract = SolidityContract(str(input_file), name="Transfer1")
|
|
|
|
code_info = contract.get_source_info(142)
|
|
|
|
self.assertEqual(code_info.filename, str(input_file))
|
|
self.assertEqual(code_info.lineno, 6)
|
|
self.assertEqual(code_info.code, "msg.sender.transfer(1 ether)")
|
|
|
|
def test_get_source_info_with_contract_name_specified_constructor(self):
|
|
input_file = TEST_FILES / "constructor_assert.sol"
|
|
contract = SolidityContract(str(input_file), name="AssertFail")
|
|
|
|
code_info = contract.get_source_info(62, constructor=True)
|
|
|
|
self.assertEqual(code_info.filename, str(input_file))
|
|
self.assertEqual(code_info.lineno, 6)
|
|
self.assertEqual(code_info.code, "assert(var1>0)")
|
|
|