示例#1
0
    def test_add_symbolic_expressions_number_from_formal_param(self):
        source = """
			pragma solidity ^0.4.22;
			contract testContract {
				function testFunction (uint paramFoo) public returns (string) {
					uint bar = 5*paramFoo;
					require(bar > 5);
					return 'helloWorld';
				}
			}
		"""
        inspected_obj = self.before_test(source)
        accessed_state_variables = inspected_obj['local_variables']
        constraints = add_symbolic_expressions(accessed_state_variables)
        self.assertTrue('bar == 5 * paramFoo' in constraints)
示例#2
0
    def test_add_symbolic_expressions_address_cast(self):
        source = """
			pragma solidity ^0.4.22;
			contract testContract {
				function testFunction () public returns (string) {
					address a = address(0x0);
					uint foo = 4;
					uint bar = 5*uint(a);
					require(bar > 5);
					return 'helloWorld';
				}
			}
		"""
        inspected_obj = self.before_test(source)
        accessed_state_variables = inspected_obj['local_variables']
        constraints = add_symbolic_expressions(accessed_state_variables)
        self.assertTrue('a == null_address' in constraints)
        self.assertTrue('bar == 5 * a' in constraints)  # cast are just skipped
示例#3
0
    def test_add_symbolic_expressions_number_from_state_list(self):
        source = """
			pragma solidity ^0.4.22;
			contract testContract {
				uint[] stateFoo;
				function testFunction () public returns (string) {
					uint paramFoo = 4;
					uint bar = 5*stateFoo[0];
					uint foo = 3*stateFoo.length; 
					require(bar > 5);
					return 'helloWorld';
				}
			}
		"""
        inspected_obj = self.before_test(source)
        accessed_state_variables = inspected_obj['local_variables']
        constraints = add_symbolic_expressions(accessed_state_variables)
        self.assertTrue('bar == 5 * stateFoo[0]' in constraints)
        self.assertTrue('foo == 3 * stateFoo_length' in constraints)
        self.assertTrue('paramFoo == 4' in constraints)
示例#4
0
    def test_add_symbolic_expressions_special_variables(self):
        source = """
			pragma solidity ^0.4.22;
			contract testContract {
				function testFunction () public returns (string) {
					uint foo = msg.value;
					uint bar = 4 * foo;
					address sender = msg.sender;
					address naddress = address(0);
					address naddress2 = address(0x0);
					require(bar > 5);
					return 'helloWorld';
				}
			}
		"""
        inspected_obj = self.before_test(source)
        accessed_state_variables = inspected_obj['local_variables']
        constraints = add_symbolic_expressions(accessed_state_variables)
        self.assertTrue('foo == msg_value' in constraints)
        self.assertTrue('sender == msg_sender' in constraints)
        self.assertTrue('bar == 4 * foo' in constraints)
        self.assertTrue('naddress == null_address' in constraints)
        self.assertTrue('naddress2 == null_address' in constraints)