def test_replace_userdefined_constant_no(source): source = f"FOO: constant(int128) = 42\n{source}" unmodified_ast = vy_ast.parse_to_ast(source) folded_ast = vy_ast.parse_to_ast(source) folding.replace_user_defined_constants(folded_ast) assert vy_ast.compare_nodes(unmodified_ast, folded_ast)
def test_replace_userdefined_attribute(source): preamble = f"ADDR: constant(address) = {dummy_address}" l_source = f"{preamble}\n{source[0]}" r_source = f"{preamble}\n{source[1]}" l_ast = vy_ast.parse_to_ast(l_source) folding.replace_user_defined_constants(l_ast) r_ast = vy_ast.parse_to_ast(r_source) assert vy_ast.compare_nodes(l_ast, r_ast)
def test_replace_userdefined_struct(source): preamble = """ struct Foo: a: uint256 b: uint256 FOO: constant(Foo) = Foo({a: 123, b: 456}) """ l_source = f"{preamble}\n{source[0]}" r_source = f"{preamble}\n{source[1]}" l_ast = vy_ast.parse_to_ast(l_source) folding.replace_user_defined_constants(l_ast) r_ast = vy_ast.parse_to_ast(r_source) assert vy_ast.compare_nodes(l_ast, r_ast)
def test_replace_userdefined_nested_struct(source): preamble = """ struct Bar: b1: uint256 b2: uint256 struct Foo: f1: Bar f2: uint256 FOO: constant(Foo) = Foo({f1: Bar({b1: 123, b2: 456}), f2: 789}) """ l_source = f"{preamble}\n{source[0]}" r_source = f"{preamble}\n{source[1]}" l_ast = vy_ast.parse_to_ast(l_source) folding.replace_user_defined_constants(l_ast) r_ast = vy_ast.parse_to_ast(r_source) assert vy_ast.compare_nodes(l_ast, r_ast)