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.
48 lines
1.8 KiB
48 lines
1.8 KiB
7 years ago
|
import unittest
|
||
6 years ago
|
from mythril.ethereum.evmcontract import EVMContract
|
||
7 years ago
|
|
||
7 years ago
|
|
||
6 years ago
|
class EVMContractTestCase(unittest.TestCase):
|
||
7 years ago
|
def setUp(self):
|
||
|
self.code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029"
|
||
7 years ago
|
self.creation_code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029"
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
class Getinstruction_listTestCase(EVMContractTestCase):
|
||
7 years ago
|
def runTest(self):
|
||
6 years ago
|
contract = EVMContract(self.code, self.creation_code)
|
||
7 years ago
|
|
||
7 years ago
|
disassembly = contract.disassembly
|
||
7 years ago
|
|
||
6 years ago
|
self.assertEqual(
|
||
|
len(disassembly.instruction_list),
|
||
|
53,
|
||
6 years ago
|
"Error disassembling code using EVMContract.get_instruction_list()",
|
||
6 years ago
|
)
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
class GetEASMTestCase(EVMContractTestCase):
|
||
7 years ago
|
def runTest(self):
|
||
6 years ago
|
contract = EVMContract(self.code)
|
||
7 years ago
|
|
||
7 years ago
|
instruction_list = contract.get_easm()
|
||
7 years ago
|
|
||
6 years ago
|
self.assertTrue(
|
||
|
"PUSH1 0x60" in instruction_list,
|
||
6 years ago
|
"Error obtaining EASM code through EVMContract.get_easm()",
|
||
6 years ago
|
)
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
class MatchesExpressionTestCase(EVMContractTestCase):
|
||
7 years ago
|
def runTest(self):
|
||
6 years ago
|
contract = EVMContract(self.code)
|
||
7 years ago
|
|
||
6 years ago
|
self.assertTrue(
|
||
|
contract.matches_expression("code#PUSH1# or code#PUSH1#"),
|
||
|
"Unexpected result in expression matching",
|
||
|
)
|
||
|
self.assertFalse(
|
||
|
contract.matches_expression("func#abcdef#"),
|
||
|
"Unexpected result in expression matching",
|
||
|
)
|