Skip to content

Commit 4825ff5

Browse files
authored
Move compiling contracts on github actions (#1322)
* compile contracts v2 with scarb * build contract on CI * Add tests to check computing class_hash for sierra prev contract versions * add cache for compiled contracts v1 and v2 * Use external OZ Account in tests * improve compile contract script
1 parent 3e8899d commit 4825ff5

File tree

101 files changed

+727
-127841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+727
-127841
lines changed

.github/workflows/checks.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
# ====================== SETUP ====================== #
7373

7474
- uses: actions/checkout@v3
75-
75+
- uses: asdf-vm/actions/setup@v3
7676
- uses: actions/setup-python@v4
7777
with:
7878
python-version: "3.12"
@@ -84,11 +84,6 @@ jobs:
8484
pip install poetry
8585
poetry config installer.modern-installation false
8686
87-
- name: Install deprecated cairo compiler
88-
run: |
89-
pip install --upgrade setuptools
90-
pip install cairo-lang==${{ env.CAIRO_LANG_VERSION }}
91-
9287
- name: Set up Python ${{ matrix.python-version }}
9388
uses: actions/setup-python@v4
9489
with:
@@ -99,21 +94,54 @@ jobs:
9994
run: |
10095
poetry install
10196
97+
# ====================== CONTRACTS v2 ====================== #
98+
- name: Cache contracts v2
99+
id: cache-contracts_v2
100+
uses: actions/cache@v3
101+
with:
102+
path: starknet_py/tests/e2e/mock/contracts_v2/target
103+
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts_v2') }}
104+
105+
- name: Compile contracts v2
106+
if: steps.cache-contracts_v2.outputs.cache-hit != 'true'
107+
run: |
108+
poetry run poe compile_contracts v2
109+
110+
# ====================== CONTRACTS v1 ====================== #
111+
112+
- name: Cache contracts v1
113+
id: cache-contracts_v1
114+
uses: actions/cache@v3
115+
with:
116+
path: starknet_py/tests/e2e/mock/contracts_v1/target
117+
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts_v1') }}
118+
119+
- name: Compile contracts v1
120+
if: steps.cache-contracts_v1.outputs.cache-hit != 'true'
121+
run: |
122+
poetry run poe compile_contracts v1
123+
102124
# ====================== CONTRACTS v0 ====================== #
103125

104-
- name: Cache contracts
126+
- name: Cache contracts v0
105127
id: cache-contracts
106128
uses: actions/cache@v3
107129
with:
108130
path: starknet_py/tests/e2e/mock/contracts_compiled
109131
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts', 'poetry.lock') }}-${{ env.CAIRO_LANG_VERSION }}
110132

111-
- name: Compile contracts
133+
- name: Install deprecated cairo compiler
134+
if: steps.cache-contracts.outputs.cache-hit != 'true'
135+
run: |
136+
pip install --upgrade setuptools
137+
pip install cairo-lang==${{ env.CAIRO_LANG_VERSION }}
138+
139+
- name: Compile contracts v0
112140
if: steps.cache-contracts.outputs.cache-hit != 'true'
113141
run: |
114-
poetry run poe compile_contracts
142+
poetry run poe compile_contracts v0
115143
116-
- name: Upload contracts
144+
- name: Upload contracts v0
117145
uses: actions/upload-artifact@v3
118146
with:
119147
name: contract-artifacts

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ cython_debug/
150150

151151
# Allow precompiled contracts
152152
!/starknet_py/tests/e2e/mock/contracts_compiled/precompiled/
153-
!/starknet_py/tests/e2e/mock/contracts_compiled_v1/precompiled/
154153

155-
# Cairo1 compiler manifest
156-
/starknet_py/tests/e2e/manifest-path
154+
# Test variables
157155
/starknet_py/tests/e2e/test-variables.env

docs/development.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Development dependencies
1010
- `poetry <https://python-poetry.org/>`_ - dependency manager.
1111
- `pyenv <https://github.com/pyenv/pyenv>`_ - recommended for installing and switching python versions locally.
1212
- `cairo-lang <https://pypi.org/project/cairo-lang/>`_ - required to compile contracts (`poe compile_contracts`)
13+
- `asdf <https://asdf-vm.com/>`_ - required to install `scarb`, that is used for contracts compilation (`poe compile_contracts`)
1314

1415
Setup
1516
-----

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ format_check.shell = "isort --check . && black --check ."
8080
format_diff.shell = "isort --diff . && black --diff ."
8181
typecheck = "pyright starknet_py"
8282
compile_contracts = "bash starknet_py/tests/e2e/mock/compile_contracts.sh"
83-
compile_contracts_v1 = "bash starknet_py/tests/e2e/mock/compile_contracts_v1.sh"
84-
compile_contracts_v2 = "bash starknet_py/tests/e2e/mock/compile_contracts_v2.sh"
8583
circular_imports_check.shell = "poetry run pytest circular.py"
8684
ci = ["lint", "format_check", "typecheck", "test_ci"]
8785
precommit.sequence = ["format", "lint", "typecheck"]

starknet_py/abi/v1/schemas_test.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@
44
from marshmallow import EXCLUDE
55

66
from starknet_py.abi.v1.schemas import ContractAbiEntrySchema
7-
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V1_DIR
8-
from starknet_py.tests.e2e.fixtures.misc import read_contract
7+
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
98

109

1110
@pytest.mark.parametrize(
1211
"contract_name",
1312
[
14-
"account",
15-
"erc20",
16-
"hello_starknet",
17-
"minimal_contract",
18-
"test_contract",
19-
"token_bridge",
13+
"Account",
14+
"ERC20",
15+
"HelloStarknet",
16+
"MinimalContract",
17+
"TestContract",
18+
"TokenBridge",
2019
],
2120
)
2221
def test_deserialize_abi(contract_name):
2322
abi = json.loads(
24-
read_contract(
25-
f"{contract_name}_compiled.json", directory=CONTRACTS_COMPILED_V1_DIR
26-
)
23+
load_contract(contract_name=contract_name, version=ContractVersion.V1)["sierra"]
2724
)["abi"]
25+
2826
deserialized = [
2927
ContractAbiEntrySchema().load(entry, unknown=EXCLUDE) for entry in abi
3028
]

starknet_py/abi/v2/parser_test.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33
import pytest
44

55
from starknet_py.abi.v2 import Abi, AbiParser
6-
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V2_DIR
7-
from starknet_py.tests.e2e.fixtures.misc import read_contract
6+
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
87

98

109
@pytest.mark.parametrize(
1110
"contract_name",
1211
[
13-
"abi_types",
14-
"account",
15-
"erc20",
16-
"hello2",
17-
"hello_starknet",
18-
"minimal_contract",
19-
"new_syntax_test_contract",
20-
"test_contract",
21-
"test_enum",
22-
"test_option",
23-
"token_bridge",
12+
"AbiTypes",
13+
"Account",
14+
"ERC20",
15+
"Hello2",
16+
"HelloStarknet",
17+
"MinimalContract",
18+
"NewSyntaxTestContract",
19+
"TestContract",
20+
"TestEnum",
21+
"TestOption",
22+
"TokenBridge",
2423
],
2524
)
2625
def test_abi_parse(contract_name):
2726
abi = json.loads(
28-
read_contract(
29-
f"{contract_name}_compiled.json", directory=CONTRACTS_COMPILED_V2_DIR
30-
)
27+
load_contract(contract_name=contract_name, version=ContractVersion.V2)["sierra"]
3128
)["abi"]
3229

3330
parser = AbiParser(abi)

starknet_py/abi/v2/schemas_test.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,28 @@
44
from marshmallow import EXCLUDE
55

66
from starknet_py.abi.v2.schemas import ContractAbiEntrySchema
7-
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V2_DIR
8-
from starknet_py.tests.e2e.fixtures.misc import read_contract
7+
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
98

109

1110
@pytest.mark.parametrize(
1211
"contract_name",
1312
[
14-
"abi_types",
15-
"account",
16-
"erc20",
17-
"hello2",
18-
"hello_starknet",
19-
"minimal_contract",
20-
"new_syntax_test_contract",
21-
"test_contract",
22-
"test_enum",
23-
"test_option",
24-
"token_bridge",
13+
"AbiTypes",
14+
"Account",
15+
"ERC20",
16+
"Hello2",
17+
"HelloStarknet",
18+
"MinimalContract",
19+
"NewSyntaxTestContract",
20+
"TestContract",
21+
"TestEnum",
22+
"TestOption",
23+
"TokenBridge",
2524
],
2625
)
2726
def test_deserialize_abi(contract_name):
2827
abi = json.loads(
29-
read_contract(
30-
f"{contract_name}_compiled.json", directory=CONTRACTS_COMPILED_V2_DIR
31-
)
28+
load_contract(contract_name, version=ContractVersion.V2)["sierra"]
3229
)["abi"]
3330
deserialized = [
3431
ContractAbiEntrySchema().load(entry, unknown=EXCLUDE) for entry in abi

starknet_py/hash/casm_class_hash_test.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,48 @@
33

44
from starknet_py.common import create_casm_class
55
from starknet_py.hash.casm_class_hash import compute_casm_class_hash
6-
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V2_DIR
7-
from starknet_py.tests.e2e.fixtures.misc import read_contract
6+
from starknet_py.tests.e2e.fixtures.constants import PRECOMPILED_CONTRACTS_DIR
7+
from starknet_py.tests.e2e.fixtures.misc import (
8+
ContractVersion,
9+
load_contract,
10+
read_contract,
11+
)
812

913

14+
@pytest.mark.parametrize(
15+
"contract, expected_casm_class_hash",
16+
[
17+
("Account", 0x108977ab61715437fc7097b6499b3cf9491361eb6a8ce6df6c8536b7feec508),
18+
("ERC20", 0x5adc857416202a5902c01168542e188c3aa6380f57c911ae98cf20bc52be367),
19+
("HelloStarknet", 0x6ff9f7df06da94198ee535f41b214dce0b8bafbdb45e6c6b09d4b3b693b1f17),
20+
("TestContract", 0x2193add92c182c9236f0c156f11dc4f18d5a78fd9b763a3c0f4a1d3bd8b87d4),
21+
("TokenBridge", 0x41d26534c7ca29e212ae48acfb9f86f69a9624977c979697c15f587fa95204),
22+
],
23+
)
24+
def test_compute_casm_class_hash(contract, expected_casm_class_hash):
25+
casm_contract_class_str = load_contract(
26+
contract, version=ContractVersion.V2
27+
)['casm']
28+
29+
casm_class = create_casm_class(casm_contract_class_str)
30+
casm_class_hash = compute_casm_class_hash(casm_class)
31+
assert casm_class_hash == expected_casm_class_hash
32+
1033
@pytest.mark.parametrize(
1134
"casm_contract_class_source, expected_casm_class_hash",
1235
[
13-
("account_compiled.casm", 0x1cf09a2ab1c531bfd02cb26a3fa9ed02986fd3bb86e6b8874072fba4e55f504),
14-
("erc20_compiled.casm", 0x6d53db94c64d3562370253db94529b99f6837cb2f3b7062e11c657be89c1dae),
15-
("hello_starknet_compiled.casm", 0x785fa5f2bacf0bfe3bc413be5820a61e1ea63f2ec27ef00331ee9f46ad07603),
16-
("minimal_contract_compiled.casm", 0x186f6c4ca3af40dbcbf3f08f828ab0ee072938aaaedccc74ef3b9840cbd9fb3),
17-
("test_contract_compiled.casm", 0x379b75c0922c68e73f6451b69e8e50b7f0745e6fa3f67ffc0b9608238eeaf45),
18-
("token_bridge_compiled.casm", 0x1d60f20e5dd449af4e6b0d63821cfa95f3469faa942caf78eba2172e2ec3468),
19-
("precompiled/starknet_contract_v2_6.casm", 0x603dd72504d8b0bc54df4f1102fdcf87fc3b2b94750a9083a5876913eec08e4),
36+
("minimal_contract_compiled_v2_1.casm",
37+
0x186f6c4ca3af40dbcbf3f08f828ab0ee072938aaaedccc74ef3b9840cbd9fb3),
38+
("minimal_contract_compiled_v2_5_4.casm",
39+
0x1d055a90aa90db474fa08a931d5e63753c6f762fa3e9597b26c8d4b003a2de6),
40+
("starknet_contract_v2_6.casm", 0x603dd72504d8b0bc54df4f1102fdcf87fc3b2b94750a9083a5876913eec08e4),
2041
],
2142
)
22-
def test_compute_casm_class_hash(casm_contract_class_source, expected_casm_class_hash):
43+
def test_precompiled_compute_casm_class_hash(casm_contract_class_source, expected_casm_class_hash):
2344
casm_contract_class_str = read_contract(
24-
casm_contract_class_source, directory=CONTRACTS_COMPILED_V2_DIR
45+
casm_contract_class_source, directory=PRECOMPILED_CONTRACTS_DIR
2546
)
2647

2748
casm_class = create_casm_class(casm_contract_class_str)
2849
casm_class_hash = compute_casm_class_hash(casm_class)
29-
3050
assert casm_class_hash == expected_casm_class_hash

starknet_py/hash/sierra_class_hash_test.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
from starknet_py.common import create_sierra_compiled_contract
44
from starknet_py.hash.sierra_class_hash import compute_sierra_class_hash
5-
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V2_DIR
6-
from starknet_py.tests.e2e.fixtures.misc import read_contract
5+
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
76

87

98
@pytest.mark.parametrize(
10-
"sierra_contract_class_source, expected_class_hash",
9+
"contract_name, expected_class_hash",
1110
# fmt: off
1211
[
13-
("account_compiled.json", 0x6cb1e2b2b7a2eb8231357f8bee5cb6683476f350d35986afff6b67bf9e66b6c),
14-
("erc20_compiled.json", 0x5dc48d64a0f3852a4ac2b06f9b2a801177f35952715f32d3a7ca60af235e762),
15-
("hello_starknet_compiled.json", 0x4ec2ecf58014bc2ffd7c84843c3525e5ecb0a2cac33c47e9c347f39fc0c0944),
16-
("minimal_contract_compiled.json", 0xa298b56801319b054855d39720eab22502e77627552e564d3bf50bd7844df9),
17-
("test_contract_compiled.json", 0x28d7f03cced748cd9913afa5549edf4a02def8508fe1ca7feea2f8d403918a6),
18-
("token_bridge_compiled.json", 0x4f2d81d7c0da5ec97f19b8195748a559de42207ff8bc3ac5f818e752c431c7b),
12+
("Account", 0x450f568a8cb6ea1bcce446355e8a1c2e5852a6b8dc3536f495cdceb62e8a7e2),
13+
("ERC20", 0x746248ba570006607113ae3f4dbb4130e81233fb818d15329c6a4aaccf94812),
14+
("HelloStarknet", 0x224518978adb773cfd4862a894e9d333192fbd24bc83841dc7d4167c09b89c5),
15+
("MinimalContract", 0x6fb1efd745d57b60023c6dc3209227e5e54d44fa16e0ae75cc03e1a7f3da08a),
16+
("TestContract", 0x3adac8a417b176d27e11b420aa1063b07a6b54bbb21091ad77b2a9156af7a3b),
17+
("TokenBridge", 0x3d138e923f01b7ed1bb82b9b4e7f6df64e0c429faf8b27539addc71c1407237),
1918
],
2019
# fmt: on
2120
)
22-
def test_compute_sierra_class_hash(sierra_contract_class_source, expected_class_hash):
23-
sierra_contract_class_str = read_contract(
24-
sierra_contract_class_source, directory=CONTRACTS_COMPILED_V2_DIR
25-
)
21+
def test_compute_sierra_class_hash(contract_name, expected_class_hash):
22+
sierra_contract_class_str = load_contract(
23+
contract_name=contract_name, version=ContractVersion.V2
24+
)["sierra"]
2625

2726
sierra_contract_class = create_sierra_compiled_contract(sierra_contract_class_str)
2827
class_hash = compute_sierra_class_hash(sierra_contract_class)

starknet_py/serialization/serialization_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
serializer_for_function,
1414
)
1515
from starknet_py.serialization.tuple_dataclass import TupleDataclass
16-
from starknet_py.tests.e2e.fixtures.constants import (
17-
CONTRACTS_COMPILED_V0_DIR,
18-
CONTRACTS_COMPILED_V1_DIR,
19-
CONTRACTS_COMPILED_V2_DIR,
16+
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR
17+
from starknet_py.tests.e2e.fixtures.misc import (
18+
ContractVersion,
19+
load_contract,
20+
read_contract,
2021
)
21-
from starknet_py.tests.e2e.fixtures.misc import read_contract
2222

2323
dog = {"name": encode_shortstring("Cooper"), "species": encode_shortstring("dog")}
2424
dog_serialized = [dog["name"], dog["species"]]
@@ -110,14 +110,14 @@ class Education(NamedTuple):
110110
parsed_abi = AbiParserV0(abi).parse()
111111

112112
abi_v1 = json.loads(
113-
read_contract("erc20_compiled.json", directory=CONTRACTS_COMPILED_V1_DIR)
113+
load_contract(contract_name="ERC20", version=ContractVersion.V1)["sierra"]
114114
)["abi"]
115115
parsed_abi_v1 = AbiParserV1(abi_v1).parse()
116116

117117
abi_v2 = json.loads(
118-
read_contract(
119-
"new_syntax_test_contract_compiled.json", directory=CONTRACTS_COMPILED_V2_DIR
120-
)
118+
load_contract(contract_name="NewSyntaxTestContract", version=ContractVersion.V2)[
119+
"sierra"
120+
]
121121
)["abi"]
122122

123123
parsed_abi_v2 = AbiParserV2(abi_v2).parse()
@@ -167,8 +167,8 @@ def test_event_serialization_v1():
167167
def test_event_serialization_v2():
168168
serializer = serializer_for_event(
169169
parsed_abi_v2.events[
170-
"new_syntax_test_contract::new_syntax_test_contract"
171-
"::counter_contract::CounterIncreased"
170+
"contracts_v2::new_syntax_test_contract::"
171+
"NewSyntaxTestContract::CounterIncreased"
172172
]
173173
)
174174

0 commit comments

Comments
 (0)