Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
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.
mythril/tests/contractstorage_test.py

33 lines
1.1 KiB

7 years ago
from mythril.ether.contractstorage import get_persistent_storage
import os
from tests import BaseTestCase
7 years ago
class GetAndSearchContractTestCase(BaseTestCase):
7 years ago
7 years ago
def setUp(self):
super(GetAndSearchContractTestCase, self).setUp()
7 years ago
script_path = os.path.dirname(os.path.realpath(__file__))
storage_dir = os.path.join(script_path, 'teststorage')
self.storage, self.db = get_persistent_storage(storage_dir)
def tearDown(self):
self.db.close()
super(GetAndSearchContractTestCase, self).tearDown()
7 years ago
7 years ago
def mockCallback(self, code_hash, code, addresses, balances):
7 years ago
self.code_hash = code_hash
7 years ago
self.isFound = True
pass
def runTest(self):
7 years ago
contract = self.storage.get_contract_by_hash(bytes.fromhex("ea061445eacbe86b7ffed2bb9e52075e"))
7 years ago
7 years ago
self.assertTrue("0x60606040" in contract.code, 'error reading contract code from database')
7 years ago
self.isFound = False
7 years ago
self.storage.search("code#PUSH1#", self.mockCallback)
7 years ago
7 years ago
self.assertTrue(self.isFound, 'storage search error')
self.assertEqual(self.code_hash, 'ea061445eacbe86b7ffed2bb9e52075e', 'storage search error')