Testing Starknet Cairo contract function with address

190 Views Asked by At

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

1

There are 1 best solutions below

0
On

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