def test_add_require_condition_with_overflow_2(self): source = """ pragma solidity ^0.4.22; contract testContract { function testFunction (int foo) public pure returns (string) { uint bar = 5*uint(foo); require(bar > uint(foo)); return 'helloWorld'; } } """ require_conditions, candidates = self.before_test(source) conditions = add_require_condition_with_overflow(require_conditions, candidates) self.assertTrue('bar_actual_value' in conditions) self.assertTrue('foo_actual_value' not in conditions)
def test_add_require_condition_with_overflow_no_requires(self): source = """ pragma solidity ^0.4.22; contract testContract { uint foo; function testFunction () public returns (string) { uint[] barList; uint bar = 5 * foo ; return 'helloWorld'; } } """ require_conditions, candidates = self.before_test(source) constraints = add_require_condition_with_overflow(require_conditions, candidates) not_empty_lines = list(filter(None, constraints.splitlines())) self.assertTrue(len(not_empty_lines) == 1 and not_empty_lines[0].startswith("# ==="))
def test_add_require_condition_with_overflow_3(self): source = """ pragma solidity ^0.4.22; contract testContract { function testFunction () public pure returns (string) { int bar = 5 * foo ; int foo = bar + 9; require(bar * (6 + foo) > foo); require(bar * (6 + foo) != ((2 % foo) - (-((2)*foo+(3)) / 3))); return 'helloWorld'; } } """ require_conditions, candidates = self.before_test(source) conditions = add_require_condition_with_overflow(require_conditions, candidates) self.assertTrue(re.findall(r'exp_\d+_actual_value !=', conditions)) self.assertTrue(re.findall(r'exp_\d+_actual_value > foo_actual_value', conditions))
def test_add_require_condition_with_overflow_7(self): source = """ pragma solidity ^0.4.22; contract testContract { uint foo; function testFunction () public returns (string) { uint[] barList; uint bar = 5 * foo ; require(bar * (6 + foo) > foo || foo > 9); require(barList.length * (6 + bar) != ((2 % bar) + (-((2)*bar+(3)) / 3))); return 'helloWorld'; } } """ require_conditions, candidates = self.before_test(source) conditions = add_require_condition_with_overflow(require_conditions, candidates) self.assertTrue(re.findall(r"Or\(exp_\d+_actual_value > foo, foo > 9\)", conditions)) self.assertTrue(re.findall(r"exp_\d+_actual_value != \(exp_\d+_actual_value\)\)", conditions))