def test_output_in_builtin_directive(): verify_exception( """ %builtins output range_check """, f""" file:?:?: ['output', 'range_check'] is not a subsequence of {SUPPORTED_BUILTINS}. %builtins output range_check ^**************************^ """)
def test_lang_directive(): verify_exception( """ %lang abc """, """ file:?:?: Unsupported %lang directive. Are you using the correct compiler? %lang abc ^*******^ """)
def test_storage_in_builtin_directive(): verify_exception( """ %builtins storage """, f""" file:?:?: ['storage'] is not a subsequence of {SUPPORTED_BUILTINS}. %builtins storage ^***************^ """)
def test_missing_lang_directive(): verify_exception( """ @external func f{}(): return() end """, """ file:?:?: External decorators can only be used in source files that contain the \ "%lang starknet" directive. @external ^*******^ """)
def test_unsupported_args(): verify_exception( """ %lang starknet @external func fc(arg : felt**): return () end """, """ file:?:?: Unsupported argument type felt**. func fc(arg : felt**): ^****^ """)
def test_bad_implicit_arg_name(): verify_exception( """ %lang starknet %builtins pedersen range_check ecdsa @external func f{hello}(): return() end """, """ file:?:?: Unexpected implicit argument 'hello' in an external function. func f{hello}(): ^***^ """)
def test_builtin_directive_after_external(): verify_exception( """ %lang starknet @external func f{}(): return() end %builtins pedersen range_check ecdsa """, """ file:?:?: Directives must appear at the top of the file. %builtins pedersen range_check ecdsa ^**********************************^ """)
def test_invalid_hint(): verify_exception( """ %lang starknet @external func fc(): %{ __storage.merkle_update() %} return () end """, """ file:?:?: Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts. %{ __storage.merkle_update() %} ^*****************************^ """)
def test_l1_handler_failures(): verify_exception( """ %lang starknet @l1_handler func f(): return () end """, """ file:?:?: The first argument of an L1 handler must be named 'from_address'. func f(): ^ """) verify_exception( """ %lang starknet @l1_handler func f(abc): return () end """, """ file:?:?: The first argument of an L1 handler must be named 'from_address'. func f(abc): ^*^ """) verify_exception( """ %lang starknet @l1_handler func f(from_address: felt*): return () end """, """ file:?:?: The type of 'from_address' must be felt. func f(from_address: felt*): ^***^ """) verify_exception( """ %lang starknet @l1_handler func f(from_address) -> (ret_val): return (ret_val=0) end """, """ file:?:?: An L1 handler can not have a return value. func f(from_address) -> (ret_val): ^*****^ """)
def test_bad_implicit_arg_type(): verify_exception( """ %lang starknet %builtins pedersen struct HashBuiltin: end @external func f{pedersen_ptr : HashBuiltin}(): return () end """, """ file:?:?: While expanding the reference 'pedersen_ptr' in: func f{pedersen_ptr : HashBuiltin}(): ^ file:?:?: Expected a 'felt' or a pointer type. Got: 'test_scope.HashBuiltin'. func f{pedersen_ptr : HashBuiltin}(): ^**********^ """)
def test_storage_var_failures(): verify_exception( """ @storage_var func f() -> (res : felt): end """, """ file:?:?: @storage_var can only be used in source files that contain the "%lang starknet" directive. @storage_var ^**********^ """) verify_exception( """ %lang starknet @storage_var func f() -> (res : felt): return () # Comment. end """, """ file:?:?: Storage variables must have an empty body. return () # Comment. ^*******^ """) verify_exception( """ %lang starknet @storage_var func f() -> (res : felt): 0 = 1 # Comment. end """, """ file:?:?: Storage variables must have an empty body. func f() -> (res : felt): ^ """) verify_exception( """ %lang starknet @storage_var func f{x, y}() -> (res : felt): end """, """ file:?:?: Storage variables must have no implicit arguments. func f{x, y}() -> (res : felt): ^**^ """) verify_exception( """ %lang starknet @storage_var @invalid_decorator func f() -> (res : felt): end """, """ file:?:?: Storage variables must have no decorators in addition to @storage_var. @invalid_decorator ^****************^ """) verify_exception( """ %lang starknet @storage_var func f(x, y : felt*) -> (res : felt): end """, """ file:?:?: Only felt arguments are supported in storage variables. func f(x, y : felt*) -> (res : felt): ^***^ """) verify_exception( """ %lang starknet @storage_var func f(): end """, """ file:?:?: Storage variables must return exactly one value. func f(): ^ """) verify_exception( """ %lang starknet @storage_var func f() -> (x : felt, y : felt): end """, """ file:?:?: Storage variables must return exactly one value. func f() -> (x : felt, y : felt): ^****************^ """) verify_exception( """ %lang starknet @storage_var func f() -> (x : felt*): end """, """ file:?:?: The return type of storage variables must consist of felts. func f() -> (x : felt*): ^*******^ """) verify_exception( """ %lang starknet # A struct of size 10. struct A: member x : (felt, felt, felt, felt, felt, felt, felt, felt, felt, felt) end # A struct of size 300. struct B: member x : (A, A, A, A, A, A, A, A, A, A) member y : (A, A, A, A, A, A, A, A, A, A) member z : (A, A, A, A, A, A, A, A, A, A) end @storage_var func f() -> (x : B): end """, """ file:?:?: The storage variable size (300) exceeds the maximum value (256). func f() -> (x : B): ^***^ """)