def test_mappings(self): mapping_config = TestVeriMan.get_test_config() mapping_config.contract.path = os.path.dirname( os.path.abspath(__file__)) + '/Mappings.sol' mapping_config.instrumentation.predicates = ['aMapping[anInt] > 3'] mapping_config.verification.verisol.use = False veriman = VeriMan() proof_found, verisol_counterexample = veriman.analyze_contract( mapping_config) self.check_contract_compiles(veriman.contract_path) self.check_functions_with_asserts( veriman, [ 'setMapping', 'setAnInt', # Because it also instruments a random function, and it choses it from a list in alphabetic order: # FIXME improve way to check read(int) is not instrumented: 'anotherFunction', 'constructor' ]) os.remove(veriman.contract_path)
def get_test_config(): test_config = VeriMan.parse_config('config_tests.json') user_config = VeriMan.parse_config('../config.json') test_config.verification.verisol.path = user_config.verification.verisol.path test_config.verification.manticore.output_path = os.path.dirname( os.path.abspath(__file__)) + '/output' return test_config
def test_inheritance(self): inheritance_config = TestVeriMan.get_test_config() inheritance_config.contract.path = os.path.dirname( os.path.abspath(__file__)) + '/Inheritance.sol' inheritance_config.contract.name = 'D' inheritance_config.instrumentation.predicates = [ 'a_var + b_var + c_var + d_var < 10', 'block.number > 10' ] inheritance_config.verification.verisol.use = False veriman = VeriMan() proof_found, verisol_counterexample = veriman.analyze_contract( inheritance_config) self.check_contract_compiles(veriman.contract_path) slither = Slither(veriman.contract_path) contract_info = slither.get_contract_from_name( inheritance_config.contract.name) expected_functions = set( list([ 'aFunction', 'toBeOverwritten', 'bFunction', 'withTheSameName', 'callsC', 'dFunction', 'constructor' ])) found_functions = list( map(lambda func: func.name, contract_info.functions_declared)) self.assertEqual(found_functions.count('withTheSameName'), 3) self.assertEqual(found_functions.count('toBeOverwritten'), 1) self.assertEqual(expected_functions, set(found_functions)) os.remove(veriman.contract_path)
def test_parameters(self): params_config = TestVeriMan.get_test_config() params_config.contract.path = os.path.dirname( os.path.abspath(__file__)) + '/InOrderWithParams.sol' params_config.instrumentation.instrument = False veriman = VeriMan() proof_found, verisol_counterexample = veriman.analyze_contract( params_config) self.check_error_output(proof_found, ['Constructor', 'a', 'b', 'c'], verisol_counterexample)
def setUpClass(cls): cls.inorder_config = TestVeriMan.get_test_config() cls.inorder_config.contract.path = os.path.dirname( os.path.abspath(__file__)) + '/InOrder.sol' cls.inorder_veriman = VeriMan() cls.inorder_veriman.pre_process_contract(cls.inorder_config)
from src.veriman import VeriMan if __name__ == '__main__': veriman = VeriMan() config = VeriMan.parse_config('../config.json') if config.verification.verisol.use and config.instrumentation.instrument: veriman.pre_process_contract(config) original_predicates = config.instrumentation.predicates for predicate in original_predicates: config.instrumentation.predicates = [predicate] proof_found, verisol_counterexample = veriman.analyze_contract(config, reuse_pre_process=True) else: proof_found, verisol_counterexample = veriman.analyze_contract(config)