This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
bench_integration.py
46 lines (41 loc) · 2.23 KB
/
bench_integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import pytest
import pytest_asyncio
from starkware.starknet.compiler.compile import compile_starknet_files
from starkware.starknet.testing.starknet import StarknetState
from starkware.starknet.services.api.contract_class import ContractClass
CONTRACT_FILE = os.path.join(os.path.dirname(__file__), "starknet_programs/first_contract.json")
FIBONACCI_FILE = os.path.join(os.path.dirname(__file__), "starknet_programs/fibonacci.json")
@pytest.mark.asyncio
async def test_invoke():
runs = 10000
starknet = await StarknetState.empty()
json_program = open(CONTRACT_FILE).read()
contract_class = ContractClass.loads(json_program)
contract_address, _ = await starknet.deploy(contract_class=contract_class, constructor_calldata=[])
for i in range(runs):
# take into account that you need to comment verify_version()
# from cairo-lang in order to be able to run the selectors below
# because invoke_raw inserts a default version=0 that throws an
# error.
res_1 = await starknet.invoke_raw(contract_address=contract_address, selector="increase_balance", calldata=[1000], max_fee=0)
res_2 = await starknet.invoke_raw(contract_address=contract_address, selector="get_balance", calldata=[], max_fee=0)
assert(res_2.call_info.retdata == [i*1000 + 1000])
@pytest.mark.asyncio
async def test_deploy():
runs = 100
starknet = await StarknetState.empty()
json_program = open(CONTRACT_FILE).read()
contract_class = ContractClass.loads(json_program)
for i in range(runs):
contract_address, _ = await starknet.deploy(contract_class=contract_class, constructor_calldata=[], contract_address_salt=i)
@pytest.mark.asyncio
async def test_fibonacci():
runs = 1000
starknet = await StarknetState.empty()
json_program = open(FIBONACCI_FILE).read()
contract_class = ContractClass.loads(json_program)
contract_address, _ = await starknet.deploy(contract_class=contract_class, constructor_calldata=[])
for i in range(runs):
call = await starknet.invoke_raw(contract_address=contract_address, selector="fib", calldata=[1, 1, 1000], max_fee=0)
assert(call.call_info.retdata == [222450955505511890955301767713383614666194461405743219770606958667979327682])