コード例 #1
0
ファイル: test_parent_setter.py プロジェクト: nibau/zkay
    def test_all_nodes_have_parent(self):
        ast = build_ast(self.example.code())
        set_parents(ast)

        # test
        v = ParentChecker()
        v.visit(ast)
コード例 #2
0
ファイル: test_parent_setter.py プロジェクト: nibau/zkay
    def test_root_children_have_parent(self):
        ast = build_ast(self.example.code())
        set_parents(ast)

        # test
        for c in ast.children():
            self.assertEqual(c.parent, ast)
コード例 #3
0
 def test_symbol_table(self):
     ast = build_ast(self.example.code())
     set_parents(ast)
     fill_symbol_table(ast)
     link_identifiers(ast)
     contract = ast.contracts[0]
     self.assertEqual(contract.idf.name, self.name)
コード例 #4
0
ファイル: test_parent_setter.py プロジェクト: nibau/zkay
    def test_contract_identifier(self):
        ast = build_ast(self.example.code())
        set_parents(ast)

        # test
        contract = ast.contracts[0]
        idf = contract.idf
        self.assertEqual(idf.parent, contract)
コード例 #5
0
    def test_fill_symbol_table(self):
        ast = build_ast(simple_storage.code())
        fill_symbol_table(ast)

        contract = ast.contracts[0]

        s = get_builtin_globals()
        s.update({'SimpleStorage': contract.idf})
        self.assertDictEqual(ast.names, s)
コード例 #6
0
    def test_link_identifiers(self):
        ast = build_ast(simple.code())
        set_parents(ast)
        link_identifiers(ast)

        self.get_ast_elements(ast)

        self.assertEqual(self.identifier_expr.target, self.decl)
        self.assertEqual(self.identifier_expr.get_annotated_type(),
                         self.decl.annotated_type)
コード例 #7
0
ファイル: test_build_ast.py プロジェクト: nibau/zkay
 def test_to_ast_and_back(self):
     # ast
     ast = build_ast(self.example.code())
     # back to string
     new_code = str(ast)
     self.assertIn(self.example.name(), new_code)
     new_code = normalize_code(new_code)
     # reference
     reference = normalize_code(self.example.code())
     # check
     self.assertEqual(reference, new_code)
コード例 #8
0
    def test_fill_symbol_table(self):
        ast = build_ast(simple.code())
        fill_symbol_table(ast)

        self.get_ast_elements(ast)

        s = get_builtin_globals()
        s.update({'Simple': self.contract.idf})
        self.assertDictEqual(ast.names, s)
        self.assertDictEqual(self.contract.names, {'f': self.f.idf})
        self.assertDictEqual(self.body.names, {'x': self.decl.idf})
コード例 #9
0
    def test_link_identifiers(self):
        ast = build_ast(simple_storage.code())
        set_parents(ast)
        link_identifiers(ast)
        assignment = ast['SimpleStorage']['set'].body[0]
        self.assertIsInstance(assignment, AssignmentStatement)

        stored_data = assignment.lhs.target
        self.assertEqual(stored_data, ast['SimpleStorage']['storedData'])

        x = assignment.rhs.target
        self.assertEqual(x.idf.name, 'x')
コード例 #10
0
    def test_alias_analysis(self):
        # perform analysis
        ast = build_ast(analysis.code())
        set_parents(ast)
        link_identifiers(ast)
        alias_analysis(ast)

        # generate string, including analysis results
        v = AnalysisCodeVisitor()
        s = v.visit(ast)
        # next statement can be enabled to determine the computed output
        # print(s)

        # check output
        self.maxDiff = None
        self.assertMultiLineEqual(analysis.code(),
                                  re.sub(" +\n", "\n", s.code()))
コード例 #11
0
def get_parsed_ast_and_fake_code(code, solc_check=True) -> Tuple[AST, str]:
    with print_step("Parsing"):
        try:
            ast = build_ast(code)
        except SyntaxException as e:
            raise ZkaySyntaxError(f'\n\nSYNTAX ERROR: {e}')

    from zkay.compiler.solidity.fake_solidity_generator import fake_solidity_code
    fake_code = fake_solidity_code(str(code))
    if solc_check:
        # Solc type checking
        with print_step("Type checking with solc"):
            try:
                check_for_zkay_solc_errors(code, fake_code)
            except SolcException as e:
                raise ZkayCompilerError(f'{e}')
    return ast, fake_code
コード例 #12
0
ファイル: test_build_ast.py プロジェクト: nibau/zkay
 def test_build_ast(self):
     ast = build_ast(self.example.code())
     self.assertIsNotNone(ast)
コード例 #13
0
 def test_alias_analysis(self):
     # perform analysis
     ast = build_ast(self.example.code())
     set_parents(ast)
     link_identifiers(ast)
     alias_analysis(ast)
コード例 #14
0
ファイル: test_deep_copy.py プロジェクト: nibau/zkay
 def test_deep_copy(self):
     ast = build_ast(self.example.code())
     ast_2 = deep_copy(ast)
     self.assertEqual(str(ast), str(ast_2))