NEWTON

NEWTON


Popular tags

    Testing Starknet Cairo contract function with address

    Asked

    6 months ago

    12

    views


    0

    I built a module with Cairo language and I would like to unit test it. The contract is pretty simple : it manages a list of authorized addresses and provide some "modifier" functions to help.

    I have taken the sample unit testing code from the documentation but nothing is referring about sending an account address to a function with python.

    How should I proceed ?

    Thanks in advance

    This question was originally posted on Stack Overflow

      pythonstarknetcairo-lang

    1 answers

    0

    You can spoof an account by providing the caller address to the invoke function like this:

    await contract.function(
        arg1=felt,
        arg2=felt2,
    ).invoke(caller_address=private_to_stark_key(123))
    
    

    If you want a more detailed example of how the python unit testing framework works you can check these 2 links

    https://github.com/starknet-edu/basecamp/blob/main/camp_4/buidl/tests/test_contract.py https://github.com/starknet-edu/starknet-debug/tree/master/python

    This answer was originally posted on Stack Overflow

    answered

    5 months ago

    Your answer

    NEWTON

    NEWTON